Commit ef58f1b7 authored by Pablo Panero's avatar Pablo Panero
Browse files

marshmallow: add b64 existence validation

parent 75c22525
......@@ -7,10 +7,21 @@
# granted to it by virtue of its status as Intergovernmental Organization
# or submit itself to any jurisdiction.
from flask import current_app
from invenio_records_rest.schemas import RecordMetadataSchemaJSONV1
from invenio_indexer.utils import default_record_to_index
from marshmallow import validates_schema, ValidationError
def has_and_needs_binary(original_data):
es_index, doc = default_record_to_index(original_data)
binary_index_list = current_app.config['SEARCH_DOC_PIPELINES']
if doc in binary_index_list and not original_data.get('b64'):
return False
return True
class CSASRecordSchemaV1(RecordMetadataSchemaJSONV1):
......@@ -29,4 +40,7 @@ class CSASRecordSchemaV1(RecordMetadataSchemaJSONV1):
if not owner or not isinstance(owner, list):
raise ValidationError('Missing or wrong type (not an array) in '
'field _access.owner')
if not has_and_needs_binary(original_data):
raise ValidationError('Record to be index belongs to binary index '
'but does not contain the [b64] field')
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment