Last active
December 2, 2016 03:34
-
-
Save nthomas-mozilla/7b68890256d05b361b2a065b123a5788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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