Fixes trash preview when a document has deleted versions (#12742)

This commit is contained in:
Trenton H
2026-05-07 10:07:35 -07:00
committed by GitHub
parent 3097f06189
commit 2354f87a40
2 changed files with 38 additions and 2 deletions
+36
View File
@@ -485,6 +485,42 @@ class TestDocumentApi(DirectoriesMixin, ConsumeTaskMixin, APITestCase):
response = self.client.get(f"/api/documents/{doc.pk}/thumb/")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_document_actions_trashed_document(self) -> None:
"""
GIVEN:
- Document with files exists
WHEN:
- Document is soft-deleted (moved to trash)
- Preview and thumb endpoints are requested
THEN:
- HTTP 200 OK for both (trashed documents remain previewable)
"""
_, filename = tempfile.mkstemp(dir=self.dirs.originals_dir)
content = b"This is a test"
content_thumbnail = b"thumbnail content"
with Path(filename).open("wb") as f:
f.write(content)
doc = Document.objects.create(
title="none",
filename=Path(filename).name,
mime_type="application/pdf",
)
with (self.dirs.thumbnail_dir / f"{doc.pk:07d}.webp").open("wb") as f:
f.write(content_thumbnail)
doc.delete()
response = self.client.get(f"/api/documents/{doc.pk}/preview/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(read_streaming_response(response), content)
response = self.client.get(f"/api/documents/{doc.pk}/thumb/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(read_streaming_response(response), content_thumbnail)
def test_document_history_action(self) -> None:
"""
GIVEN:
+2 -2
View File
@@ -1542,7 +1542,7 @@ class DocumentViewSet(
condition(etag_func=preview_etag, last_modified_func=preview_last_modified),
)
def preview(self, request, pk=None):
resolved = self._resolve_request_and_root_doc(pk, request)
resolved = self._resolve_request_and_root_doc(pk, request, include_deleted=True)
if isinstance(resolved, HttpResponseForbidden):
return resolved
@@ -1566,7 +1566,7 @@ class DocumentViewSet(
@method_decorator(cache_control(no_cache=True))
@method_decorator(last_modified(thumbnail_last_modified))
def thumb(self, request, pk=None):
resolved = self._resolve_request_and_root_doc(pk, request)
resolved = self._resolve_request_and_root_doc(pk, request, include_deleted=True)
if isinstance(resolved, HttpResponseForbidden):
return resolved