Filtered events for the user and admin dashboards

This commit is contained in:
Elijah 2024-02-18 21:47:41 +01:00
parent 791cec1872
commit 0d21770c72
4 changed files with 48 additions and 1 deletions

View File

@ -150,6 +150,7 @@ class DashboardTable(tables.Table):
model = Event model = Event
template_name = "idhub/custom_table.html" template_name = "idhub/custom_table.html"
fields = ("type", "message", "created") fields = ("type", "message", "created")
empty_text = "No events available"
class CredentialTable(tables.Table): class CredentialTable(tables.Table):

View File

@ -109,6 +109,36 @@ class DashboardView(AdminView, SingleTableView):
section = "Home" section = "Home"
model = Event 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): class People(AdminView):
title = _("User management") title = _("User management")

View File

@ -27,6 +27,7 @@ class DashboardTable(tables.Table):
model = Event model = Event
template_name = "idhub/custom_table.html" template_name = "idhub/custom_table.html"
fields = ("type", "message", "created") fields = ("type", "message", "created")
empty_text="No events available"
class PersonalInfoTable(tables.Table): class PersonalInfoTable(tables.Table):

View File

@ -67,11 +67,26 @@ class DashboardView(UserView, SingleTableView):
section = "Home" section = "Home"
def get_queryset(self, **kwargs): def get_queryset(self, **kwargs):
events_for_users = self.get_user_events()
queryset = Event.objects.select_related('user').filter( queryset = Event.objects.select_related('user').filter(
user=self.request.user) user=self.request.user).filter(type__in=events_for_users)
return queryset 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): class ProfileView(MyProfile, UpdateView, SingleTableView):
template_name = "idhub/user/profile.html" template_name = "idhub/user/profile.html"