Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Merge branch 'main' into dev

shamoon8f036c952180
diff --cc docs/changelog.md
index c361309d1,9fe928831..a5bc21432
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@@ -1,5 -1,40 +1,40 @@@
# Changelog
+ ## paperless-ngx 2.20.14
+
+ ### Bug Fixes
+
-- Fix: do not submit permissions for non-owners [@shamoon](https://github.com/shamoon) ([#12571](https://github.com/paperless-ngx/paperless-ngx/pull/12571))
-- Fix: prevent duplicate parent tag IDs [@shamoon](https://github.com/shamoon) ([#12522](https://github.com/paperless-ngx/paperless-ngx/pull/12522))
-- Fix: dont defer tag change application in workflows [@shamoon](https://github.com/shamoon) ([#12478](https://github.com/paperless-ngx/paperless-ngx/pull/12478))
-- Fix: limit share link viewset actions [@shamoon](https://github.com/shamoon) ([#12461](https://github.com/paperless-ngx/paperless-ngx/pull/12461))
-- Fix: add fallback ordering for documents by id after created [@shamoon](https://github.com/shamoon) ([#12440](https://github.com/paperless-ngx/paperless-ngx/pull/12440))
-- Fixhancement: default mail-created correspondent matching to exact [@shamoon](https://github.com/shamoon) ([#12414](https://github.com/paperless-ngx/paperless-ngx/pull/12414))
-- Fix: validate date CF value in serializer [@shamoon](https://github.com/shamoon) ([#12410](https://github.com/paperless-ngx/paperless-ngx/pull/12410))
++- Fix: do not submit permissions for non-owners [@shamoon](https://github.com/shamoon) ([#12571](https://github.com/paperless-ngx/paperless-ngx/pull/12571))
++- Fix: prevent duplicate parent tag IDs [@shamoon](https://github.com/shamoon) ([#12522](https://github.com/paperless-ngx/paperless-ngx/pull/12522))
++- Fix: dont defer tag change application in workflows [@shamoon](https://github.com/shamoon) ([#12478](https://github.com/paperless-ngx/paperless-ngx/pull/12478))
++- Fix: limit share link viewset actions [@shamoon](https://github.com/shamoon) ([#12461](https://github.com/paperless-ngx/paperless-ngx/pull/12461))
++- Fix: add fallback ordering for documents by id after created [@shamoon](https://github.com/shamoon) ([#12440](https://github.com/paperless-ngx/paperless-ngx/pull/12440))
++- Fixhancement: default mail-created correspondent matching to exact [@shamoon](https://github.com/shamoon) ([#12414](https://github.com/paperless-ngx/paperless-ngx/pull/12414))
++- Fix: validate date CF value in serializer [@shamoon](https://github.com/shamoon) ([#12410](https://github.com/paperless-ngx/paperless-ngx/pull/12410))
+
+ ### All App Changes
+
+ <details>
+ <summary>7 changes</summary>
+
-- Fix: do not submit permissions for non-owners [@shamoon](https://github.com/shamoon) ([#12571](https://github.com/paperless-ngx/paperless-ngx/pull/12571))
-- Fix: prevent duplicate parent tag IDs [@shamoon](https://github.com/shamoon) ([#12522](https://github.com/paperless-ngx/paperless-ngx/pull/12522))
-- Fix: dont defer tag change application in workflows [@shamoon](https://github.com/shamoon) ([#12478](https://github.com/paperless-ngx/paperless-ngx/pull/12478))
-- Fix: limit share link viewset actions [@shamoon](https://github.com/shamoon) ([#12461](https://github.com/paperless-ngx/paperless-ngx/pull/12461))
-- Fix: add fallback ordering for documents by id after created [@shamoon](https://github.com/shamoon) ([#12440](https://github.com/paperless-ngx/paperless-ngx/pull/12440))
-- Fixhancement: default mail-created correspondent matching to exact [@shamoon](https://github.com/shamoon) ([#12414](https://github.com/paperless-ngx/paperless-ngx/pull/12414))
-- Fix: validate date CF value in serializer [@shamoon](https://github.com/shamoon) ([#12410](https://github.com/paperless-ngx/paperless-ngx/pull/12410))
++- Fix: do not submit permissions for non-owners [@shamoon](https://github.com/shamoon) ([#12571](https://github.com/paperless-ngx/paperless-ngx/pull/12571))
++- Fix: prevent duplicate parent tag IDs [@shamoon](https://github.com/shamoon) ([#12522](https://github.com/paperless-ngx/paperless-ngx/pull/12522))
++- Fix: dont defer tag change application in workflows [@shamoon](https://github.com/shamoon) ([#12478](https://github.com/paperless-ngx/paperless-ngx/pull/12478))
++- Fix: limit share link viewset actions [@shamoon](https://github.com/shamoon) ([#12461](https://github.com/paperless-ngx/paperless-ngx/pull/12461))
++- Fix: add fallback ordering for documents by id after created [@shamoon](https://github.com/shamoon) ([#12440](https://github.com/paperless-ngx/paperless-ngx/pull/12440))
++- Fixhancement: default mail-created correspondent matching to exact [@shamoon](https://github.com/shamoon) ([#12414](https://github.com/paperless-ngx/paperless-ngx/pull/12414))
++- Fix: validate date CF value in serializer [@shamoon](https://github.com/shamoon) ([#12410](https://github.com/paperless-ngx/paperless-ngx/pull/12410))
+ </details>
+
+ ## paperless-ngx 2.20.13
+
+ ### Bug Fixes
+
-- Fix: suggest corrections only if visible results
-- Fix: require view permission for more-like search
-- Fix: validate document link targets
-- Fix: enforce permissions when attaching accounts to mail rules
++- Fix: suggest corrections only if visible results
++- Fix: require view permission for more-like search
++- Fix: validate document link targets
++- Fix: enforce permissions when attaching accounts to mail rules
+
## paperless-ngx 2.20.12
### Security
diff --cc docs/usage.md
index 1528af390,2dcfcda66..e8b884251
--- a/docs/usage.md
+++ b/docs/usage.md
@@@ -398,27 -364,25 +398,27 @@@ Global permissions define what areas o
determine if a user can create, edit, delete or view _any_ documents, but individual documents themselves
still have "object-level" permissions.
-| Type | Details |
-| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| AppConfig | _Change_ or higher permissions grants access to the "Application Configuration" area. |
-| Correspondent | Add, edit, delete or view Correspondents. |
-| CustomField | Add, edit, delete or view Custom Fields. |
-| Document | Add, edit, delete or view Documents. |
-| DocumentType | Add, edit, delete or view Document Types. |
-| Group | Add, edit, delete or view Groups. |
-| MailAccount | Add, edit, delete or view Mail Accounts. |
-| MailRule | Add, edit, delete or view Mail Rules. |
-| Note | Add, edit, delete or view Notes. |
-| PaperlessTask | View or dismiss (_Change_) File Tasks. |
-| SavedView | Add, edit, delete or view Saved Views. |
-| ShareLink | Add, delete or view Share Links. |
-| StoragePath | Add, edit, delete or view Storage Paths. |
-| Tag | Add, edit, delete or view Tags. |
-| UISettings | Add, edit, delete or view the UI settings that are used by the web app.<br/>:warning: **Users that will access the web UI must be granted at least _View_ permissions.** |
-| User | Add, edit, delete or view other user accounts via Settings > Users & Groups and `/api/users/`. These permissions are not needed for users to edit their own profile via "My Profile" or `/api/profile/`. |
-| Workflow | Add, edit, delete or view Workflows.<br/>Note that Workflows are global; all users who can access workflows see the same set. Workflows have other permission implications — see [Workflow permissions](#workflow-permissions). |
+| Type | Details |
+| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| AppConfig | _Change_ or higher permissions grants access to the "Application Configuration" area. |
+| Correspondent | Add, edit, delete or view Correspondents. |
+| CustomField | Add, edit, delete or view Custom Fields. |
+| Document | Add, edit, delete or view Documents. |
+| DocumentType | Add, edit, delete or view Document Types. |
+| Group | Add, edit, delete or view Groups. |
+| GlobalStatistics | View aggregate object counts and statistics. This does not grant access to view individual documents. |
+| MailAccount | Add, edit, delete or view Mail Accounts. |
+| MailRule | Add, edit, delete or view Mail Rules. |
+| Note | Add, edit, delete or view Notes. |
+| PaperlessTask | View or dismiss (_Change_) File Tasks. |
+| SavedView | Add, edit, delete or view Saved Views. |
+| ShareLink | Add, delete or view Share Links. |
+| StoragePath | Add, edit, delete or view Storage Paths. |
+| SystemStatus | View the system status dialog and corresponding API endpoint. Admin users also retain system status access. |
+| Tag | Add, edit, delete or view Tags. |
+| UISettings | Add, edit, delete or view the UI settings that are used by the web app.<br/>:warning: **Users that will access the web UI must be granted at least _View_ permissions.** |
- | User | Add, edit, delete or view Users. |
++| User | Add, edit, delete or view other user accounts via Settings > Users & Groups and `/api/users/`. These permissions are not needed for users to edit their own profile via "My Profile" or `/api/profile/`. |
+| Workflow | Add, edit, delete or view Workflows.<br/>Note that Workflows are global; all users who can access workflows see the same set. Workflows have other permission implications — see [Workflow permissions](#workflow-permissions). |
#### Detailed Explanation of Object Permissions {#object-permissions}
diff --cc pyproject.toml
index fca865782,e0f2ea35d..1537155a8
--- a/pyproject.toml
+++ b/pyproject.toml
@@@ -1,11 -1,12 +1,11 @@@
[project]
name = "paperless-ngx"
- version = "2.20.13"
+ version = "2.20.14"
description = "A community-supported supercharged document management system: scan, index and archive all your physical documents"
readme = "README.md"
-requires-python = ">=3.10"
+requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
- "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
diff --cc src-ui/src/environments/environment.prod.ts
index 4b66010c6,dc27a6888..0db350bc2
--- a/src-ui/src/environments/environment.prod.ts
+++ b/src-ui/src/environments/environment.prod.ts
@@@ -3,10 -3,10 +3,10 @@@ const base_url = new URL(document.baseU
export const environment = {
production: true,
apiBaseUrl: document.baseURI + 'api/',
- apiVersion: '9', // match src/paperless/settings.py
+ apiVersion: '10', // match src/paperless/settings.py
appTitle: 'Paperless-ngx',
tag: 'prod',
- version: '2.20.13',
+ version: '2.20.14',
webSocketHost: window.location.host,
webSocketProtocol: window.location.protocol == 'https:' ? 'wss:' : 'ws:',
webSocketBaseUrl: base_url.pathname + 'ws/',
diff --cc src/documents/signals/handlers.py
index a72abc2d5,4ff5a2b33..dd49a718c
--- a/src/documents/signals/handlers.py
+++ b/src/documents/signals/handlers.py
@@@ -887,29 -814,10 +887,28 @@@ def run_workflows
for workflow in workflows:
if not use_overrides:
- # This can be called from bulk_update_documents, which may be running multiple times
- # Refresh this so the matching data is fresh and instance fields are re-freshed
- # Otherwise, this instance might be behind and overwrite the work another process did
- document.refresh_from_db()
+ if TYPE_CHECKING:
+ assert isinstance(document, Document)
+ try:
+ # This can be called from bulk_update_documents, which may be running multiple times
+ # Refresh this so the matching data is fresh and instance fields are re-freshed
+ # Otherwise, this instance might be behind and overwrite the work another process did
+ document.refresh_from_db()
- doc_tag_ids = list(document.tags.values_list("pk", flat=True))
+ except Document.DoesNotExist:
+ # Document was hard deleted by a previous workflow or another process
+ logger.info(
+ "Document no longer exists, skipping remaining workflows",
+ extra={"group": logging_group},
+ )
+ break
+
+ # Check if document was soft deleted (moved to trash)
+ if document.is_deleted:
+ logger.info(
+ "Document was moved to trash, skipping remaining workflows",
+ extra={"group": logging_group},
+ )
+ break
if matching.document_matches_workflow(document, workflow, trigger_type):
action: WorkflowAction
diff --cc src/documents/tests/test_api_documents.py
index 1361aedfc,352ce7810..173a93a30
--- a/src/documents/tests/test_api_documents.py
+++ b/src/documents/tests/test_api_documents.py
@@@ -1140,85 -1084,47 +1140,122 @@@ class TestDocumentApi(DirectoriesMixin
self.assertEqual(response.status_code, status.HTTP_200_OK)
results = response.data["results"]
self.assertEqual(len(results), 25)
- self.assertEqual(len(response.data["all"]), 50)
+ self.assertEqual(response.data["count"], 50)
+ self.assertNotIn("all", response.data)
+
+ def test_pagination_all_for_api_version_9(self) -> None:
+ """
+ GIVEN:
+ - A set of documents matching a filter
+ WHEN:
+ - API request uses legacy version 9
+ THEN:
+ - Response includes "all" for backward compatibility
+ """
+ t = Tag.objects.create(name="tag")
+ docs = []
+ for i in range(4):
+ d = Document.objects.create(checksum=i, content=f"test{i}")
+ d.tags.add(t)
+ docs.append(d)
+
+ response = self.client.get(
+ f"/api/documents/?tags__id__in={t.id}",
+ headers={"Accept": "application/json; version=9"},
+ )
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertIn("all", response.data)
self.assertCountEqual(response.data["all"], [d.id for d in docs])
+ def test_default_ordering_uses_id_as_tiebreaker(self):
+ """
+ GIVEN:
+ - Documents sharing the same created date
+ WHEN:
+ - API request for documents without an explicit ordering
+ THEN:
+ - Results are correctly ordered by created > id
+ """
+ older_doc = Document.objects.create(
+ checksum="older",
+ content="older",
+ created=date(2024, 1, 1),
+ )
+ first_same_date_doc = Document.objects.create(
+ checksum="same-date-1",
+ content="same-date-1",
+ created=date(2024, 1, 2),
+ )
+ second_same_date_doc = Document.objects.create(
+ checksum="same-date-2",
+ content="same-date-2",
+ created=date(2024, 1, 2),
+ )
+
+ response = self.client.get("/api/documents/")
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertEqual(
+ [result["id"] for result in response.data["results"]],
+ [
+ second_same_date_doc.id,
+ first_same_date_doc.id,
+ older_doc.id,
+ ],
+ )
+
- def test_statistics(self):
+ def test_list_with_include_selection_data(self) -> None:
+ correspondent = Correspondent.objects.create(name="c1")
+ doc_type = DocumentType.objects.create(name="dt1")
+ storage_path = StoragePath.objects.create(name="sp1")
+ tag = Tag.objects.create(name="tag")
+
+ matching_doc = Document.objects.create(
+ checksum="A",
+ correspondent=correspondent,
+ document_type=doc_type,
+ storage_path=storage_path,
+ )
+ matching_doc.tags.add(tag)
+
+ non_matching_doc = Document.objects.create(checksum="B")
+ non_matching_doc.tags.add(Tag.objects.create(name="other"))
+
+ response = self.client.get(
+ f"/api/documents/?tags__id__in={tag.id}&include_selection_data=true",
+ )
+
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertIn("selection_data", response.data)
+
+ selected_correspondent = next(
+ item
+ for item in response.data["selection_data"]["selected_correspondents"]
+ if item["id"] == correspondent.id
+ )
+ selected_tag = next(
+ item
+ for item in response.data["selection_data"]["selected_tags"]
+ if item["id"] == tag.id
+ )
+ selected_type = next(
+ item
+ for item in response.data["selection_data"]["selected_document_types"]
+ if item["id"] == doc_type.id
+ )
+ selected_storage_path = next(
+ item
+ for item in response.data["selection_data"]["selected_storage_paths"]
+ if item["id"] == storage_path.id
+ )
+
+ self.assertEqual(selected_correspondent["document_count"], 1)
+ self.assertEqual(selected_tag["document_count"], 1)
+ self.assertEqual(selected_type["document_count"], 1)
+ self.assertEqual(selected_storage_path["document_count"], 1)
+
+ def test_statistics(self) -> None:
doc1 = Document.objects.create(
title="none1",
checksum="A",
@@@ -3379,7 -2990,59 +3416,7 @@@
self.assertEqual(create_resp.status_code, status.HTTP_201_CREATED)
self.assertEqual(create_resp.data["document"], doc.pk)
- def test_next_asn(self) -> None:
- def test_share_link_update_methods_not_allowed(self):
- """
- GIVEN:
- - An existing share link
- WHEN:
- - PUT and PATCH requests are made to its detail endpoint
- THEN:
- - The API rejects them with 405 and the link is unchanged
- """
- doc = Document.objects.create(
- title="test",
- mime_type="application/pdf",
- content="share link content",
- )
- expiration = timezone.now() + timedelta(days=7)
- create_resp = self.client.post(
- "/api/share_links/",
- data={
- "document": doc.pk,
- "expiration": expiration.isoformat(),
- "file_version": ShareLink.FileVersion.ORIGINAL,
- },
- format="json",
- )
- self.assertEqual(create_resp.status_code, status.HTTP_201_CREATED)
- share_link_id = create_resp.data["id"]
-
- patch_resp = self.client.patch(
- f"/api/share_links/{share_link_id}/",
- data={
- "expiration": None,
- "file_version": ShareLink.FileVersion.ARCHIVE,
- },
- format="json",
- )
- self.assertEqual(patch_resp.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
-
- put_resp = self.client.put(
- f"/api/share_links/{share_link_id}/",
- data={
- "document": doc.pk,
- "expiration": None,
- "file_version": ShareLink.FileVersion.ARCHIVE,
- },
- format="json",
- )
- self.assertEqual(put_resp.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
-
- share_link = ShareLink.objects.get(pk=share_link_id)
- self.assertEqual(share_link.file_version, ShareLink.FileVersion.ORIGINAL)
- self.assertIsNotNone(share_link.expiration)
-
+ def test_next_asn(self):
"""
GIVEN:
- Existing documents with ASNs, highest owned by user2
diff --cc src/documents/views.py
index 60e9f008d,732fe2232..5c957dd96
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@@ -845,89 -783,13 +846,89 @@@ class DocumentViewSet
"custom_field_",
)
+ def _get_selection_data_for_queryset(self, queryset):
+ correspondents = Correspondent.objects.annotate(
+ document_count=Count(
+ "documents",
+ filter=Q(documents__in=queryset),
+ distinct=True,
+ ),
+ )
+ tags = Tag.objects.annotate(
+ document_count=Count(
+ "documents",
+ filter=Q(documents__in=queryset),
+ distinct=True,
+ ),
+ )
+ document_types = DocumentType.objects.annotate(
+ document_count=Count(
+ "documents",
+ filter=Q(documents__in=queryset),
+ distinct=True,
+ ),
+ )
+ storage_paths = StoragePath.objects.annotate(
+ document_count=Count(
+ "documents",
+ filter=Q(documents__in=queryset),
+ distinct=True,
+ ),
+ )
+ custom_fields = CustomField.objects.annotate(
+ document_count=Count(
+ "fields__document",
+ filter=Q(fields__document__in=queryset),
+ distinct=True,
+ ),
+ )
+
+ return {
+ "selected_correspondents": [
+ {"id": t.id, "document_count": t.document_count} for t in correspondents
+ ],
+ "selected_tags": [
+ {"id": t.id, "document_count": t.document_count} for t in tags
+ ],
+ "selected_document_types": [
+ {"id": t.id, "document_count": t.document_count} for t in document_types
+ ],
+ "selected_storage_paths": [
+ {"id": t.id, "document_count": t.document_count} for t in storage_paths
+ ],
+ "selected_custom_fields": [
+ {"id": t.id, "document_count": t.document_count} for t in custom_fields
+ ],
+ }
+
def get_queryset(self):
+ latest_version_content = Subquery(
+ Document.objects.filter(root_document=OuterRef("pk"))
+ .order_by("-id")
+ .values("content")[:1],
+ )
return (
- Document.objects.distinct()
+ Document.objects.filter(root_document__isnull=True)
+ .distinct()
- .order_by("-created")
+ .order_by("-created", "-id")
+ .annotate(effective_content=Coalesce(latest_version_content, F("content")))
.annotate(num_notes=Count("notes"))
.select_related("correspondent", "storage_path", "document_type", "owner")
- .prefetch_related("tags", "custom_fields", "notes")
+ .prefetch_related(
+ Prefetch(
+ "versions",
+ queryset=Document.objects.only(
+ "id",
+ "added",
+ "checksum",
+ "version_label",
+ "root_document_id",
+ ),
+ ),
+ "tags",
+ "custom_fields",
+ "notes",
+ )
)
def get_serializer(self, *args, **kwargs):
diff --cc uv.lock
index 470d18145,830185ce6..d4bb929cc
--- a/uv.lock
+++ b/uv.lock
@@@ -2854,10 -1991,9 +2854,10 @@@ wheels =
[[package]]
name = "paperless-ngx"
- version = "2.20.13"
+ version = "2.20.14"
source = { virtual = "." }
dependencies = [
+ { name = "azure-ai-documentintelligence", marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },
{ name = "babel", marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },
{ name = "bleach", marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },
{ name = "celery", extra = ["redis"], marker = "sys_platform == 'darwin' or sys_platform == 'linux'" },