A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: Document history could include extra fields (#6989)
Trenton H61485b0f1d86
diff --git a/src-ui/src/app/components/document-history/document-history.component.html b/src-ui/src/app/components/document-history/document-history.component.htmlindex ea4a3c9bb..c63a1223c 100644--- a/src-ui/src/app/components/document-history/document-history.component.html+++ b/src-ui/src/app/components/document-history/document-history.component.html@@ -27,31 +27,33 @@}<span class="badge bg-secondary ms-auto" [class.bg-primary]="entry.action === AuditLogAction.Create">{{ entry.action | titlecase }}</span></div>- @if (entry.action === AuditLogAction.Update) {- <ul class="mt-2">- @for (change of entry.changes | keyvalue; track change.key) {- @if (change.value["type"] === 'm2m') {- <li>- <span class="fst-italic">{{ change.value["operation"] | titlecase }}</span> - <span>{{ change.key | titlecase }}</span>: - <code class="text-primary">{{ change.value["objects"].join(', ') }}</code>- </li>- }- @else if (change.value["type"] === 'custom_field') {- <li>- <span>{{ change.value["field"] }}</span>: - <code class="text-primary">{{ change.value["value"] }}</code>- </li>- }- @else {- <li>- <span>{{ change.key | titlecase }}</span>: + <ul class="mt-2">+ @for (change of entry.changes | keyvalue; track change.key) {+ @if (change.value["type"] === 'm2m') {+ <li>+ <span class="fst-italic">{{ change.value["operation"] | titlecase }}</span> + <span>{{ change.key | titlecase }}</span>: + <code class="text-primary">{{ change.value["objects"].join(', ') }}</code>+ </li>+ }+ @else if (change.value["type"] === 'custom_field') {+ <li>+ <span>{{ change.value["field"] }}</span>: + <code class="text-primary">{{ change.value["value"] }}</code>+ </li>+ }+ @else {+ <li>+ <span>{{ change.key | titlecase }}</span>: + @if (change.key === 'content') {+ <code class="text-primary">{{ change.value[1]?.substring(0,100) }}...</code>+ } @else {<code class="text-primary">{{ change.value[1] }}</code>- </li>- }+ }+ </li>}- </ul>- }+ }+ </ul></li>}}diff --git a/src/documents/tests/test_api_documents.py b/src/documents/tests/test_api_documents.pyindex 7e69cb024..4ad6cb828 100644--- a/src/documents/tests/test_api_documents.py+++ b/src/documents/tests/test_api_documents.py@@ -366,6 +366,16 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):data_type=CustomField.FieldDataType.STRING,)self.client.force_login(user=self.user)++ # Initial response should include only document's creation+ response = self.client.get(f"/api/documents/{doc.pk}/history/")++ self.assertEqual(response.status_code, status.HTTP_200_OK)+ self.assertEqual(len(response.data), 1)++ self.assertIsNone(response.data[0]["actor"])+ self.assertEqual(response.data[0]["action"], "create")+self.client.patch(f"/api/documents/{doc.pk}/",data={@@ -379,12 +389,15 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):format="json",)+ # Second response should include custom field additionresponse = self.client.get(f"/api/documents/{doc.pk}/history/")+self.assertEqual(response.status_code, status.HTTP_200_OK)- self.assertEqual(response.data[1]["actor"]["id"], self.user.id)- self.assertEqual(response.data[1]["action"], "create")+ self.assertEqual(len(response.data), 2)+ self.assertEqual(response.data[0]["actor"]["id"], self.user.id)+ self.assertEqual(response.data[0]["action"], "create")self.assertEqual(- response.data[1]["changes"],+ response.data[0]["changes"],{"custom_fields": {"type": "custom_field",@@ -393,6 +406,8 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):},},)+ self.assertIsNone(response.data[1]["actor"])+ self.assertEqual(response.data[1]["action"], "create")@override_settings(AUDIT_LOG_ENABLED=False)def test_document_history_action_disabled(self):diff --git a/src/documents/views.py b/src/documents/views.pyindex 68addd0f4..9e8e7301d 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -19,7 +19,6 @@ from django.apps import appsfrom django.conf import settingsfrom django.contrib.auth.models import Groupfrom django.contrib.auth.models import User-from django.contrib.contenttypes.models import ContentTypefrom django.db import connectionsfrom django.db.migrations.loader import MigrationLoaderfrom django.db.migrations.recorder import MigrationRecorder@@ -106,7 +105,6 @@ from documents.matching import match_storage_pathsfrom documents.matching import match_tagsfrom documents.models import Correspondentfrom documents.models import CustomField-from documents.models import CustomFieldInstancefrom documents.models import Documentfrom documents.models import DocumentTypefrom documents.models import Note@@ -799,15 +797,14 @@ class DocumentViewSet(else None),}- for entry in LogEntry.objects.filter(object_pk=doc.pk).select_related(+ for entry in LogEntry.objects.get_for_object(doc).select_related("actor",)]# custom fields- for entry in LogEntry.objects.filter(- object_pk__in=list(doc.custom_fields.values_list("id", flat=True)),- content_type=ContentType.objects.get_for_model(CustomFieldInstance),+ for entry in LogEntry.objects.get_for_objects(+ doc.custom_fields.all(),).select_related("actor"):entries.append({