Schließe die Connector-Kapselung ab, damit Paperless, IMAP und weitere Quellen über dieselbe Anbindung laufen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
75a3949f7c
commit
d6b70d8f92
75 files changed
+9477
-414
No files matched your search
+39
-10
@@ -33,9 +33,11 @@ from app.access.policy import (
|
||||
task_rights,
|
||||
)
|
||||
from app.content.documents import clean_document
|
||||
from app.core.errors import forbidden, not_found, unprocessable
|
||||
from app.core.errors import forbidden, not_found, unprocessable, unsupported
|
||||
from app.core.timeutil import utcnow
|
||||
from app.media.storage import asset_path, display_filename, sha256, sniff, write_bytes
|
||||
from app.media.port import LEGACY_PROFILE, instance_for_write, publish, stored_path
|
||||
from app.media.port import LocalAdapter
|
||||
from app.media.storage import display_filename, sha256, sniff
|
||||
|
||||
MAX_CHAPTER_DEPTH = 32
|
||||
|
||||
@@ -929,7 +931,7 @@ def update_note(conn, actor: UUID, element_id: UUID, expected: int, document: di
|
||||
document = clean_document(document)
|
||||
element, rights = require_element(conn, actor, element_id, context, "edit")
|
||||
if element["kind"] != "note":
|
||||
raise not_found()
|
||||
raise unsupported("Diese Fassung lässt sich nicht als Notiz bearbeiten.")
|
||||
if not rights.edit:
|
||||
raise forbidden()
|
||||
version = bump_version(conn, "elements", element_id, expected)
|
||||
@@ -998,6 +1000,10 @@ def add_annotation(conn, actor: UUID, binding_id: UUID, body: str, context: Ctx
|
||||
|
||||
|
||||
def create_external(conn, actor: UUID, scope_id: UUID, title: str, source: str, external_id: str, context: Ctx, placement: Ctx | None, chapter_id: UUID | None, document_on, sent_on, received_on, detail: dict | None = None, communication_direction: str | None = None) -> dict:
|
||||
from app.sourceregistry import accepts_reference
|
||||
|
||||
if not accepts_reference(source):
|
||||
raise unprocessable("Diese Quelle ist nicht registriert.")
|
||||
target, rights_context = _placement(context, placement)
|
||||
require_container_edit(conn, actor, target, rights_context)
|
||||
element = _new_element(conn, actor, scope_id, title, "external_ref")
|
||||
@@ -1005,8 +1011,11 @@ def create_external(conn, actor: UUID, scope_id: UUID, title: str, source: str,
|
||||
"INSERT INTO external_references (element_id, source, external_id, detail) VALUES (%s, %s, %s, %s)",
|
||||
(element["id"], source, external_id.strip()[:200], Json(detail or {})),
|
||||
)
|
||||
from app.sourcebind import attach_new_reference
|
||||
|
||||
attach_new_reference(conn, element["id"])
|
||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||
adopted = (detail or {}).get("direction") if source == "imap" else None
|
||||
adopted = (detail or {}).get("direction")
|
||||
chosen = chosen_direction(communication_direction) or (adopted if adopted in ("in", "out") else None)
|
||||
store_direction(conn, binding["id"], chosen, chosen is not None)
|
||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
||||
@@ -1022,16 +1031,23 @@ def create_file(conn, actor: UUID, scope_id: UUID, title: str, filename: str, da
|
||||
require_container_edit(conn, actor, target, rights_context)
|
||||
element = _new_element(conn, actor, scope_id, title, "file")
|
||||
asset_id = uuid4()
|
||||
path = asset_path(media_root, asset_id)
|
||||
write_bytes(path, data)
|
||||
content_revision = str(uuid4())
|
||||
instance = instance_for_write(conn, media_root)
|
||||
object_key = str(asset_id)
|
||||
adapter = LocalAdapter(instance["root_path"])
|
||||
publish(adapter, object_key, data)
|
||||
path = stored_path(conn, instance["id"], instance["generation"], object_key, media_root)
|
||||
rollback_files.append(path)
|
||||
digest = sha256(data)
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO media_assets (
|
||||
id, element_id, owner_subject_id, home_scope_id, original_filename,
|
||||
content_type, byte_size, sha256, status
|
||||
content_type, byte_size, sha256, status, storage_instance_id,
|
||||
storage_generation, object_key, content_revision, protection_profile,
|
||||
key_responsibility
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'active')
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'active', %s, %s, %s, %s, %s, 'none')
|
||||
""",
|
||||
(
|
||||
asset_id,
|
||||
@@ -1041,7 +1057,12 @@ def create_file(conn, actor: UUID, scope_id: UUID, title: str, filename: str, da
|
||||
display_filename(filename),
|
||||
content_type,
|
||||
len(data),
|
||||
sha256(data),
|
||||
digest,
|
||||
instance["id"],
|
||||
instance["generation"],
|
||||
object_key,
|
||||
content_revision,
|
||||
LEGACY_PROFILE,
|
||||
),
|
||||
)
|
||||
conn.execute(
|
||||
@@ -1075,7 +1096,15 @@ def delete_element(conn, actor: UUID, element_id: UUID, expected: int, media_roo
|
||||
)
|
||||
if asset is not None and asset["status"] == "active":
|
||||
conn.execute("UPDATE media_assets SET status = 'purging' WHERE id = %s", (asset["id"],))
|
||||
delete_after.append(asset_path(media_root, asset["id"]))
|
||||
delete_after.append(
|
||||
stored_path(
|
||||
conn,
|
||||
asset["storage_instance_id"],
|
||||
asset["storage_generation"],
|
||||
asset["object_key"] or str(asset["id"]),
|
||||
media_root,
|
||||
)
|
||||
)
|
||||
conn.execute("UPDATE media_assets SET status = 'purged' WHERE id = %s", (asset["id"],))
|
||||
audit(conn, actor, element["home_scope_id"], "element_deleted", "element", element_id)
|
||||
|
||||
|
||||
Reference in new issue
Block a user