Fix superadmin matching: case-insensitive username/email lookup

Azure AD returns mixed-case usernames (VadymSamoilenko) but
superadmin was created with lowercase. Use LOWER() for matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
SamoilenkoVadym 2026-02-09 21:57:49 +00:00
parent c59db0e9fd
commit f5cb1170bb

View file

@ -157,10 +157,13 @@ class Database:
logger.error(f"Error creating test user: {e}")
def _create_superadmin(self, conn: sqlite3.Connection, email: str):
"""Create or promote superadmin user."""
"""Create or promote superadmin user (case-insensitive match)."""
try:
username = email.split('@')[0]
cursor = conn.execute('SELECT id, role FROM users WHERE username = ? OR email = ?', (username, email))
cursor = conn.execute(
'SELECT id, role FROM users WHERE LOWER(username) = LOWER(?) OR LOWER(email) = LOWER(?)',
(username, email),
)
row = cursor.fetchone()
if row:
if row['role'] != 'admin':