Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #9 from dimagi/has_privs
Browse files Browse the repository at this point in the history
add has_privilege util
  • Loading branch information
snopoke committed Dec 13, 2014
2 parents ba4f298 + 97af091 commit 5840a18
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions django_prbac/utils.py
Expand Up @@ -32,3 +32,14 @@ def ensure_request_has_privilege(request, slug, **assignment):

if not request.user.prbac_role.has_privilege(privilege):
raise PermissionDenied()


def has_privilege(request, slug, **assignment):
"""
Returns true if the request has hte privilege, otherwise false
"""
try:
ensure_request_has_privilege(request, slug, **assignment)
return True
except PermissionDenied:
return False

0 comments on commit 5840a18

Please sign in to comment.