From 0d21770c72b3aea692293d4003df5caa236c3e30 Mon Sep 17 00:00:00 2001 From: Elijah Date: Sun, 18 Feb 2024 21:47:41 +0100 Subject: [PATCH] Filtered events for the user and admin dashboards --- idhub/admin/tables.py | 1 + idhub/admin/views.py | 30 ++++++++++++++++++++++++++++++ idhub/user/tables.py | 1 + idhub/user/views.py | 17 ++++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/idhub/admin/tables.py b/idhub/admin/tables.py index c783993..74dcc6f 100644 --- a/idhub/admin/tables.py +++ b/idhub/admin/tables.py @@ -150,6 +150,7 @@ class DashboardTable(tables.Table): model = Event template_name = "idhub/custom_table.html" fields = ("type", "message", "created") + empty_text = "No events available" class CredentialTable(tables.Table): diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 25ac28d..9eb204d 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -109,6 +109,36 @@ class DashboardView(AdminView, SingleTableView): section = "Home" model = Event + def get_queryset(self): + """ + Override the get_queryset method to filter events based on the user type. + """ + events_for_admins = self.get_admin_events() + return Event.objects.filter(type__in=events_for_admins) + + def get_admin_events(self): + return [ + Event.Types.EV_USR_REGISTERED, # User registered + Event.Types.EV_USR_UPDATED_BY_ADMIN, # User's data updated by admin + Event.Types.EV_USR_DELETED_BY_ADMIN, # User deactivated by admin + Event.Types.EV_DID_CREATED_BY_USER, # DID created by user + Event.Types.EV_CREDENTIAL_DELETED_BY_USER, # Credential deleted by user + Event.Types.EV_CREDENTIAL_ISSUED_FOR_USER, # Credential issued for user + Event.Types.EV_CREDENTIAL_PRESENTED_BY_USER, # Credential presented by user + Event.Types.EV_CREDENTIAL_ENABLED, # Credential enabled + Event.Types.EV_CREDENTIAL_REVOKED_BY_ADMIN, # Credential revoked by admin + Event.Types.EV_ROLE_CREATED_BY_ADMIN, # Role created by admin + Event.Types.EV_ROLE_MODIFIED_BY_ADMIN, # Role modified by admin + Event.Types.EV_ROLE_DELETED_BY_ADMIN, # Role deleted by admin + Event.Types.EV_SERVICE_CREATED_BY_ADMIN, # Service created by admin + Event.Types.EV_SERVICE_MODIFIED_BY_ADMIN, # Service modified by admin + Event.Types.EV_SERVICE_DELETED_BY_ADMIN, # Service deleted by admin + Event.Types.EV_ORG_DID_CREATED_BY_ADMIN, # Organisational DID created by admin + Event.Types.EV_ORG_DID_DELETED_BY_ADMIN, # Organisational DID deleted by admin + Event.Types.EV_USR_DEACTIVATED_BY_ADMIN, # User deactivated + Event.Types.EV_DATA_UPDATE_REQUESTED, # Data update requested. Pending approval by administrator + ] + class People(AdminView): title = _("User management") diff --git a/idhub/user/tables.py b/idhub/user/tables.py index eacdcb8..b6cb9b8 100644 --- a/idhub/user/tables.py +++ b/idhub/user/tables.py @@ -27,6 +27,7 @@ class DashboardTable(tables.Table): model = Event template_name = "idhub/custom_table.html" fields = ("type", "message", "created") + empty_text="No events available" class PersonalInfoTable(tables.Table): diff --git a/idhub/user/views.py b/idhub/user/views.py index 27c8f77..3e70336 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -67,11 +67,26 @@ class DashboardView(UserView, SingleTableView): section = "Home" def get_queryset(self, **kwargs): + events_for_users = self.get_user_events() queryset = Event.objects.select_related('user').filter( - user=self.request.user) + user=self.request.user).filter(type__in=events_for_users) return queryset + def get_user_events(self): + events_for_users = [ + Event.Types.EV_USR_WELCOME, # User welcomed + Event.Types.EV_USR_UPDATED, # Your data updated by admin + Event.Types.EV_DID_CREATED, # DID created + Event.Types.EV_DID_DELETED, # DID deleted + Event.Types.EV_CREDENTIAL_DELETED, # Credential deleted + Event.Types.EV_CREDENTIAL_ISSUED, # Credential issued + Event.Types.EV_CREDENTIAL_PRESENTED, # Credential presented + Event.Types.EV_CREDENTIAL_CAN_BE_REQUESTED, # Credential available + Event.Types.EV_CREDENTIAL_REVOKED, # Credential revoked + ] + return events_for_users + class ProfileView(MyProfile, UpdateView, SingleTableView): template_name = "idhub/user/profile.html"