mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-28 20:30:33 +00:00
feat: add include_deleted param to permitted_document_ids (#13506)
* feat: add include_deleted param to permitted_document_ids Widens permitted_document_ids to accept an include_deleted keyword-only flag (default False, preserving current behavior) so later call sites that need visibility into soft-deleted documents (e.g. trash restore) can reuse this permission check instead of duplicating it. * refactor: remove redundant deleted_at filter in permitted_document_ids Document.objects already applies filter(deleted_at__isnull=True) internally via SoftDeleteManager.get_queryset(), so the conditional filter was redundant. Simplify to just use manager.all() in both branches — manager selection alone ensures correct behavior (Document.objects excludes deleted, Document.global_objects includes all). Co-Authored-By: Claude Haiku <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session --------- Co-authored-by: Claude Haiku <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku
parent
3a484a3ff2
commit
5e54259db9
@@ -163,14 +163,18 @@ def set_permissions_for_object(
|
||||
)
|
||||
|
||||
|
||||
def permitted_document_ids(user):
|
||||
def permitted_document_ids(user, *, include_deleted: bool = False):
|
||||
"""
|
||||
Return a queryset of document IDs the user may view, limited to non-deleted
|
||||
documents. This intentionally avoids ``get_objects_for_user`` to keep the
|
||||
subquery small and index-friendly.
|
||||
Return a queryset of document IDs the user may view. By default limited
|
||||
to non-deleted documents; pass ``include_deleted=True`` for callers that
|
||||
need to check permission on soft-deleted documents (e.g. trash restore).
|
||||
This intentionally avoids ``get_objects_for_user`` to keep the subquery
|
||||
small and index-friendly.
|
||||
"""
|
||||
|
||||
base_docs = Document.objects.filter(deleted_at__isnull=True).only("id", "owner")
|
||||
manager = Document.global_objects if include_deleted else Document.objects
|
||||
base_docs = manager.all()
|
||||
base_docs = base_docs.only("id", "owner")
|
||||
|
||||
if user is None or not getattr(user, "is_authenticated", False):
|
||||
# Just Anonymous user e.g. for drf-spectacular
|
||||
|
||||
Reference in New Issue
Block a user