mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
API change: Added no_superuser_bypass kwarg to obj.access, channel.access and player.access methods, to make the call consistent with the full lockhandler.check call. This allows the cmdhandler to use access() to check the 'call' locktype and thus make it available for overloading if so desired. Resolves #752.
This commit is contained in:
parent
ef1e336339
commit
8e134af019
5 changed files with 47 additions and 25 deletions
|
|
@ -200,7 +200,7 @@ def get_and_merge_cmdsets(caller, session, player, obj,
|
|||
local_obj_cmdsets = \
|
||||
yield [lobj.cmdset.current for lobj in local_objlist
|
||||
if (lobj.cmdset.current and
|
||||
lobj.locks.check(caller, 'call', no_superuser_bypass=True))]
|
||||
lobj.access(caller, access_type='call', no_superuser_bypass=True))]
|
||||
for cset in local_obj_cmdsets:
|
||||
#This is necessary for object sets, or we won't be able to
|
||||
# separate the command sets from each other in a busy room. We
|
||||
|
|
|
|||
|
|
@ -133,17 +133,23 @@ class DefaultChannel(ChannelDB):
|
|||
self.post_leave_channel(subscriber)
|
||||
return True
|
||||
|
||||
def access(self, accessing_obj, access_type='listen', default=False):
|
||||
def access(self, accessing_obj, access_type='listen', default=False, no_superuser_bypass=False):
|
||||
"""
|
||||
Determines if another object has permission to access.
|
||||
|
||||
Args:
|
||||
accessing_obj (Object): Object trying to access this one.
|
||||
access_type (str): Type of access sought.
|
||||
default (bool): What to return if no lock of access_type was found
|
||||
access_type (str, optional): Type of access sought.
|
||||
default (bool, optional): What to return if no lock of access_type was found
|
||||
no_superuser_bypass (bool, optional): Turns off superuser
|
||||
lock bypass. Be careful with this one.
|
||||
|
||||
Returns:
|
||||
return (bool): Result of lock check.
|
||||
|
||||
"""
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default)
|
||||
return self.locks.check(accessing_obj, access_type=access_type,
|
||||
default=default, no_superuser_bypass=no_superuser_bypass)
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -768,21 +768,24 @@ class DefaultObject(ObjectDB):
|
|||
super(ObjectDB, self).delete()
|
||||
return True
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False, **kwargs):
|
||||
def access(self, accessing_obj, access_type='read', default=False, no_superuser_bypass=False, **kwargs):
|
||||
"""
|
||||
Determines if another object has permission to access this object
|
||||
in whatever way.
|
||||
|
||||
Args:
|
||||
accessing_obj (Object): Object trying to access this one
|
||||
access_type (str): Type of access sought
|
||||
default (bool): What to return if no lock of access_type was found
|
||||
accessing_obj (Object): Object trying to access this one.
|
||||
access_type (str, optional): Type of access sought.
|
||||
default (bool, optional): What to return if no lock of access_type was found.
|
||||
no_superuser_bypass (bool, optional): If `True`, don't skip
|
||||
lock check for superuser (be careful with this one).
|
||||
|
||||
Kwargs:
|
||||
Passed to the at_access hook along with the result.
|
||||
Passed on to the at_access hook along with the result of the access check.
|
||||
|
||||
"""
|
||||
result = super(DefaultObject, self).access(accessing_obj, access_type=access_type, default=default)
|
||||
result = super(DefaultObject, self).access(accessing_obj, access_type=access_type,
|
||||
default=default, no_superuser_bypass=no_superuser_bypass)
|
||||
self.at_access(result, accessing_obj, access_type, **kwargs)
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class DefaultPlayer(PlayerDB):
|
|||
ignore_errors=False, player=False)
|
||||
is_typeclass(typeclass, exact=False)
|
||||
swap_typeclass(new_typeclass, clean_attributes=False, no_default=True)
|
||||
access(accessing_obj, access_type='read', default=False)
|
||||
access(accessing_obj, access_type='read', default=False, no_superuser_bypass=False)
|
||||
check_permstring(permstring)
|
||||
|
||||
* Hook methods
|
||||
|
|
@ -429,21 +429,27 @@ class DefaultPlayer(PlayerDB):
|
|||
return None
|
||||
return matches
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False, **kwargs):
|
||||
def access(self, accessing_obj, access_type='read', default=False, no_superuser_bypass=False, **kwargs):
|
||||
"""
|
||||
Determines if another object has permission to access this object
|
||||
in whatever way.
|
||||
|
||||
Args:
|
||||
accessing_obj (Object): Object trying to access this one
|
||||
access_type (str): Type of access sought
|
||||
default (bool): What to return if no lock of access_type was found
|
||||
access_type (str, optional): Type of access sought
|
||||
default (bool, optional): What to return if no lock of access_type was found
|
||||
no_superuser_bypass (bool, optional): Turn off superuser
|
||||
lock bypassing. Be careful with this one.
|
||||
|
||||
Kwargs:
|
||||
Passed to the at_access hook along with the result.
|
||||
|
||||
Returns:
|
||||
result (bool): Result of access check.
|
||||
|
||||
"""
|
||||
result = super(DefaultPlayer, self).access(accessing_obj, access_type=access_type, default=default)
|
||||
result = super(DefaultPlayer, self).access(accessing_obj, access_type=access_type,
|
||||
default=default, no_superuser_bypass=no_superuser_bypass)
|
||||
self.at_access(result, accessing_obj, access_type, **kwargs)
|
||||
return result
|
||||
|
||||
|
|
|
|||
|
|
@ -463,21 +463,28 @@ class TypedObject(SharedMemoryModel):
|
|||
# Lock / permission methods
|
||||
#
|
||||
|
||||
def access(self, accessing_obj, access_type='read', default=False, **kwargs):
|
||||
def access(self, accessing_obj, access_type='read', default=False, no_superuser_bypass=False, **kwargs):
|
||||
"""
|
||||
Determines if another object has permission to access.
|
||||
accessing_obj - object trying to access this one
|
||||
access_type - type of access sought
|
||||
default - what to return if no lock of access_type was found
|
||||
**kwargs - this is ignored, but is there to make the api consistent with the
|
||||
object-typeclass method access, which use it to feed to its hook methods.
|
||||
Determines if another object has permission to access this one.
|
||||
|
||||
Args:
|
||||
accessing_obj (str): Object trying to access this one.
|
||||
access_type (str, optional): Type of access sought.
|
||||
default (bool, optional): What to return if no lock of access_type was found
|
||||
no_superuser_bypass (bool, optional): Turn off the superuser lock bypass (be careful with this one).
|
||||
|
||||
Kwargs:
|
||||
kwargs (any): Ignored, but is there to make the api consistent with the
|
||||
object-typeclass method access, which use it to feed to its hook methods.
|
||||
|
||||
"""
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default)
|
||||
return self.locks.check(accessing_obj, access_type=access_type, default=default,
|
||||
no_superuser_bypass=no_superuser_bypass)
|
||||
|
||||
def check_permstring(self, permstring):
|
||||
"""
|
||||
This explicitly checks if we hold particular permission without
|
||||
involving any locks. It does -not- trigger the at_access hook.
|
||||
involving any locks.
|
||||
"""
|
||||
if hasattr(self, "player"):
|
||||
if self.player and self.player.is_superuser:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue