Skip to content

Commit

Permalink
feat: report if a permission does not exist
Browse files Browse the repository at this point in the history
If the user does not have a permission, it might be because the
permission name is actually wrong.
  • Loading branch information
gforcada committed Apr 28, 2024
1 parent 7cb4816 commit 3376ab1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/plone/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,18 @@ def has_permission(permission, username=None, user=None, obj=None):
context = env.adopt_user(username, user)

with context:
return bool(getSecurityManager().checkPermission(permission, obj))
return_value = bool(getSecurityManager().checkPermission(permission, obj))
if not return_value:
names = [x[0] for x in getPermissions()]
if permission not in names:
raise InvalidParameterError(
"Cannot find a permission with name '{permission}'\n"
"Available permissions are:\n"
"{names}".format(
permission=permission, names="\n".join(sorted(names))
)
)
return return_value


@required_parameters("roles")
Expand Down

0 comments on commit 3376ab1

Please sign in to comment.