Skip to content

Commit

Permalink
Implement two missing methods from the permissions backend
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Sep 9, 2024
1 parent afde7aa commit 1be8aaf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Change log
Next version
============

- Added two missing methods to the ``PermissionsBackend`` so that the admin app
list works correctly.

0.17 (2024-08-19)
=================
Expand Down
13 changes: 11 additions & 2 deletions authlib/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ def _has_perm(self, user, perm, obj):
def get_group_permissions(self, user, obj=None):
return set()

# def get_all_permissions(self, user, obj=None):
def get_all_permissions(self, user, obj=None):
return self.get_user_permissions(user, obj=obj)

def has_perm(self, user, perm, obj=None):
return user._role_has_perm(perm=perm, obj=obj)

# def has_module_perms(self, user, app_label):
def has_module_perms(self, user_obj, app_label):
"""
Return True if user_obj has any permissions in the given app_label.
"""
return user_obj.is_active and any(
perm[: perm.index(".")] == app_label
for perm in self.get_all_permissions(user_obj)
)

# def with_perm(self, perm, is_active=True, include_superusers=True, obj=None):

# The user model and its manager will delegate permission lookup functions (get_user_permissions(), get_group_permissions(), get_all_permissions(), has_perm(), has_module_perms(), and with_perm()) to any authentication backend that implements these functions.

2 comments on commit 1be8aaf

@matthiask
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshson Wollte mich nicht vordrängeln, aber das Trigon Problem klang stark nach einem kaputten Permissions Backend.

@yoshson
Copy link

@yoshson yoshson commented on 1be8aaf Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Danke dir! Das hätte mich glaub viel Zeit gekostet!

Please sign in to comment.