Ticket #7599: get_user_permissions_patch_1.diff

File get_user_permissions_patch_1.diff, 2.4 KB (added by Jeff Kistler, 14 years ago)
  • django/contrib/auth/backends.py

    diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
    index 9d67466..215c89d 100644
    a b class ModelBackend(object):  
    1919        except User.DoesNotExist:
    2020            return None
    2121
     22    def get_user_permissions(self, user_obj):
     23        """
     24        Returns a set of permission strings directly tied to user_obj.
     25        """
     26        return set([u"%s.%s" % (p.content_type.app_label, p.codename)
     27                    for p in user_obj.user_permissions.select_related()])
     28
    2229    def get_group_permissions(self, user_obj):
    2330        """
    2431        Returns a set of permission strings that this user has through his/her
    class ModelBackend(object):  
    3542        if user_obj.is_anonymous():
    3643            return set()
    3744        if not hasattr(user_obj, '_perm_cache'):
    38             user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()])
     45            user_obj._perm_cache = self.get_user_permissions(user_obj)
    3946            user_obj._perm_cache.update(self.get_group_permissions(user_obj))
    4047        return user_obj._perm_cache
    4148
  • docs/topics/auth.txt

    diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
    index 00b95ba..1dcf2bd 100644
    a b Methods  
    209209        :meth:`~django.contrib.auth.models.User.set_unusable_password()` has
    210210        been called for this user.
    211211
     212    .. method:: models.User.get_user_permissions(obj=None)
     213
     214        Returns a list of permission strings that the user has.
     215
     216        .. versionadded:: 1.3
     217
     218        If ``obj`` is passed in, only returns the user permissions for
     219        this specific object.
     220
    212221    .. method:: models.User.get_group_permissions(obj=None)
    213222
    214223        Returns a list of permission strings that the user has, through his/her
    Handling authorization in custom backends  
    15271536Custom auth backends can provide their own permissions.
    15281537
    15291538The user model will delegate permission lookup functions
    1530 (:meth:`~django.contrib.auth.models.User.get_group_permissions()`,
     1539((:meth:`~django.contrib.auth.models.User.get_user_permissions()`,
     1540:meth:`~django.contrib.auth.models.User.get_group_permissions()`,
    15311541:meth:`~django.contrib.auth.models.User.get_all_permissions()`,
    15321542:meth:`~django.contrib.auth.models.User.has_perm()`, and
    15331543:meth:`~django.contrib.auth.models.User.has_module_perms()`) to any
Back to Top