Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Fix first OIDC user ownership

luci784e424b148b
diff --git a/backend/__init__.py b/backend/__init__.py
index c5f99bc..63f7d90 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -80,7 +80,7 @@ def ensure_owner_exists():
# Promote the user to owner if found
if first_user_id is not None:
try:
- cur.execute("UPDATE users SET is_owner = TRUE WHERE id = %s", (first_user_id,))
+ cur.execute("UPDATE users SET is_owner = TRUE, is_admin = TRUE WHERE id = %s", (first_user_id,))
conn.commit()
logger.info(f"✅ Automatically promoted user ID {first_user_id} to application owner")
diff --git a/backend/oidc_handler.py b/backend/oidc_handler.py
index a740c0d..622a1a3 100644
--- a/backend/oidc_handler.py
+++ b/backend/oidc_handler.py
@@ -292,11 +292,14 @@ def oidc_callback_route():
elif is_first_user_admin:
logger.info(f"[OIDC_HANDLER] Granting admin rights to new OIDC user {oidc_user_email_lower} as they are the first user.")
+ is_owner = user_count == 0
+ is_admin = is_admin or is_owner
+
# Insert new OIDC user
cur.execute(
- """INSERT INTO users (username, email, first_name, last_name, is_admin, oidc_sub, oidc_issuer, is_active)
- VALUES (%s, %s, %s, %s, %s, %s, %s, TRUE) RETURNING id""",
- (username, email, first_name, last_name, is_admin, oidc_subject, oidc_issuer)
+ """INSERT INTO users (username, email, first_name, last_name, is_admin, is_owner, oidc_sub, oidc_issuer, is_active)
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, TRUE) RETURNING id""",
+ (username, email, first_name, last_name, is_admin, is_owner, oidc_subject, oidc_issuer)
)
user_id = cur.fetchone()[0]
logger.info(f"[OIDC_HANDLER] New OIDC user created with ID {user_id} for sub {oidc_subject}")