feat: Nutzerdetails (Telefon/Adresse) + Formular-Fix bei Passwortfehler in /admin/users
This commit is contained in:
parent
91f6cd82e4
commit
13616c9006
30
db.py
30
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue