Nummeriere alle Einträge im Übergabepaket in der Vorgangsreihenfolge.
Notizen, Dateien, E-Mails, Kapitel und Teilvorgänge erhalten dieselbe fortlaufende Nummerierung pro Ebene; der Eintragsordner trägt den Titel, der Inhalt liegt darin. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ea28c4f246
commit
97401a6d84
3 files changed
+98
-21
No files matched your search
+18
-12
@@ -567,13 +567,16 @@ def _layout(root, chosen, loaded, notices, generated: str):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def emit(node: ExportNode, prefix: list[str]) -> None:
|
def emit(node: ExportNode, prefix: list[str]) -> None:
|
||||||
folders = [child for child in node.children if _is_folder(child) and _included(child, chosen)]
|
numbered = _ordered_numbered_children(node, chosen)
|
||||||
numbers = {child.id: index + 1 for index, child in enumerate(folders)}
|
numbers = {child.id: index + 1 for index, child in enumerate(numbered)}
|
||||||
for child in node.children:
|
for child in node.children:
|
||||||
if child.id in numbers:
|
if child.id in numbers:
|
||||||
folder = prefix + [_folder_name(child.title, numbers[child.id], prefix)]
|
folder = prefix + [_folder_name(child.title, numbers[child.id], prefix)]
|
||||||
if child.kind == "binding" and child.content_kind == "email":
|
if child.kind == "binding":
|
||||||
_emit_email(child, folder, add, rewrite, entries, loaded, notice_for, generated, chosen)
|
if child.content_kind == "email":
|
||||||
|
_emit_email(child, folder, add, rewrite, entries, loaded, notice_for, generated, chosen)
|
||||||
|
else:
|
||||||
|
_emit_loose(child, folder, add, entries, loaded, notice_for, generated, chosen)
|
||||||
else:
|
else:
|
||||||
emit(child, folder)
|
emit(child, folder)
|
||||||
else:
|
else:
|
||||||
@@ -627,12 +630,8 @@ def _emit_loose(node, prefix, add, entries, loaded, notice_for, generated: str,
|
|||||||
_emit_related(node, prefix, add, entries, loaded, notice_for, chosen, generated)
|
_emit_related(node, prefix, add, entries, loaded, notice_for, chosen, generated)
|
||||||
|
|
||||||
|
|
||||||
def _binding_bundle(prefix: list[str], host: ExportNode) -> list[str]:
|
def _binding_bundle(prefix: list[str], _host: ExportNode) -> list[str]:
|
||||||
"""One folder per entry; the main file and correspondence sit inside it."""
|
"""Main file and correspondence sit inside the numbered entry folder."""
|
||||||
if host.kind == "binding" and host.content_kind == "email":
|
|
||||||
return list(prefix)
|
|
||||||
if host.kind == "binding":
|
|
||||||
return [*prefix, _segment(host.title)]
|
|
||||||
return list(prefix)
|
return list(prefix)
|
||||||
|
|
||||||
|
|
||||||
@@ -1022,8 +1021,15 @@ def _annotation_filename(node: ExportNode, _prefix) -> str:
|
|||||||
return f"{_segment(node.title)}.md"
|
return f"{_segment(node.title)}.md"
|
||||||
|
|
||||||
|
|
||||||
def _is_folder(node: ExportNode) -> bool:
|
def _ordered_numbered_children(node: ExportNode, chosen: set[str]) -> list[ExportNode]:
|
||||||
return node.kind in {"chapter", "matter"} or (node.kind == "binding" and node.content_kind == "email")
|
"""Chapters, Teilvorgänge and every Schriftstück share one order within the parent."""
|
||||||
|
items: list[ExportNode] = []
|
||||||
|
for child in node.children:
|
||||||
|
if child.kind in {"chapter", "matter"} and _included(child, chosen):
|
||||||
|
items.append(child)
|
||||||
|
elif child.kind == "binding" and _included(child, chosen):
|
||||||
|
items.append(child)
|
||||||
|
return items
|
||||||
|
|
||||||
|
|
||||||
def _included(node: ExportNode, chosen: set[str]) -> bool:
|
def _included(node: ExportNode, chosen: set[str]) -> bool:
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ def test_dispatch_keeps_the_secured_stand_and_distinct_mail_parts(client, db, mo
|
|||||||
selected = [node["id"] for node in nodes if node["kind"] in {"dispatch_item", "evidence"}]
|
selected = [node["id"] for node in nodes if node["kind"] in {"dispatch_item", "evidence"}]
|
||||||
archive = _zip(ada, matter["id"], selected)
|
archive = _zip(ada, matter["id"], selected)
|
||||||
names = archive.namelist()
|
names = archive.namelist()
|
||||||
snapshot = next(name for name in names if name.endswith("/Anlagen/Lageplan.pdf"))
|
snapshot = next(name for name in names if name.endswith("/01 Anschreiben/Anlagen/Lageplan.pdf"))
|
||||||
assert archive.read(snapshot) == PDF_B
|
assert archive.read(snapshot) == PDF_B
|
||||||
eml_name = next(name for name in names if name.endswith("nachricht.eml"))
|
eml_name = next(name for name in names if name.endswith("nachricht.eml"))
|
||||||
assert b"Fachlicher Zusatz" in archive.read(eml_name)
|
assert b"Fachlicher Zusatz" in archive.read(eml_name)
|
||||||
@@ -517,7 +517,7 @@ def test_dispatch_keeps_the_secured_stand_and_distinct_mail_parts(client, db, mo
|
|||||||
assert gaps
|
assert gaps
|
||||||
assert all("Später geänderter Text" not in full.read(name).decode("utf-8") for name in gaps)
|
assert all("Später geänderter Text" not in full.read(name).decode("utf-8") for name in gaps)
|
||||||
assert all(b"%PDF" not in full.read(name) for name in gaps)
|
assert all(b"%PDF" not in full.read(name) for name in gaps)
|
||||||
secured = next(name for name in full.namelist() if name.endswith("/Anlagen/Lageplan.pdf"))
|
secured = next(name for name in full.namelist() if name.endswith("/01 Anschreiben/Anlagen/Lageplan.pdf"))
|
||||||
assert full.read(secured) == PDF_B
|
assert full.read(secured) == PDF_B
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ def test_handover_package_follows_the_confirmed_selection(client, db, monkeypatc
|
|||||||
names = archive.namelist()
|
names = archive.namelist()
|
||||||
assert "index.html" in names and "inhalt.md" in names
|
assert "index.html" in names and "inhalt.md" in names
|
||||||
assert any(name.startswith("01 Vertrag/") for name in names)
|
assert any(name.startswith("01 Vertrag/") for name in names)
|
||||||
assert any("02 Schrift/Schreiben-Datei/Schreiben-Datei.pdf" in name.replace("\\", "/") for name in names)
|
assert any("02 Schrift/01 Schreiben-Datei/Schreiben-Datei.pdf" in name.replace("\\", "/") for name in names)
|
||||||
assert any("Nebenpunkt" in name and name.endswith("Teilnotiz.md") for name in names)
|
assert any("Nebenpunkt" in name and name.endswith("Teilnotiz.md") for name in names)
|
||||||
mail_names = [name for name in names if "Schreiben mit Anlagen" in name]
|
mail_names = [name for name in names if "Schreiben mit Anlagen" in name]
|
||||||
assert any(name.endswith("/nachricht.eml") for name in mail_names)
|
assert any(name.endswith("/nachricht.eml") for name in mail_names)
|
||||||
@@ -370,7 +370,7 @@ def test_handover_package_follows_the_confirmed_selection(client, db, monkeypatc
|
|||||||
assert "Gespiegelte Anlage" not in whole
|
assert "Gespiegelte Anlage" not in whole
|
||||||
assert "Fremdtext" not in whole
|
assert "Fremdtext" not in whole
|
||||||
assert "bleibt Bestandteil" in whole
|
assert "bleibt Bestandteil" in whole
|
||||||
note_file = next(name for name in names if name.endswith("/Vertragnotiz/Vertragnotiz.md"))
|
note_file = next(name for name in names if name.endswith("/01 Vertragnotiz/Vertragnotiz.md"))
|
||||||
annotation_file = next(name for name in names if "Anmerkung zu Vertragnotiz" in name)
|
annotation_file = next(name for name in names if "Anmerkung zu Vertragnotiz" in name)
|
||||||
assert "Kontextvermerk speziell" not in archive.read(note_file).decode("utf-8")
|
assert "Kontextvermerk speziell" not in archive.read(note_file).decode("utf-8")
|
||||||
assert "Kontextvermerk speziell" in archive.read(annotation_file).decode("utf-8")
|
assert "Kontextvermerk speziell" in archive.read(annotation_file).decode("utf-8")
|
||||||
@@ -762,7 +762,7 @@ def test_nested_chapter_export_keeps_path_and_complete_mail(client, db, monkeypa
|
|||||||
names = _archive(response.content).namelist()
|
names = _archive(response.content).namelist()
|
||||||
heating = next(name for name in names if name.endswith("/Heizkostenbeleg/Heizkostenbeleg.pdf"))
|
heating = next(name for name in names if name.endswith("/Heizkostenbeleg/Heizkostenbeleg.pdf"))
|
||||||
assert heating.startswith(
|
assert heating.startswith(
|
||||||
"01 Nebenkostenabrechnung 2025/02 Übermittelte Abrechnungsunterlagen/01 Einzelbelege/"
|
"01 Nebenkostenabrechnung 2025/02 Übermittelte Abrechnungsunterlagen/01 Einzelbelege/01 Heizkostenbeleg/"
|
||||||
)
|
)
|
||||||
assert any(
|
assert any(
|
||||||
name.startswith("01 Nebenkostenabrechnung 2025/01 ") and "Antwort des Vermieters" in name
|
name.startswith("01 Nebenkostenabrechnung 2025/01 ") and "Antwort des Vermieters" in name
|
||||||
@@ -778,6 +778,77 @@ def test_nested_chapter_export_keeps_path_and_complete_mail(client, db, monkeypa
|
|||||||
assert "Ausgelassen" not in overview
|
assert "Ausgelassen" not in overview
|
||||||
|
|
||||||
|
|
||||||
|
def test_chapter_entries_share_one_numbering_sequence(client, db, monkeypatch):
|
||||||
|
ada = Actor(client, "ada-numbering@example.test", "Ada Numbering")
|
||||||
|
register(db, ada.email, ada.name)
|
||||||
|
ada.login()
|
||||||
|
matter = ada.request("POST", "/api/v1/matters", json={"title": "Nummernfolge"}, status=201)
|
||||||
|
chapter = ada.request(
|
||||||
|
"POST",
|
||||||
|
f"/api/v1/matters/{matter['id']}/chapters",
|
||||||
|
json={"title": "Post"},
|
||||||
|
status=201,
|
||||||
|
)
|
||||||
|
ada.request(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/notes",
|
||||||
|
json={
|
||||||
|
"title": "Erste Notiz",
|
||||||
|
"document": document("Notiztext"),
|
||||||
|
"context": {"kind": "matter", "id": matter["id"]},
|
||||||
|
"chapter_id": chapter["id"],
|
||||||
|
},
|
||||||
|
status=201,
|
||||||
|
)
|
||||||
|
mailbox = ada.request(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/connectors",
|
||||||
|
json={
|
||||||
|
"kind": "imap",
|
||||||
|
"name": "Postfach",
|
||||||
|
"host": "mail.example.test",
|
||||||
|
"username": "ada",
|
||||||
|
"password": "secret-pass",
|
||||||
|
},
|
||||||
|
status=201,
|
||||||
|
)
|
||||||
|
raw = _eml("<nummern@example.test>", "Mailtext", [("lage.pdf", PDF_A)])
|
||||||
|
ada.request(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/external-refs",
|
||||||
|
json={
|
||||||
|
"title": "Zweite E-Mail",
|
||||||
|
"source": "imap",
|
||||||
|
"external_id": "<nummern@example.test>",
|
||||||
|
"context": {"kind": "matter", "id": matter["id"]},
|
||||||
|
"chapter_id": chapter["id"],
|
||||||
|
"detail": {"connector_id": mailbox["id"], "mailbox": "INBOX", "uid": 3},
|
||||||
|
},
|
||||||
|
status=201,
|
||||||
|
)
|
||||||
|
ada.request(
|
||||||
|
"POST",
|
||||||
|
"/api/v1/files",
|
||||||
|
data={
|
||||||
|
"title": "Drittes Dokument",
|
||||||
|
"context_kind": "matter",
|
||||||
|
"context_id": matter["id"],
|
||||||
|
"chapter_id": chapter["id"],
|
||||||
|
},
|
||||||
|
files={"upload": ("drittes.pdf", PDF_C, "application/pdf")},
|
||||||
|
status=201,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr("app.retrieval.pull_rfc822", lambda *args, **kwargs: raw)
|
||||||
|
tree = ada.request("GET", f"/api/v1/matters/{matter['id']}/export-tree")["tree"]
|
||||||
|
selected = [node["id"] for node in _walk(tree) if node["exportable"]]
|
||||||
|
response = _post_zip(ada, matter["id"], {"context": {"kind": "matter", "id": matter["id"]}, "selected": selected})
|
||||||
|
assert response.status_code == 200, response.text
|
||||||
|
names = [name.replace("\\", "/") for name in _archive(response.content).namelist()]
|
||||||
|
assert any(name.endswith("01 Post/01 Erste Notiz/Erste Notiz.md") for name in names)
|
||||||
|
assert any("01 Post/02 Zweite E-Mail/nachricht.eml" in name for name in names)
|
||||||
|
assert any(name.endswith("01 Post/03 Drittes Dokument/Drittes Dokument.pdf") for name in names)
|
||||||
|
|
||||||
|
|
||||||
def test_correspondence_attachments_stay_under_each_host_in_one_chapter(client, db):
|
def test_correspondence_attachments_stay_under_each_host_in_one_chapter(client, db):
|
||||||
ada = Actor(client, "ada-host-bundle@example.test", "Ada Host Bundle")
|
ada = Actor(client, "ada-host-bundle@example.test", "Ada Host Bundle")
|
||||||
register(db, ada.email, ada.name)
|
register(db, ada.email, ada.name)
|
||||||
@@ -899,11 +970,11 @@ def test_correspondence_attachments_stay_under_each_host_in_one_chapter(client,
|
|||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
names = _archive(response.content).namelist()
|
names = _archive(response.content).namelist()
|
||||||
assert not any("anlagen-arbeitsstand" in name.lower() for name in names)
|
assert not any("anlagen-arbeitsstand" in name.lower() for name in names)
|
||||||
first_paths = [name for name in names if "Erstes Schreiben/Anlagen/" in name.replace("\\", "/")]
|
first_paths = [name for name in names if "/01 Erstes Schreiben/Anlagen/" in name.replace("\\", "/")]
|
||||||
second_paths = [name for name in names if "Zweites Schreiben/Anlagen/" in name.replace("\\", "/")]
|
second_paths = [name for name in names if "/02 Zweites Schreiben/Anlagen/" in name.replace("\\", "/")]
|
||||||
assert sorted(name.rsplit("/", 1)[-1] for name in first_paths) == ["Anlage A1.pdf", "Anlage A2.pdf"]
|
assert sorted(name.rsplit("/", 1)[-1] for name in first_paths) == ["Anlage A1.pdf", "Anlage A2.pdf"]
|
||||||
assert sorted(name.rsplit("/", 1)[-1] for name in second_paths) == ["Anlage B1.pdf", "Anlage B2.pdf"]
|
assert sorted(name.rsplit("/", 1)[-1] for name in second_paths) == ["Anlage B1.pdf", "Anlage B2.pdf"]
|
||||||
assert any("Erstes Schreiben/Belege/" in name.replace("\\", "/") for name in names)
|
assert any("/01 Erstes Schreiben/Belege/" in name.replace("\\", "/") for name in names)
|
||||||
assert not any(name.replace("\\", "/").startswith("01 Schriftwechsel/2026-04") for name in names)
|
assert not any(name.replace("\\", "/").startswith("01 Schriftwechsel/2026-04") for name in names)
|
||||||
|
|
||||||
|
|
||||||
@@ -971,6 +1042,6 @@ def test_export_warns_when_assigned_attachment_is_not_shareable(client, db):
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
names = _archive(response.content).namelist()
|
names = _archive(response.content).namelist()
|
||||||
anlagen = [name for name in names if "Schreiben/Anlagen/" in name.replace("\\", "/")]
|
anlagen = [name for name in names if "/01 Schreiben/Anlagen/" in name.replace("\\", "/")]
|
||||||
assert len(anlagen) == 1
|
assert len(anlagen) == 1
|
||||||
assert anlagen[0].endswith("/Offene Anlage.pdf")
|
assert anlagen[0].endswith("/Offene Anlage.pdf")
|
||||||
Reference in new issue
Block a user