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):
|
||||
|
||||
Reference in new issue
Block a user