Merge pull request #4516 from normanjaeckel/FixCommands
Fixed commands.
This commit is contained in:
commit
fbbd5fa135
@ -94,7 +94,7 @@ class CoreAppConfig(AppConfig):
|
|||||||
self.get_model("History").get_collection_string(), HistoryViewSet
|
self.get_model("History").get_collection_string(), HistoryViewSet
|
||||||
)
|
)
|
||||||
|
|
||||||
if "runserver" in sys.argv:
|
if "runserver" in sys.argv or "changeconfig" in sys.argv:
|
||||||
startup()
|
startup()
|
||||||
|
|
||||||
# Register client messages
|
# Register client messages
|
||||||
|
@ -41,8 +41,10 @@ class Command(BaseCommand):
|
|||||||
if database_path:
|
if database_path:
|
||||||
do_backup(database_path, path)
|
do_backup(database_path, path)
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
|
self.style.SUCCESS(
|
||||||
f"Database {database_path} successfully stored at {path}."
|
f"Database {database_path} successfully stored at {path}."
|
||||||
)
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Default database is not SQLite3. Only SQLite3 databases"
|
"Default database is not SQLite3. Only SQLite3 databases"
|
||||||
|
@ -19,4 +19,9 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
user = User.objects.get(username=options["username"])
|
user = User.objects.get(username=options["username"])
|
||||||
user.set_password(options["password"])
|
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."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@ -24,7 +24,7 @@ class Command(BaseCommand):
|
|||||||
"default_password": options["password"],
|
"default_password": options["password"],
|
||||||
}
|
}
|
||||||
user = User.objects.create_user(
|
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():
|
if options["groups_id"].isdigit():
|
||||||
user.groups.add(int(options["groups_id"]))
|
user.groups.add(int(options["groups_id"]))
|
||||||
|
@ -11,7 +11,7 @@ class Command(BaseCommand):
|
|||||||
help = "Creates or resets the admin user."
|
help = "Creates or resets the admin user."
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
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:
|
if created:
|
||||||
self.stdout.write("Admin user successfully created.")
|
self.stdout.write("Admin user successfully created.")
|
||||||
else:
|
else:
|
||||||
|
@ -60,7 +60,7 @@ class UserManager(BaseUserManager):
|
|||||||
user.save(skip_autoupdate=skip_autoupdate, using=self._db)
|
user.save(skip_autoupdate=skip_autoupdate, using=self._db)
|
||||||
return user
|
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
|
Creates an user with the username 'admin'. If such a user already
|
||||||
exists, resets it. The password is (re)set to 'admin'. The user
|
exists, resets it. The password is (re)set to 'admin'. The user
|
||||||
@ -74,7 +74,7 @@ class UserManager(BaseUserManager):
|
|||||||
created = True
|
created = True
|
||||||
admin.default_password = "admin"
|
admin.default_password = "admin"
|
||||||
admin.password = make_password(admin.default_password)
|
admin.password = make_password(admin.default_password)
|
||||||
admin.save(skip_autoupdate=True)
|
admin.save(skip_autoupdate=skip_autoupdate)
|
||||||
admin.groups.add(GROUP_ADMIN_PK)
|
admin.groups.add(GROUP_ADMIN_PK)
|
||||||
return created
|
return created
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ def create_builtin_groups_and_admin(**kwargs):
|
|||||||
group_committee.permissions.add(*committees_permissions)
|
group_committee.permissions.add(*committees_permissions)
|
||||||
|
|
||||||
# Create or reset admin user
|
# 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
|
# 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
|
# added to the group. But we do not have to update the cache by calling
|
||||||
|
@ -162,7 +162,7 @@ class UserManagerCreateOrResetAdminUser(TestCase):
|
|||||||
mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
|
mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
|
||||||
mock_permission.get = MagicMock()
|
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")
|
self.assertEqual(admin_user.default_password, "admin")
|
||||||
admin_user.save.assert_called_once_with(skip_autoupdate=True)
|
admin_user.save.assert_called_once_with(skip_autoupdate=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user