Das Modul liefert ein Feldmanifest und validiert es; ein leeres Geheimnisfeld behält das gespeicherte. Die Oberfläche rendert die Felder generisch in einer Detailansicht je Zugang mit Prüfstand, Fähigkeiten und Verwendung. Die providerspezifischen Formulare in Sources.jsx entfallen, die flachen API-Felder bleiben als Kompatibilität. Das Standardfach eines IMAP-Kontos öffnet der Picker zuerst. Die Backend-Tests wurden in der Entwicklungsumgebung nicht ausgeführt; der Lauf auf develop steht aus. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
112 lines
2.9 KiB
Python
112 lines
2.9 KiB
Python
"""Declared source and editor capabilities.
|
|
|
|
A common contract does not invent abilities the adapter does not have.
|
|
A filter is offered only when that module implements it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
PAPERLESS_CAPABILITIES = {
|
|
"kind": "paperless",
|
|
"navigate": False,
|
|
"read_original": True,
|
|
"read_preview": True,
|
|
"read_attachment": False,
|
|
"edit_content": False,
|
|
"edit_metadata": False,
|
|
"search": {
|
|
"query": True,
|
|
"title": True,
|
|
"correspondent": True,
|
|
"document_type": True,
|
|
"tags": True,
|
|
"document_range": True,
|
|
"sort": True,
|
|
"continuation": True,
|
|
},
|
|
}
|
|
|
|
IMAP_CAPABILITIES = {
|
|
"kind": "imap",
|
|
"navigate": True,
|
|
"read_original": True,
|
|
"read_preview": True,
|
|
"read_attachment": True,
|
|
"edit_content": False,
|
|
"edit_metadata": False,
|
|
"search": {
|
|
"query": True,
|
|
"title": False,
|
|
"correspondent": False,
|
|
"document_type": False,
|
|
"tags": False,
|
|
"document_range": False,
|
|
"sort": False,
|
|
"continuation": True,
|
|
},
|
|
}
|
|
|
|
CAPABILITIES = {
|
|
"paperless": PAPERLESS_CAPABILITIES,
|
|
"imap": IMAP_CAPABILITIES,
|
|
}
|
|
|
|
EDITORS = {
|
|
"note": True,
|
|
"markdown_file": False,
|
|
}
|
|
|
|
UNSUPPORTED_SEARCH = (
|
|
"title",
|
|
"correspondent",
|
|
"document_type",
|
|
"tag",
|
|
"document_from",
|
|
"document_to",
|
|
"sort",
|
|
"cursor",
|
|
)
|
|
|
|
|
|
def capability_payload() -> dict:
|
|
from app.sourceregistry import registered_sources
|
|
|
|
return {
|
|
"sources": [module.capabilities for module in registered_sources()],
|
|
"modules": [
|
|
{
|
|
"kind": module.kind,
|
|
"label": module.label,
|
|
"representation": module.representation,
|
|
"config_fields": [item.public() for item in module.config_fields],
|
|
}
|
|
for module in registered_sources()
|
|
],
|
|
"editors": EDITORS,
|
|
"protection_profiles": {
|
|
"legacy-plaintext": "cleartext",
|
|
"managed-encrypted": "locked",
|
|
"client-encrypted": "locked",
|
|
},
|
|
}
|
|
|
|
|
|
def unsupported_filters(values: dict[str, str]) -> list[str]:
|
|
return [name for name in UNSUPPORTED_SEARCH if str(values.get(name) or "").strip()]
|
|
|
|
|
|
def with_capabilities(kind: str, connector_id: str, payload: dict) -> dict:
|
|
from app.sourceregistry import require_source
|
|
|
|
body = dict(payload)
|
|
spec = require_source(kind).capabilities
|
|
body["connector_id"] = connector_id
|
|
body["capabilities"] = spec
|
|
body["unsupported"] = [name for name, enabled in spec["search"].items() if not enabled]
|
|
if spec["search"].get("continuation"):
|
|
body["continuation"] = body.get("next_before") if body.get("next_before") is not None else body.get("next_page")
|
|
else:
|
|
body["continuation"] = None
|
|
body["incomplete"] = bool(body.get("incomplete"))
|
|
return body
|