feat: E-Mail-Adresse bestehender Benutzer aenderbar (mit Eindeutigkeits-Pruefung + Audit-Log)

This commit is contained in:
mscadm 2026-07-13 16:04:14 +00:00
parent 44c5f3089b
commit c2b341316b
1 changed files with 15 additions and 0 deletions

15
db.py
View File

@ -137,6 +137,15 @@ def email_exists(email):
return cur.fetchone() is not None return cur.fetchone() is not None
def email_exists_excluding(email, exclude_user_id):
"""Wie email_exists, aber ignoriert den eigenen Datensatz -- fuer die
Eindeutigkeitspruefung beim Aendern der E-Mail eines bestehenden Nutzers."""
with get_conn() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1 FROM users WHERE email=%s AND id<>%s", (email, exclude_user_id))
return cur.fetchone() is not None
_USER_COLUMNS = ("id, email, role, active, auth_source, created_at, last_login_at, " _USER_COLUMNS = ("id, email, role, active, auth_source, created_at, last_login_at, "
"vorname, nachname, telefon, abteilung, adresse") "vorname, nachname, telefon, abteilung, adresse")
@ -167,6 +176,12 @@ def update_user_profile(tenant_id, user_id, vorname, nachname, telefon, abteilun
) )
def update_user_email(tenant_id, user_id, email):
with get_conn() as conn:
with conn.cursor() as cur:
cur.execute("UPDATE users SET email=%s WHERE tenant_id=%s AND id=%s", (email, 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: