mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-26 01:16:16 +00:00
Include permissions for suggestions
This commit is contained in:
@@ -6,6 +6,7 @@ from documents.models import DocumentType
|
||||
from documents.models import MatchingModel
|
||||
from documents.models import StoragePath
|
||||
from documents.models import Tag
|
||||
from documents.permissions import get_objects_for_user_owner_aware
|
||||
|
||||
|
||||
logger = logging.getLogger("paperless.matching")
|
||||
@@ -19,40 +20,64 @@ def log_reason(matching_model, document, reason):
|
||||
)
|
||||
|
||||
|
||||
def match_correspondents(document, classifier):
|
||||
def match_correspondents(document, classifier, user=None):
|
||||
pred_id = classifier.predict_correspondent(document.content) if classifier else None
|
||||
|
||||
correspondents = Correspondent.objects.all()
|
||||
if user is not None:
|
||||
correspondents = get_objects_for_user_owner_aware(
|
||||
user,
|
||||
"documents.view_correspondent",
|
||||
Correspondent,
|
||||
)
|
||||
else:
|
||||
correspondents = Correspondent.objects.all()
|
||||
|
||||
return list(
|
||||
filter(lambda o: matches(o, document) or o.pk == pred_id, correspondents),
|
||||
)
|
||||
|
||||
|
||||
def match_document_types(document, classifier):
|
||||
def match_document_types(document, classifier, user=None):
|
||||
pred_id = classifier.predict_document_type(document.content) if classifier else None
|
||||
|
||||
document_types = DocumentType.objects.all()
|
||||
if user is not None:
|
||||
document_types = get_objects_for_user_owner_aware(
|
||||
user,
|
||||
"documents.view_documenttype",
|
||||
DocumentType,
|
||||
)
|
||||
else:
|
||||
document_types = DocumentType.objects.all()
|
||||
|
||||
return list(
|
||||
filter(lambda o: matches(o, document) or o.pk == pred_id, document_types),
|
||||
)
|
||||
|
||||
|
||||
def match_tags(document, classifier):
|
||||
def match_tags(document, classifier, user=None):
|
||||
predicted_tag_ids = classifier.predict_tags(document.content) if classifier else []
|
||||
|
||||
tags = Tag.objects.all()
|
||||
if user is not None:
|
||||
tags = get_objects_for_user_owner_aware(user, "documents.view_tag", Tag)
|
||||
else:
|
||||
tags = Tag.objects.all()
|
||||
|
||||
return list(
|
||||
filter(lambda o: matches(o, document) or o.pk in predicted_tag_ids, tags),
|
||||
)
|
||||
|
||||
|
||||
def match_storage_paths(document, classifier):
|
||||
def match_storage_paths(document, classifier, user=None):
|
||||
pred_id = classifier.predict_storage_path(document.content) if classifier else None
|
||||
|
||||
storage_paths = StoragePath.objects.all()
|
||||
if user is not None:
|
||||
storage_paths = get_objects_for_user_owner_aware(
|
||||
user,
|
||||
"documents.view_storagepath",
|
||||
StoragePath,
|
||||
)
|
||||
else:
|
||||
storage_paths = StoragePath.objects.all()
|
||||
|
||||
return list(
|
||||
filter(
|
||||
|
Reference in New Issue
Block a user