From 13616c9006c8d086444e8b139bffbf28e4986d06 Mon Sep 17 00:00:00 2001 From: mscadm Date: Mon, 13 Jul 2026 15:43:09 +0000 Subject: [PATCH] feat: Nutzerdetails (Telefon/Adresse) + Formular-Fix bei Passwortfehler in /admin/users --- db.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/db.py b/db.py index 04acd88..9349a1f 100644 --- a/db.py +++ b/db.py @@ -104,13 +104,15 @@ def update_tenant_settings(tenant_id, dsb_name, dsb_email, retention_tickets_day # ── 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 _dict_cursor(conn) as cur: cur.execute( - """INSERT INTO users (tenant_id, email, password_hash, role) - VALUES (%s,%s,%s,%s) RETURNING id""", - (tenant_id, email, password_hash, role), + """INSERT INTO users (tenant_id, email, password_hash, role, + vorname, nachname, telefon, abteilung, adresse) + 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"] @@ -135,12 +137,15 @@ def email_exists(email): 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): with get_conn() as conn: with _dict_cursor(conn) as cur: cur.execute( - "SELECT id, email, role, active, auth_source, created_at, last_login_at " - "FROM users WHERE tenant_id=%s ORDER BY email", (tenant_id,)) + "SELECT %s FROM users WHERE tenant_id=%%s ORDER BY email" % _USER_COLUMNS, (tenant_id,)) return cur.fetchall() @@ -148,11 +153,20 @@ def get_user(tenant_id, user_id): with get_conn() as conn: with _dict_cursor(conn) as cur: cur.execute( - "SELECT id, email, role, active, auth_source, created_at, last_login_at " - "FROM users WHERE tenant_id=%s AND id=%s", (tenant_id, user_id)) + "SELECT %s FROM users WHERE tenant_id=%%s AND id=%%s" % _USER_COLUMNS, (tenant_id, user_id)) 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): with get_conn() as conn: with conn.cursor() as cur: