From 8e134af01978bc12491dd2a14ff1282257e0d616 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 1 Jun 2015 20:32:52 +0200 Subject: [PATCH] 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. --- evennia/commands/cmdhandler.py | 2 +- evennia/comms/comms.py | 14 ++++++++++---- evennia/objects/objects.py | 15 +++++++++------ evennia/players/players.py | 16 +++++++++++----- evennia/typeclasses/models.py | 25 ++++++++++++++++--------- 5 files changed, 47 insertions(+), 25 deletions(-) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 8599b06831..f2d20bb1c7 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -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 diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index 00c8097754..e71d9ee1f5 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -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): """ diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index e3182200f9..6b076d407c 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -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 diff --git a/evennia/players/players.py b/evennia/players/players.py index 1a5c681241..c6b2ffd40e 100644 --- a/evennia/players/players.py +++ b/evennia/players/players.py @@ -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 diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index 19c4b18c1b..6161b0224f 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -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: