mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-11 10:00:48 -05:00
Fix: do not accept empty string for doc link value via API (#8596)
This commit is contained in:
parent
94a20b4510
commit
8e6de2790e
@ -668,6 +668,10 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
|
|||||||
f"Value must be an id of an element in {select_options}",
|
f"Value must be an id of an element in {select_options}",
|
||||||
)
|
)
|
||||||
elif field.data_type == CustomField.FieldDataType.DOCUMENTLINK:
|
elif field.data_type == CustomField.FieldDataType.DOCUMENTLINK:
|
||||||
|
if not (isinstance(data["value"], list) or data["value"] is None):
|
||||||
|
raise serializers.ValidationError(
|
||||||
|
"Value must be a list",
|
||||||
|
)
|
||||||
doc_ids = data["value"]
|
doc_ids = data["value"]
|
||||||
if Document.objects.filter(id__in=doc_ids).count() != len(
|
if Document.objects.filter(id__in=doc_ids).count() != len(
|
||||||
data["value"],
|
data["value"],
|
||||||
|
@ -886,6 +886,7 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
|
|||||||
- Document & custom field exist
|
- Document & custom field exist
|
||||||
WHEN:
|
WHEN:
|
||||||
- API request to set a field value to a document that does not exist
|
- API request to set a field value to a document that does not exist
|
||||||
|
- API request to set a field value to empty string
|
||||||
THEN:
|
THEN:
|
||||||
- HTTP 400 is returned
|
- HTTP 400 is returned
|
||||||
- No field instance is created or attached to the document
|
- No field instance is created or attached to the document
|
||||||
@ -916,6 +917,19 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(CustomFieldInstance.objects.count(), 0)
|
self.assertEqual(CustomFieldInstance.objects.count(), 0)
|
||||||
self.assertEqual(len(doc.custom_fields.all()), 0)
|
self.assertEqual(len(doc.custom_fields.all()), 0)
|
||||||
|
|
||||||
|
resp = self.client.patch(
|
||||||
|
f"/api/documents/{doc.id}/",
|
||||||
|
data={
|
||||||
|
"custom_fields": [
|
||||||
|
{"field": custom_field_documentlink.id, "value": ""},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
|
self.assertEqual(CustomFieldInstance.objects.count(), 0)
|
||||||
|
|
||||||
def test_custom_field_not_null(self):
|
def test_custom_field_not_null(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user