]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix
authorshamoon <4887959+shamoon@users.noreply.github.com>
Mon, 21 Apr 2025 19:55:33 +0000 (12:55 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 2 Jul 2025 18:01:48 +0000 (11:01 -0700)
src/documents/views.py
src/paperless/ai/matching.py
src/paperless/tests/test_ai_matching.py

index 0c4059a15984348f939cb03e277bbdc5b482a535..41ce6bf9d54e8f1c98cb56d86055bc6851b95234 100644 (file)
@@ -787,6 +787,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", []),
index 82521c0c4ae3a7267f5fec56b68529bcea98fe9c..822f2accc853cf51d6570570c83f3027f7fadd00 100644 (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"],
index 55ec6f2e1cbf0605a8d5a4855a4433f3762a7f38..e5eaf27d1af775f4d5b408775a3b5ddc2ded9253 100644 (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")