Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
modification that prevents the error (UserRole matching query does no…
Browse files Browse the repository at this point in the history
…t exist) on a database that already contains users with no permissions assigned
  • Loading branch information
Nuno Correia committed Feb 27, 2013
1 parent 39095c7 commit 110601e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion userroles/decorators.py
Expand Up @@ -9,5 +9,7 @@ def role_required(*roles):
and django.contrib.auth.decorators.permission_required.
"""
def check_role(user):
return getattr(user, 'role', None) in roles
if not hasattr(user, 'role'):
return False
return getattr(user, 'role', None) in roles
return user_passes_test(check_role)

0 comments on commit 110601e

Please sign in to comment.