change user_name still used as login and add display_name for dashboard view instead of username on login
This commit is contained in:
1 parent
7a562c18ec
commit
11b0ca26a5
33 files changed
+180
-145
No files matched your search
@@ -7,7 +7,7 @@ from apps.accounts.models import ApiKey, User
|
||||
|
||||
def ensure_bootstrap_user(
|
||||
*,
|
||||
user_login: str,
|
||||
user_name: str,
|
||||
password: str,
|
||||
status: str,
|
||||
is_superuser: bool,
|
||||
@@ -15,9 +15,9 @@ def ensure_bootstrap_user(
|
||||
stdout,
|
||||
) -> User:
|
||||
user, created = User.objects.get_or_create(
|
||||
user_login=user_login,
|
||||
user_name=user_name,
|
||||
defaults={
|
||||
"user_name": user_login,
|
||||
"display_name": user_name,
|
||||
"status": status,
|
||||
"is_superuser": is_superuser,
|
||||
},
|
||||
@@ -25,7 +25,7 @@ def ensure_bootstrap_user(
|
||||
|
||||
if not created and user.status != status:
|
||||
stdout.write(
|
||||
f"Updating {user_login!r} status {user.status!r} → {status!r}"
|
||||
f"Updating {user_name!r} status {user.status!r} → {status!r}"
|
||||
)
|
||||
|
||||
should_set_password = created or not user.has_usable_password() or force_password
|
||||
@@ -35,12 +35,12 @@ def ensure_bootstrap_user(
|
||||
user.is_superuser = is_superuser
|
||||
user.save()
|
||||
action = "Created" if created else "Updated password for"
|
||||
stdout.write(f"{action} {status} user {user_login}")
|
||||
stdout.write(f"{action} {status} user {user_name}")
|
||||
else:
|
||||
user.status = status
|
||||
user.is_superuser = is_superuser
|
||||
user.save(update_fields=["status", "is_superuser", "updated_at"])
|
||||
stdout.write(f"User {user_login} already exists (password unchanged)")
|
||||
stdout.write(f"User {user_name} already exists (password unchanged)")
|
||||
|
||||
return user
|
||||
|
||||
@@ -71,7 +71,7 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
admin = ensure_bootstrap_user(
|
||||
user_login=admin_user_name,
|
||||
user_name=admin_user_name,
|
||||
password=admin_password,
|
||||
status=User.STATUS_SUPERUSER,
|
||||
is_superuser=True,
|
||||
@@ -91,7 +91,7 @@ class Command(BaseCommand):
|
||||
"BOOTSTRAP_STAFF_PASSWORD is required when BOOTSTRAP_STAFF_USER is set."
|
||||
)
|
||||
ensure_bootstrap_user(
|
||||
user_login=staff_user_name,
|
||||
user_name=staff_user_name,
|
||||
password=staff_password,
|
||||
status=User.STATUS_GM,
|
||||
is_superuser=False,
|
||||
|
||||
@@ -75,10 +75,10 @@ class Command(BaseCommand):
|
||||
defaults["managed_by"] = managed_by
|
||||
|
||||
user, created = User.objects.get_or_create(
|
||||
user_login=spec["user_name"],
|
||||
user_name=spec["user_name"],
|
||||
defaults={
|
||||
**defaults,
|
||||
"user_name": spec["user_name"],
|
||||
"display_name": spec["user_name"],
|
||||
},
|
||||
)
|
||||
user.status = spec["status"]
|
||||
@@ -93,7 +93,7 @@ class Command(BaseCommand):
|
||||
role = spec["status"]
|
||||
if user.is_superuser:
|
||||
role = f"{role}+superuser"
|
||||
link = f", managed_by={managed_by.user_name}" if managed_by else ""
|
||||
link = f", managed_by={managed_by.display_name}" if managed_by else ""
|
||||
action = "Created" if created else "Updated"
|
||||
self.stdout.write(
|
||||
f"{action} user {spec['user_name']} / {spec['password']} ({role}{link})"
|
||||
@@ -102,8 +102,8 @@ class Command(BaseCommand):
|
||||
|
||||
def _remove_legacy_staff(self, gm: User) -> None:
|
||||
staff = (
|
||||
User.objects.filter(user_login="staff").first()
|
||||
or User.objects.filter(user_name="staff").first()
|
||||
User.objects.filter(user_name="staff").first()
|
||||
or User.objects.filter(display_name="staff").first()
|
||||
)
|
||||
if not staff:
|
||||
return
|
||||
|
||||
@@ -186,7 +186,7 @@ class Command(BaseCommand):
|
||||
if site.user_id != user.pk:
|
||||
site.user = user
|
||||
site.save(update_fields=["user", "updated_at"])
|
||||
self.stdout.write(f"Sukawarna site owner: {user.user_name} ({user.status})")
|
||||
self.stdout.write(f"Sukawarna site owner: {user.display_name} ({user.status})")
|
||||
|
||||
kandang, _ = Kandang.objects.get_or_create(
|
||||
kandang_name="Kandang 1",
|
||||
|
||||
@@ -73,7 +73,7 @@ class Command(BaseCommand):
|
||||
if site.user_id != user.pk:
|
||||
site.user = user
|
||||
site.save(update_fields=["user", "updated_at"])
|
||||
self.stdout.write(f"Sukawarna site owner: {user.user_name} ({user.status})")
|
||||
self.stdout.write(f"Sukawarna site owner: {user.display_name} ({user.status})")
|
||||
|
||||
kandang, _ = Kandang.objects.get_or_create(
|
||||
kandang_name="Kandang 2",
|
||||
|
||||
Reference in new issue
Block a user