Correct object retrieval

This commit is contained in:
shamoon 2025-04-21 11:34:13 -07:00
parent 131ae28794
commit dd78c5d496
No known key found for this signature in database

View File

@ -6,6 +6,7 @@ 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
from documents.models import Tag from documents.models import Tag
from documents.permissions import get_objects_for_user_owner_aware
MATCH_THRESHOLD = 0.7 MATCH_THRESHOLD = 0.7
@ -13,30 +14,37 @@ 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) -> list[Tag]:
queryset = ( queryset = get_objects_for_user_owner_aware(
Tag.objects.filter(owner=user) if user.is_authenticated else Tag.objects.all() user,
["view_tag"],
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) -> list[Correspondent]:
queryset = ( queryset = get_objects_for_user_owner_aware(
Correspondent.objects.filter(owner=user) user,
if user.is_authenticated ["view_correspondent"],
else Correspondent.objects.all() 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]) -> list[DocumentType]:
return _match_names_to_queryset(names, DocumentType.objects.all(), "name") queryset = get_objects_for_user_owner_aware(
None,
["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) -> list[StoragePath]:
queryset = ( queryset = get_objects_for_user_owner_aware(
StoragePath.objects.filter(owner=user) user,
if user.is_authenticated ["view_storagepath"],
else StoragePath.objects.all() StoragePath,
) )
return _match_names_to_queryset(names, queryset, "name") return _match_names_to_queryset(names, queryset, "name")