Schließe die Connector-Kapselung ab, damit Paperless, IMAP und weitere Quellen über dieselbe Anbindung laufen.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Failing after 2m18s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 10s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-19 15:00:50 +02:00
1 parent 75a3949f7c
commit d6b70d8f92
75 files changed
+9477 -414

No files matched your search

+66 -23
View File
@@ -26,9 +26,10 @@ from app.access.policy import (
require_case,
require_matter,
)
from app.core.errors import conflict, not_found, unprocessable
from app.core.errors import Problem, conflict, not_found, unprocessable
from app.core.timeutil import dump_date, dump_dt
from app.media.storage import asset_path, display_filename, read_bytes, sha256, write_bytes
from app.media.port import LEGACY_PROFILE, LocalAdapter, instance_for_write, publish, read_clear_bytes, stored_path
from app.media.storage import display_filename, sha256
from app.retrieval import FilePayload, MailPayload, RetrievalFailure, load_external, load_file
CHANNELS = {"email": "per E-Mail", "post": "per Post", "other": "sonstiger Weg"}
@@ -415,9 +416,25 @@ def load_snapshot_file(conn, snapshot_id: UUID, media_root: str) -> FilePayload
row = conn.execute("SELECT * FROM dispatch_snapshots WHERE id = %s", (snapshot_id,)).fetchone()
if row is None:
return RetrievalFailure("missing", "Die gesicherte Fassung ist nicht mehr vorhanden.")
profile = row["protection_profile"] or "legacy-plaintext"
if profile != "legacy-plaintext":
return RetrievalFailure(
"unsupported",
"Dieser Inhalt ist geschützt und kann hier nicht im Klartext gelesen werden.",
)
try:
data = read_bytes(_snapshot_path(media_root, row["id"]))
except Exception:
data = read_clear_bytes(
conn,
instance_id=row["storage_instance_id"],
generation=row["storage_generation"],
object_key=row["object_key"] or f"dispatch/{row['id']}",
media_root=media_root,
protection_profile=profile,
expected_sha256=row["sha256"],
)
except Problem as exc:
if exc.code == "processing":
return RetrievalFailure("missing", "Die gesicherte Fassung lässt sich nicht unverändert lesen.")
return RetrievalFailure("missing", "Die gesicherte Fassung ist nicht mehr vorhanden.")
if sha256(data) != row["sha256"]:
return RetrievalFailure("missing", "Die gesicherte Fassung lässt sich nicht unverändert lesen.")
@@ -573,7 +590,7 @@ def purge_element_dispatch_files(conn, element_id: UUID, media_root: str) -> lis
(item_id,),
).fetchone()
if snap is not None:
paths.append(_snapshot_path(media_root, snap["id"]))
paths.append(_snapshot_disk(conn, snap["id"], media_root))
conn.execute("DELETE FROM dispatch_snapshots WHERE id = %s", (snap["id"],))
conn.execute(
"""
@@ -596,7 +613,7 @@ def purge_element_dispatch_files(conn, element_id: UUID, media_root: str) -> lis
(evidence_id,),
).fetchone()
if snap is not None:
paths.append(_snapshot_path(media_root, snap["id"]))
paths.append(_snapshot_disk(conn, snap["id"], media_root))
conn.execute("DELETE FROM dispatch_snapshots WHERE id = %s", (snap["id"],))
conn.execute(
"""
@@ -916,17 +933,22 @@ def _working_bytes(conn, actor, element, media_root: str):
def _store_snapshot(conn, scope_id, actor, payload: FilePayload, media_root: str, cleanup: list[Path], dispatch_item_id: UUID | None = None, evidence_id: UUID | None = None) -> UUID:
snapshot_id = uuid4()
path = _snapshot_path(media_root, snapshot_id)
write_bytes(path, payload.data)
cleanup.append(path)
instance = instance_for_write(conn, media_root)
object_key = f"dispatch/{snapshot_id}"
content_revision = str(uuid4())
adapter = LocalAdapter(instance["root_path"])
publish(adapter, object_key, payload.data)
cleanup.append(stored_path(conn, instance["id"], instance["generation"], object_key, media_root))
digest = sha256(payload.data)
conn.execute(
"""
INSERT INTO dispatch_snapshots (
id, dispatch_item_id, evidence_id, home_scope_id, owner_subject_id,
original_filename, content_type, byte_size, sha256
original_filename, content_type, byte_size, sha256,
storage_instance_id, storage_generation, object_key, content_revision,
protection_profile, key_responsibility
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, 'none')
""",
(
snapshot_id,
@@ -938,6 +960,11 @@ def _store_snapshot(conn, scope_id, actor, payload: FilePayload, media_root: str
payload.media_type or "application/octet-stream",
len(payload.data),
digest,
instance["id"],
instance["generation"],
object_key,
content_revision,
LEGACY_PROFILE,
),
)
return snapshot_id
@@ -956,20 +983,36 @@ def _snapshot_file(conn, media_root: str, dispatch_item_id: UUID | None = None,
).fetchone()
if row is None:
raise not_found()
data = read_bytes(_snapshot_path(media_root, row["id"]))
if sha256(data) != row["sha256"]:
raise not_found()
profile = row["protection_profile"] or "legacy-plaintext"
data = read_clear_bytes(
conn,
instance_id=row["storage_instance_id"],
generation=row["storage_generation"],
object_key=row["object_key"] or f"dispatch/{row['id']}",
media_root=media_root,
protection_profile=profile,
expected_sha256=row["sha256"],
)
return FilePayload(row["original_filename"], row["content_type"], data, row["sha256"])
def _snapshot_path(media_root: str, snapshot_id: UUID) -> Path:
root = Path(media_root).resolve()
folder = (root / "dispatch").resolve()
folder.mkdir(parents=True, exist_ok=True)
target = (folder / str(snapshot_id)).resolve()
if target.parent != folder:
raise unprocessable("Ungültiger Speicherpfad.")
return target
def _snapshot_disk(conn, snapshot_id: UUID, media_root: str) -> Path:
row = conn.execute(
"""
SELECT id, storage_instance_id, storage_generation, object_key
FROM dispatch_snapshots WHERE id = %s
""",
(snapshot_id,),
).fetchone()
if row is None:
return stored_path(conn, None, "legacy-local-1", f"dispatch/{snapshot_id}", media_root)
return stored_path(
conn,
row["storage_instance_id"],
row["storage_generation"],
row["object_key"] or f"dispatch/{row['id']}",
media_root,
)
def _snapshot_id(conn, dispatch_item_id: UUID | None = None, evidence_id: UUID | None = None) -> str | None:
@@ -1416,5 +1459,5 @@ def _delete_dispatch_files(conn, dispatch_id: UUID, media_root: str) -> list[Pat
(dispatch_id, dispatch_id),
).fetchall()
for row in rows:
paths.append(_snapshot_path(media_root, row["id"]))
paths.append(_snapshot_disk(conn, row["id"], media_root))
return paths