From 26643a71a7a9976e486db0e4ec4c559bab2d7c8f Mon Sep 17 00:00:00 2001 From: Andrew Bastien Date: Thu, 23 Nov 2023 13:14:42 -0500 Subject: [PATCH] Adjusting checks to use utils.inherits_from() --- evennia/commands/default/building.py | 5 +++-- evennia/commands/default/general.py | 3 ++- evennia/comms/comms.py | 5 +++-- evennia/locks/lockfuncs.py | 5 +++-- evennia/locks/lockhandler.py | 5 +++-- evennia/typeclasses/models.py | 3 ++- evennia/utils/evmenu.py | 12 ++++++++---- evennia/utils/evmore.py | 3 ++- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index b3a319285d..5e4d14c4f9 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -8,6 +8,7 @@ from django.conf import settings from django.core.paginator import Paginator from django.db.models import Max, Min, Q +import evennia from evennia import InterruptCommand from evennia.commands.cmdhandler import get_and_merge_cmdsets from evennia.locks.lockhandler import LockException @@ -2739,7 +2740,7 @@ class CmdExamine(ObjManipCommand): all_cmdsets = [(cmdset.key, cmdset) for cmdset in current_cmdset.merged_from] # we always at least try to add account- and session sets since these are ignored # if we merge on the object level. - if hasattr(obj, "has_account") and obj.account: + if inherits_from(obj, evennia.DefaultObject) and obj.account: # get Attribute-cmdsets if they exist all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.account.cmdset.all()]) if obj.sessions.count(): @@ -2924,7 +2925,7 @@ class CmdExamine(ObjManipCommand): objdata["Sessions"] = self.format_sessions(obj) objdata["Email"] = self.format_email(obj) objdata["Last Login"] = self.format_last_login(obj) - if hasattr(obj, "has_account") and obj.has_account: + if inherits_from(obj, evennia.DefaultObject) and obj.has_account: objdata["Account"] = self.format_account_key(obj.account) objdata[" Account Typeclass"] = self.format_account_typeclass(obj.account) objdata[" Account Permissions"] = self.format_account_permissions(obj.account) diff --git a/evennia/commands/default/general.py b/evennia/commands/default/general.py index 8ba1cb3462..268325afb7 100644 --- a/evennia/commands/default/general.py +++ b/evennia/commands/default/general.py @@ -5,6 +5,7 @@ import re from django.conf import settings +import evennia from evennia.typeclasses.attributes import NickTemplateInvalid from evennia.utils import utils @@ -723,6 +724,6 @@ class CmdAccess(COMMAND_DEFAULT_CLASS): string += "\n|wYour access|n:" string += f"\nCharacter |c{caller.key}|n: {cperms}" - if hasattr(caller, "has_account"): + if utils.inherits_from(caller, evennia.DefaultObject): string += f"\nAccount |c{caller.account.key}|n: {pperms}" caller.msg(string) diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index 22d20d2d86..9bbe014cc7 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -8,11 +8,12 @@ from django.contrib.contenttypes.models import ContentType from django.urls import reverse from django.utils.text import slugify +import evennia from evennia.comms.managers import ChannelManager from evennia.comms.models import ChannelDB from evennia.typeclasses.models import TypeclassBase from evennia.utils import create, logger -from evennia.utils.utils import make_iter +from evennia.utils.utils import make_iter, inherits_from class DefaultChannel(ChannelDB, metaclass=TypeclassBase): @@ -165,7 +166,7 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase): """ has_sub = self.subscriptions.has(subscriber) - if not has_sub and hasattr(subscriber, "has_account"): + if not has_sub and inherits_from(subscriber, evennia.DefaultObject): # it's common to send an Object when we # by default only allow Accounts to subscribe. has_sub = self.subscriptions.has(subscriber.account) diff --git a/evennia/locks/lockfuncs.py b/evennia/locks/lockfuncs.py index ff35844e8b..d477b5a1ca 100644 --- a/evennia/locks/lockfuncs.py +++ b/evennia/locks/lockfuncs.py @@ -18,6 +18,7 @@ from ast import literal_eval from django.conf import settings +import evennia from evennia.utils import utils _PERMISSION_HIERARCHY = [pe.lower() for pe in settings.PERMISSION_HIERARCHY] @@ -515,7 +516,7 @@ def is_ooc(accessing_obj, accessed_obj, *args, **kwargs): function will still return True. """ obj = accessed_obj.obj if hasattr(accessed_obj, "obj") else accessed_obj - account = obj.account if hasattr(obj, "has_account") else obj + account = obj.account if utils.inherits_from(obj, evennia.DefaultObject) else obj if not account: return True try: @@ -657,7 +658,7 @@ def has_account(accessing_obj, accessed_obj, *args, **kwargs): This is a useful lock for traverse-locking Exits to restrain NPC mobiles from moving outside their areas. """ - return hasattr(accessing_obj, "has_account") and accessing_obj.has_account + return utils.inherits_from(accessing_obj, evennia.DefaultObject) and accessing_obj.has_account def serversetting(accessing_obj, accessed_obj, *args, **kwargs): diff --git a/evennia/locks/lockhandler.py b/evennia/locks/lockhandler.py index 825cbd759f..737c071fc4 100644 --- a/evennia/locks/lockhandler.py +++ b/evennia/locks/lockhandler.py @@ -109,6 +109,7 @@ import re from django.conf import settings from django.utils.translation import gettext as _ +import evennia from evennia.utils import logger, utils __all__ = ("LockHandler", "LockException") @@ -553,7 +554,7 @@ class LockHandler: if not no_superuser_bypass and ( (hasattr(accessing_obj, "is_superuser") and accessing_obj.is_superuser) or ( - hasattr(accessing_obj, "has_account") + utils.inherits_from(accessing_obj, evennia.DefaultObject) and hasattr(accessing_obj.account, "is_superuser") and accessing_obj.account.is_superuser ) @@ -627,7 +628,7 @@ class LockHandler: if no_superuser_bypass and ( (hasattr(accessing_obj, "is_superuser") and accessing_obj.is_superuser) or ( - hasattr(accessing_obj, "has_account") + utils.inherits_from(accessing_obj, evennia.DefaultObject) and hasattr(accessing_obj.account, "is_superuser") and accessing_obj.account.is_superuser ) diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index ecd2e017c0..9758b1f8ce 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -35,6 +35,7 @@ from django.urls import reverse from django.utils.encoding import smart_str from django.utils.text import slugify +import evennia from evennia.locks.lockhandler import LockHandler from evennia.server.signals import SIGNAL_TYPED_OBJECT_POST_RENAME from evennia.typeclasses import managers @@ -700,7 +701,7 @@ class TypedObject(SharedMemoryModel): result (bool): If the permstring is passed or not. """ - if hasattr(self, "has_account"): + if inherits_from(self, evennia.DefaultObject): if ( self.account and self.account.is_superuser diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index 30e6b3e01d..3ca3aadbc5 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -277,6 +277,7 @@ from django.conf import settings # i18n from django.utils.translation import gettext as _ +import evennia from evennia import CmdSet, Command from evennia.commands import cmdhandler from evennia.utils import logger @@ -291,6 +292,7 @@ from evennia.utils.utils import ( mod_import, pad, to_str, + inherits_from, ) # read from protocol NAWS later? @@ -423,7 +425,7 @@ class CmdEvMenuNode(Command): if _restore(caller): return orig_caller = caller - caller = caller.account if hasattr(caller, "has_account") else None + caller = caller.account if inherits_from(caller, evennia.DefaultObject) else None menu = caller.ndb._evmenu if caller else None if not menu: if caller and _restore(caller): @@ -1497,7 +1499,7 @@ class CmdGetInput(Command): caller = self.caller try: getinput = caller.ndb._getinput - if not getinput and (hasattr(caller, "has_account")): + if not getinput and inherits_from(caller, evennia.DefaultObject): getinput = caller.account.ndb._getinput if getinput: caller = caller.account @@ -1618,7 +1620,9 @@ class CmdYesNoQuestion(Command): def _clean(self, caller): del caller.ndb._yes_no_question - if not caller.cmdset.has(YesNoQuestionCmdSet) and hasattr(caller, "has_account"): + if not caller.cmdset.has(YesNoQuestionCmdSet) and inherits_from( + caller, evennia.DefaultObject + ): caller.account.cmdset.remove(YesNoQuestionCmdSet) else: caller.cmdset.remove(YesNoQuestionCmdSet) @@ -1628,7 +1632,7 @@ class CmdYesNoQuestion(Command): caller = self.caller try: yes_no_question = caller.ndb._yes_no_question - if not yes_no_question and hasattr(caller, "has_account"): + if not yes_no_question and inherits_from(caller, evennia.DefaultObject): yes_no_question = caller.account.ndb._yes_no_question caller = caller.account diff --git a/evennia/utils/evmore.py b/evennia/utils/evmore.py index 24c04117e3..48356ac7da 100644 --- a/evennia/utils/evmore.py +++ b/evennia/utils/evmore.py @@ -41,6 +41,7 @@ from django.core.paginator import Paginator from django.db.models.query import QuerySet from django.utils.translation import gettext as _ +import evennia from evennia.commands import cmdhandler from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command @@ -78,7 +79,7 @@ class CmdMore(Command): Implement the command """ more = self.caller.ndb._more - if not more and hasattr(self.caller, "has_account"): + if not more and inherits_from(self.caller, evennia.DefaultObject): more = self.caller.account.ndb._more if not more: self.caller.msg("Error in loading the pager. Contact an admin.")