From 1be8aafd1b832f8631aa9762a8c1d41acd01fc50 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 9 Sep 2024 13:02:50 +0200 Subject: [PATCH] Implement two missing methods from the permissions backend --- CHANGELOG.rst | 2 ++ authlib/backends.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 92a4260..2b189a3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) ================= diff --git a/authlib/backends.py b/authlib/backends.py index e2d1b9d..f815caf 100644 --- a/authlib/backends.py +++ b/authlib/backends.py @@ -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.