Code

Ticket #12441: 12441.diff

File 12441.diff, 1.9 KB (added by alexkoshelev, 4 years ago)

patch

Line 
1Index: django/contrib/admin/sites.py
2===================================================================
3--- django/contrib/admin/sites.py       (revision 11974)
4+++ django/contrib/admin/sites.py       (working copy)
5@@ -141,6 +141,13 @@
6         """
7         return request.user.is_authenticated() and request.user.is_staff
8 
9+    def has_module_perms(self, request, app_label):
10+        """
11+        Returns True if the given HttpRequest has permission to view
12+        given application admin site.
13+        """
14+        return request.user.has_module_perms(app_label)
15+
16     def check_dependencies(self):
17         """
18         Check that all things needed to run the admin have been correctly installed.
19@@ -336,10 +343,9 @@
20         apps that have been registered in this site.
21         """
22         app_dict = {}
23-        user = request.user
24         for model, model_admin in self._registry.items():
25             app_label = model._meta.app_label
26-            has_module_perms = user.has_module_perms(app_label)
27+            has_module_perms = self.has_module_perms(request, app_label)
28 
29             if has_module_perms:
30                 perms = model_admin.get_model_perms(request)
31@@ -397,12 +403,11 @@
32         )
33 
34     def app_index(self, request, app_label, extra_context=None):
35-        user = request.user
36-        has_module_perms = user.has_module_perms(app_label)
37+        has_module_perms = self.has_module_perms(request, app_label)
38         app_dict = {}
39-        for model, model_admin in self._registry.items():
40-            if app_label == model._meta.app_label:
41-                if has_module_perms:
42+        if has_module_perms:
43+            for model, model_admin in self._registry.items():
44+                if app_label == model._meta.app_label:
45                     perms = model_admin.get_model_perms(request)
46 
47                     # Check whether user has any perm for this module.