Halte Anlagen und Versand als eigene Verwendung fest, damit die uebermittelte Fassung und ihre Nachweise spaeter nicht still mit der Arbeitsfassung verschmelzen.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Successful in 1m37s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 09:57:59 +02:00
1 parent f21c64a944
commit 3c190c87b4
27 files changed
+3953 -71

No files matched your search

+247
View File
@@ -0,0 +1,247 @@
"""HTTP for attachment roles, documented dispatches and secured editions."""
from __future__ import annotations
from uuid import UUID
from fastapi import APIRouter, Depends, Request, Response
from psycopg import Connection
from app.access.policy import Ctx
from app.api.deps import Principal, get_conn, get_principal
from app.api.schemas import (
AttachmentAssignIn,
AttachmentDetachIn,
AttachmentOrderIn,
DispatchCorrectIn,
DispatchEvidenceIn,
DispatchIn,
FoldIn,
)
from app.correspondence import (
GapNote,
add_dispatch_evidence,
assign_attachments,
correct_dispatch,
detach_attachment,
dispatch_view,
open_container,
order_attachments,
read_snapshot,
record_dispatch,
set_fold,
)
from app.core.errors import not_found
from app.media.storage import content_disposition
router = APIRouter()
def _ctx(value) -> Ctx:
return Ctx(value.kind, value.id)
def _placement(value) -> Ctx | None:
if value is None:
return None
return Ctx(value.kind, value.id)
@router.post("/api/v1/elements/{element_id}/attachments", status_code=201)
def post_attachments(
element_id: UUID,
body: AttachmentAssignIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return assign_attachments(
conn,
principal.account_id,
element_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.attachment_element_ids,
body.fold,
[],
)
@router.post("/api/v1/elements/{element_id}/attachments/order")
def post_attachment_order(
element_id: UUID,
body: AttachmentOrderIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return order_attachments(
conn,
principal.account_id,
element_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.attachment_element_ids,
)
@router.post("/api/v1/elements/{element_id}/attachments/{attachment_id}/detach", status_code=204)
def post_detach(
element_id: UUID,
attachment_id: UUID,
body: AttachmentDetachIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
detach_attachment(
conn,
principal.account_id,
element_id,
attachment_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
)
@router.patch("/api/v1/bindings/{binding_id}/fold")
def patch_fold(
binding_id: UUID,
body: FoldIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return set_fold(
conn,
principal.account_id,
binding_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.fold,
)
@router.post("/api/v1/elements/{element_id}/dispatches", status_code=201)
def post_dispatch(
element_id: UUID,
body: DispatchIn,
request: Request,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
request.state.cleanup_files = []
return record_dispatch(
conn,
principal.account_id,
element_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.channel,
body.sent_on,
body.counterpart,
body.attachment_element_ids,
[item.model_dump() for item in body.evidence],
body.historical_gap,
request.app.state.settings.media_root,
request.state.cleanup_files,
)
@router.post("/api/v1/dispatches/{dispatch_id}/evidence", status_code=201)
def post_evidence(
dispatch_id: UUID,
body: DispatchEvidenceIn,
request: Request,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
request.state.cleanup_files = []
return add_dispatch_evidence(
conn,
principal.account_id,
dispatch_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.element_id,
body.role,
body.fold,
request.app.state.settings.media_root,
request.state.cleanup_files,
)
@router.post("/api/v1/dispatches/{dispatch_id}/correct")
def post_correct(
dispatch_id: UUID,
body: DispatchCorrectIn,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
return correct_dispatch(
conn,
principal.account_id,
dispatch_id,
body.expected_version,
_ctx(body.context),
_placement(body.placement),
body.channel,
body.sent_on,
body.clear_sent_on,
body.counterpart,
body.clear_counterpart,
)
@router.get("/api/v1/dispatches/{dispatch_id}")
def get_dispatch(
dispatch_id: UUID,
context_kind: str,
context_id: UUID,
placement_kind: str | None = None,
placement_id: UUID | None = None,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
context = Ctx(context_kind, context_id)
placement = Ctx(placement_kind, placement_id) if placement_kind and placement_id else None
_row, page, scope = open_container(conn, principal.account_id, context, placement, "read")
return dispatch_view(conn, principal.account_id, dispatch_id, page, scope)
@router.get("/api/v1/dispatches/{dispatch_id}/items/{item_id}/content")
def get_dispatch_item(
dispatch_id: UUID,
item_id: UUID,
context_kind: str,
context_id: UUID,
request: Request,
placement_kind: str | None = None,
placement_id: UUID | None = None,
principal: Principal = Depends(get_principal),
conn: Connection = Depends(get_conn),
):
context = Ctx(context_kind, context_id)
placement = Ctx(placement_kind, placement_id) if placement_kind and placement_id else None
result = read_snapshot(
conn,
principal.account_id,
dispatch_id,
item_id,
context,
placement,
request.app.state.settings.media_root,
)
if isinstance(result, GapNote):
raise not_found()
return Response(
content=result.data,
media_type=result.media_type or "application/octet-stream",
headers={
"Content-Disposition": content_disposition(result.filename),
"X-Content-Type-Options": "nosniff",
"Cache-Control": "private, no-store",
},
)
+12 -3
View File
@@ -1460,9 +1460,17 @@ def patch_case_order(
conn: Connection = Depends(get_conn),
):
version = set_content_order(
conn, principal.account_id, "case", case_id, body.expected_version, body.mode, body.direction, None
conn,
principal.account_id,
"case",
case_id,
body.expected_version,
body.mode,
body.direction,
None,
body.view,
)
return {"version": version, "mode": body.mode, "direction": body.direction}
return {"version": version, "mode": body.mode, "direction": body.direction, "view": body.view}
@router.post("/api/v1/cases/{case_id}/bindings/order")
@@ -1514,8 +1522,9 @@ def patch_matter_order(
body.mode,
body.direction,
_ctx_model(body.context),
body.view,
)
return {"version": version, "mode": body.mode, "direction": body.direction}
return {"version": version, "mode": body.mode, "direction": body.direction, "view": body.view}
@router.post("/api/v1/matters/{matter_id}/bindings/order")
+67
View File
@@ -197,6 +197,7 @@ class ContentOrderIn(APIModel):
expected_version: int = Field(ge=1)
mode: Literal["date", "position"]
direction: Literal["asc", "desc"] = "asc"
view: Literal["structure", "chronology"] | None = None
context: ContextIn | None = None
@@ -366,3 +367,69 @@ class ExportIn(APIModel):
context: ContextIn | None = None
selected: list[str] = Field(default_factory=list, max_length=2000)
assignments: dict[str, UUID] = Field(default_factory=dict)
class EvidenceIn(APIModel):
element_id: UUID
role: Literal["email", "submission", "delivery", "other"]
fold: Literal["keep", "evidence"] = "keep"
class AttachmentAssignIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
attachment_element_ids: list[UUID] = Field(min_length=1, max_length=100)
fold: Literal["keep", "attachment"] = "keep"
class AttachmentOrderIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
attachment_element_ids: list[UUID] = Field(min_length=1, max_length=100)
class AttachmentDetachIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
class FoldIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
fold: Literal["attachment", "evidence"] | None = None
class DispatchIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
channel: Literal["email", "post", "other"]
sent_on: date | None = None
counterpart: str | None = Field(default=None, max_length=200)
attachment_element_ids: list[UUID] = Field(default_factory=list, max_length=100)
evidence: list[EvidenceIn] = Field(default_factory=list, max_length=20)
historical_gap: bool = False
class DispatchEvidenceIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
element_id: UUID
role: Literal["email", "submission", "delivery", "other"]
fold: Literal["keep", "evidence"] = "keep"
class DispatchCorrectIn(APIModel):
expected_version: int = Field(ge=1)
context: ContextIn
placement: ContextIn | None = None
channel: Literal["email", "post", "other"] | None = None
sent_on: date | None = None
clear_sent_on: bool = False
counterpart: str | None = Field(default=None, max_length=200)
clear_counterpart: bool = False