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)
|
||||
@@ -149,6 +149,12 @@ def test_folder_pages_newest_first_and_search_stays_inside(client, db, monkeypat
|
||||
assert preview["direction"] == "in"
|
||||
assert preview["message_to"] == "Gegenseite <gegen@example.test>"
|
||||
assert "Einwendung" in preview["text"]
|
||||
other = ada.request(
|
||||
"GET",
|
||||
"/api/v1/sources/imap/messages",
|
||||
params={"connector_id": account, "mailbox": "&AMQ-nderungen"},
|
||||
)
|
||||
assert other["items"][0]["direction"] is None
|
||||
assert preview["attachments"][0]["filename"] == "einwendung.pdf"
|
||||
ada.request(
|
||||
"GET",
|
||||
@@ -169,3 +175,43 @@ def test_foreign_mailbox_stays_hidden(client, db, monkeypatch):
|
||||
ben.login()
|
||||
ben.request("GET", "/api/v1/sources/imap/mailboxes", params={"connector_id": account}, status=404)
|
||||
ben.request("GET", "/api/v1/sources/imap/messages", params={"connector_id": account}, status=404)
|
||||
|
||||
|
||||
class HugeIMAP(FakeIMAP):
|
||||
def uid(self, command, *args):
|
||||
spec = " ".join(str(part) for part in args[1:]) if len(args) > 1 else ""
|
||||
if command == "FETCH" and "BODY.PEEK[]" in spec:
|
||||
return "OK", [(b"rfc822", b"x" * 8_000_001)]
|
||||
if "BODY.PEEK[TEXT]" in spec:
|
||||
return "OK", [(b"text", "Kurzer Auszug der grossen Nachricht.".encode())]
|
||||
return super().uid(command, *args)
|
||||
|
||||
|
||||
def test_oversized_message_still_returns_text(client, db, monkeypatch):
|
||||
ada = Actor(client, "ada-huge@example.test", "Ada Gross")
|
||||
register(db, ada.email, ada.name)
|
||||
ada.login()
|
||||
monkeypatch.setattr(sources.imaplib, "IMAP4_SSL", HugeIMAP)
|
||||
account = ada.request(
|
||||
"POST",
|
||||
"/api/v1/connectors",
|
||||
json={
|
||||
"kind": "imap",
|
||||
"name": "Gross",
|
||||
"host": "imap.example.test",
|
||||
"port": 993,
|
||||
"username": "ada@example.test",
|
||||
"password": "Postfach-Geheim",
|
||||
"security": "ssl",
|
||||
},
|
||||
status=201,
|
||||
)["id"]
|
||||
preview = ada.request(
|
||||
"GET",
|
||||
"/api/v1/sources/imap/message",
|
||||
params={"connector_id": account, "mailbox": "INBOX", "uid": 2},
|
||||
)
|
||||
assert "Kurzer Auszug" in preview["text"]
|
||||
assert preview["text_truncated"] is True
|
||||
assert preview["direction"] == "in"
|
||||
assert preview["message_from"]
|
||||
@@ -5,18 +5,16 @@ from __future__ import annotations
|
||||
from tests.support import Actor, document, register
|
||||
|
||||
|
||||
def _note(actor: Actor, title: str, matter_id: str, **dates) -> None:
|
||||
actor.request(
|
||||
"POST",
|
||||
"/api/v1/notes",
|
||||
json={
|
||||
"title": title,
|
||||
"document": document(title),
|
||||
"context": {"kind": "matter", "id": matter_id},
|
||||
"dates": dates,
|
||||
},
|
||||
status=201,
|
||||
)
|
||||
def _note(actor: Actor, title: str, matter_id: str, direction: str | None = None, **dates) -> None:
|
||||
body = {
|
||||
"title": title,
|
||||
"document": document(title),
|
||||
"context": {"kind": "matter", "id": matter_id},
|
||||
"dates": dates,
|
||||
}
|
||||
if direction in ("in", "out"):
|
||||
body["communication_direction"] = direction
|
||||
actor.request("POST", "/api/v1/notes", json=body, status=201)
|
||||
|
||||
|
||||
def _by_title(detail: dict) -> dict:
|
||||
@@ -30,9 +28,9 @@ def test_reply_names_its_letter_and_leaves_the_gap(client, db):
|
||||
register(db, ben.email, ben.name)
|
||||
ada.login()
|
||||
matter = ada.request("POST", "/api/v1/matters", json={"title": "Schriftwechsel"}, status=201)
|
||||
_note(ada, "Anschreiben", matter["id"], document_on="2026-03-12", received_on="2026-03-12")
|
||||
_note(ada, "Zwischennachricht", matter["id"], document_on="2026-04-02", received_on="2026-04-02")
|
||||
_note(ada, "Antwort", matter["id"], document_on="2026-05-18", sent_on="2026-05-18")
|
||||
_note(ada, "Anschreiben", matter["id"], "in", document_on="2026-03-12", received_on="2026-03-12")
|
||||
_note(ada, "Zwischennachricht", matter["id"], document_on="2026-04-02", received_on="2026-04-02", sent_on="2026-04-02")
|
||||
_note(ada, "Antwort", matter["id"], "out", document_on="2026-05-18", sent_on="2026-05-18")
|
||||
detail = ada.request("GET", f"/api/v1/matters/{matter['id']}")
|
||||
ada.request(
|
||||
"PATCH",
|
||||
@@ -80,6 +78,8 @@ def test_reply_names_its_letter_and_leaves_the_gap(client, db):
|
||||
]
|
||||
assert linked["Anschreiben"]["referred_by"][0]["title"] == "Antwort"
|
||||
assert linked["Anschreiben"]["referred_by"][0]["direction"] == "out"
|
||||
gap = next(item for item in shown["bindings"] if item["element"]["title"] == "Zwischennachricht")
|
||||
assert gap["communication"]["direction"] is None
|
||||
assert "refers_to" not in linked["Zwischennachricht"]
|
||||
assert "referred_by" not in linked["Zwischennachricht"]
|
||||
ada.request(
|
||||
|
||||
Reference in new issue
Block a user