mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-15 10:13:15 -05:00
Fix: prevent self-linking when bulk edit doc link (#9629)
This commit is contained in:
parent
f269919410
commit
6dea158de9
@ -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
|
||||
continue
|
||||
CustomFieldInstance.objects.update_or_create(
|
||||
document_id=doc_id,
|
||||
field_id=field_id,
|
||||
|
@ -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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user