def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes( endpoints) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes)
def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes(endpoints) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes )
def extend_default_endpoint_prefixes(): """Extend redirects between PID types.""" endpoint_prefixes = utils.build_default_endpoint_prefixes( {'recid': {'pid_type': 'recid'}}) current_records_rest = app.extensions[ 'invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes )
def extend_default_endpoint_prefixes(): """Fix the endpoint prefixes as .""" endpoint_prefixes = utils.build_default_endpoint_prefixes( endpoints) #app.logger.info("- Fixing endpoint: {}".format(endpoint_prefixes)) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes)
def extend_default_endpoint_prefixes(_): """TODO.""" # FIXME remove hasattr() after 1.0.0a7 is released if hasattr(utils, 'build_default_endpoint_prefixes'): endpoint_prefixes = utils.build_default_endpoint_prefixes( app.config['DEPOSIT_REST_ENDPOINTS'] ) current_records_rest = app.extensions['invenio-records-rest'] current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes )
def extend_default_endpoint_prefixes(): """Extend redirects between PID types.""" endpoint_prefixes = utils.build_default_endpoint_prefixes( dict(app.config['DEPOSIT_REST_ENDPOINTS'])) current_records_rest = app.extensions['invenio-records-rest'] overlap = set(endpoint_prefixes.keys()) & set( current_records_rest.default_endpoint_prefixes) if overlap: raise RuntimeError( 'Deposit wants to override endpoint prefixes {0}.'.format( ', '.join(overlap))) current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes)
def test_get_default_endpoint_for_inconsistent(app): with pytest.raises(ValueError) as excinfo: build_default_endpoint_prefixes({ 'recid1': { 'pid_type': 'recid', 'default_endpoint_prefix': True, }, 'recid2': { 'pid_type': 'recid', 'default_endpoint_prefix': True, }, }) assert 'More than one' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: build_default_endpoint_prefixes({ 'recid1': { 'pid_type': 'recid', }, 'recid2': { 'pid_type': 'recid', }, }) assert 'No endpoint-prefix' in str(excinfo.value)
def extend_default_endpoint_prefixes(_): """Extend redirects between PID types.""" endpoint_prefixes = utils.build_default_endpoint_prefixes( dict(app.config['DEPOSIT_REST_ENDPOINTS']) ) current_records_rest = app.extensions['invenio-records-rest'] overlap = set(endpoint_prefixes.keys()) & set( current_records_rest.default_endpoint_prefixes ) if overlap: raise RuntimeError( 'Deposit wants to override endpoint prefixes {0}.'.format( ', '.join(overlap) ) ) current_records_rest.default_endpoint_prefixes.update( endpoint_prefixes )
def _register_blueprints(self, app): if 'invenio_records_rest' not in app.blueprints: return rest_blueprint = app.blueprints['invenio_records_rest'] mapping_prefix = app.config.get('SEARCH_INDEX_PREFIX', None) endpoint_configs = app.config.get( 'DRAFT_ENABLED_RECORDS_REST_ENDPOINTS', {}) last_deferred_function_index = len(rest_blueprint.deferred_functions) permission_factories = {} extra_published_record_endpoints = {} extra_draft_record_endpoints = {} for url_prefix, config in endpoint_configs.items(): config = copy.copy(config) if 'draft_pid_type' not in config: raise Exception('Add "draft_pid_type" to ' 'DRAFT_ENABLED_RECORDS_REST_ENDPOINTS[%s]' % url_prefix) json_schemas = config.pop('json_schemas', []) if not isinstance(json_schemas, (list, tuple)): json_schemas = [json_schemas] published_index = (config.pop('published_search_index', None) or config.pop('search_index', None)) if not published_index: published_index = get_search_index(json_schemas, url_prefix) if mapping_prefix and published_index.startswith( mapping_prefix): published_index = published_index[len(mapping_prefix):] published_endpoint = f'published_{url_prefix}' draft_endpoint = f'draft_{url_prefix}' record_marshmallow = config.pop('record_marshmallow') metadata_marshmallow = config.pop('metadata_marshmallow') publish_permission_factory = config.pop( 'publish_permission_factory') unpublish_permission_factory = config.pop( 'unpublish_permission_factory') edit_permission_factory = config.pop('edit_permission_factory') permission_factories[url_prefix] = { 'publish_permission_factory': publish_permission_factory, 'unpublish_permission_factory': unpublish_permission_factory, 'edit_permission_factory': edit_permission_factory } extra_published_record_endpoints[url_prefix] = { e: obj_or_import_string(a) for e, a in config.pop('extra_published_record_endpoints', {}).items() } extra_draft_record_endpoints[url_prefix] = { e: obj_or_import_string(a) for e, a in config.pop('extra_draft_record_endpoints', {}).items() } published_endpoint_config = create_published_endpoint( url_prefix=url_prefix, published_endpoint=published_endpoint, draft_endpoint=draft_endpoint, record_marshmallow=record_marshmallow, search_index=published_index, publish_permission_factory=publish_permission_factory, unpublish_permission_factory=unpublish_permission_factory, edit_permission_factory=edit_permission_factory, extra_urls=extra_published_record_endpoints[url_prefix], **config) draft_index = (config.pop('draft_search_index', None) or config.pop('search_index', None)) if not draft_index: draft_schemas = [ self.get_draft_schema(x) for x in json_schemas ] draft_index = get_search_index(draft_schemas, url_prefix) if mapping_prefix and draft_index.startswith(mapping_prefix): draft_index = draft_index[len(mapping_prefix):] draft_endpoint_config = create_draft_endpoint( url_prefix=url_prefix, published_endpoint=published_endpoint, draft_endpoint=draft_endpoint, record_marshmallow=record_marshmallow, metadata_marshmallow=metadata_marshmallow, search_index=draft_index, publish_permission_factory=publish_permission_factory, unpublish_permission_factory=unpublish_permission_factory, edit_permission_factory=edit_permission_factory, extra_urls=extra_draft_record_endpoints[url_prefix], **config) for rule in create_url_rules(published_endpoint, **published_endpoint_config): rest_blueprint.add_url_rule(**rule) for rule in create_url_rules(draft_endpoint, **draft_endpoint_config): rest_blueprint.add_url_rule(**rule) default_prefixes = build_default_endpoint_prefixes({ published_endpoint: published_endpoint_config, draft_endpoint: draft_endpoint_config }) current_records_rest.default_endpoint_prefixes.update( default_prefixes) draft_endpoint_config['endpoint'] = draft_endpoint published_endpoint_config['endpoint'] = published_endpoint self.draft_endpoints[url_prefix] = { **draft_endpoint_config, **permission_factories[url_prefix] } self.published_endpoints[url_prefix] = { **published_endpoint_config, **permission_factories[url_prefix] } state = rest_blueprint.make_setup_state(app, {}, False) for deferred in rest_blueprint.deferred_functions[ last_deferred_function_index:]: deferred(state) blueprint = Blueprint("invenio_records_draft", __name__, url_prefix="/") for prefix in self.draft_endpoints.keys(): draft_config = self.draft_endpoints[prefix] draft_endpoint_name = draft_config['endpoint'] published_config = self.published_endpoints[prefix] published_endpoint_name = published_config['endpoint'] permissions = permission_factories[prefix] draft_url = url_for( 'invenio_records_rest.{0}_list'.format(draft_endpoint_name), _external=False) published_url = url_for('invenio_records_rest.{0}_list'.format( published_endpoint_name), _external=False) published_record_validator = \ endpoint_configs[prefix].get('published_record_validator', None) metadata_marshmallow = \ endpoint_configs[prefix].get('metadata_marshmallow', None) blueprint.add_url_rule( rule=f'{draft_url}{pid_getter(draft_config)}/publish', view_func=PublishRecordAction.as_view( PublishRecordAction.view_name.format(draft_endpoint_name), publish_permission_factory=permissions[ 'publish_permission_factory'], published_record_class=published_config['record_class'], published_pid_type=published_config['pid_type'], published_endpoint_name=published_endpoint_name)) blueprint.add_url_rule( rule=f'{published_url}{pid_getter(published_config)}/unpublish', view_func=UnpublishRecordAction.as_view( UnpublishRecordAction.view_name.format( published_endpoint_name), unpublish_permission_factory=permissions[ 'unpublish_permission_factory'], draft_pid_type=draft_config['pid_type'], draft_record_class=draft_config['record_class'], draft_endpoint_name=draft_endpoint_name)) blueprint.add_url_rule( rule=f'{published_url}{pid_getter(published_config)}/edit', view_func=EditRecordAction.as_view( EditRecordAction.view_name.format(published_endpoint_name), edit_permission_factory=permissions[ 'edit_permission_factory'], draft_pid_type=draft_config['pid_type'], draft_record_class=draft_config['record_class'], draft_endpoint_name=draft_endpoint_name)) for rule, action in extra_published_record_endpoints[prefix].items( ): blueprint.add_url_rule( rule= f'{published_url}{pid_getter(published_config)}/{rule}', view_func=action.as_view( action.view_name.format(published_endpoint_name), draft_config=draft_config, **published_config)) for rule, action in extra_draft_record_endpoints[prefix].items(): blueprint.add_url_rule( rule=f'{draft_url}{pid_getter(draft_config)}/{rule}', view_func=action.as_view( action.view_name.format(draft_endpoint_name), published_config=published_config, **draft_config)) app.register_blueprint(blueprint)