Mache Datenräume zu Teams, damit Akten und Vorgänge mit beliebigen Räumen geteilt werden können.
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:
1 parent
1c2f045e7d
commit
21c2d05fb8
19 files changed
+634
-297
No files matched your search
@@ -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")
|
||||
|
||||
|
||||
Reference in new issue
Block a user