Allow admin manager of contributors to use user autocomplete
authorJonathan S. Katz <jonathan.katz@excoventures.com>
Sat, 28 Jan 2023 19:23:58 +0000 (14:23 -0500)
committerJonathan S. Katz <jonathan.katz@excoventures.com>
Mon, 30 Jan 2023 15:29:07 +0000 (10:29 -0500)
This adds a permission check in the user admin view logic to allow
someone administrating contributors to use the autocomplete
functionality even if the user does not have permission to modify
the users directly.

pgweb/account/admin.py

index 7e0e747a87496926e68847ef6010935e417952d3..888405b5b7bb0f9c8720c0e23771fe570a4c2b91 100644 (file)
@@ -132,6 +132,17 @@ class PGUserAdmin(UserAdmin):
             fs[1][1]['fields'] = list(fs[1][1]['fields']) + ['extraemail', ]
         return fs
 
+    def has_view_permission(self, request, obj=None):
+        """
+        We have a special check for view permissions here based on if the user
+        has access to modifying contributors. This allows us to allow the
+        editor to return a list of usernames from the dropdown. If this is not
+        the autocomplete / user editor workflow, then we proceed as normal.
+        """
+        if request.path == '/admin/autocomplete/' and request.GET.get('app_label') == 'contributors' and request.GET.get('model_name') == 'contributor' and request.user.has_perm("contributors.change_contributor"):
+            return True
+        return super().has_view_permission(request, obj)
+
     @property
     def search_fields(self):
         sf = list(super().search_fields)