Mache die Inhaltsliste zur einen Arbeitsflaeche mit Vorschauzeilen, damit Pfad, Herkunft und eigene Reihenfolge im Alltag erhalten bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
52bda91aad
commit
3465ed57f6
16 files changed
+1375
-314
No files matched your search
@@ -58,12 +58,14 @@ from app.api.schemas import (
|
||||
MemberIn,
|
||||
BindingOrderIn,
|
||||
ContentOrderIn,
|
||||
ChapterMoveIn,
|
||||
DatesPatch,
|
||||
NoteIn,
|
||||
NotePatch,
|
||||
RoomIn,
|
||||
ScopeIn,
|
||||
TaskDeadlineIn,
|
||||
SummaryPatch,
|
||||
TaskIn,
|
||||
TaskPatch,
|
||||
)
|
||||
@@ -105,12 +107,14 @@ from app.ops import (
|
||||
patch_matter,
|
||||
patch_task,
|
||||
revoke_grant,
|
||||
move_binding_chapter,
|
||||
reorder_bindings,
|
||||
set_content_order,
|
||||
set_exception,
|
||||
unlink_matter_case,
|
||||
update_dates,
|
||||
update_note,
|
||||
update_summary,
|
||||
)
|
||||
from app.present import (
|
||||
LABELS,
|
||||
@@ -512,6 +516,12 @@ def cases(principal: Principal = Depends(get_principal), conn: Connection = Depe
|
||||
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
|
||||
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}
|
||||
|
||||
@@ -1236,6 +1246,42 @@ def patch_element_dates(
|
||||
return {"id": str(element["id"]), "version": element["version"]}
|
||||
|
||||
|
||||
@router.patch("/api/v1/elements/{element_id}/summary")
|
||||
def patch_element_summary(
|
||||
element_id: UUID,
|
||||
body: SummaryPatch,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
element = update_summary(
|
||||
conn,
|
||||
principal.account_id,
|
||||
element_id,
|
||||
body.expected_version,
|
||||
body.summary,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
return {"id": str(element["id"]), "version": element["version"], "summary": element["summary"]}
|
||||
|
||||
|
||||
@router.patch("/api/v1/bindings/{binding_id}/chapter")
|
||||
def patch_binding_chapter(
|
||||
binding_id: UUID,
|
||||
body: ChapterMoveIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
version = move_binding_chapter(
|
||||
conn,
|
||||
principal.account_id,
|
||||
binding_id,
|
||||
body.expected_version,
|
||||
body.chapter_id,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
return {"version": version}
|
||||
|
||||
|
||||
@router.get("/api/v1/cases/{case_id}/course")
|
||||
def case_course(case_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
case, rights = require_case(conn, principal.account_id, case_id, "read")
|
||||
|
||||
@@ -156,6 +156,18 @@ class DatesPatch(APIModel):
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class SummaryPatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
summary: str | None = Field(default=None, max_length=400)
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class ChapterMoveIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
chapter_id: UUID | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class NotePatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
document: DocumentIn
|
||||
|
||||
@@ -898,3 +898,41 @@ def update_dates(
|
||||
bump_version(conn, "elements", element_id, expected)
|
||||
record_dates(conn, actor, element["home_scope_id"], element_id, context or Ctx("matter", element_id), document_on, sent_on, received_on)
|
||||
return get_element(conn, element_id)
|
||||
|
||||
|
||||
def update_summary(conn, actor: UUID, element_id: UUID, expected: int, summary: str | None, context: Ctx | None) -> dict:
|
||||
element, rights = require_element(conn, actor, element_id, context, "edit")
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
cleaned = (summary or "").strip()
|
||||
if len(cleaned) > 400:
|
||||
raise unprocessable("Die Kurzbeschreibung ist zu lang.")
|
||||
bump_version(conn, "elements", element_id, expected)
|
||||
conn.execute("UPDATE elements SET summary = %s WHERE id = %s", (cleaned or None, element_id))
|
||||
audit(conn, actor, element["home_scope_id"], "summary_changed", "element", element_id, context)
|
||||
return get_element(conn, element_id)
|
||||
|
||||
|
||||
def move_binding_chapter(conn, actor: UUID, binding_id: UUID, expected: int, chapter_id: UUID | None, context: Ctx | None) -> int:
|
||||
"""Move one visible binding inside its container. No new binding and no grant."""
|
||||
binding = conn.execute("SELECT * FROM bindings WHERE id = %s", (binding_id,)).fetchone()
|
||||
if binding is None:
|
||||
raise not_found()
|
||||
kind = binding["context_kind"]
|
||||
container_id = binding["context_id"]
|
||||
if kind == "case":
|
||||
container, rights = require_case(conn, actor, container_id, "edit")
|
||||
table = "cases"
|
||||
page = Ctx("case", container_id)
|
||||
else:
|
||||
container, rights = require_matter(conn, actor, container_id, context, "edit")
|
||||
table = "matters"
|
||||
page = context or Ctx("matter", container_id)
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
require_element(conn, actor, binding["element_id"], page, "read")
|
||||
chapter_for(conn, chapter_id, kind, container_id)
|
||||
version = bump_version(conn, table, container_id, expected)
|
||||
conn.execute("UPDATE bindings SET chapter_id = %s WHERE id = %s", (chapter_id, binding_id))
|
||||
audit(conn, actor, container["home_scope_id"], "binding_chapter", kind, container_id, page)
|
||||
return version
|
||||
+211
-41
@@ -73,21 +73,58 @@ def _dates(conn, element: dict) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _plain_excerpt(document: dict | None) -> str | None:
|
||||
if not isinstance(document, dict):
|
||||
return None
|
||||
parts = []
|
||||
for block in document.get("blocks") or []:
|
||||
if not isinstance(block, dict):
|
||||
continue
|
||||
text = str(block.get("text") or "").strip()
|
||||
if text:
|
||||
parts.append(text)
|
||||
raw = " ".join(parts).strip()
|
||||
if not raw:
|
||||
return None
|
||||
return raw[:180]
|
||||
|
||||
|
||||
def _preview_meta(kind: str, content_type: str | None, source: str | None) -> dict:
|
||||
if kind == "note":
|
||||
return {"available": False, "media": "note", "source": "note"}
|
||||
media = (content_type or "").split(";")[0].strip().lower()
|
||||
if kind == "file" and media.startswith("image/"):
|
||||
return {"available": True, "media": "image", "source": "file"}
|
||||
if kind == "file" and media == "application/pdf":
|
||||
return {"available": True, "media": "pdf", "source": "file"}
|
||||
if kind == "external_ref" and source == "paperless":
|
||||
return {"available": True, "media": "paperless", "source": "paperless"}
|
||||
if kind == "file":
|
||||
return {"available": False, "media": "file", "source": "file"}
|
||||
return {"available": False, "media": "none", "source": source}
|
||||
|
||||
|
||||
def _element_body(conn, element: dict) -> dict:
|
||||
payload = {
|
||||
"id": str(element["id"]),
|
||||
"kind": element["kind"],
|
||||
"title": element["title"],
|
||||
"summary": element.get("summary") or None,
|
||||
"excerpt": None,
|
||||
"version": element["version"],
|
||||
"owner_subject_id": str(element["owner_subject_id"]),
|
||||
"dates": _dates(conn, element),
|
||||
"preview": _preview_meta(element["kind"], None, None),
|
||||
}
|
||||
if element["kind"] == "note":
|
||||
body = conn.execute(
|
||||
"SELECT document_json FROM note_bodies WHERE element_id = %s",
|
||||
(element["id"],),
|
||||
).fetchone()
|
||||
payload["document"] = body["document_json"] if body else {"version": 1, "blocks": []}
|
||||
document = body["document_json"] if body else {"version": 1, "blocks": []}
|
||||
payload["document"] = document
|
||||
payload["excerpt"] = _plain_excerpt(document)
|
||||
payload["preview"] = _preview_meta("note", None, "note")
|
||||
elif element["kind"] == "file":
|
||||
asset = conn.execute(
|
||||
"""
|
||||
@@ -103,6 +140,7 @@ def _element_body(conn, element: dict) -> dict:
|
||||
"byte_size": asset["byte_size"],
|
||||
"status": asset["status"],
|
||||
}
|
||||
payload["preview"] = _preview_meta("file", asset["content_type"], "file")
|
||||
elif element["kind"] == "external_ref":
|
||||
ref = conn.execute(
|
||||
"SELECT source, external_id, detail FROM external_references WHERE element_id = %s",
|
||||
@@ -114,6 +152,7 @@ def _element_body(conn, element: dict) -> dict:
|
||||
"external_id": ref["external_id"],
|
||||
"detail": ref["detail"] or {},
|
||||
}
|
||||
payload["preview"] = _preview_meta("external_ref", None, ref["source"])
|
||||
return payload
|
||||
|
||||
|
||||
@@ -224,36 +263,144 @@ def course_items(bindings: list[dict]) -> list[dict]:
|
||||
return dated + undated
|
||||
|
||||
|
||||
def _matter_href(matter_id: UUID, context: Ctx | None) -> str:
|
||||
href = f"/matters/{matter_id}"
|
||||
if context is not None and context.kind == "case":
|
||||
href += f"?context_kind=case&context_id={context.id}"
|
||||
return href
|
||||
|
||||
|
||||
def _append_matter_steps(conn, actor: UUID, trail: list[dict], matter: dict, context: Ctx | None) -> None:
|
||||
"""Object path only. The same labels apply from a case, a list or a direct link."""
|
||||
page = context if context is not None and context.kind == "case" else None
|
||||
if matter["parent_matter_id"]:
|
||||
parent = get_matter(conn, matter["parent_matter_id"])
|
||||
if parent is not None and matter_title_if_readable(conn, actor, parent["id"]):
|
||||
trail.append({"label": f"Vorgang {parent['title']}", "href": _matter_href(parent["id"], page if _parent_keeps_context(conn, actor, parent, page) else None)})
|
||||
kind = "Teilvorgang" if matter["parent_matter_id"] else "Vorgang"
|
||||
trail.append({"label": f"{kind} {matter['title']}", "href": None})
|
||||
|
||||
|
||||
def _parent_keeps_context(conn, actor: UUID, parent: dict, page: Ctx | None) -> bool:
|
||||
return page is not None and matter_rights(conn, actor, parent, page).read
|
||||
|
||||
|
||||
def case_trail(conn, actor: UUID, case: dict) -> list[dict]:
|
||||
trail = [{"label": "Akten", "href": "/cases"}]
|
||||
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:
|
||||
trail.append({"label": parent["title"], "href": f"/cases/{parent['id']}"})
|
||||
trail.append({"label": case["title"], "href": None})
|
||||
trail.append({"label": f"Akte {parent['title']}", "href": f"/cases/{parent['id']}"})
|
||||
kind = "Unterakte" if case["parent_case_id"] else "Akte"
|
||||
trail.append({"label": f"{kind} {case['title']}", "href": None})
|
||||
return trail
|
||||
|
||||
|
||||
def matter_trail(conn, actor: UUID, matter: dict, context: Ctx | None) -> list[dict]:
|
||||
if context is not None and context.kind == "case":
|
||||
case = get_case(conn, context.id)
|
||||
if case is not None and case_rights(conn, actor, case).read:
|
||||
trail = case_trail(conn, actor, case)
|
||||
trail[-1]["href"] = f"/cases/{case['id']}"
|
||||
trail.append({"label": matter["title"], "href": None})
|
||||
return trail
|
||||
trail = [{"label": "Vorgänge", "href": "/matters"}]
|
||||
if matter["parent_matter_id"]:
|
||||
parent = get_matter(conn, matter["parent_matter_id"])
|
||||
if parent is not None and matter_rights(conn, actor, parent, context).read:
|
||||
href = f"/matters/{parent['id']}"
|
||||
if context is not None and context.kind == "case":
|
||||
href += f"?context_kind=case&context_id={context.id}"
|
||||
trail.append({"label": parent["title"], "href": href})
|
||||
trail.append({"label": matter["title"], "href": None})
|
||||
_append_matter_steps(conn, actor, trail, matter, context)
|
||||
return trail
|
||||
|
||||
|
||||
def _case_chain_label(conn, actor: UUID, case: dict) -> str:
|
||||
parts = []
|
||||
current = case
|
||||
guard = 0
|
||||
while current is not None and guard < 4:
|
||||
if not case_rights(conn, actor, current).read:
|
||||
break
|
||||
kind = "Unterakte" if current["parent_case_id"] else "Akte"
|
||||
parts.append(f"{kind} {current['title']}")
|
||||
parent_id = current["parent_case_id"]
|
||||
current = get_case(conn, parent_id) if parent_id else None
|
||||
guard += 1
|
||||
parts.reverse()
|
||||
return " → ".join(parts)
|
||||
|
||||
|
||||
def _placement_rows(conn, matter_id: UUID) -> list[dict]:
|
||||
return conn.execute(
|
||||
"""
|
||||
SELECT c.*
|
||||
FROM matter_case_links l
|
||||
JOIN cases c ON c.id = l.case_id AND c.deleted_at IS NULL
|
||||
WHERE l.matter_id = %s
|
||||
ORDER BY c.title, c.id
|
||||
""",
|
||||
(matter_id,),
|
||||
).fetchall()
|
||||
|
||||
|
||||
def matter_placements(conn, actor: UUID, matter_id: UUID, context: Ctx | None) -> list[dict]:
|
||||
"""Readable case assignments of this matter and its readable parent chain."""
|
||||
items = []
|
||||
seen: set[UUID] = set()
|
||||
matter = get_matter(conn, matter_id)
|
||||
guard = 0
|
||||
while matter is not None and guard < 4:
|
||||
for link in _placement_rows(conn, matter["id"]):
|
||||
if link["id"] in seen or not case_rights(conn, actor, link).read:
|
||||
continue
|
||||
seen.add(link["id"])
|
||||
items.append(
|
||||
{
|
||||
"case_id": str(link["id"]),
|
||||
"label": _case_chain_label(conn, actor, link),
|
||||
"href": f"/cases/{link['id']}",
|
||||
"current": context is not None and context.kind == "case" and context.id == link["id"],
|
||||
}
|
||||
)
|
||||
parent_id = matter["parent_matter_id"]
|
||||
if parent_id is None or matter_title_if_readable(conn, actor, parent_id) is None:
|
||||
break
|
||||
matter = get_matter(conn, parent_id)
|
||||
guard += 1
|
||||
return items
|
||||
|
||||
|
||||
def _matter_node(row: dict) -> dict:
|
||||
return {
|
||||
"id": str(row["id"]),
|
||||
"title": row["title"],
|
||||
"status": row["record_status"],
|
||||
"kind_label": "Teilvorgang" if row["parent_matter_id"] else "Vorgang",
|
||||
"parent_matter_id": str(row["parent_matter_id"]) if row["parent_matter_id"] else None,
|
||||
"children": [],
|
||||
}
|
||||
|
||||
|
||||
def _matter_tree(conn, actor: UUID, case_id: UUID, linked: list[dict]) -> list[dict]:
|
||||
"""One level: a Teilvorgang sits under its Vorgang, not beside it."""
|
||||
context = Ctx("case", case_id)
|
||||
rows = list(linked)
|
||||
seen = {row["id"] for row in rows}
|
||||
for row in list(rows):
|
||||
children = conn.execute(
|
||||
"""
|
||||
SELECT * FROM matters
|
||||
WHERE parent_matter_id = %s AND deleted_at IS NULL
|
||||
ORDER BY title, id
|
||||
""",
|
||||
(row["id"],),
|
||||
).fetchall()
|
||||
for child in children:
|
||||
if child["id"] in seen:
|
||||
continue
|
||||
if matter_rights(conn, actor, child, context).read:
|
||||
rows.append(child)
|
||||
seen.add(child["id"])
|
||||
nodes = {row["id"]: _matter_node(row) for row in rows}
|
||||
roots = []
|
||||
for row in rows:
|
||||
parent_id = row["parent_matter_id"]
|
||||
node = nodes[row["id"]]
|
||||
if parent_id and parent_id in nodes:
|
||||
nodes[parent_id]["children"].append(node)
|
||||
else:
|
||||
roots.append(node)
|
||||
return roots
|
||||
|
||||
|
||||
def case_summary(case: dict, rights) -> dict:
|
||||
return {
|
||||
"id": str(case["id"]),
|
||||
@@ -307,15 +454,8 @@ def case_detail(conn, actor: UUID, case: dict, rights) -> dict:
|
||||
matter_right = matter_rights(conn, actor, link, Ctx("case", case["id"]))
|
||||
if not matter_right.read:
|
||||
continue
|
||||
matters.append(
|
||||
{
|
||||
"id": str(link["id"]),
|
||||
"link_id": str(link["link_id"]),
|
||||
"title": link["title"],
|
||||
"status": link["record_status"],
|
||||
}
|
||||
)
|
||||
payload["matters"] = matters
|
||||
matters.append(link)
|
||||
payload["matters"] = _matter_tree(conn, actor, case["id"], matters)
|
||||
context = Ctx("case", case["id"])
|
||||
payload["bindings"] = _ordered_bindings(
|
||||
conn, actor, "case", case["id"], context, payload["content_order"], payload["content_order_dir"]
|
||||
@@ -331,7 +471,8 @@ def case_detail(conn, actor: UUID, case: dict, rights) -> dict:
|
||||
""",
|
||||
(case["id"],),
|
||||
).fetchall():
|
||||
if not matter_rights(conn, actor, link, context).read:
|
||||
matter_right = matter_rights(conn, actor, link, context)
|
||||
if not matter_right.read:
|
||||
continue
|
||||
items = _ordered_bindings(
|
||||
conn,
|
||||
@@ -348,12 +489,29 @@ def case_detail(conn, actor: UUID, case: dict, rights) -> dict:
|
||||
{
|
||||
"matter_id": str(link["id"]),
|
||||
"title": link["title"],
|
||||
"version": link["version"],
|
||||
"rights": matter_right.as_dict(),
|
||||
"chapters": _chapters(conn, "matter", link["id"]),
|
||||
"content_order": link.get("content_order") or "position",
|
||||
"content_order_dir": link.get("content_order_dir") or "asc",
|
||||
"bindings": items,
|
||||
}
|
||||
)
|
||||
payload["contained"] = contained
|
||||
payload["tasks"] = []
|
||||
payload["deadlines"] = []
|
||||
payload["task_deadline_links"] = []
|
||||
|
||||
def _walk(nodes):
|
||||
for node in nodes:
|
||||
yield node
|
||||
yield from _walk(node["children"])
|
||||
|
||||
for node in _walk(payload["matters"]):
|
||||
tracked = _tracking(conn, actor, UUID(node["id"]), context)
|
||||
payload["tasks"].extend(tracked["tasks"])
|
||||
payload["deadlines"].extend(tracked["deadlines"])
|
||||
payload["task_deadline_links"].extend(tracked["links"])
|
||||
if rights.share or case["owner_subject_id"] == actor:
|
||||
payload["grants"] = _grants(conn, "case", case["id"])
|
||||
return payload
|
||||
@@ -373,7 +531,9 @@ def matter_summary(conn, actor: UUID, matter: dict) -> dict:
|
||||
"title": matter["title"],
|
||||
"status": matter["record_status"],
|
||||
"version": matter["version"],
|
||||
"kind_label": "Teilvorgang" if matter["parent_matter_id"] else "Vorgang",
|
||||
"parent_matter_id": str(matter["parent_matter_id"]) if matter["parent_matter_id"] else None,
|
||||
"parent_title": matter_title_if_readable(conn, actor, matter["parent_matter_id"]),
|
||||
"home_scope_id": str(matter["home_scope_id"]),
|
||||
"home_scope_name": room_name(conn, matter["home_scope_id"]),
|
||||
"contexts": matter_contexts(conn, actor, matter),
|
||||
@@ -401,6 +561,7 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
"content_order": matter.get("content_order") or "position",
|
||||
"content_order_dir": matter.get("content_order_dir") or "asc",
|
||||
"trail": matter_trail(conn, actor, matter, context),
|
||||
"placements": matter_placements(conn, actor, matter["id"], context),
|
||||
"kind_label": "Teilvorgang" if matter["parent_matter_id"] else "Vorgang",
|
||||
"rights": rights.as_dict(),
|
||||
"context": None if context is None else context.as_dict(),
|
||||
@@ -452,19 +613,31 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
payload["content_order"],
|
||||
payload["content_order_dir"],
|
||||
)
|
||||
payload["tasks"] = []
|
||||
tracked = _tracking(conn, actor, matter["id"], context)
|
||||
payload["tasks"] = tracked["tasks"]
|
||||
payload["deadlines"] = tracked["deadlines"]
|
||||
payload["task_deadline_links"] = tracked["links"]
|
||||
if rights.share or matter["owner_subject_id"] == actor:
|
||||
payload["grants"] = _grants(conn, "matter", matter["id"])
|
||||
if matter["owner_subject_id"] == actor:
|
||||
payload["exception"] = _exception(conn, "matter", matter["id"], context)
|
||||
return payload
|
||||
|
||||
|
||||
def _tracking(conn, actor: UUID, matter_id: UUID, context: Ctx | None) -> dict:
|
||||
tasks = []
|
||||
for task in conn.execute(
|
||||
"""
|
||||
SELECT * FROM tasks
|
||||
WHERE matter_id = %s AND deleted_at IS NULL
|
||||
ORDER BY due_on NULLS LAST, created_at
|
||||
""",
|
||||
(matter["id"],),
|
||||
(matter_id,),
|
||||
).fetchall():
|
||||
task_right = task_rights(conn, actor, task, context)
|
||||
if task_right.read:
|
||||
payload["tasks"].append(task_payload(conn, actor, task, task_right))
|
||||
payload["deadlines"] = []
|
||||
tasks.append(task_payload(conn, actor, task, task_right))
|
||||
deadlines = []
|
||||
visible_deadlines = set()
|
||||
for deadline in conn.execute(
|
||||
"""
|
||||
@@ -472,14 +645,14 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
WHERE matter_id = %s AND deleted_at IS NULL
|
||||
ORDER BY due_on, created_at
|
||||
""",
|
||||
(matter["id"],),
|
||||
(matter_id,),
|
||||
).fetchall():
|
||||
deadline_right = deadline_rights(conn, actor, deadline, context)
|
||||
if deadline_right.read:
|
||||
payload["deadlines"].append(deadline_payload(conn, actor, deadline))
|
||||
deadlines.append(deadline_payload(conn, actor, deadline))
|
||||
visible_deadlines.add(deadline["id"])
|
||||
visible_tasks = {UUID(item["id"]) for item in payload["tasks"]}
|
||||
links = []
|
||||
visible_tasks = {UUID(item["id"]) for item in tasks}
|
||||
if visible_tasks and visible_deadlines:
|
||||
for link in conn.execute(
|
||||
"SELECT task_id, deadline_id FROM task_deadline_links WHERE task_id = ANY(%s::uuid[])",
|
||||
@@ -487,12 +660,7 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
).fetchall():
|
||||
if link["deadline_id"] in visible_deadlines:
|
||||
links.append({"task_id": str(link["task_id"]), "deadline_id": str(link["deadline_id"])})
|
||||
payload["task_deadline_links"] = links
|
||||
if rights.share or matter["owner_subject_id"] == actor:
|
||||
payload["grants"] = _grants(conn, "matter", matter["id"])
|
||||
if matter["owner_subject_id"] == actor:
|
||||
payload["exception"] = _exception(conn, "matter", matter["id"], context)
|
||||
return payload
|
||||
return {"tasks": tasks, "deadlines": deadlines, "links": links}
|
||||
|
||||
|
||||
def task_payload(conn, actor: UUID, task: dict, rights=None) -> dict:
|
||||
@@ -600,6 +768,8 @@ LABELS = {
|
||||
"correspondence_received": "Zugang",
|
||||
"correspondence_recorded": "Erfassung",
|
||||
"chapter_created": "Kapitel angelegt",
|
||||
"summary_changed": "Kurzbeschreibung geändert",
|
||||
"binding_chapter": "In ein Kapitel eingeordnet",
|
||||
"content_order": "Ordnungsart geändert",
|
||||
"content_reordered": "Eigene Reihenfolge geändert",
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE elements
|
||||
ADD COLUMN summary text;
|
||||
|
||||
ALTER TABLE elements
|
||||
ADD CONSTRAINT elements_summary_len CHECK (summary IS NULL OR char_length(summary) BETWEEN 1 AND 400);
|
||||
@@ -359,13 +359,84 @@ def test_direct_matter_trail_invents_no_case(client, db):
|
||||
ben.login()
|
||||
opened = ben.request("GET", f"/api/v1/matters/{matter['id']}?context_kind=case&context_id={child['id']}")
|
||||
labels = [item["label"] for item in opened["trail"]]
|
||||
assert labels[0] == "Akten"
|
||||
assert "Wohnung" in labels
|
||||
assert "Nebenkosten" in labels
|
||||
assert "Vermietung" not in labels
|
||||
assert "Geheim" not in labels
|
||||
assert labels == ["Vorgänge", "Vorgang Nebenkosten"]
|
||||
assert opened["context"]["id"] == child["id"]
|
||||
assert [item["label"] for item in opened["placements"]] == ["Unterakte Wohnung"]
|
||||
assert opened["placements"][0]["current"] is True
|
||||
assert all(item["title"] != "Geheim" for item in opened["case_links"])
|
||||
ada.login()
|
||||
direct = ada.request("GET", f"/api/v1/matters/{matter['id']}")
|
||||
assert direct["trail"][0]["label"] == "Vorgänge"
|
||||
assert "Vermietung" not in [item["label"] for item in direct["trail"]]
|
||||
assert [item["label"] for item in direct["trail"]] == labels
|
||||
assert "Geheim" not in " ".join(item["label"] for item in opened["placements"])
|
||||
assert any(item["label"] == "Akte Geheim" for item in direct["placements"])
|
||||
|
||||
|
||||
def test_teilvorgang_keeps_its_parent_in_the_trail(client, db):
|
||||
ada = Actor(client, "ada-child@example.test", "Ada Kind")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
parent = matter_of(ada, "Hauptvorgang")
|
||||
child = ada.request(
|
||||
"POST",
|
||||
"/api/v1/matters",
|
||||
json={"title": "Prüfung", "parent_matter_id": parent["id"]},
|
||||
status=201,
|
||||
)
|
||||
direct = ada.request("GET", f"/api/v1/matters/{child['id']}")
|
||||
assert [item["label"] for item in direct["trail"]] == ["Vorgänge", "Vorgang Hauptvorgang", "Teilvorgang Prüfung"]
|
||||
case = case_of(ada, "Sammelakte")
|
||||
ada.request("POST", f"/api/v1/matters/{parent['id']}/case-links", json={"case_id": case["id"]}, status=201)
|
||||
opened = ada.request("GET", f"/api/v1/matters/{child['id']}?context_kind=case&context_id={case['id']}")
|
||||
assert [item["label"] for item in opened["trail"]] == [item["label"] for item in direct["trail"]]
|
||||
assert opened["trail"][1]["href"].endswith(f"context_id={case['id']}")
|
||||
assert opened["placements"][0]["label"] == "Akte Sammelakte"
|
||||
assert opened["placements"][0]["current"] is True
|
||||
listed = ada.request("GET", "/api/v1/matters")
|
||||
rows = {item["title"]: item for item in listed["items"]}
|
||||
assert rows["Prüfung"]["kind_label"] == "Teilvorgang"
|
||||
assert rows["Prüfung"]["parent_title"] == "Hauptvorgang"
|
||||
assert rows["Hauptvorgang"]["kind_label"] == "Vorgang"
|
||||
|
||||
|
||||
_PNG = bytes.fromhex(
|
||||
"89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c489"
|
||||
"0000000a49444154789c63000100000500010d0a2db40000000049454e44ae426082"
|
||||
)
|
||||
|
||||
|
||||
def test_summary_and_preview_follow_the_read_right(client, db):
|
||||
ada = Actor(client, "ada-preview@example.test", "Ada Vorschau")
|
||||
ben = Actor(client, "ben-preview@example.test", "Ben Vorschau")
|
||||
register(db, ada.email, ada.name)
|
||||
register(db, ben.email, ben.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Mappe")
|
||||
_note(ada, "Einwendungstext", matter)
|
||||
detail = _matter(ada, matter["id"])
|
||||
note = detail["bindings"][0]["element"]
|
||||
assert note["excerpt"] == "Einwendungstext"
|
||||
assert note["summary"] is None
|
||||
assert note["preview"]["available"] is False
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/elements/{note['id']}/summary",
|
||||
json={
|
||||
"expected_version": note["version"],
|
||||
"summary": "Kurze Einwendung",
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
},
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/files",
|
||||
data={"title": "Scan", "context_kind": "matter", "context_id": matter["id"]},
|
||||
files={"upload": ("punkt.png", _PNG, "image/png")},
|
||||
status=201,
|
||||
)
|
||||
detail = _matter(ada, matter["id"])
|
||||
by_title = {item["element"]["title"]: item["element"] for item in detail["bindings"]}
|
||||
assert by_title["Einwendungstext"]["summary"] == "Kurze Einwendung"
|
||||
assert by_title["Scan"]["preview"] == {"available": True, "media": "image", "source": "file"}
|
||||
ben.login()
|
||||
ben.request("GET", f"/api/v1/matters/{matter['id']}", status=404)
|
||||
ben.request("GET", f"/api/v1/files/{by_title['Scan']['id']}/content", status=404)
|
||||
Reference in new issue
Block a user