From 8c7ba963afbe6b643e28308466adc8cc42208416 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lo=C3=AFc=20Le=20Ninan?= Date: Sat, 7 Jun 2014 23:45:50 +0200 Subject: [PATCH] #303 : enhancement : add a command to delete users --- mediagoblin/gmg_commands/__init__.py | 4 ++++ mediagoblin/gmg_commands/users.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index fd546aac..0cb239a2 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -37,6 +37,10 @@ SUBCOMMAND_MAP = { 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup', 'func': 'mediagoblin.gmg_commands.users:changepw', 'help': 'Changes a user\'s password'}, + 'deleteuser': { + 'setup': 'mediagoblin.gmg_commands.users:deleteuser_parser_setup', + 'func': 'mediagoblin.gmg_commands.users:deleteuser', + 'help': 'Deletes a user'}, 'dbupdate': { 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup', 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate', diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 4a730d9e..186557e0 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -115,3 +115,23 @@ def changepw(args): print 'Password successfully changed' else: print 'The user doesn\'t exist' + + +def deleteuser_parser_setup(subparser): + subparser.add_argument( + 'username', + help="Username to delete") + + +def deleteuser(args): + commands_util.setup_app(args) + + db = mg_globals.database + + user = db.User.query.filter_by( + username=unicode(args.username.lower())).one() + if user: + user.delete() + print 'The user %s has been deleted' % args.username + else: + print 'The user %s doesn\'t exist' % args.username -- 2.25.1