Fix: let documents without an owner use every OCR template

Unowned documents only matched unowned templates, so they never matched
templates created in the UI. Consider every template, as matching does.
This commit is contained in:
stumpylog committed 2026-11-19 08:43:29 -08:00
1 parent 0117fed721
commit 0f4a71ed88
2 files changed
+25 -11

No files matched your search

+10 -7
View File
@@ -128,15 +128,18 @@ def get_templates_for_document(
) -> list[OcrTemplate]:
"""
The enabled templates that match the selected file's content and that the
root document's owner can view. For a manual run, the templates are further
limited to those the requester can view, so a user editing someone else's
document never runs or sees that owner's private templates.
root document's owner can view. A document without an owner considers every
template, as matching does for tags, correspondents and the like. For a
manual run, the templates are further limited to those the requester can
view, so a user editing someone else's document never runs or sees that
owner's private templates.
"""
owner = get_root_document(document).owner
templates = OcrTemplate.objects.filter(
enabled=True,
id__in=permitted_object_ids(owner, OcrTemplate, "view_ocrtemplate"),
)
templates = OcrTemplate.objects.filter(enabled=True)
if owner is not None:
templates = templates.filter(
id__in=permitted_object_ids(owner, OcrTemplate, "view_ocrtemplate"),
)
if requester is not None:
templates = templates.filter(
id__in=permitted_object_ids(requester, OcrTemplate, "view_ocrtemplate"),