Fix bugs in API perm checking
This commit is contained in:
parent
07f994ce91
commit
43d678d8ca
5 changed files with 41 additions and 8 deletions
|
|
@ -167,7 +167,8 @@ def perm(accessing_obj, accessed_obj, *args, **kwargs):
|
|||
try:
|
||||
permission = args[0].lower()
|
||||
perms_object = accessing_obj.permissions.all()
|
||||
except (AttributeError, IndexError):
|
||||
except (AttributeError, IndexError) as err:
|
||||
print("accessing_obj err:", err)
|
||||
return False
|
||||
|
||||
gtmode = kwargs.pop("_greater_than", False)
|
||||
|
|
|
|||
|
|
@ -693,6 +693,29 @@ def check_lockstring(
|
|||
access_type=access_type,
|
||||
)
|
||||
|
||||
def check_perm(
|
||||
obj, permission, no_superuser_bypass=False):
|
||||
"""
|
||||
Shortcut for checking if an object has the given `permission`. If the
|
||||
permission is in `settings.PERMISSION_HIERARCHY`, the check passes
|
||||
if the object has this permission or higher.
|
||||
|
||||
This is equivalent to calling the perm() lockfunc, but without needing
|
||||
an accessed object.
|
||||
|
||||
Args:
|
||||
obj (Object, Account): The object to check access. If this has a linked
|
||||
Account, the account is checked instead (same rules as per perm()).
|
||||
permission (str): The permission string to check.
|
||||
no_superuser_bypass (bool, optional): If unset, the superuser
|
||||
will always pass this check.
|
||||
|
||||
"""
|
||||
from evennia.locks.lockfuncs import perm
|
||||
if not no_superuser_bypass and obj.is_superuser:
|
||||
return True
|
||||
return perm(obj, None, permission)
|
||||
|
||||
|
||||
def validate_lockstring(lockstring):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue