Unterscheide Eingang und Ausgang an der Einbindung und ermoegliche Umbenennen, Archivieren, Loeschen und Verschieben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
20625b4596
commit
ad6240a5da
27 files changed
+1191
-88
No files matched your search
@@ -0,0 +1,192 @@
|
||||
"""Communication direction lives on the binding and is never inferred from dates."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tests.support import Actor, bind_to, case_of, document, matter_of, register
|
||||
|
||||
|
||||
def _matter(actor: Actor, matter_id: str) -> dict:
|
||||
return actor.request("GET", f"/api/v1/matters/{matter_id}")
|
||||
|
||||
|
||||
def _binding(detail: dict, title: str) -> dict:
|
||||
return next(item for item in detail["bindings"] if item["element"]["title"] == title)
|
||||
|
||||
|
||||
def _note(actor: Actor, matter_id: str, title: str, direction: str | None = None, **dates) -> dict:
|
||||
body = {
|
||||
"title": title,
|
||||
"document": document(title),
|
||||
"context": {"kind": "matter", "id": matter_id},
|
||||
}
|
||||
if dates:
|
||||
body["dates"] = dates
|
||||
if direction in ("in", "out"):
|
||||
body["communication_direction"] = direction
|
||||
return actor.request("POST", "/api/v1/notes", json=body, status=201)
|
||||
|
||||
|
||||
def test_dates_do_not_invent_a_direction_and_explicit_choice_survives(client, db):
|
||||
ada = Actor(client, "ada-richtung@example.test", "Ada Richtung")
|
||||
ben = Actor(client, "ben-richtung@example.test", "Ben Richtung")
|
||||
register(db, ada.email, ada.name)
|
||||
register(db, ben.email, ben.name)
|
||||
ada.login()
|
||||
matter = matter_of(ada, "Kautionsabrechnung")
|
||||
_note(ada, matter["id"], "Beide Daten", document_on="2026-10-12", sent_on="2026-10-01", received_on="2026-10-12")
|
||||
_note(ada, matter["id"], "Telefon Eingang", "in")
|
||||
_note(ada, matter["id"], "Telefon Ausgang", "out")
|
||||
_note(ada, matter["id"], "Gedankenprotokoll")
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/external-refs",
|
||||
json={
|
||||
"title": "Scan ohne Richtung",
|
||||
"source": "paperless",
|
||||
"external_id": "scan-42",
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
"detail": {"open_url": "https://example.test/scan-42"},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
ada.request(
|
||||
"POST",
|
||||
"/api/v1/external-refs",
|
||||
json={
|
||||
"title": "Mail der Verwaltung",
|
||||
"source": "imap",
|
||||
"external_id": "<verwaltung@example.test>",
|
||||
"context": {"kind": "matter", "id": matter["id"]},
|
||||
"detail": {
|
||||
"direction": "in",
|
||||
"message_from": "Hausverwaltung Mueller",
|
||||
"mailbox": "INBOX",
|
||||
},
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
shown = _matter(ada, matter["id"])
|
||||
both = _binding(shown, "Beide Daten")
|
||||
assert both["communication"] == {"direction": None, "explicit": False}
|
||||
assert both["element"]["dates"]["sent_on"] == "2026-10-01"
|
||||
assert both["element"]["dates"]["received_on"] == "2026-10-12"
|
||||
assert _binding(shown, "Telefon Eingang")["communication"]["direction"] == "in"
|
||||
assert _binding(shown, "Telefon Ausgang")["communication"]["direction"] == "out"
|
||||
assert _binding(shown, "Gedankenprotokoll")["communication"]["direction"] is None
|
||||
assert _binding(shown, "Scan ohne Richtung")["communication"]["direction"] is None
|
||||
mail = _binding(shown, "Mail der Verwaltung")
|
||||
assert mail["communication"] == {"direction": "in", "explicit": True}
|
||||
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{mail['id']}/communication",
|
||||
json={"expected_version": mail["element"]["version"], "direction": None, "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
cleared = _binding(_matter(ada, matter["id"]), "Mail der Verwaltung")
|
||||
assert cleared["communication"] == {"direction": None, "explicit": True}
|
||||
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{both['id']}/communication",
|
||||
json={"expected_version": both["element"]["version"], "direction": "out", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
)
|
||||
chosen = _binding(_matter(ada, matter["id"]), "Beide Daten")
|
||||
assert chosen["communication"] == {"direction": "out", "explicit": True}
|
||||
|
||||
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()
|
||||
visible = _binding(_matter(ben, matter["id"]), "Beide Daten")
|
||||
assert visible["communication"]["direction"] == "out"
|
||||
ben.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{visible['id']}/communication",
|
||||
json={"expected_version": visible["element"]["version"], "direction": "in", "context": {"kind": "matter", "id": matter["id"]}},
|
||||
status=403,
|
||||
)
|
||||
|
||||
|
||||
def test_a_second_binding_keeps_its_own_direction(client, db):
|
||||
ada = Actor(client, "ada-bindung@example.test", "Ada Bindung")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
first = case_of(ada, "Erste Akte")
|
||||
second = case_of(ada, "Zweite Akte")
|
||||
created = ada.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={
|
||||
"title": "Gemeinsame Notiz",
|
||||
"document": {"version": 1, "blocks": [{"type": "markdown", "text": "# Anruf\n\n**Eingang**"}]},
|
||||
"context": {"kind": "case", "id": first["id"]},
|
||||
"communication_direction": "in",
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
bind_to(ada, created["id"], first["id"], second["id"])
|
||||
left = ada.request("GET", f"/api/v1/cases/{first['id']}")
|
||||
right = ada.request("GET", f"/api/v1/cases/{second['id']}")
|
||||
left_binding = next(item for item in left["bindings"] if item["element"]["title"] == "Gemeinsame Notiz")
|
||||
right_binding = next(item for item in right["bindings"] if item["element"]["title"] == "Gemeinsame Notiz")
|
||||
assert left_binding["communication"]["direction"] == "in"
|
||||
assert right_binding["communication"]["direction"] is None
|
||||
assert left_binding["element"]["document"]["blocks"][0]["type"] == "markdown"
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/bindings/{right_binding['id']}/communication",
|
||||
json={"expected_version": right_binding["element"]["version"], "direction": "out", "context": {"kind": "case", "id": second["id"]}},
|
||||
)
|
||||
left_again = ada.request("GET", f"/api/v1/cases/{first['id']}")
|
||||
right_again = ada.request("GET", f"/api/v1/cases/{second['id']}")
|
||||
assert next(item for item in left_again["bindings"] if item["element"]["id"] == created["id"])["communication"]["direction"] == "in"
|
||||
assert next(item for item in right_again["bindings"] if item["element"]["id"] == created["id"])["communication"]["direction"] == "out"
|
||||
|
||||
|
||||
def test_chapter_and_matter_can_be_renamed_and_moved(client, db):
|
||||
ada = Actor(client, "ada-struktur@example.test", "Ada Struktur")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
case = case_of(ada, "Vermietung")
|
||||
other = case_of(ada, "Ferienhaus")
|
||||
matter = matter_of(ada, "Nebenkosten")
|
||||
ada.request("POST", f"/api/v1/matters/{matter['id']}/case-links", json={"case_id": case["id"]}, status=201)
|
||||
parent = matter_of(ada, "Wohnung")
|
||||
ada.request("POST", f"/api/v1/matters/{parent['id']}/case-links", json={"case_id": other["id"]}, status=201)
|
||||
chapter = ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/chapters",
|
||||
json={"title": "Schreiben"},
|
||||
status=201,
|
||||
)
|
||||
detail = _matter(ada, matter["id"])
|
||||
ada.request(
|
||||
"PATCH",
|
||||
f"/api/v1/chapters/{chapter['id']}/title",
|
||||
json={"expected_version": detail["version"], "title": "Korrespondenz", "context": {"kind": "case", "id": case["id"]}},
|
||||
)
|
||||
current = _matter(ada, matter["id"])
|
||||
assert current["chapters"][0]["title"] == "Korrespondenz"
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/matters/{matter['id']}/move",
|
||||
json={
|
||||
"expected_version": current["version"],
|
||||
"context": {"kind": "case", "id": case["id"]},
|
||||
"case_id": other["id"],
|
||||
"parent_matter_id": parent["id"],
|
||||
},
|
||||
)
|
||||
moved = _matter(ada, matter["id"])
|
||||
assert moved["parent_matter_id"] == parent["id"]
|
||||
assert any(item["case_id"] == other["id"] for item in moved["placements"])
|
||||
assert all(item["case_id"] != case["id"] for item in moved["placements"])
|
||||
ada.request(
|
||||
"POST",
|
||||
f"/api/v1/cases/{case['id']}/delete",
|
||||
json={"expected_version": ada.request("GET", f"/api/v1/cases/{case['id']}")["version"]},
|
||||
)
|
||||
ada.request("GET", f"/api/v1/cases/{case['id']}", status=404)
|
||||
Reference in new issue
Block a user