mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-29 14:07:33 +00:00
Fix: immediately re-add doc to index after trash restore (#13818)
This commit is contained in:
@@ -93,6 +93,36 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(response.data["count"], 0)
|
||||
self.assertEqual(len(results), 0)
|
||||
|
||||
def test_search_after_restore_from_trash(self) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Indexed document that was moved to the trash
|
||||
WHEN:
|
||||
- The document is restored from the trash
|
||||
THEN:
|
||||
- The document is searchable again without a reindex
|
||||
"""
|
||||
doc = Document.objects.create(
|
||||
title="invoice",
|
||||
content="the thing i bought at a shop and paid with bank account",
|
||||
checksum="A",
|
||||
pk=1,
|
||||
)
|
||||
get_backend().add_or_update(doc)
|
||||
|
||||
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
|
||||
|
||||
self.client.delete(f"/api/documents/{doc.pk}/")
|
||||
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 0)
|
||||
|
||||
response = self.client.post(
|
||||
"/api/trash/",
|
||||
{"action": "restore", "documents": [doc.pk]},
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
|
||||
|
||||
def test_simple_text_search(self) -> None:
|
||||
tagged = Tag.objects.create(name="invoice")
|
||||
matching_doc = Document.objects.create(
|
||||
|
||||
@@ -5432,8 +5432,15 @@ class TrashView(ListModelMixin, PassUserMixin):
|
||||
return HttpResponseForbidden("Insufficient permissions")
|
||||
action = serializer.validated_data.get("action")
|
||||
if action == "restore":
|
||||
for doc in Document.deleted_objects.filter(id__in=doc_ids).all():
|
||||
restored = list(Document.deleted_objects.filter(id__in=doc_ids))
|
||||
for doc in restored:
|
||||
doc.restore(strict=False)
|
||||
if restored:
|
||||
from documents.search import get_backend
|
||||
|
||||
with get_backend().batch_update() as batch:
|
||||
for doc in restored:
|
||||
batch.add_or_update(doc)
|
||||
elif action == "empty":
|
||||
if doc_ids is None:
|
||||
doc_ids = [doc.id for doc in docs]
|
||||
|
||||
Reference in New Issue
Block a user