Skip to content

Instantly share code, notes, and snippets.

@nthomas-mozilla
Last active December 2, 2016 03:34
Show Gist options
  • Save nthomas-mozilla/7b68890256d05b361b2a065b123a5788 to your computer and use it in GitHub Desktop.
Save nthomas-mozilla/7b68890256d05b361b2a065b123a5788 to your computer and use it in GitHub Desktop.
def hasPermission(self, username, thing, action, product=None, transaction=None):
perm = self.getPermission(username, "admin", transaction=transaction)
if perm:
options = perm["options"]
if options and options.get("products") and product not in options["products"]:
# Supporting product-wise admin permissions. If there are no options
# with admin, we assume that the user has admin access over all
# products.
return False
return True
perm = self.getPermission(username, thing, transaction=transaction)
if perm:
options = perm["options"]
if options:
# If a user has a permission that doesn't explicitly limit the type of
# actions they can perform, they are allowed to do any type of action.
if options.get("actions") and action not in options["actions"]:
return False
# Similarly, permissions without products specified grant that
# that permission without any limitation on the product.
if options.get("products") and product not in options["products"]:
return False
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment