Der Baum Meine Ablage steht jetzt auch auf den Seiten von Akte und Vorgang und ersetzt die Spalte Struktur. Ein Klick öffnet den Eintrag und klappt seine Struktur auf: Überblick, Kapitel und Unterkapitel, Unterakten, Vorgänge und Teilvorgänge. Der Pfad bleibt offen, die aktuelle Zeile ist hervorgehoben und nach dem Neuladen stimmt der Fokus wieder. Ein Vorgang steht unter jeder Akte, in der er liegt, und unter Vorgänge; ein Klick unter einer Akte öffnet ihn in diesem Aktenkontext. So wechselt man direkt von Vorgang zu Vorgang. Kapitel anlegen und verschieben geht im Baum. Die Struktur eines Knotens kommt aus neuen schlanken Endpunkten (cases und matters outline), die nur Lesbares liefern, und wird beim Aufklappen einmal nachgeladen. Die Zweispaltenansicht mit dem Lesebereich beginnt erst, wenn neben dem Baum genug Platz bleibt. Im Browser gegen die lokale Umgebung durchgespielt (Akte, Vorgang unter der Akte, Wechsel zwischen Vorgängen, Kapitel anlegen, Neuladen, Vorgang ohne Akte, Handy, Hell und Dunkel). Die Backend-Suite läuft mit 149 Tests grün, der Frontend-Build und 37 Node-Tests ebenfalls. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
171 lines
6.7 KiB
Python
171 lines
6.7 KiB
Python
"""Overviews for the library: cases and matters as tiles, and what lies in a room.
|
|
|
|
A room is a virtual folder. Cases and matters stay where they are; a share puts them into a room.
|
|
Counts only include what the person may read. Hidden entries are neither named nor counted.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections import Counter
|
|
from uuid import UUID
|
|
|
|
from app.access.policy import (
|
|
ROOM_RIGHTS,
|
|
Ctx,
|
|
Rights,
|
|
case_rights,
|
|
get_case,
|
|
list_cases,
|
|
list_matters,
|
|
matter_rights,
|
|
room_name,
|
|
)
|
|
from app.present import _chapters, _matter_tree, case_summary, matter_summary
|
|
|
|
|
|
def shared_rooms(conn, kind: str, resource_id: UUID) -> list[dict]:
|
|
rows = conn.execute(
|
|
"""
|
|
SELECT r.id, r.name, s.access 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),
|
|
).fetchall()
|
|
return [{"id": str(row["id"]), "name": row["name"], "access": row["access"]} for row in rows]
|
|
|
|
|
|
def readable_matter_count(conn, actor: UUID, case: dict) -> int:
|
|
rows = conn.execute(
|
|
"""
|
|
SELECT m.* FROM matter_case_links l JOIN matters m ON m.id = l.matter_id
|
|
WHERE l.case_id = %s AND m.deleted_at IS NULL AND m.parent_matter_id IS NULL
|
|
""",
|
|
(case["id"],),
|
|
).fetchall()
|
|
context = Ctx("case", case["id"])
|
|
return sum(1 for matter in rows if matter_rights(conn, actor, matter, context).read)
|
|
|
|
|
|
def case_items(conn, actor: UUID, visible: list[tuple[dict, Rights]]) -> list[dict]:
|
|
children = Counter(case["parent_case_id"] for case, _ in visible if case["parent_case_id"])
|
|
items = []
|
|
for case, rights in visible:
|
|
summary = case_summary(case, rights)
|
|
owner = case["owner_subject_id"] == actor
|
|
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"] = owner
|
|
summary["shared_with"] = shared_rooms(conn, "case", case["id"]) if owner else []
|
|
summary["child_cases"] = children.get(case["id"], 0)
|
|
summary["matter_count"] = readable_matter_count(conn, actor, case)
|
|
if case["parent_case_id"]:
|
|
parent = get_case(conn, case["parent_case_id"])
|
|
if parent is not None and case_rights(conn, actor, parent).read:
|
|
summary["parent_title"] = parent["title"]
|
|
items.append(summary)
|
|
return items
|
|
|
|
|
|
def matter_items(conn, actor: UUID, visible: list[tuple[dict, list[dict]]]) -> list[dict]:
|
|
children = Counter(matter["parent_matter_id"] for matter, _ in visible if matter["parent_matter_id"])
|
|
items = []
|
|
for matter, _contexts in visible:
|
|
summary = matter_summary(conn, actor, matter)
|
|
summary["child_matters"] = children.get(matter["id"], 0)
|
|
items.append(summary)
|
|
return items
|
|
|
|
|
|
def room_contents(conn, actor: UUID, room_id: UUID) -> tuple[list[tuple[dict, Rights]], list[tuple[dict, list[dict]]]]:
|
|
"""Cases and matters shared with the room that the person may read, with their readable sub-entries."""
|
|
rows = conn.execute(
|
|
"SELECT resource_kind, resource_id FROM room_shares WHERE room_id = %s",
|
|
(room_id,),
|
|
).fetchall()
|
|
case_ids = {row["resource_id"] for row in rows if row["resource_kind"] == "case"}
|
|
matter_ids = {row["resource_id"] for row in rows if row["resource_kind"] == "matter"}
|
|
cases = [
|
|
(case, rights)
|
|
for case, rights in list_cases(conn, actor)
|
|
if case["id"] in case_ids
|
|
or (case["rights_mode"] == "inherit_parent" and case["parent_case_id"] in case_ids)
|
|
]
|
|
matters = [
|
|
(matter, contexts)
|
|
for matter, contexts in list_matters(conn, actor)
|
|
if matter["id"] in matter_ids or matter["parent_matter_id"] in matter_ids
|
|
]
|
|
return cases, matters
|
|
|
|
|
|
def room_effect(conn, room_id: UUID, actor: UUID, access: str) -> list[dict]:
|
|
"""Who gets which rights through a share with this room."""
|
|
rows = conn.execute(
|
|
"""
|
|
SELECT m.subject_id, m.role, a.display_name
|
|
FROM room_memberships m JOIN auth_accounts a ON a.id = m.subject_id
|
|
WHERE m.room_id = %s AND m.status = 'active' AND a.status = 'active' AND m.subject_id <> %s
|
|
ORDER BY a.display_name, a.id
|
|
""",
|
|
(room_id, actor),
|
|
).fetchall()
|
|
effect = []
|
|
for row in rows:
|
|
rights = ROOM_RIGHTS.get(row["role"], Rights())
|
|
if access == "read":
|
|
rights = Rights(read=rights.read)
|
|
effect.append(
|
|
{
|
|
"display_name": row["display_name"],
|
|
"role": row["role"],
|
|
"rights": {"read": rights.read, "edit": rights.edit},
|
|
}
|
|
)
|
|
return effect
|
|
|
|
|
|
def case_outline(conn, actor: UUID, case: dict) -> dict:
|
|
"""What the navigation tree shows below a case. Only readable entries; no bindings or texts."""
|
|
chapters = _chapters(conn, "case", case["id"], case.get("content_order") or "position", case.get("content_order_dir") or "asc")
|
|
subcases = []
|
|
for row in conn.execute(
|
|
"SELECT * FROM cases WHERE parent_case_id = %s AND deleted_at IS NULL ORDER BY title, id",
|
|
(case["id"],),
|
|
).fetchall():
|
|
if case_rights(conn, actor, row).read:
|
|
subcases.append({"id": str(row["id"]), "title": row["title"], "status": row["record_status"]})
|
|
linked = []
|
|
for link in conn.execute(
|
|
"""
|
|
SELECT m.* FROM matter_case_links l JOIN matters m ON m.id = l.matter_id
|
|
WHERE l.case_id = %s AND m.deleted_at IS NULL ORDER BY m.title, m.id
|
|
""",
|
|
(case["id"],),
|
|
).fetchall():
|
|
if matter_rights(conn, actor, link, Ctx("case", case["id"])).read:
|
|
linked.append(link)
|
|
return {
|
|
"kind": "case",
|
|
"id": str(case["id"]),
|
|
"chapters": chapters,
|
|
"subcases": subcases,
|
|
"matters": _matter_tree(conn, actor, case["id"], linked),
|
|
}
|
|
|
|
|
|
def matter_outline(conn, actor: UUID, matter: dict, context: Ctx | None) -> dict:
|
|
"""What the navigation tree shows below a matter: its chapters and its readable Teilvorgänge."""
|
|
chapters = _chapters(
|
|
conn, "matter", matter["id"], matter.get("content_order") or "position", matter.get("content_order_dir") or "asc"
|
|
)
|
|
children = []
|
|
for row in conn.execute(
|
|
"SELECT * FROM matters WHERE parent_matter_id = %s AND deleted_at IS NULL ORDER BY title, id",
|
|
(matter["id"],),
|
|
).fetchall():
|
|
if matter_rights(conn, actor, row, context).read:
|
|
children.append({"id": str(row["id"]), "title": row["title"], "status": row["record_status"]})
|
|
return {"kind": "matter", "id": str(matter["id"]), "chapters": chapters, "submatters": children}
|