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
+154
-3
@@ -56,6 +56,9 @@ from app.api.schemas import (
|
||||
MatterIn,
|
||||
MatterPatch,
|
||||
MemberIn,
|
||||
BindingOrderIn,
|
||||
ContentOrderIn,
|
||||
DatesPatch,
|
||||
NoteIn,
|
||||
NotePatch,
|
||||
RoomIn,
|
||||
@@ -102,8 +105,11 @@ from app.ops import (
|
||||
patch_matter,
|
||||
patch_task,
|
||||
revoke_grant,
|
||||
reorder_bindings,
|
||||
set_content_order,
|
||||
set_exception,
|
||||
unlink_matter_case,
|
||||
update_dates,
|
||||
update_note,
|
||||
)
|
||||
from app.present import (
|
||||
@@ -112,6 +118,7 @@ from app.present import (
|
||||
case_detail,
|
||||
case_summary,
|
||||
deadline_payload,
|
||||
course_items,
|
||||
matter_detail,
|
||||
matter_summary,
|
||||
note_update_payload,
|
||||
@@ -725,6 +732,7 @@ def post_note(body: NoteIn, principal: Principal = Depends(get_principal), conn:
|
||||
Ctx(body.context.kind, body.context.id),
|
||||
_ctx_model(body.placement),
|
||||
body.chapter_id,
|
||||
body.dates.document_on if body.dates else None,
|
||||
)
|
||||
element = created["element"]
|
||||
return _created(
|
||||
@@ -1143,8 +1151,127 @@ def search(q: str, principal: Principal = Depends(get_principal), conn: Connecti
|
||||
return {"items": items[:50], "next_cursor": None}
|
||||
|
||||
|
||||
@router.patch("/api/v1/cases/{case_id}/content-order")
|
||||
def patch_case_order(
|
||||
case_id: UUID,
|
||||
body: ContentOrderIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
version = set_content_order(
|
||||
conn, principal.account_id, "case", case_id, body.expected_version, body.mode, body.direction, None
|
||||
)
|
||||
return {"version": version, "mode": body.mode, "direction": body.direction}
|
||||
|
||||
|
||||
@router.post("/api/v1/cases/{case_id}/bindings/order")
|
||||
def post_case_binding_order(
|
||||
case_id: UUID,
|
||||
body: BindingOrderIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
version = reorder_bindings(
|
||||
conn, principal.account_id, "case", case_id, body.expected_version, body.binding_ids, None
|
||||
)
|
||||
return {"version": version}
|
||||
|
||||
|
||||
@router.patch("/api/v1/matters/{matter_id}/content-order")
|
||||
def patch_matter_order(
|
||||
matter_id: UUID,
|
||||
body: ContentOrderIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
version = set_content_order(
|
||||
conn,
|
||||
principal.account_id,
|
||||
"matter",
|
||||
matter_id,
|
||||
body.expected_version,
|
||||
body.mode,
|
||||
body.direction,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
return {"version": version, "mode": body.mode, "direction": body.direction}
|
||||
|
||||
|
||||
@router.post("/api/v1/matters/{matter_id}/bindings/order")
|
||||
def post_matter_binding_order(
|
||||
matter_id: UUID,
|
||||
body: BindingOrderIn,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
version = reorder_bindings(
|
||||
conn,
|
||||
principal.account_id,
|
||||
"matter",
|
||||
matter_id,
|
||||
body.expected_version,
|
||||
body.binding_ids,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
return {"version": version}
|
||||
|
||||
|
||||
@router.patch("/api/v1/elements/{element_id}/dates")
|
||||
def patch_element_dates(
|
||||
element_id: UUID,
|
||||
body: DatesPatch,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
element = update_dates(
|
||||
conn,
|
||||
principal.account_id,
|
||||
element_id,
|
||||
body.expected_version,
|
||||
body.document_on,
|
||||
body.sent_on,
|
||||
body.received_on,
|
||||
_ctx_model(body.context),
|
||||
)
|
||||
return {"id": str(element["id"]), "version": element["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")
|
||||
detail = case_detail(conn, principal.account_id, case, rights)
|
||||
return {"items": course_items(detail["bindings"]), "next_cursor": None}
|
||||
|
||||
|
||||
@router.get("/api/v1/matters/{matter_id}/course")
|
||||
def matter_course(
|
||||
matter_id: UUID,
|
||||
context_kind: str | None = None,
|
||||
context_id: str | None = None,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
context = parse_query_context(context_kind, context_id)
|
||||
matter, rights = require_matter(conn, principal.account_id, matter_id, context, "read")
|
||||
detail = matter_detail(conn, principal.account_id, matter, rights, context)
|
||||
return {"items": course_items(detail["bindings"]), "next_cursor": None}
|
||||
|
||||
|
||||
@router.get("/api/v1/views/recent-matters")
|
||||
def recent_matters(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
rows = [matter for matter, _contexts in list_matters(conn, principal.account_id)]
|
||||
rows.sort(key=lambda item: (item["updated_at"], str(item["id"])), reverse=True)
|
||||
items = [matter_summary(conn, principal.account_id, matter) for matter in rows[:8]]
|
||||
return {"items": items, "next_cursor": None}
|
||||
|
||||
|
||||
@router.get("/api/v1/cases/{case_id}/chronology")
|
||||
def case_chronology(case_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||
def case_chronology(
|
||||
case_id: UUID,
|
||||
cursor: str | None = None,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
case, _rights = require_case(conn, principal.account_id, case_id, "read")
|
||||
page = Ctx("case", case["id"])
|
||||
rows = conn.execute(
|
||||
@@ -1166,7 +1293,7 @@ def case_chronology(case_id: UUID, principal: Principal = Depends(get_principal)
|
||||
""",
|
||||
{"case": case_id},
|
||||
).fetchall()
|
||||
return {"items": _visible_events(conn, principal.account_id, rows, page)}
|
||||
return _event_page(_visible_events(conn, principal.account_id, rows, page), cursor)
|
||||
|
||||
|
||||
@router.get("/api/v1/matters/{matter_id}/chronology")
|
||||
@@ -1174,6 +1301,7 @@ def matter_chronology(
|
||||
matter_id: UUID,
|
||||
context_kind: str | None = None,
|
||||
context_id: str | None = None,
|
||||
cursor: str | None = None,
|
||||
principal: Principal = Depends(get_principal),
|
||||
conn: Connection = Depends(get_conn),
|
||||
):
|
||||
@@ -1198,7 +1326,7 @@ def matter_chronology(
|
||||
""",
|
||||
{"matter": matter_id},
|
||||
).fetchall()
|
||||
return {"items": _visible_events(conn, principal.account_id, rows, page)}
|
||||
return _event_page(_visible_events(conn, principal.account_id, rows, page), cursor)
|
||||
|
||||
|
||||
def _parse_date(value: str | None) -> date | None:
|
||||
@@ -1237,18 +1365,41 @@ def _case_contexts(conn, actor, matter) -> list[dict]:
|
||||
return [item for item in readable_matter_contexts(conn, actor, matter) if item["kind"] == "case"]
|
||||
|
||||
|
||||
def _event_page(items: list[dict], cursor: str | None, limit: int = 40) -> dict:
|
||||
start = 0
|
||||
if cursor:
|
||||
ids = [item["id"] for item in items]
|
||||
if cursor not in ids:
|
||||
return {"items": [], "next_cursor": None}
|
||||
start = ids.index(cursor) + 1
|
||||
chunk = items[start:start + limit]
|
||||
next_cursor = chunk[-1]["id"] if chunk and start + limit < len(items) else None
|
||||
return {"items": chunk, "next_cursor": next_cursor}
|
||||
|
||||
|
||||
def _visible_events(conn, actor: UUID, rows: list[dict], page: Ctx) -> list[dict]:
|
||||
names: dict = {}
|
||||
items = []
|
||||
for event in rows:
|
||||
title = _event_title(conn, actor, event, page)
|
||||
if title is None:
|
||||
continue
|
||||
actor_id = event["actor_subject_id"]
|
||||
if actor_id not in names:
|
||||
row = None
|
||||
if actor_id is not None:
|
||||
row = conn.execute(
|
||||
"SELECT display_name FROM auth_accounts WHERE id = %s",
|
||||
(actor_id,),
|
||||
).fetchone()
|
||||
names[actor_id] = row["display_name"] if row else None
|
||||
items.append(
|
||||
{
|
||||
"id": str(event["id"]),
|
||||
"action": event["action"],
|
||||
"label": LABELS.get(event["action"], "Ereignis"),
|
||||
"title": title,
|
||||
"actor_display_name": names[actor_id],
|
||||
"occurred_on": event["occurred_on"].isoformat() if event["occurred_on"] else None,
|
||||
"occurred_at": event["occurred_at"].astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||
"resource_kind": event["resource_kind"],
|
||||
|
||||
@@ -132,6 +132,28 @@ class NoteIn(APIModel):
|
||||
context: ContextIn
|
||||
placement: ContextIn | None = None
|
||||
chapter_id: UUID | None = None
|
||||
dates: DatesIn | None = None
|
||||
|
||||
|
||||
class ContentOrderIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
mode: Literal["date", "position"]
|
||||
direction: Literal["asc", "desc"] = "asc"
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class BindingOrderIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
binding_ids: list[UUID] = Field(min_length=0, max_length=500)
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class DatesPatch(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
document_on: date | None = None
|
||||
sent_on: date | None = None
|
||||
received_on: date | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
class NotePatch(APIModel):
|
||||
|
||||
+125
-9
@@ -76,9 +76,10 @@ def create_case(conn, actor: UUID, scope_id: UUID, title: str, parent_case_id: U
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO cases (
|
||||
home_scope_id, owner_subject_id, created_by, title, rights_mode
|
||||
home_scope_id, owner_subject_id, created_by, title, rights_mode,
|
||||
content_order, content_order_dir
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, 'explicit')
|
||||
VALUES (%s, %s, %s, %s, 'explicit', 'date', 'asc')
|
||||
RETURNING *
|
||||
""",
|
||||
(scope_id, actor, actor, title),
|
||||
@@ -92,9 +93,10 @@ def create_case(conn, actor: UUID, scope_id: UUID, title: str, parent_case_id: U
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO cases (
|
||||
home_scope_id, owner_subject_id, created_by, title, parent_case_id, rights_mode
|
||||
home_scope_id, owner_subject_id, created_by, title, parent_case_id, rights_mode,
|
||||
content_order, content_order_dir
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, 'date', 'asc')
|
||||
RETURNING *
|
||||
""",
|
||||
(parent["home_scope_id"], actor, actor, title, parent["id"], rights_mode),
|
||||
@@ -156,8 +158,10 @@ def create_matter(conn, actor: UUID, scope_id: UUID, title: str, parent_matter_i
|
||||
if parent_matter_id is None:
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO matters (home_scope_id, owner_subject_id, created_by, title)
|
||||
VALUES (%s, %s, %s, %s) RETURNING *
|
||||
INSERT INTO matters (
|
||||
home_scope_id, owner_subject_id, created_by, title, content_order, content_order_dir
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, 'date', 'asc') RETURNING *
|
||||
""",
|
||||
(scope_id, actor, actor, title),
|
||||
).fetchone()
|
||||
@@ -168,9 +172,10 @@ def create_matter(conn, actor: UUID, scope_id: UUID, title: str, parent_matter_i
|
||||
row = conn.execute(
|
||||
"""
|
||||
INSERT INTO matters (
|
||||
home_scope_id, owner_subject_id, created_by, title, parent_matter_id
|
||||
home_scope_id, owner_subject_id, created_by, title, parent_matter_id,
|
||||
content_order, content_order_dir
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s) RETURNING *
|
||||
VALUES (%s, %s, %s, %s, %s, 'date', 'asc') RETURNING *
|
||||
""",
|
||||
(parent["home_scope_id"], actor, actor, title, parent["id"]),
|
||||
).fetchone()
|
||||
@@ -440,7 +445,17 @@ def record_dates(conn, actor: UUID, scope_id: UUID, element_id: UUID, context: C
|
||||
audit(conn, actor, scope_id, "correspondence_recorded", "element", element_id, context)
|
||||
|
||||
|
||||
def create_note(conn, actor: UUID, scope_id: UUID, title: str, document: dict, context: Ctx, placement: Ctx | None, chapter_id: UUID | None) -> dict:
|
||||
def create_note(
|
||||
conn,
|
||||
actor: UUID,
|
||||
scope_id: UUID,
|
||||
title: str,
|
||||
document: dict,
|
||||
context: Ctx,
|
||||
placement: Ctx | None,
|
||||
chapter_id: UUID | None,
|
||||
document_on: date | None = None,
|
||||
) -> dict:
|
||||
document = clean_document(document)
|
||||
target, rights_context = _placement(context, placement)
|
||||
require_container_edit(conn, actor, target, rights_context)
|
||||
@@ -451,6 +466,8 @@ def create_note(conn, actor: UUID, scope_id: UUID, title: str, document: dict, c
|
||||
)
|
||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||
audit(conn, actor, scope_id, "note_created", "element", element["id"], rights_context or target)
|
||||
if document_on is not None:
|
||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, None, None)
|
||||
return {"element": element, "binding": binding, "document": document}
|
||||
|
||||
|
||||
@@ -782,3 +799,102 @@ def link_task_deadline(conn, actor: UUID, task_id: UUID, deadline_id: UUID, cont
|
||||
""",
|
||||
(task_id, deadline_id, actor),
|
||||
)
|
||||
|
||||
|
||||
def set_content_order(
|
||||
conn,
|
||||
actor: UUID,
|
||||
kind: str,
|
||||
container_id: UUID,
|
||||
expected: int,
|
||||
mode: str,
|
||||
direction: str,
|
||||
context: Ctx | None,
|
||||
) -> int:
|
||||
if kind == "case":
|
||||
container, rights = require_case(conn, actor, container_id, "edit")
|
||||
table = "cases"
|
||||
else:
|
||||
container, rights = require_matter(conn, actor, container_id, context, "edit")
|
||||
table = "matters"
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
version = bump_version(conn, table, container_id, expected)
|
||||
conn.execute(
|
||||
f"UPDATE {table} SET content_order = %s, content_order_dir = %s WHERE id = %s",
|
||||
(mode, direction, container_id),
|
||||
)
|
||||
audit(conn, actor, container["home_scope_id"], "content_order", kind, container_id, context)
|
||||
return version
|
||||
|
||||
|
||||
def reorder_bindings(
|
||||
conn,
|
||||
actor: UUID,
|
||||
kind: str,
|
||||
container_id: UUID,
|
||||
expected: int,
|
||||
binding_ids: list[UUID],
|
||||
context: Ctx | None,
|
||||
) -> int:
|
||||
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()
|
||||
version = bump_version(conn, table, container_id, expected)
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT * FROM bindings
|
||||
WHERE context_kind = %s AND context_id = %s
|
||||
ORDER BY position, id
|
||||
""",
|
||||
(kind, container_id),
|
||||
).fetchall()
|
||||
visible_ids = []
|
||||
for row in rows:
|
||||
element = get_element(conn, row["element_id"])
|
||||
if element is not None and element_rights(conn, actor, element, page).read:
|
||||
visible_ids.append(row["id"])
|
||||
submitted = list(binding_ids)
|
||||
if len(submitted) != len(set(submitted)):
|
||||
raise unprocessable("Dieselbe Einbindung steht mehrfach in der Ordnung.")
|
||||
if any(item not in set(visible_ids) for item in submitted):
|
||||
raise not_found()
|
||||
if set(submitted) != set(visible_ids):
|
||||
raise unprocessable("Die Ordnung ist unvollständig. Bitte neu laden.")
|
||||
visible_set = set(visible_ids)
|
||||
coming = iter(submitted)
|
||||
sequence = []
|
||||
for row in rows:
|
||||
if row["id"] in visible_set:
|
||||
sequence.append(next(coming))
|
||||
else:
|
||||
sequence.append(row["id"])
|
||||
for index, binding_id in enumerate(sequence):
|
||||
conn.execute("UPDATE bindings SET position = %s WHERE id = %s", (index, binding_id))
|
||||
audit(conn, actor, container["home_scope_id"], "content_reordered", kind, container_id, context)
|
||||
return version
|
||||
|
||||
|
||||
def update_dates(
|
||||
conn,
|
||||
actor: UUID,
|
||||
element_id: UUID,
|
||||
expected: int,
|
||||
document_on: date | None,
|
||||
sent_on: date | None,
|
||||
received_on: date | None,
|
||||
context: Ctx | None,
|
||||
) -> dict:
|
||||
element, rights = require_element(conn, actor, element_id, context, "edit")
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
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)
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Display order for bindings. Stored positions stay intact when sorting by date."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def arrange(items: list[dict], mode: str, direction: str) -> list[dict]:
|
||||
"""Return a new list. Undated entries stay last in both date directions."""
|
||||
if mode == "position":
|
||||
ordered = sorted(items, key=lambda item: (item["_raw_position"], item["id"]))
|
||||
else:
|
||||
dated = [item for item in items if item.get("_document_on")]
|
||||
undated = [item for item in items if not item.get("_document_on")]
|
||||
if direction == "desc":
|
||||
dated.sort(key=lambda item: (item["_raw_position"], item["id"]))
|
||||
dated.sort(key=lambda item: item["_document_on"], reverse=True)
|
||||
else:
|
||||
dated.sort(key=lambda item: (item["_document_on"], item["_raw_position"], item["id"]))
|
||||
undated.sort(key=lambda item: (item["_raw_position"], item["id"]))
|
||||
ordered = dated + undated
|
||||
result = []
|
||||
for index, item in enumerate(ordered):
|
||||
visible = {key: value for key, value in item.items() if not key.startswith("_")}
|
||||
visible["position"] = index
|
||||
result.append(visible)
|
||||
return result
|
||||
+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",
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
ALTER TABLE cases
|
||||
ADD COLUMN content_order text NOT NULL DEFAULT 'position',
|
||||
ADD COLUMN content_order_dir text NOT NULL DEFAULT 'asc';
|
||||
|
||||
ALTER TABLE cases
|
||||
ADD CONSTRAINT cases_content_order CHECK (content_order IN ('date', 'position')),
|
||||
ADD CONSTRAINT cases_content_order_dir CHECK (content_order_dir IN ('asc', 'desc'));
|
||||
|
||||
ALTER TABLE matters
|
||||
ADD COLUMN content_order text NOT NULL DEFAULT 'position',
|
||||
ADD COLUMN content_order_dir text NOT NULL DEFAULT 'asc';
|
||||
|
||||
ALTER TABLE matters
|
||||
ADD CONSTRAINT matters_content_order CHECK (content_order IN ('date', 'position')),
|
||||
ADD CONSTRAINT matters_content_order_dir CHECK (content_order_dir IN ('asc', 'desc'));
|
||||
@@ -0,0 +1,371 @@
|
||||
"""Persistent content order, fachliche dates and context limits."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tests.support import Actor, binding_for, case_of, document, grant, matter_of, register
|
||||
|
||||
|
||||
def _note(actor: Actor, title: str, container: dict, *, kind: str = "matter", document_on: str | None = None) -> None:
|
||||
body = {
|
||||
"title": title,
|
||||
"document": document(title),
|
||||
"context": {"kind": kind, "id": container["id"]},
|
||||
}
|
||||
if document_on:
|
||||
body["dates"] = {"document_on": document_on}
|
||||
actor.request("POST", "/api/v1/notes", json=body, status=201)
|
||||
|
||||
|
||||
def _matter(actor: Actor, matter_id: str) -> dict:
|
||||
return actor.request("GET", f"/api/v1/matters/{matter_id}")
|
||||
|
||||
|
||||
def _titles(detail: dict) -> list[str]:
|
||||
return [item["element"]["title"] for item in detail["bindings"]]
|
||||
|
||||
|
||||
def test_date_order_keeps_undated_last_and_ignores_recorded_time(client, db):
|
||||
ada = Actor(client, "ada-order@example.test", "Ada Ordnung")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Fristenmappe")
|
||||
dates = ["2024-05-02", "2020-01-01", "2024-05-02", "2022-07-07", "2023-03-03", "2021-02-02"]
|
||||
for index, day in enumerate(dates):
|
||||
_note(ada, f"D{index}-{day}", matter, document_on=day)
|
||||
_note(ada, "Ohne-A", matter)
|
||||
_note(ada, "Ohne-B", matter)
|
||||
detail = _matter(ada, matter["id"])
|
||||
titles = _titles(detail)
|
||||
assert titles[:6] == ["D1-2020-01-01", "D5-2021-02-02", "D3-2022-07-07", "D4-2023-03-03", "D0-2024-05-02", "D2-2024-05-02"]
|
||||
assert titles[6:] == ["Ohne-A", "Ohne-B"]
|
||||
assert all(item["element"]["dates"]["document_on"] is None for item in detail["bindings"] if item["element"]["title"].startswith("Ohne"))
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/matters/{matter['id']}/content-order",
|
||||
json={"expected_version": detail["version"], "mode": "date", "direction": "desc"},
|
||||
)
|
||||
descending = _titles(_matter(ada, matter["id"]))
|
||||
assert descending[:6] == ["D0-2024-05-02", "D2-2024-05-02", "D4-2023-03-03", "D3-2022-07-07", "D5-2021-02-02", "D1-2020-01-01"]
|
||||
assert descending[6:] == ["Ohne-A", "Ohne-B"]
|
||||
|
||||
|
||||
def test_custom_order_survives_reload_login_and_date_mode(client, db):
|
||||
ada = Actor(client, "ada-seq@example.test", "Ada Folge")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Reihenfolge")
|
||||
for title, day in (("Alpha", "2020-01-01"), ("Beta", "2021-01-01"), ("Gamma", "2022-01-01")):
|
||||
_note(ada, title, matter, document_on=day)
|
||||
detail = _matter(ada, matter["id"])
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/matters/{matter['id']}/content-order",
|
||||
json={"expected_version": detail["version"], "mode": "position", "direction": "asc"},
|
||||
)
|
||||
detail = _matter(ada, matter["id"])
|
||||
ids = [binding_for(detail, name)["id"] for name in ("Gamma", "Alpha", "Beta")]
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": detail["version"], "binding_ids": ids},
|
||||
)
|
||||
ada.login()
|
||||
restored = _matter(ada, matter["id"])
|
||||
assert _titles(restored) == ["Gamma", "Alpha", "Beta"]
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/matters/{matter['id']}/content-order",
|
||||
json={"expected_version": restored["version"], "mode": "date", "direction": "asc"},
|
||||
)
|
||||
dated = _matter(ada, matter["id"])
|
||||
assert _titles(dated) == ["Alpha", "Beta", "Gamma"]
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/matters/{matter['id']}/content-order",
|
||||
json={"expected_version": dated["version"], "mode": "position", "direction": "asc"},
|
||||
)
|
||||
assert _titles(_matter(ada, matter["id"])) == ["Gamma", "Alpha", "Beta"]
|
||||
_note(ada, "Delta", matter)
|
||||
assert _titles(_matter(ada, matter["id"]))[-1] == "Delta"
|
||||
|
||||
|
||||
def test_same_element_has_independent_positions(client, db):
|
||||
ada = Actor(client, "ada-two@example.test", "Ada Zwei")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
left = case_of(ada, "Akte A")
|
||||
right = case_of(ada, "Akte B")
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={"title": "Gemeinsam", "document": document("Wort"), "context": {"kind": "case", "id": left["id"]}},
|
||||
status=201,
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={"title": "Nur A", "document": document("A"), "context": {"kind": "case", "id": left["id"]}},
|
||||
status=201,
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={"title": "Nur B", "document": document("B"), "context": {"kind": "case", "id": right["id"]}},
|
||||
status=201,
|
||||
)
|
||||
shared = binding_for(ada.request("GET", f"/api/v1/cases/{left['id']}"), "Gemeinsam")
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/bindings",
|
||||
json={
|
||||
"element_id": shared["element"]["id"],
|
||||
"source_context": {"kind": "case", "id": left["id"]},
|
||||
"target": {"kind": "case", "id": right["id"]},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
for case in (left, right):
|
||||
detail = ada.request("GET", f"/api/v1/cases/{case['id']}")
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/cases/{case['id']}/content-order",
|
||||
json={"expected_version": detail["version"], "mode": "position", "direction": "asc"},
|
||||
)
|
||||
left_detail = ada.request("GET", f"/api/v1/cases/{left['id']}")
|
||||
right_detail = ada.request("GET", f"/api/v1/cases/{right['id']}")
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/cases/{left['id']}/bindings/order",
|
||||
json={
|
||||
"expected_version": left_detail["version"],
|
||||
"binding_ids": [binding_for(left_detail, "Gemeinsam")["id"], binding_for(left_detail, "Nur A")["id"]],
|
||||
},
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/cases/{right['id']}/bindings/order",
|
||||
json={
|
||||
"expected_version": right_detail["version"],
|
||||
"binding_ids": [binding_for(right_detail, "Nur B")["id"], binding_for(right_detail, "Gemeinsam")["id"]],
|
||||
},
|
||||
)
|
||||
assert _titles(ada.request("GET", f"/api/v1/cases/{left['id']}")) == ["Gemeinsam", "Nur A"]
|
||||
assert _titles(ada.request("GET", f"/api/v1/cases/{right['id']}")) == ["Nur B", "Gemeinsam"]
|
||||
left_note = binding_for(ada.request("GET", f"/api/v1/cases/{left['id']}"), "Gemeinsam")
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/bindings/{left_note['id']}/annotations",
|
||||
json={"body": "Nur in A"},
|
||||
status=201,
|
||||
)
|
||||
right_note = binding_for(ada.request("GET", f"/api/v1/cases/{right['id']}"), "Gemeinsam")
|
||||
assert right_note["annotations"] == []
|
||||
assert left_note["element"]["id"] == right_note["element"]["id"]
|
||||
|
||||
|
||||
def test_chapters_and_contained_matters_stay_distinct(client, db):
|
||||
ada = Actor(client, "ada-chap@example.test", "Ada Kapitel")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
case = case_of(ada, "Sammelakte")
|
||||
matter = matter_of(ada, "Enthaltener Vorgang")
|
||||
ada.request("POST", f"/api/v1/matters/{matter['id']}/case-links", json={"case_id": case["id"]}, status=201)
|
||||
chapter = ada.request("POST", f"/api/v1/cases/{case['id']}/chapters", json={"title": "Belege"}, status=201)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={
|
||||
"title": "Im Kapitel",
|
||||
"document": document("kapitel"),
|
||||
"context": {"kind": "case", "id": case["id"]},
|
||||
"chapter_id": chapter["id"],
|
||||
"dates": {"document_on": "2021-01-01"},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={"title": "Ohne Kapitel", "document": document("lose"), "context": {"kind": "case", "id": case["id"]}},
|
||||
status=201,
|
||||
)
|
||||
_note(ada, "Im Vorgang", matter, document_on="2019-01-01")
|
||||
detail = ada.request("GET", f"/api/v1/cases/{case['id']}")
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/cases/{case['id']}/content-order",
|
||||
json={"expected_version": detail["version"], "mode": "date", "direction": "desc"},
|
||||
)
|
||||
detail = ada.request("GET", f"/api/v1/cases/{case['id']}")
|
||||
direct = {item["element"]["title"]: item["chapter_id"] for item in detail["bindings"]}
|
||||
assert direct["Im Kapitel"] == chapter["id"]
|
||||
assert direct["Ohne Kapitel"] is None
|
||||
assert [item["element"]["title"] for item in detail["bindings"]] == ["Im Kapitel", "Ohne Kapitel"]
|
||||
assert detail["contained"][0]["title"] == "Enthaltener Vorgang"
|
||||
assert detail["contained"][0]["bindings"][0]["element"]["title"] == "Im Vorgang"
|
||||
assert "Im Vorgang" not in direct
|
||||
|
||||
|
||||
def test_course_is_not_a_copy_of_the_audit_log(client, db):
|
||||
ada = Actor(client, "ada-course@example.test", "Ada Verlauf")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Verlauf")
|
||||
created = ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={
|
||||
"title": "Schreiben",
|
||||
"document": document("Text"),
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
"dates": {"document_on": "2024-04-04"},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/elements/{created['id']}/dates",
|
||||
json={"expected_version": created["version"], "document_on": "2024-04-05", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
course = ada.request("GET", f"/api/v1/matters/{matter['id']}/course")
|
||||
audit = ada.request("GET", f"/api/v1/matters/{matter['id']}/chronology")
|
||||
assert [item["title"] for item in course["items"]] == ["Schreiben"]
|
||||
assert course["items"][0]["document_on"] == "2024-04-05"
|
||||
assert "recorded_at" not in course["items"][0]
|
||||
assert len(audit["items"]) > len(course["items"])
|
||||
|
||||
|
||||
def test_reorder_rejects_readers_foreign_ids_and_conflicts(client, db):
|
||||
ada = Actor(client, "ada-guard@example.test", "Ada Schutz")
|
||||
ben = Actor(client, "ben-guard@example.test", "Ben Schutz")
|
||||
register(db, ada.email, ada.name)
|
||||
register(db, ben.email, ben.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Geschützt")
|
||||
hidden_case = case_of(ada, "Verborgene Akte")
|
||||
for title in ("Sichtbar", "Verborgen"):
|
||||
_note(ada, title, matter)
|
||||
detail = _matter(ada, matter["id"])
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/matters/{matter['id']}/content-order",
|
||||
json={"expected_version": detail["version"], "mode": "position", "direction": "asc"},
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/grants",
|
||||
json={"email": ben.email, "can_read": True, "can_edit": False, "can_share": False},
|
||||
status=201,
|
||||
)
|
||||
ben.login()
|
||||
ben_view = _matter(ben, matter["id"])
|
||||
ben.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": ben_view["version"], "binding_ids": [item["id"] for item in ben_view["bindings"]]},
|
||||
status=403,
|
||||
)
|
||||
ben.request("GET", f"/api/v1/cases/{hidden_case['id']}", status=404)
|
||||
ada.login()
|
||||
ada_view = _matter(ada, matter["id"])
|
||||
visible_id = binding_for(ada_view, "Sichtbar")["id"]
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": ada_view["version"], "binding_ids": [visible_id]},
|
||||
status=422,
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={"title": "Fremd", "document": document("x"), "context": {"kind": "case", "id": hidden_case["id"]}},
|
||||
status=201,
|
||||
)
|
||||
foreign = binding_for(ada.request("GET", f"/api/v1/cases/{hidden_case['id']}"), "Fremd")
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": ada_view["version"], "binding_ids": [foreign["id"], visible_id]},
|
||||
status=404,
|
||||
)
|
||||
hidden = binding_for(ada_view, "Verborgen")
|
||||
ada.request(
|
||||
"PUT",
|
||||
"/api/v1/exceptions",
|
||||
json={
|
||||
"resource_kind": "element",
|
||||
"resource_id": hidden["element"]["id"],
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
"remove_read": True,
|
||||
},
|
||||
)
|
||||
masked = _matter(ada, matter["id"])
|
||||
assert _titles(masked) == ["Sichtbar"]
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": masked["version"], "binding_ids": [binding_for(masked, "Sichtbar")["id"]]},
|
||||
)
|
||||
conflict = ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/bindings/order",
|
||||
json={"expected_version": masked["version"], "binding_ids": [binding_for(masked, "Sichtbar")["id"]]},
|
||||
status=409,
|
||||
)
|
||||
assert conflict["detail"] == "Der Stand hat sich geändert. Bitte neu laden."
|
||||
kept = db.execute("SELECT id FROM bindings WHERE id = %s", (hidden["id"],)).fetchone()
|
||||
assert kept is not None
|
||||
ben.login()
|
||||
assert "Verborgen" not in str(_matter(ben, matter["id"]))
|
||||
|
||||
|
||||
def test_existing_position_mode_is_not_rewritten(client, db):
|
||||
ada = Actor(client, "ada-keep@example.test", "Ada Bestand")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
room = ada.scope["id"]
|
||||
row = db.execute(
|
||||
"""
|
||||
INSERT INTO cases (home_scope_id, owner_subject_id, created_by, title, rights_mode)
|
||||
VALUES (%s, (SELECT id FROM auth_accounts WHERE email = %s), (SELECT id FROM auth_accounts WHERE email = %s), 'Altakte', 'explicit')
|
||||
RETURNING id
|
||||
""",
|
||||
(room, ada.email, ada.email),
|
||||
).fetchone()
|
||||
db.commit()
|
||||
detail = ada.request("GET", f"/api/v1/cases/{row['id']}")
|
||||
assert detail["content_order"] == "position"
|
||||
assert detail["content_order_dir"] == "asc"
|
||||
|
||||
|
||||
def test_direct_matter_trail_invents_no_case(client, db):
|
||||
ada = Actor(client, "ada-trail@example.test", "Ada Pfad")
|
||||
ben = Actor(client, "ben-trail@example.test", "Ben Pfad")
|
||||
register(db, ada.email, ada.name)
|
||||
register(db, ben.email, ben.name)
|
||||
ada.login()
|
||||
parent = case_of(ada, "Vermietung")
|
||||
child = ada.request(
|
||||
"POST",
|
||||
"/api/v1/cases",
|
||||
json={"title": "Wohnung", "parent_case_id": parent["id"], "rights_mode": "explicit"},
|
||||
status=201,
|
||||
)
|
||||
matter = matter_of(ada, "Nebenkosten")
|
||||
other = case_of(ada, "Geheim")
|
||||
ada.request("POST", f"/api/v1/matters/{matter['id']}/case-links", json={"case_id": child["id"]}, status=201)
|
||||
ada.request("POST", f"/api/v1/matters/{matter['id']}/case-links", json={"case_id": other["id"]}, status=201)
|
||||
grant(ada, child["id"], ben.email)
|
||||
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 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"]]
|
||||
Reference in new issue
Block a user