Compare commits

..
Author SHA1 Message Date
shamoon 9189d4549e Fix: exclude version documents from bulk edit "select all matching" 2026-08-25 14:54:52 -07:00
3 changed files with 50 additions and 13 deletions
@@ -11,6 +11,7 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase as DjangoTestCase
from django.utils import timezone
from rest_framework import status
from rest_framework.test import APITestCase
@@ -21,6 +22,7 @@ from documents.filters import TitleContentFilter
from documents.models import Document
from documents.tests.utils import DirectoriesMixin
from documents.tests.utils import read_streaming_response
from documents.views import DocumentSelectionMixin
if TYPE_CHECKING:
from pathlib import Path
@@ -923,3 +925,36 @@ class TestVersionAwareFilters(TestCase):
self.assertIs(result, queryset)
queryset.filter.assert_not_called()
class TestBulkSelectionExcludesVersions(DjangoTestCase):
def test_select_all_matching_does_not_select_version_documents(self) -> None:
"""
"Select all matching" reconstructs the document list, which never
contains version documents as rows of their own.
"""
user = User.objects.create_superuser(username="bulk_versions")
root = Document.objects.create(
title="shared-title root",
checksum="bulk-root",
mime_type="application/pdf",
content="root",
)
Document.objects.create(
title="shared-title version",
checksum="bulk-version",
mime_type="application/pdf",
root_document=root,
version_index=1,
content="version",
)
selected = DocumentSelectionMixin()._resolve_document_ids(
user=user,
validated_data={
"all": True,
"filters": {"title__icontains": "shared-title"},
},
)
self.assertEqual(selected, [root.id])
+4 -2
View File
@@ -1133,8 +1133,7 @@ class DocumentViewSet(
"custom_fields",
queryset=CustomFieldInstance.objects.select_related("field"),
),
# NotesSerializer nests the author, this avoids query per note
Prefetch("notes", queryset=Note.objects.select_related("user")),
"notes",
)
)
@@ -2795,8 +2794,11 @@ class DocumentSelectionMixin:
for key, value in filters.items()
if key not in _TANTIVY_SEARCH_PARAM_NAMES
}
# Operations are addressed to roots, a caller that wants
# to act on a specific version passes its id explicitly instead
permitted_documents = Document.objects.filter(
id__in=permitted_document_ids(user),
root_document__isnull=True,
)
# orm-filtered docs
filtered_documents = DocumentFilterSet(
+11 -11
View File
@@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: paperless-ngx\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-08-25 21:36+0000\n"
"POT-Creation-Date: 2026-08-24 21:43+0000\n"
"PO-Revision-Date: 2022-02-17 04:17\n"
"Last-Translator: \n"
"Language-Team: English\n"
@@ -1580,7 +1580,7 @@ msgid "workflow runs"
msgstr ""
#: documents/serialisers.py:523 documents/serialisers.py:875
#: documents/serialisers.py:2827 documents/views.py:311 documents/views.py:2613
#: documents/serialisers.py:2827 documents/views.py:311 documents/views.py:2612
#: paperless_mail/serialisers.py:155
msgid "Insufficient permissions."
msgstr ""
@@ -1621,7 +1621,7 @@ msgstr ""
msgid "Duplicate document identifiers are not allowed."
msgstr ""
#: documents/serialisers.py:2913 documents/views.py:4607
#: documents/serialisers.py:2913 documents/views.py:4606
#, python-format
msgid "Documents not found: %(ids)s"
msgstr ""
@@ -1889,36 +1889,36 @@ msgstr ""
msgid "Unable to parse URI {value}"
msgstr ""
#: documents/views.py:304 documents/views.py:2610
#: documents/views.py:304 documents/views.py:2609
msgid "Invalid more_like_id"
msgstr ""
#: documents/views.py:1587
#: documents/views.py:1586
msgid "Invalid AI configuration."
msgstr ""
#: documents/views.py:1598
#: documents/views.py:1597
msgid "AI backend request timed out."
msgstr ""
#: documents/views.py:2435 documents/views.py:2756
#: documents/views.py:2434 documents/views.py:2755
msgid "Specify only one of text, title_search, query, or more_like_id."
msgstr ""
#: documents/views.py:4620
#: documents/views.py:4619
#, python-format
msgid "Insufficient permissions to share document %(id)s."
msgstr ""
#: documents/views.py:4666
#: documents/views.py:4665
msgid "Bundle is already being processed."
msgstr ""
#: documents/views.py:4727
#: documents/views.py:4726
msgid "The share link bundle is still being prepared. Please try again later."
msgstr ""
#: documents/views.py:4737
#: documents/views.py:4736
msgid "The share link bundle is unavailable."
msgstr ""