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

+83 -32
View File
@@ -8,7 +8,7 @@ from uuid import UUID, uuid4
from psycopg.types.json import Json
from app.access.roles import ensure_can_create
from app.access.roles import ensure_can_create, room_role
from app.access.policy import (
Ctx,
Rights,
@@ -75,15 +75,27 @@ def _placement(context: Ctx, placement: Ctx | None) -> tuple[Ctx, Ctx]:
def default_visibility(conn, scope_id: UUID) -> str:
"""New cases and matters follow the room preset. The personal room is always private."""
"""Whether new cases and matters are shared with their room at once. The personal room never is."""
room = conn.execute("SELECT kind, default_visibility FROM data_rooms WHERE id = %s", (scope_id,)).fetchone()
if room is not None and room["kind"] == "organization" and room["default_visibility"] == "room":
return "room"
return "private"
def _auto_share(conn, actor: UUID, kind: str, resource: dict) -> None:
if default_visibility(conn, resource["home_scope_id"]) == "room":
conn.execute(
"""
INSERT INTO room_shares (resource_kind, resource_id, room_id, access, created_by)
VALUES (%s, %s, %s, 'edit', %s)
ON CONFLICT DO NOTHING
""",
(kind, resource["id"], resource["home_scope_id"], actor),
)
def _shareable(conn, actor: UUID, kind: str, resource_id: UUID) -> dict:
"""The own case or matter of an organization room. Only the owner changes its room share."""
"""The own case or matter. Only the owner decides which rooms it is shared with."""
if kind == "case":
resource = get_case(conn, resource_id)
elif kind == "matter":
@@ -92,31 +104,71 @@ def _shareable(conn, actor: UUID, kind: str, resource_id: UUID) -> dict:
raise unprocessable("Die Raumfreigabe gilt für Akten und Vorgänge.")
if resource is None or resource["owner_subject_id"] != actor:
raise not_found()
room = conn.execute("SELECT kind FROM data_rooms WHERE id = %s", (resource["home_scope_id"],)).fetchone()
if room is None or room["kind"] != "organization":
raise unprocessable("Im persönlichen Datenraum gibt es keine Raumfreigabe.")
return resource
def set_visibility(conn, actor: UUID, kind: str, resource_id: UUID, value: str) -> dict:
if value not in {"private", "room"}:
raise unprocessable("Die Sichtbarkeit ist ungültig.")
def _target_room(conn, actor: UUID, room_id: UUID) -> dict:
room = conn.execute("SELECT id, kind, status FROM data_rooms WHERE id = %s", (room_id,)).fetchone()
if room is None or room["kind"] != "organization" or room["status"] != "active":
raise not_found()
if room_role(conn, actor, room_id) not in {"member", "manager"}:
raise forbidden("Du kannst nur mit Datenräumen teilen, in denen du Mitglied oder Verwalter bist.")
return room
def share_with_room(conn, actor: UUID, kind: str, resource_id: UUID, room_id: UUID, access: str) -> dict:
if access not in {"read", "edit"}:
raise unprocessable("Die Freigabeart ist ungültig.")
resource = _shareable(conn, actor, kind, resource_id)
table = "cases" if kind == "case" else "matters"
if resource["visibility"] != value:
conn.execute(f"UPDATE {table} SET visibility = %s WHERE id = %s", (value, resource_id))
audit(conn, actor, resource["home_scope_id"], "visibility_changed", kind, resource_id, detail={"visibility": value})
return {"id": str(resource_id), "visibility": value}
_target_room(conn, actor, room_id)
existing = conn.execute(
"SELECT access FROM room_shares WHERE resource_kind = %s AND resource_id = %s AND room_id = %s",
(kind, resource_id, room_id),
).fetchone()
conn.execute(
"""
INSERT INTO room_shares (resource_kind, resource_id, room_id, access, created_by)
VALUES (%s, %s, %s, %s, %s)
ON CONFLICT (resource_kind, resource_id, room_id) DO UPDATE SET access = EXCLUDED.access
""",
(kind, resource_id, room_id, access, actor),
)
if existing is None or existing["access"] != access:
audit(
conn,
actor,
resource["home_scope_id"],
"room_shared" if existing is None else "room_share_changed",
kind,
resource_id,
detail={"room_id": str(room_id), "access": access},
)
return {"room_id": str(room_id), "access": access}
def unshare_from_room(conn, actor: UUID, kind: str, resource_id: UUID, room_id: UUID) -> None:
resource = _shareable(conn, actor, kind, resource_id)
row = conn.execute(
"DELETE FROM room_shares WHERE resource_kind = %s AND resource_id = %s AND room_id = %s RETURNING id",
(kind, resource_id, room_id),
).fetchone()
if row is None:
raise not_found()
audit(conn, actor, resource["home_scope_id"], "room_unshared", kind, resource_id, detail={"room_id": str(room_id)})
def set_person_exclusion(conn, actor: UUID, kind: str, resource_id: UUID, subject_id: UUID, excluded: bool) -> None:
"""Take one room member out of the room share of an own case or matter."""
"""Take one person out of the room shares of an own case or matter."""
resource = _shareable(conn, actor, kind, resource_id)
if subject_id == actor:
raise unprocessable("Du kannst dich nicht selbst ausnehmen.")
member = conn.execute(
"SELECT 1 FROM room_memberships WHERE room_id = %s AND subject_id = %s AND status = 'active'",
(resource["home_scope_id"], subject_id),
"""
SELECT 1 FROM room_shares s
JOIN room_memberships m ON m.room_id = s.room_id AND m.subject_id = %s AND m.status = 'active'
WHERE s.resource_kind = %s AND s.resource_id = %s
""",
(subject_id, kind, resource_id),
).fetchone()
if member is None:
raise not_found()
@@ -157,12 +209,12 @@ def create_case(conn, actor: UUID, scope_id: UUID, title: str, parent_case_id: U
"""
INSERT INTO cases (
home_scope_id, owner_subject_id, created_by, title, rights_mode,
content_order, content_order_dir, visibility
content_order, content_order_dir
)
VALUES (%s, %s, %s, %s, 'explicit', 'date', 'asc', %s)
VALUES (%s, %s, %s, %s, 'explicit', 'date', 'asc')
RETURNING *
""",
(scope_id, actor, actor, title, default_visibility(conn, scope_id)),
(scope_id, actor, actor, title),
).fetchone()
else:
parent, _rights = require_case(conn, actor, parent_case_id, "edit")
@@ -174,16 +226,14 @@ def create_case(conn, actor: UUID, scope_id: UUID, title: str, parent_case_id: U
"""
INSERT INTO cases (
home_scope_id, owner_subject_id, created_by, title, parent_case_id, rights_mode,
content_order, content_order_dir, visibility
content_order, content_order_dir
)
VALUES (%s, %s, %s, %s, %s, %s, 'date', 'asc', %s)
VALUES (%s, %s, %s, %s, %s, %s, 'date', 'asc')
RETURNING *
""",
(
parent["home_scope_id"], actor, actor, title, parent["id"], rights_mode,
default_visibility(conn, parent["home_scope_id"]),
),
(parent["home_scope_id"], actor, actor, title, parent["id"], rights_mode),
).fetchone()
_auto_share(conn, actor, "case", row)
audit(conn, actor, row["home_scope_id"], "case_created", "case", row["id"])
return row
@@ -425,11 +475,11 @@ def create_matter(conn, actor: UUID, scope_id: UUID, title: str, parent_matter_i
row = conn.execute(
"""
INSERT INTO matters (
home_scope_id, owner_subject_id, created_by, title, content_order, content_order_dir, visibility
home_scope_id, owner_subject_id, created_by, title, content_order, content_order_dir
)
VALUES (%s, %s, %s, %s, 'date', 'asc', %s) RETURNING *
VALUES (%s, %s, %s, %s, 'date', 'asc') RETURNING *
""",
(scope_id, actor, actor, title, default_visibility(conn, scope_id)),
(scope_id, actor, actor, title),
).fetchone()
else:
parent, _rights = require_matter(conn, actor, parent_matter_id, context, "edit")
@@ -439,12 +489,13 @@ def create_matter(conn, actor: UUID, scope_id: UUID, title: str, parent_matter_i
"""
INSERT INTO matters (
home_scope_id, owner_subject_id, created_by, title, parent_matter_id,
content_order, content_order_dir, visibility
content_order, content_order_dir
)
VALUES (%s, %s, %s, %s, %s, 'date', 'asc', %s) RETURNING *
VALUES (%s, %s, %s, %s, %s, 'date', 'asc') RETURNING *
""",
(parent["home_scope_id"], actor, actor, title, parent["id"], default_visibility(conn, parent["home_scope_id"])),
(parent["home_scope_id"], actor, actor, title, parent["id"]),
).fetchone()
_auto_share(conn, actor, "matter", row)
audit(conn, actor, row["home_scope_id"], "matter_created", "matter", row["id"], context)
return row