A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: exclude version documents from bulk edit "all" (#13791)
shamoon7330c4d9cb61
diff --git a/src/documents/tests/test_api_document_versions.py b/src/documents/tests/test_api_document_versions.pyindex 41822af71..ae14fb4cc 100644--- a/src/documents/tests/test_api_document_versions.py+++ b/src/documents/tests/test_api_document_versions.py@@ -11,6 +11,7 @@ from django.contrib.auth.models import Userfrom django.contrib.contenttypes.models import ContentTypefrom django.core.exceptions import FieldErrorfrom django.core.files.uploadedfile import SimpleUploadedFile+from django.test import TestCase as DjangoTestCasefrom django.utils import timezonefrom rest_framework import statusfrom rest_framework.test import APITestCase@@ -21,6 +22,7 @@ from documents.filters import TitleContentFilterfrom documents.models import Documentfrom documents.tests.utils import DirectoriesMixinfrom documents.tests.utils import read_streaming_response+from documents.views import DocumentSelectionMixinif 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])diff --git a/src/documents/views.py b/src/documents/views.pyindex 29cde306b..36a976624 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -2795,8 +2795,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 insteadpermitted_documents = Document.objects.filter(id__in=permitted_document_ids(user),+ root_document__isnull=True,)# orm-filtered docsfiltered_documents = DocumentFilterSet(