diff --git a/ssmain/management/commands/makeadmin.py b/ssmain/management/commands/makeadmin.py new file mode 100644 index 0000000..0f8da9b --- /dev/null +++ b/ssmain/management/commands/makeadmin.py @@ -0,0 +1,37 @@ +# Society Self-Service +# Copyright © 2018-2019 Yingtong Li (RunasSudo) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.core.management.base import BaseCommand, CommandError + +from django.contrib.auth.models import User + +class Command(BaseCommand): + help = 'Makes the user with the specified email an administrator' + + def add_arguments(self, parser): + parser.add_argument('email') + + def handle(self, *args, **options): + try: + user = User.objects.get(email=options['email']) + except User.DoesNotExist: + raise CommandError('No user with this email') + + user.is_staff = True + user.is_superuser = True + user.save() + + self.stdout.write(self.style.SUCCESS('Success'))