From b660c8055fb3c2b881a61df2478052388bfb8e27 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 21 Oct 2017 17:56:42 -0400 Subject: [PATCH] Add view to show list of events performed by an user. Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + docs/releases/2.8.rst | 1 + mayan/apps/events/apps.py | 7 ++++++- mayan/apps/events/links.py | 4 ++++ mayan/apps/events/urls.py | 9 ++++++--- mayan/apps/events/views.py | 28 ++++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index a91c0abb14..ec0be8a9f8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,7 @@ - Remove Vagrant section of the document. Anything related to Vagrant has been move into its own repository at: https://gitlab.com/mayan-edms/mayan-edms-vagrant +- Add view to show list of events performed by an user. 2.7.3 (2017-09-11) ================== diff --git a/docs/releases/2.8.rst b/docs/releases/2.8.rst index 2f94584fb1..5b9b5c53b2 100644 --- a/docs/releases/2.8.rst +++ b/docs/releases/2.8.rst @@ -25,6 +25,7 @@ What's new - Remove Vagrant section of the document. Anything related to Vagrant has been move into its own repository at: https://gitlab.com/mayan-edms/mayan-edms-vagrant +- Add view to show list of events performed by an user. Removals -------- diff --git a/mayan/apps/events/apps.py b/mayan/apps/events/apps.py index 4f1485ac68..6551a3a0ff 100644 --- a/mayan/apps/events/apps.py +++ b/mayan/apps/events/apps.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django.apps import apps +from django.contrib.auth import get_user_model from django.utils.translation import ugettext_lazy as _ from common import ( @@ -14,7 +15,7 @@ from rest_api.classes import APIEndPoint from .links import ( link_events_list, link_event_types_subscriptions_list, link_notification_mark_read, link_notification_mark_read_all, - link_user_notifications_list, + link_user_events, link_user_notifications_list, ) from .licenses import * # NOQA from .widgets import event_object_link, event_type_link @@ -38,6 +39,7 @@ class EventsApp(MayanAppConfig): Action = apps.get_model(app_label='actstream', model_name='Action') Notification = self.get_model(model_name='Notification') StoredEventType = self.get_model(model_name='StoredEventType') + User = get_user_model() APIEndPoint(app=self, version_string='1') @@ -94,6 +96,9 @@ class EventsApp(MayanAppConfig): menu_object.bind_links( links=(link_notification_mark_read,), sources=(Notification,) ) + menu_object.bind_links( + links=(link_user_events,), sources=(User,) + ) menu_secondary.bind_links( links=(link_notification_mark_read_all,), sources=('events:user_notifications_list',) diff --git a/mayan/apps/events/links.py b/mayan/apps/events/links.py index 63bc728cf8..182f2501e4 100644 --- a/mayan/apps/events/links.py +++ b/mayan/apps/events/links.py @@ -63,6 +63,10 @@ link_object_event_types_user_subcriptions_list_with_icon = Link( permissions=(permission_events_view,), text=_('Subscriptions'), view='events:object_event_types_user_subcriptions_list', ) +link_user_events = Link( + args='resolved_object.pk', text=_('User events'), + view='events:user_events' +) link_user_notifications_list = Link( icon='fa fa-bell', text=get_notification_count, view='events:user_notifications_list' diff --git a/mayan/apps/events/urls.py b/mayan/apps/events/urls.py index f0c96c8467..25b2d9e26c 100644 --- a/mayan/apps/events/urls.py +++ b/mayan/apps/events/urls.py @@ -10,7 +10,7 @@ from .api_views import ( from .views import ( EventListView, EventTypeSubscriptionListView, NotificationListView, NotificationMarkRead, NotificationMarkReadAll, ObjectEventListView, - ObjectEventTypeSubscriptionListView, VerbEventListView + ObjectEventTypeSubscriptionListView, UserEventListView, VerbEventListView ) urlpatterns = [ @@ -36,14 +36,17 @@ urlpatterns = [ ObjectEventTypeSubscriptionListView.as_view(), name='object_event_types_user_subcriptions_list' ), + url( + r'^user/(?P\d+)/events/$', UserEventListView.as_view(), + name='user_events' + ), url( r'^user/event_types/subscriptions/$', EventTypeSubscriptionListView.as_view(), name='event_types_user_subcriptions_list' ), url( - r'^user/notifications/$', - NotificationListView.as_view(), + r'^user/notifications/$', NotificationListView.as_view(), name='user_notifications_list' ), ] diff --git a/mayan/apps/events/views.py b/mayan/apps/events/views.py index aa8cbd8f72..748f24d69a 100644 --- a/mayan/apps/events/views.py +++ b/mayan/apps/events/views.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, unicode_literals from django.contrib import messages +from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.http import Http404, HttpResponseRedirect from django.shortcuts import get_object_or_404 @@ -240,6 +241,33 @@ class ObjectEventTypeSubscriptionListView(FormView): return ModelEventType.get_for_instance(instance=self.get_object()) +class UserEventListView(SingleObjectListView): + view_permission = permission_events_view + + def get_extra_context(self): + return { + 'extra_columns': ( + { + 'name': _('Target'), + 'attribute': encapsulate( + lambda entry: event_object_link(entry) + ) + }, + ), + 'hide_object': True, + 'object': self.get_user(), + 'title': _( + 'Events for user: %s' + ) % self.get_user(), + } + + def get_object_list(self): + return Action.objects.actor(obj=self.get_user()) + + def get_user(self): + return get_object_or_404(get_user_model(), pk=self.kwargs['pk']) + + class VerbEventListView(SingleObjectListView): def get_extra_context(self): return {