fix: persist preview admin access

This commit is contained in:
mohamad
2026-10-29 04:00:21 +08:00
parent 641f4e6cee
commit cb54e96db6
5 changed files with 75 additions and 2 deletions
@@ -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