Unterscheide Eingang und Ausgang an der Einbindung und ermoegliche Umbenennen, Archivieren, Loeschen und Verschieben.
Deploy Development / deploy (push) Successful in 26s
Test Suite / pytest-backend (push) Successful in 1m4s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 8s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 18:30:26 +02:00
1 parent 20625b4596
commit ad6240a5da
27 files changed
+1191 -88

No files matched your search

+35 -16
View File
@@ -195,12 +195,13 @@ def _exception(conn, kind: str, resource_id: UUID, context: Ctx | None) -> dict
return {"remove_read": row["can_read"], "remove_edit": row["can_edit"], "remove_share": row["can_share"]}
def _reference_view(conn, actor: UUID, element_id: UUID, context: Ctx) -> dict | None:
element = get_element(conn, element_id)
if element is None or not element_rights(conn, actor, element, context).read:
return None
dates = _dates(conn, element)
direction = None
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
if binding.get("direction_explicit"):
return {"direction": stored, "explicit": True}
source = None
if element["kind"] == "external_ref":
ref = conn.execute(
"SELECT source, detail FROM external_references WHERE element_id = %s",
@@ -208,12 +209,28 @@ def _reference_view(conn, actor: UUID, element_id: UUID, context: Ctx) -> dict |
).fetchone()
detail = (ref["detail"] or {}) if ref is not None and ref["source"] == "imap" else {}
if detail.get("direction") in ("in", "out"):
direction = detail["direction"]
if direction is None:
if dates["sent_on"] and not dates["received_on"]:
direction = "out"
elif dates["received_on"] and not dates["sent_on"]:
direction = "in"
source = detail["direction"]
return {"direction": source, "explicit": False}
def _reference_view(conn, actor: UUID, element_id: UUID, context: Ctx, container: Ctx) -> dict | None:
element = get_element(conn, element_id)
if element is None or not element_rights(conn, actor, element, context).read:
return None
dates = _dates(conn, element)
row = conn.execute(
"""
SELECT communication_direction, direction_explicit
FROM bindings
WHERE element_id = %s AND context_kind = %s AND context_id = %s
""",
(element["id"], container.kind, container.id),
).fetchone()
direction = communication_from_row(
conn,
row or {"communication_direction": None, "direction_explicit": False},
element,
)["direction"]
return {
"id": str(element["id"]),
"title": element["title"],
@@ -222,7 +239,7 @@ def _reference_view(conn, actor: UUID, element_id: UUID, context: Ctx) -> dict |
}
def _attach_references(conn, actor: UUID, element: dict, context: Ctx, body: dict) -> None:
def _attach_references(conn, actor: UUID, element: dict, context: Ctx, container: Ctx, body: dict) -> None:
refers = []
for row in conn.execute(
"""
@@ -233,7 +250,7 @@ def _attach_references(conn, actor: UUID, element: dict, context: Ctx, body: dic
""",
(element["id"],),
).fetchall():
view = _reference_view(conn, actor, row["refers_to_element_id"], context)
view = _reference_view(conn, actor, row["refers_to_element_id"], context, container)
if view is not None:
refers.append(view)
replies = []
@@ -246,7 +263,7 @@ def _attach_references(conn, actor: UUID, element: dict, context: Ctx, body: dic
""",
(element["id"],),
).fetchall():
view = _reference_view(conn, actor, row["element_id"], context)
view = _reference_view(conn, actor, row["element_id"], context, container)
if view is not None:
replies.append(view)
if refers:
@@ -263,13 +280,15 @@ def binding_payload(conn, actor: UUID, binding: dict, context: Ctx) -> dict | No
if not rights.read:
return None
body = _element_body(conn, element)
_attach_references(conn, actor, element, context, body)
container = Ctx(binding["context_kind"], binding["context_id"])
_attach_references(conn, actor, element, context, container, body)
payload = {
"id": str(binding["id"]),
"position": binding["position"],
"chapter_id": str(binding["chapter_id"]) if binding["chapter_id"] else None,
"rights": rights.as_dict(),
"annotations": _annotations(conn, binding["id"]),
"communication": communication_from_row(conn, binding, element),
"element": body,
}
if element["owner_subject_id"] == actor: