Fixed commands.

This commit is contained in:
Norman Jäckel 2019-03-19 20:26:12 +01:00
parent 398ffc30ea
commit 35198f6e64
8 changed files with 16 additions and 9 deletions

View File

@ -94,7 +94,7 @@ class CoreAppConfig(AppConfig):
self.get_model("History").get_collection_string(), HistoryViewSet
)
if "runserver" in sys.argv:
if "runserver" in sys.argv or "changeconfig" in sys.argv:
startup()
# Register client messages

View File

@ -41,7 +41,9 @@ class Command(BaseCommand):
if database_path:
do_backup(database_path, path)
self.stdout.write(
f"Database {database_path} successfully stored at {path}."
self.style.SUCCESS(
f"Database {database_path} successfully stored at {path}."
)
)
else:
raise CommandError(

View File

@ -19,4 +19,9 @@ class Command(BaseCommand):
def handle(self, *args, **options):
user = User.objects.get(username=options["username"])
user.set_password(options["password"])
user.save()
user.save(skip_autoupdate=True)
self.stdout.write(
self.style.SUCCESS(
f"Password of user {options['username']} successfully changed."
)
)

View File

@ -24,7 +24,7 @@ class Command(BaseCommand):
"default_password": options["password"],
}
user = User.objects.create_user(
options["username"], options["password"], **user_data
options["username"], options["password"], skip_autoupdate=True, **user_data
)
if options["groups_id"].isdigit():
user.groups.add(int(options["groups_id"]))

View File

@ -11,7 +11,7 @@ class Command(BaseCommand):
help = "Creates or resets the admin user."
def handle(self, *args, **options):
created = User.objects.create_or_reset_admin_user()
created = User.objects.create_or_reset_admin_user(skip_autoupdate=True)
if created:
self.stdout.write("Admin user successfully created.")
else:

View File

@ -60,7 +60,7 @@ class UserManager(BaseUserManager):
user.save(skip_autoupdate=skip_autoupdate, using=self._db)
return user
def create_or_reset_admin_user(self):
def create_or_reset_admin_user(self, skip_autoupdate=False):
"""
Creates an user with the username 'admin'. If such a user already
exists, resets it. The password is (re)set to 'admin'. The user
@ -74,7 +74,7 @@ class UserManager(BaseUserManager):
created = True
admin.default_password = "admin"
admin.password = make_password(admin.default_password)
admin.save(skip_autoupdate=True)
admin.save(skip_autoupdate=skip_autoupdate)
admin.groups.add(GROUP_ADMIN_PK)
return created

View File

@ -178,7 +178,7 @@ def create_builtin_groups_and_admin(**kwargs):
group_committee.permissions.add(*committees_permissions)
# Create or reset admin user
User.objects.create_or_reset_admin_user()
User.objects.create_or_reset_admin_user(skip_autoupdate=True)
# After each group was created, the permissions (many to many fields) where
# added to the group. But we do not have to update the cache by calling

View File

@ -162,7 +162,7 @@ class UserManagerCreateOrResetAdminUser(TestCase):
mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
mock_permission.get = MagicMock()
manager.create_or_reset_admin_user()
manager.create_or_reset_admin_user(skip_autoupdate=True)
self.assertEqual(admin_user.default_password, "admin")
admin_user.save.assert_called_once_with(skip_autoupdate=True)