Skip to content

Commit

Permalink
Be more forgiving
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Sep 17, 2023
1 parent 4cd626f commit ca8dcf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Change log
Next version
============

- Changed the roles implementation to allow using arbitrary names for the role
field.
- Stopped crashing when encountering an unknown role -- doing nothing in
``has_perm`` is an acceptable fallback.


0.16 (2023-09-17)
=================
Expand Down
4 changes: 2 additions & 2 deletions authlib/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def contribute_to_class(self, cls, name):
super().contribute_to_class(cls, name)

def _role_has_perm(self, *, perm, obj):
if callback := _roles()[self.role].get("callback"):
return self.is_active and callback(user=self, perm=perm, obj=obj)
if (r := _roles()[getattr(self, name)]) and (cb := r.get("callback")):
return self.is_active and cb(user=self, perm=perm, obj=obj)

cls._role_has_perm = _role_has_perm

Expand Down

0 comments on commit ca8dcf0

Please sign in to comment.