Warne vor bereits eingefügten Quelldokumenten und biete Nicht einfügen, erneut einfügen oder zusätzliches Einbinden an.
Deploy Development / deploy (push) Successful in 44s

Prüfstufen hier, darin, Umfeld stehen als Kontoeinstellung bereit. Der Server antwortet bei einem sicheren Treffer mit 409 und bindet auf Wunsch das vorhandene Element zusätzlich ein.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-10-25 10:06:52 +01:00
1 parent a6dc24d8fe
commit f925661937
19 files changed
+748 -133

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
"""Placing a source document into a container: a new reference, or one more binding of an existing element."""
from __future__ import annotations
from fastapi import APIRouter, Depends
from fastapi.responses import JSONResponse
from psycopg import Connection
from app.access.policy import Ctx
from app.api.deps import Principal, get_conn, get_principal
from app.api.schemas import ExistingIn, ExternalIn
from app.ops import bind_existing_external, create_external, existing_externals
router = APIRouter()
def _ctx_model(value) -> Ctx | None:
return None if value is None else Ctx(value.kind, value.id)
def place_external(conn, principal: Principal, body: ExternalIn) -> dict:
context = Ctx(body.context.kind, body.context.id)
placement = _ctx_model(body.placement)
if body.bind_element_id is not None:
return bind_existing_external(conn, principal.account_id, principal.scope_id, body.bind_element_id, context, placement, body.chapter_id)
return create_external(
conn,
principal.account_id,
principal.scope_id,
body.title,
body.source,
body.external_id,
context,
placement,
body.chapter_id,
body.dates.document_on,
body.dates.sent_on,
body.dates.received_on,
body.detail.model_dump(mode="json", exclude_none=True) if body.detail else None,
duplicate=body.duplicate,
)
@router.post("/api/v1/external-refs/existing")
def existing(body: ExistingIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
"""Read only: which of these documents are already present around the target. Nothing is written."""
items = [
{"source": item.source, "external_id": item.external_id, "connector_id": str(item.connector_id) if item.connector_id else None}
for item in body.items
]
result = existing_externals(conn, principal.account_id, Ctx(body.context.kind, body.context.id), _ctx_model(body.placement), items)
return JSONResponse(result, headers={"Cache-Control": "no-store"})
+2 -16
View File
@@ -34,6 +34,7 @@ from app.access.policy import (
)
from app.access.limits import ensure_can_add_member
from app.api.deps import Principal, get_conn, get_principal, get_session
from app.api.externals import place_external
from app.api.schemas import (
AcceptInviteIn,
AnnotationIn,
@@ -113,7 +114,6 @@ from app.ops import (
create_chapter,
create_cross_link,
create_deadline,
create_external,
create_file,
create_matter,
create_note,
@@ -860,21 +860,7 @@ def post_annotation(
@router.post("/api/v1/external-refs")
def post_external(body: ExternalIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
element = create_external(
conn,
principal.account_id,
principal.scope_id,
body.title,
body.source,
body.external_id,
Ctx(body.context.kind, body.context.id),
_ctx_model(body.placement),
body.chapter_id,
body.dates.document_on,
body.dates.sent_on,
body.dates.received_on,
body.detail.model_dump(mode="json", exclude_none=True) if body.detail else None,
)
element = place_external(conn, principal, body)
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})
+16
View File
@@ -352,6 +352,22 @@ class ExternalIn(APIModel):
chapter_id: UUID | None = None
dates: DatesIn = DatesIn()
detail: ExternalDetail | None = None
# "ask": a document that is already present at the account's check level answers 409.
# "insert": the user chose to insert it again. `bind_element_id` binds that element instead of creating one.
duplicate: Literal["ask", "insert"] = "ask"
bind_element_id: UUID | None = None
class ExistingItemIn(APIModel):
source: str = Field(min_length=1, max_length=40)
external_id: str = Field(min_length=1, max_length=200)
connector_id: UUID | None = None
class ExistingIn(APIModel):
context: ContextIn
placement: ContextIn | None = None
items: list[ExistingItemIn] = Field(min_length=1, max_length=100)
class ConnectorIn(APIModel):
+4 -18
View File
@@ -8,15 +8,15 @@ from fastapi import APIRouter, Depends, Request
from fastapi.responses import JSONResponse, Response
from psycopg import Connection
from app.access.policy import Ctx, element_rights, get_element, parse_query_context
from app.access.policy import element_rights, get_element, parse_query_context
from app.api.deps import Principal, get_conn, get_principal
from app.api.routes import _created, _ctx_model
from app.api.routes import _created
from app.api.schemas import ConnectorIn, ExternalIn, SourceAssignmentIn
from app.core.errors import DOWNLOAD_REFUSED, forbidden, not_found, unprocessable, unsupported
from app.mailpack import _inline_images, parse_mail, sanitize_html
from app.remoteimages import RemoteImages
from app.media.storage import content_disposition
from app.ops import create_external
from app.api.externals import place_external
from app.retrieval import RetrievalFailure
from app.sourcebind import assign_reference
from app.sourceport import capability_payload, with_capabilities
@@ -370,21 +370,7 @@ def read_mail(
def link_source(body: ExternalIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
if get_source(body.source) is None:
raise unprocessable("Verknüpft werden registrierte Quellen.")
element = create_external(
conn,
principal.account_id,
principal.scope_id,
body.title,
body.source,
body.external_id,
Ctx(body.context.kind, body.context.id),
_ctx_model(body.placement),
body.chapter_id,
body.dates.document_on,
body.dates.sent_on,
body.dates.received_on,
body.detail.model_dump(mode="json", exclude_none=True) if body.detail else None,
)
element = place_external(conn, principal, body)
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})