claim default campaign for the admin on startup so setup wizard works
Some checks failed
Build and Push / build (push) Has been cancelled
Some checks failed
Build and Push / build (push) Has been cancelled
This commit is contained in:
@@ -90,11 +90,19 @@ def get_user_from_token(token: str) -> Optional[dict]:
|
|||||||
|
|
||||||
|
|
||||||
def ensure_admin_exists():
|
def ensure_admin_exists():
|
||||||
"""Called on startup — creates the admin user if no users exist."""
|
"""Called on startup — creates the admin user if no users exist,
|
||||||
|
and ensures the 'default' campaign is owned by the admin."""
|
||||||
conn = db.get_conn()
|
conn = db.get_conn()
|
||||||
row = conn.execute("SELECT COUNT(*) as cnt FROM users").fetchone()
|
row = conn.execute("SELECT COUNT(*) as cnt FROM users").fetchone()
|
||||||
if row["cnt"] > 0:
|
if row["cnt"] == 0:
|
||||||
return
|
|
||||||
pw = ADMIN_PASSWORD or os.urandom(8).hex()
|
pw = ADMIN_PASSWORD or os.urandom(8).hex()
|
||||||
db.create_user(ADMIN_USERNAME, hash_password(pw), is_admin=True)
|
db.create_user(ADMIN_USERNAME, hash_password(pw), is_admin=True)
|
||||||
print(f"[auth] Created admin user '{ADMIN_USERNAME}' (password: {pw})")
|
print(f"[auth] Created admin user '{ADMIN_USERNAME}' (password: {pw})")
|
||||||
|
|
||||||
|
# Claim the "default" campaign for the admin so setup wizard works
|
||||||
|
admin = db.get_user_by_username(ADMIN_USERNAME)
|
||||||
|
if admin:
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE campaigns SET created_by = ? WHERE id = 'default' AND created_by IS NULL",
|
||||||
|
(admin["id"],),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user