diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 155030a68..1f33b957c 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -236,6 +236,15 @@ class BulkEditSerializer(serializers.Serializer): raise serializers.ValidationError( f"Some documents in {name} don't exist or were specified twice.") + def _validate_tag_id_list(self, tags, name="tags"): + if not type(tags) == list: + raise serializers.ValidationError(f"{name} must be a list") + if not all([type(i) == int for i in tags]): + raise serializers.ValidationError(f"{name} must be a list of integers") + count = Tag.objects.filter(id__in=tags).count() + if not count == len(tags): + raise serializers.ValidationError( + f"Some tags in {name} don't exist or were specified twice.") def validate_documents(self, documents): self._validate_document_id_list(documents) @@ -296,12 +305,12 @@ class BulkEditSerializer(serializers.Serializer): def _validate_parameters_modify_tags(self, parameters): if "add_tags" in parameters: - self._validate_document_id_list(parameters['add_tags'], "add_tags") + self._validate_tag_id_list(parameters['add_tags'], "add_tags") else: raise serializers.ValidationError("add_tags not specified") if "remove_tags" in parameters: - self._validate_document_id_list(parameters['remove_tags'], "remove_tags") + self._validate_tag_id_list(parameters['remove_tags'], "remove_tags") else: raise serializers.ValidationError("remove_tags not specified")