feat: E-Mail-Adresse bestehender Benutzer aenderbar (mit Eindeutigkeits-Pruefung + Audit-Log)
This commit is contained in:
parent
44c5f3089b
commit
c2b341316b
15
db.py
15
db.py
|
|
@ -137,6 +137,15 @@ def email_exists(email):
|
|||
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, "
|
||||
"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):
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
|
|
|||
Loading…
Reference in New Issue