Ejemplo n.º 1
0
def _user_has_module_perms(user, app_label):
    anon = user.is_anonymous()
    active = user.is_active
    for backend in auth.get_backends():
        if (not active and not anon and backend.supports_inactive_user) or \
                    (not anon or backend.supports_anonymous_user):
            if hasattr(backend, "has_module_perms"):
                if backend.has_module_perms(user, app_label):
                    return True
    return False
Ejemplo n.º 2
0
def _user_get_all_permissions(user, obj):
    permissions = set()
    anon = user.is_anonymous()
    for backend in auth.get_backends():
        if not anon or backend.supports_anonymous_user:
            if hasattr(backend, "get_all_permissions"):
                if obj is not None:
                    if backend.supports_object_permissions:
                        permissions.update(
                            backend.get_all_permissions(user, obj)
                        )
                else:
                    permissions.update(backend.get_all_permissions(user))
    return permissions
Ejemplo n.º 3
0
def _user_has_perm(user, perm, obj):
    anon = user.is_anonymous()
    active = user.is_active
    for backend in auth.get_backends():
        if (not active and not anon and backend.supports_inactive_user) or \
                    (not anon or backend.supports_anonymous_user):
            if hasattr(backend, "has_perm"):
                if obj is not None:
                    if (backend.supports_object_permissions and
                        backend.has_perm(user, perm, obj)):
                            return True
                else:
                    if backend.has_perm(user, perm):
                        return True
    return False
Ejemplo n.º 4
0
 def get_group_permissions(self, obj=None):
     """
     Returns a list of permission strings that this user has through
     his/her groups. This method queries all available auth backends.
     If an object is passed in, only permissions matching this object
     are returned.
     """
     permissions = set()
     for backend in auth.get_backends():
         if hasattr(backend, "get_group_permissions"):
             if obj is not None:
                 if backend.supports_object_permissions:
                     permissions.update(
                         backend.get_group_permissions(self, obj)
                     )
             else:
                 permissions.update(backend.get_group_permissions(self))
     return permissions