Mache Datenräume zu Teams, damit Akten und Vorgänge mit beliebigen Räumen geteilt werden können.
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 4m51s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 21s

Die Raumfreigabe hängt nicht mehr am Heimatraum. Der Owner teilt eine Akte, Unterakte oder einen Vorgang mit jedem Raum, in dem er schreiben darf; die Mitglieder erhalten Rechte nach ihrer Rolle, begrenzbar auf nur lesen, mit Personenausnahme. Ein einzelner Vorgang lässt sich teilen, ohne die Akte oder die anderen Vorgänge offenzulegen. Wer ein Team verlässt oder Leser wird, nimmt seine Freigaben mit; wer entfernt wird, arbeitet danach im persönlichen Raum und sieht weiter alles, was ihm gehört. Der Heimatraum ist nur noch Ablage.

Die Migration übernimmt die bisherigen Raumfreigaben in die neue Tabelle room_shares und wurde mit Bestandsdaten geprüft. Die Sitzung meldet einen Raumwechsel jetzt mit eigenem Fehlercode, die Oberfläche lädt sie dann neu.

Die lokale Suite läuft mit 132 Tests grün, der Frontend-Build 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:
LarsandClaude Sonnet 5.5 committed 2026-10-20 21:51:49 +02:00
1 parent 1c2f045e7d
commit 21c2d05fb8
19 files changed
+634 -297

No files matched your search

+71 -23
View File
@@ -95,6 +95,21 @@ def _drop_edit_rights_in_room(conn, subject_id: UUID, room_id: UUID) -> None:
)
def _drop_shares_of(conn, room_id: UUID, subject_id: UUID) -> None:
"""Whoever leaves a team, or may no longer write in it, takes the shares of their own entries with them."""
conn.execute(
"""
DELETE FROM room_shares s
WHERE s.room_id = %s
AND (
(s.resource_kind = 'case' AND s.resource_id IN (SELECT id FROM cases WHERE owner_subject_id = %s))
OR (s.resource_kind = 'matter' AND s.resource_id IN (SELECT id FROM matters WHERE owner_subject_id = %s))
)
""",
(room_id, subject_id, subject_id),
)
def _set_role(conn, actor: UUID, room_id: UUID, subject_id: UUID, role: str, *, added: bool) -> None:
if role not in ROOM_ROLES:
raise unprocessable("Diese Raumrolle gibt es nicht.")
@@ -108,6 +123,7 @@ def _set_role(conn, actor: UUID, room_id: UUID, subject_id: UUID, role: str, *,
)
if role == "reader":
_drop_edit_rights_in_room(conn, subject_id, room_id)
_drop_shares_of(conn, room_id, subject_id)
_audit_membership(conn, actor, room_id, subject_id, "membership_added" if added else "membership_role_changed", role)
@@ -270,23 +286,27 @@ def transfer_owner(
@router.get("/api/v1/rooms/{room_id}/exposure")
def exposure(room_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
"""How many of the own cases and matters in this room are private or shared with the room."""
"""Own cases and matters: shared with this room (`room`) or filed here but not shared (`private`)."""
_room(conn, room_id)
if room_role(conn, principal.account_id, room_id) is None:
raise forbidden()
result: dict = {}
for table, key in (("cases", "cases"), ("matters", "matters")):
rows = conn.execute(
for table, kind in (("cases", "case"), ("matters", "matter")):
row = conn.execute(
f"""
SELECT visibility, count(*) AS n FROM {table}
WHERE home_scope_id = %s AND owner_subject_id = %s AND deleted_at IS NULL
GROUP BY visibility
SELECT
count(*) FILTER (WHERE EXISTS (
SELECT 1 FROM room_shares s
WHERE s.resource_kind = %s AND s.resource_id = t.id AND s.room_id = %s)) AS shared,
count(*) FILTER (WHERE t.home_scope_id = %s AND NOT EXISTS (
SELECT 1 FROM room_shares s
WHERE s.resource_kind = %s AND s.resource_id = t.id AND s.room_id = %s)) AS filed
FROM {table} t
WHERE t.owner_subject_id = %s AND t.deleted_at IS NULL
""",
(room_id, principal.account_id),
).fetchall()
counts = {"private": 0, "room": 0}
counts.update({row["visibility"]: row["n"] for row in rows})
result[key] = counts
(kind, room_id, room_id, kind, room_id, principal.account_id),
).fetchone()
result[table] = {"room": row["shared"], "private": row["filed"]}
return JSONResponse(result, headers=_NO_STORE)
@@ -297,21 +317,39 @@ def set_my_content(
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
"""Set the room share of every own case and matter in this room at once."""
"""`room`: share every own entry filed in this room with it. `private`: end all own shares to it."""
_room(conn, room_id)
if room_role(conn, principal.account_id, room_id) is None:
role = room_role(conn, principal.account_id, room_id)
if role is None:
raise forbidden()
changed = 0
for table in ("cases", "matters"):
rows = conn.execute(
f"""
UPDATE {table} SET visibility = %s
WHERE home_scope_id = %s AND owner_subject_id = %s AND deleted_at IS NULL AND visibility <> %s
RETURNING id
""",
(body.visibility, room_id, principal.account_id, body.visibility),
).fetchall()
changed += len(rows)
if body.visibility == "room":
if role not in {"member", "manager"}:
raise forbidden("Als Leser kannst du nichts mit dem Datenraum teilen.")
for table, kind in (("cases", "case"), ("matters", "matter")):
rows = conn.execute(
f"""
INSERT INTO room_shares (resource_kind, resource_id, room_id, access, created_by)
SELECT %s, t.id, %s, 'edit', %s FROM {table} t
WHERE t.home_scope_id = %s AND t.owner_subject_id = %s AND t.deleted_at IS NULL
ON CONFLICT DO NOTHING
RETURNING id
""",
(kind, room_id, principal.account_id, room_id, principal.account_id),
).fetchall()
changed += len(rows)
else:
for table, kind in (("cases", "case"), ("matters", "matter")):
rows = conn.execute(
f"""
DELETE FROM room_shares s
WHERE s.room_id = %s AND s.resource_kind = %s
AND s.resource_id IN (SELECT id FROM {table} WHERE owner_subject_id = %s)
RETURNING s.id
""",
(room_id, kind, principal.account_id),
).fetchall()
changed += len(rows)
if changed:
audit(
conn,
@@ -417,6 +455,16 @@ def remove_member(
"UPDATE room_memberships SET status = 'removed' WHERE room_id = %s AND subject_id = %s",
(room_id, subject_id),
)
_drop_shares_of(conn, room_id, subject_id)
# The removed person works in the personal room again; own entries stay visible there.
conn.execute(
"""
UPDATE auth_sessions
SET scope_kind = 'personal', scope_id = account_id, epoch = epoch + 1
WHERE account_id = %s AND scope_id = %s AND revoked_at IS NULL
""",
(subject_id, room_id),
)
_audit_membership(conn, principal.account_id, room_id, subject_id, "membership_removed")
return Response(status_code=204)