Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Adding a note doesn't update the "modified" parameter of a document
### Description

I'm working on an app that relies on the "modified" attribute of a document to determine whether it was changed recently.

This works well unless the only change made to a document was the addition of a note, which case "modified" isn't updated.

### Steps to reproduce

1. Go to any document and add a note
2. Head to /api/documents/{id_of_document}/ and see "modified" unchanged

### Webserver logs

```bash
Not applicable
```


### Browser logs

_No response_

### Paperless-ngx version

1.17.4

### Host OS

Ubuntu Server

### Installation method

Docker - official image

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_


Discussion:
The document isn’t being modified, notes are stored in paperless
> The document isn’t being modified, notes are stored in paperless

Does the API feature any other endpoint to get new notes then?
On second thought, modified is the paperless modified time. Let me look at this.

Resolving patch:
diff --git a/src/documents/views.py b/src/documents/views.py
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -522,6 +522,9 @@ def notes(self, request, pk=None):
                 )
                 c.save()
 
+                doc.modified = timezone.now()
+                doc.save()
+
                 from documents import index
 
                 index.add_or_update_document(self.get_object())
@@ -545,6 +548,9 @@ def notes(self, request, pk=None):
             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())


Test patch:
diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py
--- a/src/documents/tests/test_api.py
+++ b/src/documents/tests/test_api.py
@@ -2354,13 +2354,18 @@ def test_create_note(self):
         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 @@ def test_create_note(self):
 
         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 @@ def test_notes_permissions_aware(self):
     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 @@ def test_delete_note(self):
         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):
         """