Halte die Richtung an der einzelnen Einbindung und mach sie in der Uebersicht waehlbar.
Deploy Development / deploy (push) Successful in 28s
Deploy Development / deploy (push) Successful in 28s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
2664021e7f
commit
95381030bc
12 files changed
+185
-52
No files matched your search
@@ -1027,7 +1027,7 @@ def post_file(
|
||||
settings.media_root,
|
||||
settings.upload_max_bytes,
|
||||
request.state.cleanup_files,
|
||||
communication_direction if communication_direction in {"in", "out"} else None,
|
||||
communication_direction if communication_direction in {"in", "out", "local"} else None,
|
||||
)
|
||||
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class MatterMoveIn(APIModel):
|
||||
|
||||
class CommunicationIn(APIModel):
|
||||
expected_version: int = Field(ge=1)
|
||||
direction: Literal["in", "out"] | None = None
|
||||
direction: Literal["in", "out", "local"] | None = None
|
||||
context: ContextIn | None = None
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class NoteIn(APIModel):
|
||||
placement: ContextIn | None = None
|
||||
chapter_id: UUID | None = None
|
||||
dates: DatesIn | None = None
|
||||
communication_direction: Literal["in", "out"] | None = None
|
||||
communication_direction: Literal["in", "out", "local"] | None = None
|
||||
|
||||
|
||||
class ContentOrderIn(APIModel):
|
||||
|
||||
+11
-5
@@ -665,10 +665,14 @@ 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 chosen_direction(value: str | None) -> str | None:
|
||||
return value if value in ("in", "out", "local") else None
|
||||
|
||||
|
||||
def store_direction(conn, binding_id: UUID, direction: str | None, explicit: bool) -> None:
|
||||
if not explicit:
|
||||
return
|
||||
if direction not in (None, "in", "out"):
|
||||
if direction not in (None, "in", "out", "local"):
|
||||
raise unprocessable("Die Richtung ist ungültig.")
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -703,7 +707,8 @@ def create_note(
|
||||
(element["id"], Json(document)),
|
||||
)
|
||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||
store_direction(conn, binding["id"], communication_direction, communication_direction in ("in", "out"))
|
||||
chosen = chosen_direction(communication_direction)
|
||||
store_direction(conn, binding["id"], chosen, chosen is not None)
|
||||
audit(conn, actor, scope_id, "note_created", "element", element["id"], rights_context or target)
|
||||
if document_on is not None or sent_on is not None or received_on is not None:
|
||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
||||
@@ -792,8 +797,8 @@ def create_external(conn, actor: UUID, scope_id: UUID, title: str, source: str,
|
||||
)
|
||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||
adopted = (detail or {}).get("direction") if source == "imap" else None
|
||||
chosen = communication_direction if communication_direction in ("in", "out") else adopted if adopted in ("in", "out") else None
|
||||
store_direction(conn, binding["id"], chosen, chosen in ("in", "out"))
|
||||
chosen = chosen_direction(communication_direction) or (adopted if adopted in ("in", "out") else None)
|
||||
store_direction(conn, binding["id"], chosen, chosen is not None)
|
||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
||||
audit(conn, actor, scope_id, "external_ref_added", "element", element["id"], rights_context or target)
|
||||
return element | {"binding_id": binding["id"]}
|
||||
@@ -837,7 +842,8 @@ def create_file(conn, actor: UUID, scope_id: UUID, title: str, filename: str, da
|
||||
(element["id"], asset_id),
|
||||
)
|
||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||
store_direction(conn, binding["id"], communication_direction, communication_direction in ("in", "out"))
|
||||
chosen = chosen_direction(communication_direction)
|
||||
store_direction(conn, binding["id"], chosen, chosen is not None)
|
||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
||||
audit(conn, actor, scope_id, "file_added", "element", element["id"], rights_context or target)
|
||||
return element | {"binding_id": binding["id"], "asset_id": asset_id}
|
||||
|
||||
@@ -198,7 +198,7 @@ def _exception(conn, kind: str, resource_id: UUID, context: Ctx | None) -> dict
|
||||
def communication_from_row(conn, binding: dict, element: dict) -> dict:
|
||||
"""Explicit binding direction wins. An adopted mailbox direction may prefill. Dates never do."""
|
||||
stored = binding.get("communication_direction")
|
||||
stored = stored if stored in ("in", "out") else None
|
||||
stored = stored if stored in ("in", "out", "local") else None
|
||||
if binding.get("direction_explicit"):
|
||||
return {"direction": stored, "explicit": True}
|
||||
source = None
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE bindings DROP CONSTRAINT bindings_communication_direction;
|
||||
|
||||
ALTER TABLE bindings
|
||||
ADD CONSTRAINT bindings_communication_direction
|
||||
CHECK (communication_direction IS NULL OR communication_direction IN ('in', 'out', 'local'));
|
||||
@@ -194,3 +194,65 @@ def test_chapter_and_matter_can_be_renamed_and_moved(client, db):
|
||||
json={"expected_version": ada.request("GET", f"/api/v1/cases/{case['id']}")["version"]},
|
||||
)
|
||||
ada.request("GET", f"/api/v1/cases/{case['id']}", status=404)
|
||||
|
||||
|
||||
def test_one_beleg_does_not_classify_the_chapter(client, db):
|
||||
ada = Actor(client, "ada-kapitel@example.test", "Ada Kapitel")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Schriftverkehr")
|
||||
chapter = ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/chapters",
|
||||
json={"title": "Belege"},
|
||||
status=201,
|
||||
)
|
||||
for title, external_id in (("Eingangsschreiben", "pl-1"), ("Antwortschreiben", "pl-2"), ("Rechnung", "pl-3")):
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/external-refs",
|
||||
json={
|
||||
"title": title,
|
||||
"source": "paperless",
|
||||
"external_id": external_id,
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
"chapter_id": chapter["id"],
|
||||
"dates": {"document_on": "2026-10-01"},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
detail = _matter(ada, matter["id"])
|
||||
incoming = _binding(detail, "Eingangsschreiben")
|
||||
reply = _binding(detail, "Antwortschreiben")
|
||||
invoice = _binding(detail, "Rechnung")
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/elements/{reply['element']['id']}/references",
|
||||
json={"refers_to_element_id": incoming["element"]["id"], "context": {"kind": "matter", "id": matter["id"]}},
|
||||
status=204,
|
||||
)
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{incoming['id']}/communication",
|
||||
json={"expected_version": incoming["element"]["version"], "direction": "in", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
shown = _matter(ada, matter["id"])
|
||||
assert _binding(shown, "Eingangsschreiben")["communication"] == {"direction": "in", "explicit": True}
|
||||
assert _binding(shown, "Antwortschreiben")["communication"]["direction"] is None
|
||||
assert _binding(shown, "Rechnung")["communication"]["direction"] is None
|
||||
assert _binding(shown, "Antwortschreiben")["element"]["refers_to"][0]["direction"] == "in"
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{reply['id']}/communication",
|
||||
json={"expected_version": reply["element"]["version"], "direction": "out", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{invoice['id']}/communication",
|
||||
json={"expected_version": invoice["element"]["version"], "direction": "local", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
final = _matter(ada, matter["id"])
|
||||
assert _binding(final, "Eingangsschreiben")["communication"]["direction"] == "in"
|
||||
assert _binding(final, "Antwortschreiben")["communication"]["direction"] == "out"
|
||||
assert _binding(final, "Rechnung")["communication"] == {"direction": "local", "explicit": True}
|
||||
assert all(item["chapter_id"] == chapter["id"] for item in final["bindings"])
|
||||
Reference in new issue
Block a user