A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Fix: prevent self-linking when bulk edit doc link (#9629)
shamoon6dea158de9bb
diff --git a/src/documents/bulk_edit.py b/src/documents/bulk_edit.pyindex b8e76f7c8..13773fe87 100644--- a/src/documents/bulk_edit.py+++ b/src/documents/bulk_edit.py@@ -179,6 +179,12 @@ def modify_custom_fields(custom_field.data_type]defaults[value_field] = value+ if (+ custom_field.data_type == CustomField.FieldDataType.DOCUMENTLINK+ and doc_id in value+ ):+ # Prevent self-linking+ continueCustomFieldInstance.objects.update_or_create(document_id=doc_id,field_id=field_id,diff --git a/src/documents/tests/test_bulk_edit.py b/src/documents/tests/test_bulk_edit.pyindex dd59a6217..fb84c9070 100644--- a/src/documents/tests/test_bulk_edit.py+++ b/src/documents/tests/test_bulk_edit.py@@ -336,6 +336,35 @@ class TestBulkEdit(DirectoriesMixin, TestCase):self.doc2.custom_fields.filter(field=cf3).first().value,)+ def test_modify_custom_fields_doclink_self_link(self):+ """+ GIVEN:+ - 2 existing documents+ - Existing doc link custom field+ WHEN:+ - Doc link field is modified to include self link+ THEN:+ - Self link should not be created+ """+ cf = CustomField.objects.create(+ name="cf",+ data_type=CustomField.FieldDataType.DOCUMENTLINK,+ )+ bulk_edit.modify_custom_fields(+ [self.doc1.id, self.doc2.id],+ add_custom_fields={cf.id: [self.doc1.id]},+ remove_custom_fields=[],+ )++ self.assertEqual(+ self.doc1.custom_fields.first().value,+ [self.doc2.id],+ )+ self.assertEqual(+ self.doc2.custom_fields.first().value,+ [self.doc1.id],+ )+def test_delete(self):self.assertEqual(Document.objects.count(), 5)bulk_edit.delete([self.doc1.id, self.doc2.id])