update erd db and add display name to user access table
This commit is contained in:
1 parent
ed84d989b7
commit
ae2ea27ae2
13 files changed
+91
-10
No files matched your search
@@ -18,6 +18,7 @@ def ensure_bootstrap_user(
|
||||
user, created = User.objects.get_or_create(
|
||||
user_name=user_name,
|
||||
defaults={
|
||||
"display_name": user_name,
|
||||
"status": status,
|
||||
"is_staff": is_staff,
|
||||
"is_superuser": is_superuser,
|
||||
@@ -31,6 +32,8 @@ def ensure_bootstrap_user(
|
||||
)
|
||||
|
||||
should_set_password = created or not user.has_usable_password() or force_password
|
||||
if not (user.display_name or "").strip():
|
||||
user.display_name = user_name
|
||||
if should_set_password:
|
||||
user.set_password(password)
|
||||
user.status = status
|
||||
@@ -43,7 +46,9 @@ def ensure_bootstrap_user(
|
||||
user.status = status
|
||||
user.is_staff = is_staff
|
||||
user.is_superuser = is_superuser
|
||||
user.save(update_fields=["status", "is_staff", "is_superuser", "updated_at"])
|
||||
user.save(
|
||||
update_fields=["display_name", "status", "is_staff", "is_superuser", "updated_at"]
|
||||
)
|
||||
stdout.write(f"User {user_name} already exists (password unchanged)")
|
||||
|
||||
return user
|
||||
|
||||
@@ -16,13 +16,23 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
user, created = User.objects.get_or_create(
|
||||
user_name="admin",
|
||||
defaults={"status": User.STATUS_SUPERADMIN, "is_staff": True, "is_superuser": True},
|
||||
defaults={
|
||||
"display_name": "Admin",
|
||||
"status": User.STATUS_SUPERADMIN,
|
||||
"is_staff": True,
|
||||
"is_superuser": True,
|
||||
},
|
||||
)
|
||||
if created or not user.has_usable_password():
|
||||
user.set_password("admin123")
|
||||
user.status = User.STATUS_SUPERADMIN
|
||||
if not (user.display_name or "").strip():
|
||||
user.display_name = "Admin"
|
||||
user.save()
|
||||
self.stdout.write("Created/updated user admin / admin123")
|
||||
elif not (user.display_name or "").strip():
|
||||
user.display_name = "Admin"
|
||||
user.save(update_fields=["display_name", "updated_at"])
|
||||
|
||||
raw_key = None
|
||||
bootstrap = settings.BOOTSTRAP_API_KEY
|
||||
|
||||
@@ -178,10 +178,16 @@ class Command(BaseCommand):
|
||||
|
||||
user, created = User.objects.get_or_create(
|
||||
user_name="staff",
|
||||
defaults={"status": User.STATUS_ACTIVE, "is_staff": True},
|
||||
defaults={
|
||||
"display_name": "Staff",
|
||||
"status": User.STATUS_ACTIVE,
|
||||
"is_staff": True,
|
||||
},
|
||||
)
|
||||
user.status = User.STATUS_ACTIVE
|
||||
user.is_staff = True
|
||||
if not (user.display_name or "").strip():
|
||||
user.display_name = "Staff"
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
if created:
|
||||
|
||||
@@ -65,10 +65,16 @@ class Command(BaseCommand):
|
||||
|
||||
user, created = User.objects.get_or_create(
|
||||
user_name="staff",
|
||||
defaults={"status": User.STATUS_ACTIVE, "is_staff": True},
|
||||
defaults={
|
||||
"display_name": "Staff",
|
||||
"status": User.STATUS_ACTIVE,
|
||||
"is_staff": True,
|
||||
},
|
||||
)
|
||||
user.status = User.STATUS_ACTIVE
|
||||
user.is_staff = True
|
||||
if not (user.display_name or "").strip():
|
||||
user.display_name = "Staff"
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
if created:
|
||||
|
||||
Reference in new issue
Block a user