]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: fix breaking api change to document notes user field (#9714)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 19 Apr 2025 22:02:33 +0000 (15:02 -0700)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 22:02:33 +0000 (22:02 +0000)
src/documents/serialisers.py
src/documents/tests/test_api_documents.py
src/paperless/settings.py

index 782f4d6c874a77ff6c262ebb491653b215a41b04..b6f61103f822ce5d681aab8414a3bba7b7abca51 100644 (file)
@@ -877,6 +877,20 @@ class NotesSerializer(serializers.ModelSerializer):
         fields = ["id", "note", "created", "user"]
         ordering = ["-created"]
 
+    def to_representation(self, instance):
+        ret = super().to_representation(instance)
+
+        request = self.context.get("request")
+        api_version = int(
+            request.version if request else settings.REST_FRAMEWORK["DEFAULT_VERSION"],
+        )
+
+        if api_version < 8:
+            user_id = ret["user"]["id"]
+            ret["user"] = user_id
+
+        return ret
+
 
 class DocumentSerializer(
     OwnedObjectSerializer,
index a0a380e41fe2fc9b94b64903529045d746897728..0af1f5040602f154d66e7b8f6e636852a77abd83 100644 (file)
@@ -2227,6 +2227,26 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
             },
         )
 
+    def test_docnote_serializer_v7(self):
+        doc = Document.objects.create(
+            title="test",
+            mime_type="application/pdf",
+            content="this is a document which will have notes!",
+        )
+        Note.objects.create(
+            note="This is a note.",
+            document=doc,
+            user=self.user,
+        )
+        self.assertEqual(
+            self.client.get(
+                f"/api/documents/{doc.pk}/",
+                headers={"Accept": "application/json; version=7"},
+                format="json",
+            ).data["notes"][0]["user"],
+            self.user.id,
+        )
+
     def test_create_note(self):
         """
         GIVEN:
index 361854a93cd584ff95933c25c7ec4b1bc0002fc3..743151ef1cce61e414867594aa12c4e5b6be735d 100644 (file)
@@ -342,10 +342,10 @@ REST_FRAMEWORK = {
         "rest_framework.authentication.SessionAuthentication",
     ],
     "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.AcceptHeaderVersioning",
-    "DEFAULT_VERSION": "7",
+    "DEFAULT_VERSION": "8",
     # Make sure these are ordered and that the most recent version appears
     # last. See api.md#api-versioning when adding new versions.
-    "ALLOWED_VERSIONS": ["1", "2", "3", "4", "5", "6", "7"],
+    "ALLOWED_VERSIONS": ["1", "2", "3", "4", "5", "6", "7", "8"],
     # DRF Spectacular default schema
     "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
 }