feat: Nutzerdetails (Telefon/Adresse) + Formular-Fix bei Passwortfehler in /admin/users

This commit is contained in:
mscadm 2026-07-13 15:43:09 +00:00
parent 91f6cd82e4
commit 13616c9006
1 changed files with 22 additions and 8 deletions

30
db.py
View File

@ -104,13 +104,15 @@ def update_tenant_settings(tenant_id, dsb_name, dsb_email, retention_tickets_day
# ── Users ─────────────────────────────────────────────────────────────────────── # ── Users ───────────────────────────────────────────────────────────────────────
def create_user(tenant_id, email, password_hash, role="admin"): def create_user(tenant_id, email, password_hash, role="admin",
vorname=None, nachname=None, telefon=None, abteilung=None, adresse=None):
with get_conn() as conn: with get_conn() as conn:
with _dict_cursor(conn) as cur: with _dict_cursor(conn) as cur:
cur.execute( cur.execute(
"""INSERT INTO users (tenant_id, email, password_hash, role) """INSERT INTO users (tenant_id, email, password_hash, role,
VALUES (%s,%s,%s,%s) RETURNING id""", vorname, nachname, telefon, abteilung, adresse)
(tenant_id, email, password_hash, role), VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id""",
(tenant_id, email, password_hash, role, vorname, nachname, telefon, abteilung, adresse),
) )
return cur.fetchone()["id"] return cur.fetchone()["id"]
@ -135,12 +137,15 @@ def email_exists(email):
return cur.fetchone() is not None return cur.fetchone() is not None
_USER_COLUMNS = ("id, email, role, active, auth_source, created_at, last_login_at, "
"vorname, nachname, telefon, abteilung, adresse")
def list_users(tenant_id): def list_users(tenant_id):
with get_conn() as conn: with get_conn() as conn:
with _dict_cursor(conn) as cur: with _dict_cursor(conn) as cur:
cur.execute( cur.execute(
"SELECT id, email, role, active, auth_source, created_at, last_login_at " "SELECT %s FROM users WHERE tenant_id=%%s ORDER BY email" % _USER_COLUMNS, (tenant_id,))
"FROM users WHERE tenant_id=%s ORDER BY email", (tenant_id,))
return cur.fetchall() return cur.fetchall()
@ -148,11 +153,20 @@ def get_user(tenant_id, user_id):
with get_conn() as conn: with get_conn() as conn:
with _dict_cursor(conn) as cur: with _dict_cursor(conn) as cur:
cur.execute( cur.execute(
"SELECT id, email, role, active, auth_source, created_at, last_login_at " "SELECT %s FROM users WHERE tenant_id=%%s AND id=%%s" % _USER_COLUMNS, (tenant_id, user_id))
"FROM users WHERE tenant_id=%s AND id=%s", (tenant_id, user_id))
return cur.fetchone() return cur.fetchone()
def update_user_profile(tenant_id, user_id, vorname, nachname, telefon, abteilung, adresse):
with get_conn() as conn:
with conn.cursor() as cur:
cur.execute(
"""UPDATE users SET vorname=%s, nachname=%s, telefon=%s, abteilung=%s, adresse=%s
WHERE tenant_id=%s AND id=%s""",
(vorname, nachname, telefon, abteilung, adresse, tenant_id, user_id),
)
def set_user_role(tenant_id, user_id, role): def set_user_role(tenant_id, user_id, role):
with get_conn() as conn: with get_conn() as conn:
with conn.cursor() as cur: with conn.cursor() as cur: