Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
webservices
cern-search
cern-search-rest-api
Commits
ef58f1b7
Commit
ef58f1b7
authored
Mar 11, 2019
by
Pablo Panero
Browse files
marshmallow: add b64 existence validation
parent
75c22525
Changes
1
Hide whitespace changes
Inline
Side-by-side
cern_search_rest_api/modules/cernsearch/marshmallow/json.py
View file @
ef58f1b7
...
...
@@ -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
):
@
validates_schema
(
pass_original
=
True
)
...
...
@@ -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'
)
return
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'
)
return
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment