fix: persist preview admin access
This commit is contained in:
@@ -31,9 +31,10 @@ class Command(BaseCommand):
|
||||
user.email = email
|
||||
user.is_staff = True
|
||||
user.is_superuser = True
|
||||
user.is_active = True
|
||||
user.set_password(password)
|
||||
user.save(
|
||||
update_fields=["email", "is_staff", "is_superuser", "password"]
|
||||
update_fields=["email", "is_staff", "is_superuser", "is_active", "password"]
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
@@ -41,9 +42,16 @@ class Command(BaseCommand):
|
||||
)
|
||||
)
|
||||
return
|
||||
fields_to_update = []
|
||||
for field in ("is_staff", "is_superuser", "is_active"):
|
||||
if not getattr(user, field):
|
||||
setattr(user, field, True)
|
||||
fields_to_update.append(field)
|
||||
if fields_to_update:
|
||||
user.save(update_fields=fields_to_update)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"Admin '{username}' already exists; its password was preserved."
|
||||
f"Admin '{username}' is ready; its password was preserved."
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user