mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-23 10:39:25 -05:00
Fix
This commit is contained in:
parent
b938d0aeba
commit
c872e50739
@ -754,6 +754,7 @@ class DocumentViewSet(
|
|||||||
)
|
)
|
||||||
matched_types = match_document_types_by_name(
|
matched_types = match_document_types_by_name(
|
||||||
llm_resp.get("document_types", []),
|
llm_resp.get("document_types", []),
|
||||||
|
request.user,
|
||||||
)
|
)
|
||||||
matched_paths = match_storage_paths_by_name(
|
matched_paths = match_storage_paths_by_name(
|
||||||
llm_resp.get("storage_paths", []),
|
llm_resp.get("storage_paths", []),
|
||||||
|
@ -2,6 +2,8 @@ import difflib
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from documents.models import Correspondent
|
from documents.models import Correspondent
|
||||||
from documents.models import DocumentType
|
from documents.models import DocumentType
|
||||||
from documents.models import StoragePath
|
from documents.models import StoragePath
|
||||||
@ -13,7 +15,7 @@ MATCH_THRESHOLD = 0.8
|
|||||||
logger = logging.getLogger("paperless.ai.matching")
|
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(
|
queryset = get_objects_for_user_owner_aware(
|
||||||
user,
|
user,
|
||||||
["view_tag"],
|
["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")
|
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(
|
queryset = get_objects_for_user_owner_aware(
|
||||||
user,
|
user,
|
||||||
["view_correspondent"],
|
["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")
|
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(
|
queryset = get_objects_for_user_owner_aware(
|
||||||
None,
|
user,
|
||||||
["view_documenttype"],
|
["view_documenttype"],
|
||||||
DocumentType,
|
DocumentType,
|
||||||
)
|
)
|
||||||
return _match_names_to_queryset(names, queryset, "name")
|
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(
|
queryset = get_objects_for_user_owner_aware(
|
||||||
user,
|
user,
|
||||||
["view_storagepath"],
|
["view_storagepath"],
|
||||||
|
@ -51,7 +51,7 @@ class TestAIMatching(TestCase):
|
|||||||
def test_match_document_types_by_name(self, mock_get_objects):
|
def test_match_document_types_by_name(self, mock_get_objects):
|
||||||
mock_get_objects.return_value = DocumentType.objects.all()
|
mock_get_objects.return_value = DocumentType.objects.all()
|
||||||
names = ["Test Document Type 1", "Nonexistent Document Type"]
|
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(len(result), 1)
|
||||||
self.assertEqual(result[0].name, "Test Document Type 1")
|
self.assertEqual(result[0].name, "Test Document Type 1")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user