Jeder Datenraum hat einen Eigentümer, der Verwalter bleibt, den Raum übertragen kann und im Notfall vom Betreiber ersetzt wird. Neue Akten und Vorgänge folgen der Voreinstellung des Raums: Bei "im Raum teilen" lesen Leser sie und bearbeiten Mitglieder und Verwalter; Weitergeben und Löschen bleiben beim Owner, der eine Akte privat stellen oder einzelne Personen ausnehmen kann. Bestehende Akten bleiben privat. Beim ersten weiteren Mitglied zeigt die Oberfläche, was sichtbar wird. Das Löschen von Akte und Vorgang verlangt jetzt den Owner statt nur das Bearbeitungsrecht und schließt damit R-01. Die Rechte der Raumfreigabe gelten nur bei aktivem Raum, aktiver Mitgliedschaft und aktivem Konto. Die lokale Suite läuft mit 128 Tests grün, der Frontend-Build und 19 Node-Tests ebenfalls. Die Oberfläche wurde noch nicht im Browser bedient. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
"""Room share of a case or matter: shared with the room members by role, or private."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import JSONResponse
|
|
from psycopg import Connection
|
|
|
|
from app.access.policy import ROOM_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
|
|
|
|
router = APIRouter()
|
|
|
|
_NO_STORE = {"Cache-Control": "no-store"}
|
|
|
|
|
|
def _view(conn, actor: UUID, kind: str, resource_id: UUID) -> dict:
|
|
resource = _shareable(conn, actor, kind, resource_id)
|
|
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, resource["home_scope_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
|
|
],
|
|
}
|
|
|
|
|
|
def _register(kind: str, plural: str) -> None:
|
|
base = f"/api/v1/{plural}/{{resource_id}}/room-share"
|
|
|
|
@router.get(base, name=f"get_{kind}_room_share")
|
|
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")
|
|
def put_share(
|
|
resource_id: UUID,
|
|
body: VisibilityIn,
|
|
principal: Principal = Depends(get_principal),
|
|
conn: Connection = Depends(get_conn),
|
|
):
|
|
return set_visibility(conn, principal.account_id, kind, resource_id, body.visibility)
|
|
|
|
@router.put(base + "/people/{subject_id}", name=f"put_{kind}_room_share_person")
|
|
def put_person(
|
|
resource_id: UUID,
|
|
subject_id: UUID,
|
|
body: ExclusionIn,
|
|
principal: Principal = Depends(get_principal),
|
|
conn: Connection = Depends(get_conn),
|
|
):
|
|
set_person_exclusion(conn, principal.account_id, kind, resource_id, subject_id, body.excluded)
|
|
return {"subject_id": str(subject_id), "excluded": body.excluded}
|
|
|
|
|
|
_register("case", "cases")
|
|
_register("matter", "matters")
|
|
|
|
|