Liefere Zähler, Rauminhalt und Teilen im Stapel für die neue Ablage.

Akten und Vorgänge melden Unterakten, Vorgänge und die Räume, mit denen sie geteilt sind, jeweils nur aus Lesbarem. Neue Endpunkte zeigen die Räume als Kacheln, den Inhalt eines Raums und teilen mehrere Einträge auf einmal oder gar nicht. Beim Anlegen lässt sich ein Eintrag gleich in einen Raum legen.

Die lokale Suite läuft mit 148 Tests grün.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-10-22 11:38:02 +02:00
1 parent 30b6544514
commit d39c7d7999
9 files changed
+411 -24

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
"""Library endpoints: rooms as tiles, what lies in a room, and sharing several entries at once."""
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.roles import room_role
from app.api.deps import Principal, get_conn, get_principal
from app.api.schemas import BatchShareIn
from app.core.errors import forbidden
from app.library import case_items, matter_items, room_contents, room_effect
from app.ops import share_with_room
router = APIRouter()
_NO_STORE = {"Cache-Control": "no-store"}
@router.get("/api/v1/rooms/overview")
def rooms_overview(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
"""The team rooms of the person as tiles. Names of members are only shown to managers."""
actor = principal.account_id
rooms = conn.execute(
"""
SELECT r.id, r.name, r.owner_id, r.default_visibility, m.role,
(SELECT count(*) FROM room_memberships x WHERE x.room_id = r.id AND x.status = 'active') AS members
FROM room_memberships m JOIN data_rooms r ON r.id = m.room_id
WHERE m.subject_id = %s AND m.status = 'active' AND r.kind = 'organization' AND r.status = 'active'
ORDER BY r.name, r.id
""",
(actor,),
).fetchall()
items = []
for room in rooms:
cases, matters = room_contents(conn, actor, room["id"])
people = []
if room["role"] == "manager":
people = [
row["display_name"]
for row in conn.execute(
"""
SELECT a.display_name FROM room_memberships x JOIN auth_accounts a ON a.id = x.subject_id
WHERE x.room_id = %s AND x.status = 'active'
ORDER BY a.display_name, a.id LIMIT 6
""",
(room["id"],),
).fetchall()
]
items.append(
{
"id": str(room["id"]),
"name": room["name"],
"role": room["role"],
"is_owner": room["owner_id"] == actor,
"private": room["members"] <= 1,
"default_visibility": room["default_visibility"],
"member_count": room["members"],
"members": people,
"case_count": sum(1 for case, _ in cases if not case["parent_case_id"]),
"matter_count": sum(1 for matter, _ in matters if not matter["parent_matter_id"]),
}
)
return JSONResponse({"items": items}, headers=_NO_STORE)
@router.get("/api/v1/rooms/{room_id}/contents")
def contents(room_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
"""Cases and matters shared with the room that the person may read."""
if room_role(conn, principal.account_id, room_id) is None:
raise forbidden()
cases, matters = room_contents(conn, principal.account_id, room_id)
return JSONResponse(
{
"cases": case_items(conn, principal.account_id, cases),
"matters": matter_items(conn, principal.account_id, matters),
},
headers=_NO_STORE,
)
@router.post("/api/v1/rooms/{room_id}/shares")
def share_many(
room_id: UUID,
body: BatchShareIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
"""Share several own entries with the room. All or none: one failure rolls the request back."""
for item in body.items:
share_with_room(conn, principal.account_id, item.kind, item.id, room_id, body.access)
return {
"shared": len(body.items),
"access": body.access,
"effect": room_effect(conn, room_id, principal.account_id, body.access),
}
+4 -1
View File
@@ -12,6 +12,7 @@ from psycopg import Connection
from app.access.policy import ROOM_RIGHTS, Rights
from app.api.deps import Principal, get_conn, get_principal
from app.api.schemas import ExclusionIn, RoomShareIn
from app.library import room_effect
from app.ops import _shareable, set_person_exclusion, share_with_room, unshare_from_room
router = APIRouter()
@@ -108,7 +109,9 @@ def _register(kind: str, plural: str) -> None:
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return share_with_room(conn, principal.account_id, kind, resource_id, room_id, body.access)
shared = share_with_room(conn, principal.account_id, kind, resource_id, room_id, body.access)
shared["effect"] = room_effect(conn, room_id, principal.account_id, body.access)
return shared
@router.delete(base + "/rooms/{room_id}", status_code=204, name=f"delete_{kind}_room_share")
def delete_share(
+8 -17
View File
@@ -165,9 +165,10 @@ from app.present import (
matter_detail,
matter_summary,
note_update_payload,
shared_room_names,
task_payload,
)
from app.library import case_items, matter_items
from app.ops import share_with_room as _share_with_room
from app.seed import demo_public
router = APIRouter()
@@ -382,20 +383,7 @@ def find_principal(email: str, principal: Principal = Depends(get_principal), co
@router.get("/api/v1/cases")
def cases(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
items = []
for case, rights in list_cases(conn, principal.account_id):
summary = case_summary(case, rights)
summary["home_scope_name"] = room_name(conn, case["home_scope_id"])
summary["kind_label"] = "Unterakte" if case["parent_case_id"] else "Akte"
summary["parent_title"] = None
summary["is_owner"] = case["owner_subject_id"] == principal.account_id
summary["shared_with"] = shared_room_names(conn, "case", case["id"]) if summary["is_owner"] else []
if case["parent_case_id"]:
parent = get_case(conn, case["parent_case_id"])
if parent is not None and case_rights(conn, principal.account_id, parent).read:
summary["parent_title"] = parent["title"]
items.append(summary)
return {"items": items, "next_cursor": None}
return {"items": case_items(conn, principal.account_id, list_cases(conn, principal.account_id)), "next_cursor": None}
@router.post("/api/v1/cases")
@@ -408,6 +396,8 @@ def post_case(body: CaseIn, principal: Principal = Depends(get_principal), conn:
body.parent_case_id,
body.rights_mode,
)
if body.share_with_room_id is not None:
_share_with_room(conn, principal.account_id, "case", case["id"], body.share_with_room_id, "edit")
rights = case_rights(conn, principal.account_id, case)
return _created(f"/api/v1/cases/{case['id']}", case_summary(case, rights))
@@ -492,8 +482,7 @@ def post_case_grant(
@router.get("/api/v1/matters")
def matters(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
items = [matter_summary(conn, principal.account_id, matter) for matter, _contexts in list_matters(conn, principal.account_id)]
return {"items": items, "next_cursor": None}
return {"items": matter_items(conn, principal.account_id, list_matters(conn, principal.account_id)), "next_cursor": None}
@router.post("/api/v1/matters")
@@ -506,6 +495,8 @@ def post_matter(body: MatterIn, principal: Principal = Depends(get_principal), c
body.parent_matter_id,
_ctx_model(body.context),
)
if body.share_with_room_id is not None:
_share_with_room(conn, principal.account_id, "matter", matter["id"], body.share_with_room_id, "edit")
return _created(f"/api/v1/matters/{matter['id']}", matter_summary(conn, principal.account_id, matter))
+12
View File
@@ -77,6 +77,16 @@ class VisibilityIn(APIModel):
visibility: Literal["private", "room"]
class ShareItemIn(APIModel):
kind: Literal["case", "matter"]
id: UUID
class BatchShareIn(APIModel):
items: list[ShareItemIn] = Field(min_length=1, max_length=200)
access: Literal["read", "edit"] = "edit"
class RoomShareIn(APIModel):
access: Literal["read", "edit"] = "edit"
@@ -122,6 +132,7 @@ class CaseIn(APIModel):
parent_case_id: UUID | None = None
rights_mode: Literal["inherit_parent", "explicit"] = "inherit_parent"
home_scope_id: UUID | None = None
share_with_room_id: UUID | None = None
class CasePatch(APIModel):
@@ -197,6 +208,7 @@ class MatterIn(APIModel):
parent_matter_id: UUID | None = None
context: ContextIn | None = None
home_scope_id: UUID | None = None
share_with_room_id: UUID | None = None
class MatterPatch(APIModel):