From 965e97329493bc7ac56f982ae072351d0b4b11f6 Mon Sep 17 00:00:00 2001 From: Will Hutcheson Date: Fri, 12 Oct 2018 16:37:27 -0500 Subject: [PATCH] Move delaccount functionality to @accounts/delete Implement #1477 --- evennia/commands/default/admin.py | 76 +--------------------- evennia/commands/default/cmdset_account.py | 1 - evennia/commands/default/system.py | 52 ++++++++++++++- 3 files changed, 51 insertions(+), 78 deletions(-) diff --git a/evennia/commands/default/admin.py b/evennia/commands/default/admin.py index 3bb4e7e512..08890dfcdc 100644 --- a/evennia/commands/default/admin.py +++ b/evennia/commands/default/admin.py @@ -16,7 +16,7 @@ COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) PERMISSION_HIERARCHY = [p.lower() for p in settings.PERMISSION_HIERARCHY] # limit members for API inclusion -__all__ = ("CmdBoot", "CmdBan", "CmdUnban", "CmdDelAccount", +__all__ = ("CmdBoot", "CmdBan", "CmdUnban", "CmdEmit", "CmdNewPassword", "CmdPerm", "CmdWall") @@ -133,7 +133,7 @@ class CmdBan(COMMAND_DEFAULT_CLASS): reason to be able to later remember why the ban was put in place. It is often preferable to ban an account from the server than to - delete an account with @delaccount. If banned by name, that account + delete an account with @accounts/delete. If banned by name, that account account can no longer be logged into. IP (Internet Protocol) address banning allows blocking all access @@ -256,78 +256,6 @@ class CmdUnban(COMMAND_DEFAULT_CLASS): logger.log_sec('Unbanned: %s (Caller: %s, IP: %s).' % (value.strip(), self.caller, self.session.address)) -class CmdDelAccount(COMMAND_DEFAULT_CLASS): - """ - delete an account from the server - - Usage: - @delaccount[/switch] [: reason] - - Switch: - delobj - also delete the account's currently - assigned in-game object. - - Completely deletes a user from the server database, - making their nick and e-mail again available. - """ - - key = "@delaccount" - switch_options = ("delobj",) - locks = "cmd:perm(delaccount) or perm(Developer)" - help_category = "Admin" - - def func(self): - """Implements the command.""" - - caller = self.caller - args = self.args - - if hasattr(caller, 'account'): - caller = caller.account - - if not args: - self.msg("Usage: @delaccount [: reason]") - return - - reason = "" - if ':' in args: - args, reason = [arg.strip() for arg in args.split(':', 1)] - - # We use account_search since we want to be sure to find also accounts - # that lack characters. - accounts = search.account_search(args) - - if not accounts: - self.msg('Could not find an account by that name.') - return - - if len(accounts) > 1: - string = "There were multiple matches:\n" - string += "\n".join(" %s %s" % (account.id, account.key) for account in accounts) - self.msg(string) - return - - # one single match - - account = accounts.first() - - if not account.access(caller, 'delete'): - string = "You don't have the permissions to delete that account." - self.msg(string) - return - - uname = account.username - # boot the account then delete - self.msg("Informing and disconnecting account ...") - string = "\nYour account '%s' is being *permanently* deleted.\n" % uname - if reason: - string += " Reason given:\n '%s'" % reason - account.msg(string) - logger.log_sec('Account Deleted: %s (Reason: %s, Caller: %s, IP: %s).' % (account, reason, caller, self.session.address)) - account.delete() - self.msg("Account %s was successfully deleted." % uname) - - class CmdEmit(COMMAND_DEFAULT_CLASS): """ admin command for emitting message to multiple objects diff --git a/evennia/commands/default/cmdset_account.py b/evennia/commands/default/cmdset_account.py index d7b887c017..8173e461c5 100644 --- a/evennia/commands/default/cmdset_account.py +++ b/evennia/commands/default/cmdset_account.py @@ -55,7 +55,6 @@ class AccountCmdSet(CmdSet): self.add(system.CmdPy()) # Admin commands - self.add(admin.CmdDelAccount()) self.add(admin.CmdNewPassword()) # Comm commands diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index c454de9aff..070420f4c3 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -18,7 +18,7 @@ from evennia.server.sessionhandler import SESSIONS from evennia.scripts.models import ScriptDB from evennia.objects.models import ObjectDB from evennia.accounts.models import AccountDB -from evennia.utils import logger, utils, gametime, create +from evennia.utils import logger, utils, gametime, create, search from evennia.utils.eveditor import EvEditor from evennia.utils.evtable import EvTable from evennia.utils.utils import crop, class_from_module @@ -460,17 +460,22 @@ class CmdObjects(COMMAND_DEFAULT_CLASS): class CmdAccounts(COMMAND_DEFAULT_CLASS): """ - list all registered accounts + Manage registered accounts Usage: @accounts [nr] + @accounts/delete [: reason] - Lists statistics about the Accounts registered with the game. + Switches: + delete - delete an account from the server + + By default, lists statistics about the Accounts registered with the game. It will list the amount of latest registered accounts If not given, defaults to 10. """ key = "@accounts" aliases = ["@listaccounts"] + switch_options = ("delete",) locks = "cmd:perm(listaccounts) or perm(Admin)" help_category = "System" @@ -478,6 +483,47 @@ class CmdAccounts(COMMAND_DEFAULT_CLASS): """List the accounts""" caller = self.caller + args = self.args + + if "delete" in self.switches: + account = getattr(caller, "account") + if not account or not account.check_permstring("Developer"): + caller.msg("You are not allowed to delete accounts.") + return + if not args: + caller.msg("Usage: @accounts/delete [: reason]") + return + reason = "" + if ":" in args: + args, reason = [arg.strip() for arg in args.split(":", 1)] + # We use account_search since we want to be sure to find also accounts + # that lack characters. + accounts = search.account_search(args) + if not accounts: + self.msg("Could not find an account by that name.") + return + if len(accounts) > 1: + string = "There were multiple matches:\n" + string += "\n".join(" %s %s" % (account.id, account.key) for account in accounts) + self.msg(string) + return + account = accounts.first() + if not account.access(caller, "delete"): + self.msg("You don't have the permissions to delete that account.") + return + username = account.username + # Boot the account then delete it. + self.msg("Informing and disconnecting account ...") + string = "\nYour account '%s' is being *permanently* deleted.\n" % username + if reason: + string += " Reason given:\n '%s'" % reason + account.msg(string) + logger.log_sec("Account Deleted: %s (Reason: %s, Caller: %s, IP: %s)." % (account, reason, caller, self.session.address)) + account.delete() + self.msg("Account %s was successfully deleted." % username) + return + + # No switches, default to displaying a list of accounts. if self.args and self.args.isdigit(): nlim = int(self.args) else: