This commit is contained in:
shamoon 2025-04-21 12:55:33 -07:00
parent b938d0aeba
commit c872e50739
No known key found for this signature in database
3 changed files with 9 additions and 6 deletions

View File

@ -754,6 +754,7 @@ class DocumentViewSet(
)
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", []),

View File

@ -2,6 +2,8 @@ import difflib
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
@ -13,7 +15,7 @@ MATCH_THRESHOLD = 0.8
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"],
@ -22,7 +24,7 @@ def match_tags_by_name(names: list[str], user) -> list[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"],
@ -31,16 +33,16 @@ def match_correspondents_by_name(names: list[str], user) -> list[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"],

View File

@ -51,7 +51,7 @@ class TestAIMatching(TestCase):
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")