Use cache in management commands
This requires to have a correct setup when using these commands
This commit is contained in:
parent
d2043f508c
commit
ca56b4f8b4
@ -24,7 +24,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
if user.check_password("admin"):
|
if user.check_password("admin"):
|
||||||
user.set_password(options["password"])
|
user.set_password(options["password"])
|
||||||
user.save(skip_autoupdate=True)
|
user.save()
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS("Password of user admin successfully changed.")
|
self.style.SUCCESS("Password of user admin successfully changed.")
|
||||||
)
|
)
|
||||||
|
@ -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)
|
@ -1,5 +1,7 @@
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from openslides.utils.autoupdate import inform_changed_data
|
||||||
|
|
||||||
from ...models import User
|
from ...models import User
|
||||||
|
|
||||||
|
|
||||||
@ -43,11 +45,11 @@ class Command(BaseCommand):
|
|||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
options["username"],
|
options["username"],
|
||||||
options["password"],
|
options["password"],
|
||||||
skip_autoupdate=True,
|
|
||||||
**user_data,
|
**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"]))
|
||||||
|
inform_changed_data(user)
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS(f"Created user {options['username']}.")
|
self.style.SUCCESS(f"Created user {options['username']}.")
|
||||||
)
|
)
|
||||||
|
@ -11,8 +11,8 @@ 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(skip_autoupdate=True)
|
created = User.objects.create_or_reset_admin_user()
|
||||||
if created:
|
if created:
|
||||||
self.stdout.write("Admin user successfully created.")
|
self.stdout.write(self.style.SUCCESS("Admin user successfully created."))
|
||||||
else:
|
else:
|
||||||
self.stdout.write("Admin user successfully reset.")
|
self.stdout.write(self.style.SUCCESS("Admin user successfully reset."))
|
||||||
|
@ -22,6 +22,7 @@ from openslides.utils.manager import BaseManager
|
|||||||
|
|
||||||
from ..core.config import config
|
from ..core.config import config
|
||||||
from ..utils.auth import GROUP_ADMIN_PK
|
from ..utils.auth import GROUP_ADMIN_PK
|
||||||
|
from ..utils.autoupdate import inform_changed_data
|
||||||
from ..utils.models import (
|
from ..utils.models import (
|
||||||
CASCADE_AND_AUTOUPDATE,
|
CASCADE_AND_AUTOUPDATE,
|
||||||
SET_NULL_AND_AUTOUPDATE,
|
SET_NULL_AND_AUTOUPDATE,
|
||||||
@ -87,6 +88,8 @@ class UserManager(BaseUserManager):
|
|||||||
admin.password = make_password(admin.default_password)
|
admin.password = make_password(admin.default_password)
|
||||||
admin.save(skip_autoupdate=skip_autoupdate)
|
admin.save(skip_autoupdate=skip_autoupdate)
|
||||||
admin.groups.add(GROUP_ADMIN_PK)
|
admin.groups.add(GROUP_ADMIN_PK)
|
||||||
|
if not skip_autoupdate:
|
||||||
|
inform_changed_data(admin)
|
||||||
return created
|
return created
|
||||||
|
|
||||||
def generate_username(self, first_name, last_name):
|
def generate_username(self, first_name, last_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user