)
matched_types = match_document_types_by_name(
llm_resp.get("document_types", []),
+ request.user,
)
matched_paths = match_storage_paths_by_name(
llm_resp.get("storage_paths", []),
import logging
import re
+from django.contrib.auth.models import User
+
from documents.models import Correspondent
from documents.models import DocumentType
from documents.models import StoragePath
logger = logging.getLogger("paperless.ai.matching")
-def match_tags_by_name(names: list[str], user) -> list[Tag]:
+def match_tags_by_name(names: list[str], user: User) -> list[Tag]:
queryset = get_objects_for_user_owner_aware(
user,
["view_tag"],
return _match_names_to_queryset(names, queryset, "name")
-def match_correspondents_by_name(names: list[str], user) -> list[Correspondent]:
+def match_correspondents_by_name(names: list[str], user: User) -> list[Correspondent]:
queryset = get_objects_for_user_owner_aware(
user,
["view_correspondent"],
return _match_names_to_queryset(names, queryset, "name")
-def match_document_types_by_name(names: list[str]) -> list[DocumentType]:
+def match_document_types_by_name(names: list[str], user: User) -> list[DocumentType]:
queryset = get_objects_for_user_owner_aware(
- None,
+ user,
["view_documenttype"],
DocumentType,
)
return _match_names_to_queryset(names, queryset, "name")
-def match_storage_paths_by_name(names: list[str], user) -> list[StoragePath]:
+def match_storage_paths_by_name(names: list[str], user: User) -> list[StoragePath]:
queryset = get_objects_for_user_owner_aware(
user,
["view_storagepath"],
def test_match_document_types_by_name(self, mock_get_objects):
mock_get_objects.return_value = DocumentType.objects.all()
names = ["Test Document Type 1", "Nonexistent Document Type"]
- result = match_document_types_by_name(names)
+ result = match_document_types_by_name(names, user=None)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].name, "Test Document Type 1")