From: Loïc Le Ninan Date: Sat, 7 Jun 2014 21:45:50 +0000 (+0200) Subject: #303 : enhancement : add a command to delete users X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8c7ba963afbe6b643e28308466adc8cc42208416;p=mediagoblin.git #303 : enhancement : add a command to delete users --- 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