Ordne Akten und Vorgaenge nach fachlichem Datum oder eigener Reihenfolge und mache den Inhalt zur Arbeitsansicht.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
27925093e2
commit
52bda91aad
22 files changed
+2079
-258
No files matched your search
+127
-22
@@ -22,6 +22,7 @@ from app.access.policy import (
|
||||
)
|
||||
from app.access.policy import SHARED_NOTICE
|
||||
from app.core.timeutil import dump_date, dump_dt
|
||||
from app.order import arrange
|
||||
|
||||
|
||||
def rights_dict(rights) -> dict:
|
||||
@@ -179,6 +180,80 @@ def _grants(conn, kind: str, resource_id: UUID) -> list[dict]:
|
||||
]
|
||||
|
||||
|
||||
def _ordered_bindings(conn, actor: UUID, kind: str, container_id: UUID, context: Ctx, mode: str, direction: str) -> list[dict]:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT * FROM bindings
|
||||
WHERE context_kind = %s AND context_id = %s
|
||||
ORDER BY position, id
|
||||
""",
|
||||
(kind, container_id),
|
||||
).fetchall()
|
||||
visible = []
|
||||
for binding in rows:
|
||||
item = binding_payload(conn, actor, binding, context)
|
||||
if item is None:
|
||||
continue
|
||||
item["_raw_position"] = binding["position"]
|
||||
item["_document_on"] = item["element"]["dates"]["document_on"]
|
||||
visible.append(item)
|
||||
return arrange(visible, mode or "position", direction or "asc")
|
||||
|
||||
|
||||
def course_items(bindings: list[dict]) -> list[dict]:
|
||||
"""One fachlicher Eintrag je Unterlage. Das Erfassungsdatum ist kein Belegdatum."""
|
||||
items = []
|
||||
for binding in bindings:
|
||||
dates = binding["element"]["dates"]
|
||||
items.append(
|
||||
{
|
||||
"id": binding["element"]["id"],
|
||||
"binding_id": binding["id"],
|
||||
"title": binding["element"]["title"],
|
||||
"kind": binding["element"]["kind"],
|
||||
"document_on": dates["document_on"],
|
||||
"sent_on": dates["sent_on"],
|
||||
"received_on": dates["received_on"],
|
||||
"dated": dates["document_on"] is not None,
|
||||
}
|
||||
)
|
||||
dated = [item for item in items if item["dated"]]
|
||||
undated = [item for item in items if not item["dated"]]
|
||||
dated.sort(key=lambda item: (item["document_on"], item["id"]))
|
||||
undated.sort(key=lambda item: item["id"])
|
||||
return dated + undated
|
||||
|
||||
|
||||
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})
|
||||
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})
|
||||
return trail
|
||||
|
||||
|
||||
def case_summary(case: dict, rights) -> dict:
|
||||
return {
|
||||
"id": str(case["id"]),
|
||||
@@ -194,6 +269,10 @@ def case_summary(case: dict, rights) -> dict:
|
||||
|
||||
def case_detail(conn, actor: UUID, case: dict, rights) -> dict:
|
||||
payload = case_summary(case, rights)
|
||||
payload["content_order"] = case.get("content_order") or "position"
|
||||
payload["content_order_dir"] = case.get("content_order_dir") or "asc"
|
||||
payload["trail"] = case_trail(conn, actor, case)
|
||||
payload["kind_label"] = "Unterakte" if case["parent_case_id"] else "Akte"
|
||||
payload["home_scope_name"] = room_name(conn, case["home_scope_id"])
|
||||
payload["is_owner"] = case["owner_subject_id"] == actor
|
||||
if case["parent_case_id"]:
|
||||
@@ -238,19 +317,43 @@ def case_detail(conn, actor: UUID, case: dict, rights) -> dict:
|
||||
)
|
||||
payload["matters"] = matters
|
||||
context = Ctx("case", case["id"])
|
||||
bindings = []
|
||||
for binding in conn.execute(
|
||||
payload["bindings"] = _ordered_bindings(
|
||||
conn, actor, "case", case["id"], context, payload["content_order"], payload["content_order_dir"]
|
||||
)
|
||||
contained = []
|
||||
for link in conn.execute(
|
||||
"""
|
||||
SELECT * FROM bindings
|
||||
WHERE context_kind = 'case' AND context_id = %s
|
||||
ORDER BY position, created_at
|
||||
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():
|
||||
item = binding_payload(conn, actor, binding, context)
|
||||
if item is not None:
|
||||
bindings.append(item)
|
||||
payload["bindings"] = bindings
|
||||
if not matter_rights(conn, actor, link, context).read:
|
||||
continue
|
||||
items = _ordered_bindings(
|
||||
conn,
|
||||
actor,
|
||||
"matter",
|
||||
link["id"],
|
||||
context,
|
||||
link.get("content_order") or "position",
|
||||
link.get("content_order_dir") or "asc",
|
||||
)
|
||||
if not items:
|
||||
continue
|
||||
contained.append(
|
||||
{
|
||||
"matter_id": str(link["id"]),
|
||||
"title": link["title"],
|
||||
"content_order": link.get("content_order") or "position",
|
||||
"content_order_dir": link.get("content_order_dir") or "asc",
|
||||
"bindings": items,
|
||||
}
|
||||
)
|
||||
payload["contained"] = contained
|
||||
if rights.share or case["owner_subject_id"] == actor:
|
||||
payload["grants"] = _grants(conn, "case", case["id"])
|
||||
return payload
|
||||
@@ -295,6 +398,10 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
"home_scope_id": str(matter["home_scope_id"]),
|
||||
"home_scope_name": room_name(conn, matter["home_scope_id"]),
|
||||
"is_owner": matter["owner_subject_id"] == actor,
|
||||
"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),
|
||||
"kind_label": "Teilvorgang" if matter["parent_matter_id"] else "Vorgang",
|
||||
"rights": rights.as_dict(),
|
||||
"context": None if context is None else context.as_dict(),
|
||||
"chapters": _chapters(conn, "matter", matter["id"]),
|
||||
@@ -336,19 +443,15 @@ def matter_detail(conn, actor: UUID, matter: dict, rights, context: Ctx | None)
|
||||
if title is not None:
|
||||
crosses.append({"id": str(link["id"]), "matter_id": str(link["to_matter_id"]), "title": title})
|
||||
payload["cross_links"] = crosses
|
||||
bindings = []
|
||||
for binding in conn.execute(
|
||||
"""
|
||||
SELECT * FROM bindings
|
||||
WHERE context_kind = 'matter' AND context_id = %s
|
||||
ORDER BY position, created_at
|
||||
""",
|
||||
(matter["id"],),
|
||||
).fetchall():
|
||||
item = binding_payload(conn, actor, binding, page)
|
||||
if item is not None:
|
||||
bindings.append(item)
|
||||
payload["bindings"] = bindings
|
||||
payload["bindings"] = _ordered_bindings(
|
||||
conn,
|
||||
actor,
|
||||
"matter",
|
||||
matter["id"],
|
||||
page,
|
||||
payload["content_order"],
|
||||
payload["content_order_dir"],
|
||||
)
|
||||
payload["tasks"] = []
|
||||
for task in conn.execute(
|
||||
"""
|
||||
@@ -497,4 +600,6 @@ LABELS = {
|
||||
"correspondence_received": "Zugang",
|
||||
"correspondence_recorded": "Erfassung",
|
||||
"chapter_created": "Kapitel angelegt",
|
||||
"content_order": "Ordnungsart geändert",
|
||||
"content_reordered": "Eigene Reihenfolge geändert",
|
||||
}
|
||||
Reference in new issue
Block a user