django-arctic
django-arctic copied to clipboard
User role not added to roles raises error on checking permission
In class RoleAuthentication there is a method called check_permission
. In case the role of user is not defined in roles.py, it raises KeyError
.
I'd suggest to change method to:
@classmethod
def check_permission(cls, role, permission):
"""
Check if role contains permission
"""
result = permission in settings.ARCTIC_ROLES.get(role, [])
# will try to call a method with the same name as the permission
# to enable an object level permission check.
if result:
try:
return getattr(cls, permission)(role)
except AttributeError:
pass
return result
Is this still an issue? @VolodiaKhl
I can confirm this issue. I ran unittests with an admin user, calling if self.check_permission(self.request.user.urole.role.name, 'dashboard_widgets'):
. Admin is not existing in the ARCTIC_ROLES, so it breaks.