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

+2 -2
View File
@@ -21,7 +21,7 @@ from psycopg import Connection
from app.access.policy import ensure_member_or_personal
from app.auth.security import hash_secret, read_session_token
from app.core.errors import forbidden, password_change_required, unauthorized
from app.core.errors import forbidden, password_change_required, scope_changed, unauthorized
from app.core.timeutil import utcnow
@@ -108,7 +108,7 @@ def get_principal(request: Request, conn: Connection = Depends(get_conn)) -> Pri
except ValueError as exc:
raise forbidden("Der Datenraum ist nicht gewählt.") from exc
if kind != row["scope_kind"] or scope_id != row["scope_id"]:
raise forbidden("Der gewählte Datenraum entspricht nicht mehr der Sitzung.")
raise scope_changed()
room = ensure_member_or_personal(conn, row["account_id"], kind, scope_id)
return Principal(
account_id=row["account_id"],
+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)
+84 -36
View File
@@ -1,55 +1,94 @@
"""Room share of a case or matter: shared with the room members by role, or private."""
"""Room shares of a case or matter. A room is a team: the owner shares an entry with any of the
rooms he is a member of, independent of where the entry is filed."""
from __future__ import annotations
from uuid import UUID
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Response
from fastapi.responses import JSONResponse
from psycopg import Connection
from app.access.policy import ROOM_RIGHTS
from app.access.policy import ROOM_RIGHTS, Rights
from app.api.deps import Principal, get_conn, get_principal
from app.api.schemas import ExclusionIn, VisibilityIn
from app.ops import _shareable, set_person_exclusion, set_visibility
from app.api.schemas import ExclusionIn, RoomShareIn
from app.ops import _shareable, set_person_exclusion, share_with_room, unshare_from_room
router = APIRouter()
_NO_STORE = {"Cache-Control": "no-store"}
def _capped(role: str, access: str) -> Rights:
rights = ROOM_RIGHTS.get(role, Rights())
return Rights(read=rights.read) if access == "read" else rights
def _view(conn, actor: UUID, kind: str, resource_id: UUID) -> dict:
resource = _shareable(conn, actor, kind, resource_id)
members = conn.execute(
_shareable(conn, actor, kind, resource_id)
shares = conn.execute(
"""
SELECT m.subject_id, m.role, a.display_name,
EXISTS (
SELECT 1 FROM access_grants g
WHERE g.is_exception AND g.grantee_subject_id = m.subject_id
AND g.resource_kind = %s AND g.resource_id = %s AND g.context_kind IS NULL
) AS excluded
FROM room_memberships m
JOIN auth_accounts a ON a.id = m.subject_id
WHERE m.room_id = %s AND m.status = 'active' AND m.subject_id <> %s
ORDER BY a.display_name, a.id
SELECT s.room_id, s.access, r.name, r.status
FROM room_shares s JOIN data_rooms r ON r.id = s.room_id
WHERE s.resource_kind = %s AND s.resource_id = %s
ORDER BY r.name, r.id
""",
(kind, resource_id, resource["home_scope_id"], actor),
(kind, resource_id),
).fetchall()
result = []
for share in shares:
members = conn.execute(
"""
SELECT m.subject_id, m.role, a.display_name,
EXISTS (
SELECT 1 FROM access_grants g
WHERE g.is_exception AND g.grantee_subject_id = m.subject_id
AND g.resource_kind = %s AND g.resource_id = %s AND g.context_kind IS NULL
) AS excluded
FROM room_memberships m
JOIN auth_accounts a ON a.id = m.subject_id
WHERE m.room_id = %s AND m.status = 'active' AND m.subject_id <> %s
ORDER BY a.display_name, a.id
""",
(kind, resource_id, share["room_id"], actor),
).fetchall()
result.append(
{
"room_id": str(share["room_id"]),
"room_name": share["name"],
"archived": share["status"] != "active",
"access": share["access"],
"members": [
{
"subject_id": str(row["subject_id"]),
"display_name": row["display_name"],
"role": row["role"],
"excluded": row["excluded"],
"rights": {
"read": _capped(row["role"], share["access"]).read,
"edit": _capped(row["role"], share["access"]).edit,
},
}
for row in members
],
}
)
shared_ids = {item["room_id"] for item in result}
candidates = conn.execute(
"""
SELECT r.id, r.name, m.role
FROM room_memberships m JOIN data_rooms r ON r.id = m.room_id
WHERE m.subject_id = %s AND m.status = 'active' AND m.role IN ('member', 'manager')
AND r.kind = 'organization' AND r.status = 'active'
ORDER BY r.name, r.id
""",
(actor,),
).fetchall()
return {
"id": str(resource_id),
"visibility": resource["visibility"],
"members": [
{
"subject_id": str(row["subject_id"]),
"display_name": row["display_name"],
"role": row["role"],
"excluded": row["excluded"],
"rights": {
"read": ROOM_RIGHTS[row["role"]].read if row["role"] in ROOM_RIGHTS else False,
"edit": ROOM_RIGHTS[row["role"]].edit if row["role"] in ROOM_RIGHTS else False,
},
}
for row in members
"shares": result,
"available": [
{"id": str(row["id"]), "name": row["name"]} for row in candidates if str(row["id"]) not in shared_ids
],
}
@@ -61,14 +100,25 @@ def _register(kind: str, plural: str) -> None:
def get_share(resource_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
return JSONResponse(_view(conn, principal.account_id, kind, resource_id), headers=_NO_STORE)
@router.put(base, name=f"put_{kind}_room_share")
@router.put(base + "/rooms/{room_id}", name=f"put_{kind}_room_share")
def put_share(
resource_id: UUID,
body: VisibilityIn,
room_id: UUID,
body: RoomShareIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return set_visibility(conn, principal.account_id, kind, resource_id, body.visibility)
return share_with_room(conn, principal.account_id, kind, resource_id, room_id, body.access)
@router.delete(base + "/rooms/{room_id}", status_code=204, name=f"delete_{kind}_room_share")
def delete_share(
resource_id: UUID,
room_id: UUID,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
unshare_from_room(conn, principal.account_id, kind, resource_id, room_id)
return Response(status_code=204)
@router.put(base + "/people/{subject_id}", name=f"put_{kind}_room_share_person")
def put_person(
@@ -84,5 +134,3 @@ def _register(kind: str, plural: str) -> None:
_register("case", "cases")
_register("matter", "matters")
+4
View File
@@ -72,6 +72,10 @@ class VisibilityIn(APIModel):
visibility: Literal["private", "room"]
class RoomShareIn(APIModel):
access: Literal["read", "edit"] = "edit"
class ExclusionIn(APIModel):
excluded: bool