Skip to content

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

Fix: update document modified time on note creation / deletion (#4374)

shamoon99f260225ad3
diff --git a/docs/api.md b/docs/api.md
index df86ef1e5..749c9e062 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -6,7 +6,7 @@ provides a browsable API for most of its endpoints, which you can
inspect at `http://<paperless-host>:<port>/api/`. This also documents
most of the available filters and ordering fields.
-The API provides 7 main endpoints:
+The API provides the following main endpoints:
- `/api/documents/`: Full CRUD support, except POSTing new documents.
See below.
@@ -19,6 +19,7 @@ The API provides 7 main endpoints:
- `/api/mail_rules/`: Full CRUD support.
- `/api/users/`: Full CRUD support.
- `/api/groups/`: Full CRUD support.
+- `/api/share_links/`: Full CRUD support.
All of these endpoints except for the logging endpoint allow you to
fetch (and edit and delete where appropriate) individual objects by
@@ -47,6 +48,7 @@ fields:
Read-only.
- `archived_file_name`: Verbose filename of the archived document.
Read-only. Null if no archived document is available.
+- `notes`: Array of notes associated with the document.
- `set_permissions`: Allows setting document permissions. Optional,
write-only. See [below](#permissions).
@@ -124,6 +126,11 @@ File metadata is reported as a list of objects in the following form:
depends on the file type and the metadata available in that specific
document. Paperless only reports PDF metadata at this point.
+## Documents additional endpoints
+
+- `/api/documents/<id>/notes/`: Retrieve notes for a document.
+- `/api/documents/<id>/share_links/`: Retrieve share links for a document.
+
## Authorization
The REST api provides three different forms of authentication.
diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py
index 783d2d444..84d743469 100644
--- a/src/documents/tests/test_api.py
+++ b/src/documents/tests/test_api.py
@@ -2354,13 +2354,18 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
WHEN:
- API request is made to add a note
THEN:
- - note is created and associated with document
+ - note is created and associated with document, modified time is updated
"""
doc = Document.objects.create(
title="test",
mime_type="application/pdf",
content="this is a document which will have notes added",
+ created=timezone.now() - timedelta(days=1),
)
+ # set to yesterday
+ doc.modified = timezone.now() - timedelta(days=1)
+ self.assertEqual(doc.modified.day, (timezone.now() - timedelta(days=1)).day)
+
resp = self.client.post(
f"/api/documents/{doc.pk}/notes/",
data={"note": "this is a posted note"},
@@ -2382,6 +2387,10 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertEqual(resp_data["note"], "this is a posted note")
+ doc = Document.objects.get(pk=doc.pk)
+ # modified was updated to today
+ self.assertEqual(doc.modified.day, timezone.now().day)
+
def test_notes_permissions_aware(self):
"""
GIVEN:
@@ -2441,17 +2450,21 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
def test_delete_note(self):
"""
GIVEN:
- - Existing document
+ - Existing document, existing note
WHEN:
- - API request is made to add a note
+ - API request is made to delete a note
THEN:
- - note is created and associated with document
+ - note is deleted, document modified is updated
"""
doc = Document.objects.create(
title="test",
mime_type="application/pdf",
content="this is a document which will have notes!",
+ created=timezone.now() - timedelta(days=1),
)
+ # set to yesterday
+ doc.modified = timezone.now() - timedelta(days=1)
+ self.assertEqual(doc.modified.day, (timezone.now() - timedelta(days=1)).day)
note = Note.objects.create(
note="This is a note.",
document=doc,
@@ -2466,6 +2479,9 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(Note.objects.all()), 0)
+ doc = Document.objects.get(pk=doc.pk)
+ # modified was updated to today
+ self.assertEqual(doc.modified.day, timezone.now().day)
def test_get_notes_no_doc(self):
"""
diff --git a/src/documents/views.py b/src/documents/views.py
index 2445a09b0..02049d18f 100644
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -522,6 +522,9 @@ class DocumentViewSet(
)
c.save()
+ doc.modified = timezone.now()
+ doc.save()
+
from documents import index
index.add_or_update_document(self.get_object())
@@ -545,6 +548,9 @@ class DocumentViewSet(
note = Note.objects.get(id=int(request.GET.get("id")))
note.delete()
+ doc.modified = timezone.now()
+ doc.save()
+
from documents import index
index.add_or_update_document(self.get_object())