Ticket #12441: 12441.diff

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

patch

  • django/contrib/admin/sites.py

     
    141141        """
    142142        return request.user.is_authenticated() and request.user.is_staff
    143143
     144    def has_module_perms(self, request, app_label):
     145        """
     146        Returns True if the given HttpRequest has permission to view
     147        given application admin site.
     148        """
     149        return request.user.has_module_perms(app_label)
     150
    144151    def check_dependencies(self):
    145152        """
    146153        Check that all things needed to run the admin have been correctly installed.
     
    336343        apps that have been registered in this site.
    337344        """
    338345        app_dict = {}
    339         user = request.user
    340346        for model, model_admin in self._registry.items():
    341347            app_label = model._meta.app_label
    342             has_module_perms = user.has_module_perms(app_label)
     348            has_module_perms = self.has_module_perms(request, app_label)
    343349
    344350            if has_module_perms:
    345351                perms = model_admin.get_model_perms(request)
     
    397403        )
    398404
    399405    def app_index(self, request, app_label, extra_context=None):
    400         user = request.user
    401         has_module_perms = user.has_module_perms(app_label)
     406        has_module_perms = self.has_module_perms(request, app_label)
    402407        app_dict = {}
    403         for model, model_admin in self._registry.items():
    404             if app_label == model._meta.app_label:
    405                 if has_module_perms:
     408        if has_module_perms:
     409            for model, model_admin in self._registry.items():
     410                if app_label == model._meta.app_label:
    406411                    perms = model_admin.get_model_perms(request)
    407412
    408413                    # Check whether user has any perm for this module.
Back to Top