Führe Hauptnutzer und Mitarbeiter ein, damit der Betreiber Kunden und Hauptnutzer ihre Teams verwalten.
Eine Einladung erzeugt jetzt ein Mitarbeiter-Konto mit dem Eigentümer des Raums als Förderer. Mitarbeiter arbeiten nur in den eingeladenen Räumen nach ihrer Rolle, legen keine Räume und im persönlichen Raum nichts an und starten ihre Sitzung im Team-Raum. Einladen darf nur der Eigentümer als Hauptnutzer; nur ein Hauptnutzer kann Raum-Eigentümer sein. Hauptnutzer sehen unter Mein Team die Personen in ihren Räumen und verwalten ihre Mitarbeiter (deaktivieren, Einmal-Passwort, aus Räumen entfernen). Der Betreiber sieht die Team-Übersicht mit CSV-Export und macht einen Mitarbeiter zum Hauptnutzer. Eine zentrale Prüfstelle für Grenzen (access/limits.py) wird beim Anlegen von Räumen und beim Aufnehmen und Einladen von Mitgliedern aufgerufen; Tarife folgen später. Die lokale Suite läuft mit 143 Tests grün, der Frontend-Build und 24 Node-Tests ebenfalls. Die Oberfläche wurde noch nicht im Browser bedient. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e47f50d513
commit
6d7b7c5f85
26 files changed
+966
-43
No files matched your search
@@ -46,11 +46,15 @@ def create_account(
|
||||
is_superadmin: bool = False,
|
||||
origin: str = "operator",
|
||||
must_change_password: bool = False,
|
||||
account_kind: str = "main",
|
||||
sponsor_id: UUID | None = None,
|
||||
) -> dict:
|
||||
email = normalize_email(email)
|
||||
display_name = display_name.strip()
|
||||
if origin not in {"operator", "fixture"}:
|
||||
raise unprocessable("Die Kontenherkunft ist ungültig.")
|
||||
if account_kind not in {"main", "employee"} or (account_kind == "employee") != (sponsor_id is not None):
|
||||
raise unprocessable("Die Kontoart ist ungültig.")
|
||||
check_password_policy(password)
|
||||
if conn.execute("SELECT 1 FROM auth_accounts WHERE email = %s", (email,)).fetchone():
|
||||
raise unprocessable("Für diese E-Mail gibt es bereits ein Konto.")
|
||||
@@ -60,11 +64,14 @@ def create_account(
|
||||
"""
|
||||
INSERT INTO auth_accounts (
|
||||
id, email, display_name, password_hash, is_superadmin, origin,
|
||||
must_change_password, password_changed_at
|
||||
must_change_password, password_changed_at, account_kind, sponsor_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, now())
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, now(), %s, %s)
|
||||
""",
|
||||
(account_id, email, display_name, password_hash, is_superadmin, origin, must_change_password),
|
||||
(
|
||||
account_id, email, display_name, password_hash, is_superadmin, origin,
|
||||
must_change_password, account_kind, sponsor_id,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -75,25 +82,54 @@ def create_account(
|
||||
)
|
||||
return conn.execute(
|
||||
"""
|
||||
SELECT id, email, display_name, is_superadmin, status, must_change_password
|
||||
SELECT id, email, display_name, is_superadmin, status, must_change_password, account_kind
|
||||
FROM auth_accounts WHERE id = %s
|
||||
""",
|
||||
(account_id,),
|
||||
).fetchone()
|
||||
|
||||
|
||||
def promote_to_main(conn, actor: UUID, account_id: UUID) -> None:
|
||||
"""Only the operator turns an employee into a main user."""
|
||||
account = _account(conn, account_id, lock=True)
|
||||
if account["account_kind"] == "main":
|
||||
return
|
||||
conn.execute("UPDATE auth_accounts SET account_kind = 'main', sponsor_id = NULL WHERE id = %s", (account_id,))
|
||||
# A raised kind starts from a fresh login.
|
||||
revoke_sessions(conn, account_id)
|
||||
audit(conn, actor, None, "employee_promoted", "account", account_id)
|
||||
|
||||
|
||||
def initial_scope(conn, account_id: UUID) -> tuple[str, UUID]:
|
||||
"""Where a new session starts: the personal room, or for an employee the first team room."""
|
||||
account = conn.execute("SELECT account_kind FROM auth_accounts WHERE id = %s", (account_id,)).fetchone()
|
||||
if account is not None and account["account_kind"] == "employee":
|
||||
room = conn.execute(
|
||||
"""
|
||||
SELECT r.id FROM room_memberships m JOIN data_rooms r ON r.id = m.room_id
|
||||
WHERE m.subject_id = %s AND m.status = 'active' AND r.kind = 'organization' AND r.status = 'active'
|
||||
ORDER BY r.name, r.id LIMIT 1
|
||||
""",
|
||||
(account_id,),
|
||||
).fetchone()
|
||||
if room is not None:
|
||||
return "organization", room["id"]
|
||||
return "personal", account_id
|
||||
|
||||
|
||||
def start_session(conn, settings: Settings, account_id: UUID, label: str | None = None) -> tuple[str, str]:
|
||||
token = new_secret()
|
||||
csrf = new_secret()
|
||||
scope_kind, scope_id = initial_scope(conn, account_id)
|
||||
session = conn.execute(
|
||||
"""
|
||||
INSERT INTO auth_sessions (
|
||||
account_id, secret_hash, csrf_token, scope_kind, scope_id, expires_at, label, last_seen_at
|
||||
)
|
||||
VALUES (%s, %s, %s, 'personal', %s, %s, %s, now())
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, now())
|
||||
RETURNING id
|
||||
""",
|
||||
(account_id, hash_secret(token), csrf, account_id, session_expiry(settings), (label or None) and label[:80]),
|
||||
(account_id, hash_secret(token), csrf, scope_kind, scope_id, session_expiry(settings), (label or None) and label[:80]),
|
||||
).fetchone()
|
||||
conn.execute("UPDATE auth_accounts SET last_login_at = now() WHERE id = %s", (account_id,))
|
||||
audit(conn, account_id, None, "session_started", "session", session["id"])
|
||||
|
||||
Reference in new issue
Block a user