#303 : enhancement : add a command to delete users
authorLoïc Le Ninan <loic.leninan@gmail.com>
Sat, 7 Jun 2014 21:45:50 +0000 (23:45 +0200)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 11 Jun 2014 21:42:26 +0000 (16:42 -0500)
mediagoblin/gmg_commands/__init__.py
mediagoblin/gmg_commands/users.py

index fd546aac1e1bc6b84471e53b470f6d0d3e9c672d..0cb239a226b7ede49d40de04548a9df6785e7284 100644 (file)
@@ -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',
index 4a730d9e866756afb0d4ef25274439d6b9a80261..186557e09d88822ac9391c98f73a2c5318e1be9b 100644 (file)
@@ -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