From 9a2f9683ab43f091ed28ffd0505896ad0da29215 Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Sun, 26 May 2024 18:40:41 +0200 Subject: [PATCH 1/2] Check for user rights for emails --- members/admin/emailitem_admin.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/members/admin/emailitem_admin.py b/members/admin/emailitem_admin.py index 2c9734a4..65630f48 100644 --- a/members/admin/emailitem_admin.py +++ b/members/admin/emailitem_admin.py @@ -139,6 +139,17 @@ class EmailItemAdmin(admin.ModelAdmin): ) readonly_fields = ("created_dtm", "send_error", "sent_dtm") + + def get_queryset(self, request): + qs = super(EmailItemAdmin, self).get_queryset(request) + if request.user.is_superuser or request.user.has_perm( + "members.view_all_departments" + ): + return qs + departments = Department.objects.filter(adminuserinformation__user=request.user) + return qs.filter(department__in=departments) | qs.filter(activity__department__in=departments) + + fieldsets = [ ( "Modtager information", From fe5ec15cb8ca2fa74dd84dd4dd2769608f2094fc Mon Sep 17 00:00:00 2001 From: Kristoffer Rath Hansen Date: Sun, 26 May 2024 18:55:27 +0200 Subject: [PATCH 2/2] Ran black --- members/admin/emailitem_admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/members/admin/emailitem_admin.py b/members/admin/emailitem_admin.py index 65630f48..477f2d0b 100644 --- a/members/admin/emailitem_admin.py +++ b/members/admin/emailitem_admin.py @@ -139,7 +139,6 @@ class EmailItemAdmin(admin.ModelAdmin): ) readonly_fields = ("created_dtm", "send_error", "sent_dtm") - def get_queryset(self, request): qs = super(EmailItemAdmin, self).get_queryset(request) if request.user.is_superuser or request.user.has_perm( @@ -147,8 +146,9 @@ def get_queryset(self, request): ): return qs departments = Department.objects.filter(adminuserinformation__user=request.user) - return qs.filter(department__in=departments) | qs.filter(activity__department__in=departments) - + return qs.filter(department__in=departments) | qs.filter( + activity__department__in=departments + ) fieldsets = [ (