def _user_get_all_permissions(user, obj): permissions = set() for backend in auth.get_backends(): if hasattr(backend, "get_all_permissions"): if obj is not None: permissions.update(backend.get_all_permissions(user, obj)) else: permissions.update(backend.get_all_permissions(user)) return permissions
def _user_has_module_perms(user, app_label): anon = user.is_anonymous() active = user.is_active for backend in auth.get_backends(): if anon or active or backend.supports_inactive_user: if hasattr(backend, "has_module_perms"): if backend.has_module_perms(user, app_label): return True return False
def _user_has_perm(user, perm, obj): anon = user.is_anonymous() active = user.is_active for backend in auth.get_backends(): if anon or active or backend.supports_inactive_user: if hasattr(backend, "has_perm"): if obj is not None: if backend.has_perm(user, perm, obj): return True else: if backend.has_perm(user, perm): return True return False
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: permissions.update(backend.get_group_permissions(self, obj)) else: permissions.update(backend.get_group_permissions(self)) return permissions