Example #1
0
def _user_has_module_perms(user, app_label):
    anon = user.is_anonymous()
    for backend in auth.get_backends():
        if 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
 def get_group_permissions(self):
     """
     Returns a list of permission strings that this user has through
     his/her groups. This method queries all available auth backends.
     """
     permissions = set()
     for backend in auth.get_backends():
         if hasattr(backend, "get_group_permissions"):
             permissions.update(backend.get_group_permissions(self))
     return permissions
Example #3
0
 def get_group_permissions(self):
     """
     Returns a list of permission strings that this user has through
     his/her groups. This method queries all available auth backends.
     """
     permissions = set()
     for backend in auth.get_backends():
         if hasattr(backend, "get_group_permissions"):
             permissions.update(backend.get_group_permissions(self))
     return permissions
Example #4
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
Example #5
0
def _user_has_perm(user, perm, obj):
    anon = user.is_anonymous()
    for backend in auth.get_backends():
        if 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
Example #6
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
    def has_module_perms(self, app_label):
        """
        Returns True if the user has any permissions in the given app
        label. Uses pretty much the same logic as has_perm, above.
        """
        if not self.is_active:
            return False

        if self.is_superuser:
            return True

        for backend in auth.get_backends():
            if hasattr(backend, "has_module_perms"):
                if backend.has_module_perms(self, app_label):
                    return True
        return False
Example #8
0
    def has_module_perms(self, app_label):
        """
        Returns True if the user has any permissions in the given app
        label. Uses pretty much the same logic as has_perm, above.
        """
        if not self.is_active:
            return False

        if self.is_superuser:
            return True

        for backend in auth.get_backends():
            if hasattr(backend, "has_module_perms"):
                if backend.has_module_perms(self, app_label):
                    return True
        return False
Example #9
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
    def has_perm(self, perm):
        """
        Returns True if the user has the specified permission. This method
        queries all available auth backends, but returns immediately if any
        backend returns True. Thus, a user who has permission from a single
        auth backend is assumed to have permission in general.
        """
        # Inactive users have no permissions.
        if not self.is_active:
            return False

        # Superusers have all permissions.
        if self.is_superuser:
            return True

        # Otherwise we need to check the backends.
        for backend in auth.get_backends():
            if hasattr(backend, "has_perm"):
                if backend.has_perm(self, perm):
                    return True
        return False
Example #11
0
    def has_perm(self, perm):
        """
        Returns True if the user has the specified permission. This method
        queries all available auth backends, but returns immediately if any
        backend returns True. Thus, a user who has permission from a single
        auth backend is assumed to have permission in general.
        """
        # Inactive users have no permissions.
        if not self.is_active:
            return False

        # Superusers have all permissions.
        if self.is_superuser:
            return True

        # Otherwise we need to check the backends.
        for backend in auth.get_backends():
            if hasattr(backend, "has_perm"):
                if backend.has_perm(self, perm):
                    return True
        return False
 def get_all_permissions(self):
     permissions = set()
     for backend in auth.get_backends():
         if hasattr(backend, "get_all_permissions"):
             permissions.update(backend.get_all_permissions(self))
     return permissions
Example #13
0
 def get_all_permissions(self):
     permissions = set()
     for backend in auth.get_backends():
         if hasattr(backend, "get_all_permissions"):
             permissions.update(backend.get_all_permissions(self))
     return permissions