Zeige den Bezug zwischen Schreiben und lies eine E-Mail vor dem Uebernehmen.
Die Liste behaelt die Schreiben dazwischen. Richtung, Absender, Empfaenger und Anhaenge bleiben an der Nachricht erkennbar. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
97bffc6175
commit
f27df3ff35
19 files changed
+1049
-49
No files matched your search
+65
-1
@@ -118,6 +118,8 @@ def _preview_meta(kind: str, content_type: str | None, source: str | None) -> di
|
||||
return {"available": True, "media": "pdf", "source": "file"}
|
||||
if kind == "external_ref" and source == "paperless":
|
||||
return {"available": True, "media": "paperless", "source": "paperless"}
|
||||
if kind == "external_ref" and source == "imap":
|
||||
return {"available": True, "media": "email", "source": "imap"}
|
||||
if kind == "file":
|
||||
return {"available": False, "media": "file", "source": "file"}
|
||||
return {"available": False, "media": "none", "source": source}
|
||||
@@ -193,6 +195,66 @@ 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
|
||||
if element["kind"] == "external_ref":
|
||||
ref = conn.execute(
|
||||
"SELECT source, detail FROM external_references WHERE element_id = %s",
|
||||
(element["id"],),
|
||||
).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"
|
||||
return {
|
||||
"id": str(element["id"]),
|
||||
"title": element["title"],
|
||||
"document_on": dates["document_on"],
|
||||
"direction": direction,
|
||||
}
|
||||
|
||||
|
||||
def _attach_references(conn, actor: UUID, element: dict, context: Ctx, body: dict) -> None:
|
||||
refers = []
|
||||
for row in conn.execute(
|
||||
"""
|
||||
SELECT refers_to_element_id
|
||||
FROM element_references
|
||||
WHERE element_id = %s
|
||||
ORDER BY created_at, refers_to_element_id
|
||||
""",
|
||||
(element["id"],),
|
||||
).fetchall():
|
||||
view = _reference_view(conn, actor, row["refers_to_element_id"], context)
|
||||
if view is not None:
|
||||
refers.append(view)
|
||||
replies = []
|
||||
for row in conn.execute(
|
||||
"""
|
||||
SELECT element_id
|
||||
FROM element_references
|
||||
WHERE refers_to_element_id = %s
|
||||
ORDER BY created_at, element_id
|
||||
""",
|
||||
(element["id"],),
|
||||
).fetchall():
|
||||
view = _reference_view(conn, actor, row["element_id"], context)
|
||||
if view is not None:
|
||||
replies.append(view)
|
||||
if refers:
|
||||
body["refers_to"] = refers
|
||||
if replies:
|
||||
body["referred_by"] = replies
|
||||
|
||||
|
||||
def binding_payload(conn, actor: UUID, binding: dict, context: Ctx) -> dict | None:
|
||||
element = get_element(conn, binding["element_id"])
|
||||
if element is None:
|
||||
@@ -200,13 +262,15 @@ def binding_payload(conn, actor: UUID, binding: dict, context: Ctx) -> dict | No
|
||||
rights = element_rights(conn, actor, element, context)
|
||||
if not rights.read:
|
||||
return None
|
||||
body = _element_body(conn, element)
|
||||
_attach_references(conn, actor, element, context, 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"]),
|
||||
"element": _element_body(conn, element),
|
||||
"element": body,
|
||||
}
|
||||
if element["owner_subject_id"] == actor:
|
||||
payload["exception"] = _exception(conn, "element", element["id"], context)
|
||||
|
||||
Reference in new issue
Block a user