Merge pull request #5639 from FinnStutzenstein/useCacheInManagementCommands

Use cache in management commands
This commit is contained in:
Finn Stutzenstein 2020-10-28 08:20:01 +01:00 committed by GitHub
commit 266f9b73e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 5 deletions

View File

@ -24,7 +24,7 @@ class Command(BaseCommand):
if user.check_password("admin"):
user.set_password(options["password"])
user.save(skip_autoupdate=True)
user.save()
self.stdout.write(
self.style.SUCCESS("Password of user admin successfully changed.")
)

View File

@ -0,0 +1,16 @@
import sys
from django.core.management.base import BaseCommand
class Command(BaseCommand):
"""
Overwrites the django auth's changepassword. It does not respect our cache and our
own implementation should be used instead.
"""
def run_from_argv(self, *args, **kwargs):
self.stderr.write(
"This command is disabled, use insecurepasswordchange instead."
)
sys.exit(1)

View File

@ -1,5 +1,7 @@
from django.core.management.base import BaseCommand
from openslides.utils.autoupdate import inform_changed_data
from ...models import User
@ -43,11 +45,11 @@ class Command(BaseCommand):
user = User.objects.create_user(
options["username"],
options["password"],
skip_autoupdate=True,
**user_data,
)
if options["groups_id"].isdigit():
user.groups.add(int(options["groups_id"]))
inform_changed_data(user)
self.stdout.write(
self.style.SUCCESS(f"Created user {options['username']}.")
)

View File

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

View File

@ -22,6 +22,7 @@ from openslides.utils.manager import BaseManager
from ..core.config import config
from ..utils.auth import GROUP_ADMIN_PK
from ..utils.autoupdate import inform_changed_data
from ..utils.models import (
CASCADE_AND_AUTOUPDATE,
SET_NULL_AND_AUTOUPDATE,
@ -87,6 +88,8 @@ class UserManager(BaseUserManager):
admin.password = make_password(admin.default_password)
admin.save(skip_autoupdate=skip_autoupdate)
admin.groups.add(GROUP_ADMIN_PK)
if not skip_autoupdate:
inform_changed_data(admin)
return created
def generate_username(self, first_name, last_name):