Commit be4dbbea authored by Pablo Panero's avatar Pablo Panero Committed by Pablo Panero
Browse files

serializer: remove base64 content from the response

parent d695e7ed
......@@ -93,7 +93,7 @@ RECORDS_REST_ENDPOINTS = dict(
'application/json': ('invenio_records_rest.serializers'
'application/json': ('cern_search_rest_api.modules.cernsearch.serializers'
......@@ -104,7 +104,7 @@ RECORDS_REST_ENDPOINTS = dict(
search_index=os.getenv('CERN_SEARCH_INSTANCE', 'cernsearch-test'),
'application/json': ('invenio_records_rest.serializers'
'application/json': ('cern_search_rest_api.modules.cernsearch.serializers'
......@@ -16,7 +16,7 @@ from .providers import CERNSearchRecordIdProvider
def recid_fetcher(record_uuid, data):
"""Fetch PID from record."""
return FetchedPID(
# provider=CERNSearchRecordIdProvider,
\ No newline at end of file
......@@ -9,6 +9,6 @@
from __future__ import absolute_import, print_function
from .json import CSASRecordSchemaV1
from .json import CSASRecordSchemaV1, CSASRecordSearchSchemaJSONV1
__all__ = ('CSASRecordSchemaV1',)
\ No newline at end of file
__all__ = ('CSASRecordSchemaV1', 'CSASRecordSearchSchemaJSONV1')
\ No newline at end of file
......@@ -11,7 +11,10 @@
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
from invenio_records_rest.schemas.json import RecordSchemaJSONV1
from marshmallow import validates_schema, ValidationError, post_dump
from cern_search_rest_api.modules.cernsearch.utils import record_from_index
def has_and_needs_binary(original_data):
......@@ -46,3 +49,15 @@ class CSASRecordSchemaV1(RecordMetadataSchemaJSONV1):
raise ValidationError('Record to be index belongs to binary index '
'but does not contain the [b64] field')
class CSASRecordSearchSchemaJSONV1(RecordSchemaJSONV1):
def remove_base64(self, data):
""" If needed remove the base64 data from the response """
es_index, doc = record_from_index(data)
binary_index_list = current_app.config['SEARCH_DOC_PIPELINES']
if doc in binary_index_list:
return data
\ No newline at end of file
......@@ -14,20 +14,21 @@ from invenio_records_rest.serializers.response import record_responsify, \
from cern_search_rest_api.modules.cernsearch.marshmallow import \
CSASRecordSchemaV1, CSASRecordSearchSchemaJSONV1
# Serializers
# ===========
#: JSON serializer definition.
json_v1 = JSONSerializer(CSASRecordSchemaV1, replace_refs=True)
json_v1_records = JSONSerializer(CSASRecordSearchSchemaJSONV1)
# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
json_v1_response = record_responsify(json_v1_records, 'application/json')
#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')
json_v1_search = search_responsify(json_v1_records, 'application/json')
__all__ = (
......@@ -9,9 +9,34 @@
"""Helper methods for CERN Search records."""
from flask import g
from flask import current_app, g
from invenio_search import current_search
from invenio_search.utils import schema_to_index
def get_user_provides():
"""Extract the user's provides from g."""
return [need.value for need in g.identity.provides]
def record_from_index(record):
"""Get index/doc_type given a record.
It tries to extract from `record['$schema']` the index and doc_type.
If it fails, return the default values.
:param record: The record object.
:returns: Tuple (index, doc_type).
index_names = current_search.mappings.keys()
schema = record.get('metadata').get('$schema', '')
if isinstance(schema, dict):
schema = schema.get('$ref', '')
index, doc_type = schema_to_index(schema, index_names=index_names)
if index and doc_type:
return index, doc_type
return (current_app.config['INDEXER_DEFAULT_INDEX'],
\ No newline at end of file
Markdown is supported
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