fix: Skip default admin@local.host creation during container startup if an admin user already exists
This commit is contained in:
Binary file not shown.
@@ -13,6 +13,12 @@ class Command(BaseCommand):
|
|||||||
parser.add_argument('--password', type=str, default=os.getenv('ADMIN_PASSWORD', 'adminpassword'), help='Passwort für den Admin')
|
parser.add_argument('--password', type=str, default=os.getenv('ADMIN_PASSWORD', 'adminpassword'), help='Passwort für den Admin')
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
has_existing_admin = User.objects.filter(is_superuser=True).exists() or User.objects.filter(is_admin_user=True).exists()
|
||||||
|
explicit_env_set = bool(os.getenv('ADMIN_USERNAME') or os.getenv('ADMIN_EMAIL'))
|
||||||
|
|
||||||
|
if has_existing_admin and not explicit_env_set and not os.getenv('FORCE_CREATE_ADMIN'):
|
||||||
|
self.stdout.write(self.style.SUCCESS("ℹ️ Mindestens ein Admin-Benutzer existiert bereits. Es wurde kein neuer Standard-Admin ('admin@local.host') erstellt."))
|
||||||
|
else:
|
||||||
username = options['username'] or os.getenv('ADMIN_USERNAME', 'admin')
|
username = options['username'] or os.getenv('ADMIN_USERNAME', 'admin')
|
||||||
email = options['email'] or os.getenv('ADMIN_EMAIL', 'admin@local.host')
|
email = options['email'] or os.getenv('ADMIN_EMAIL', 'admin@local.host')
|
||||||
password = options['password'] or os.getenv('ADMIN_PASSWORD', 'adminpassword')
|
password = options['password'] or os.getenv('ADMIN_PASSWORD', 'adminpassword')
|
||||||
|
|||||||
Reference in New Issue
Block a user