diff --git a/invenio_vocabularies/config.py b/invenio_vocabularies/config.py index 70370fa9..b0abf832 100644 --- a/invenio_vocabularies/config.py +++ b/invenio_vocabularies/config.py @@ -127,6 +127,10 @@ def is_edmo(val): } """Names allowed identifier schemes.""" + +VOCABULARIES_NAMES_RESTRICTED_SCHEMES = [] +"""Names restricted names schemes [not visible in search endpoint].""" + VOCABULARIES_SUBJECTS_SCHEMES = { "gnd": {"label": _("GND"), "validator": idutils.is_gnd, "datacite": "GND"}, "url": {"label": _("URL"), "validator": idutils.is_url}, diff --git a/invenio_vocabularies/contrib/names/config.py b/invenio_vocabularies/contrib/names/config.py index f5ddab0b..cd7b6f9e 100644 --- a/invenio_vocabularies/contrib/names/config.py +++ b/invenio_vocabularies/contrib/names/config.py @@ -24,6 +24,10 @@ names_schemes = LocalProxy(lambda: current_app.config["VOCABULARIES_NAMES_SCHEMES"]) +restricted_names_schemes = LocalProxy( + lambda: current_app.config["VOCABULARIES_NAMES_RESTRICTED_SCHEMES"] +) + class NamesSearchOptions(SearchOptions): """Search options.""" diff --git a/invenio_vocabularies/contrib/names/schema.py b/invenio_vocabularies/contrib/names/schema.py index 16040d09..c3d23c39 100644 --- a/invenio_vocabularies/contrib/names/schema.py +++ b/invenio_vocabularies/contrib/names/schema.py @@ -19,7 +19,7 @@ from ..affiliations.schema import ( AffiliationRelationSchema as BaseAffiliationRelationSchema, ) -from .config import names_schemes +from .config import names_schemes, restricted_names_schemes class AffiliationRelationSchema(BaseAffiliationRelationSchema): @@ -66,7 +66,7 @@ def validate_names(self, data, **kwargs): raise ValidationError({"family_name": messages}) @validates_schema - def validate_affiliatons(self, data, **kwargs): + def validate_affiliations(self, data, **kwargs): """Validate names.""" affiliations = data.get("affiliations", []) seen_names = set() @@ -104,3 +104,14 @@ def dump_name(self, data, **kwargs): elif family_name: data["name"] = family_name return data + + @post_dump + def filter_exposed_identifiers(self, data, **kwargs): + identifiers = data.get("identifiers") + filtered_ids = [ + identifier + for identifier in identifiers + if identifier["scheme"] not in restricted_names_schemes + ] + data["identifiers"] = filtered_ids + return data diff --git a/invenio_vocabularies/contrib/names/services.py b/invenio_vocabularies/contrib/names/services.py index a6ab939b..7200dc1a 100644 --- a/invenio_vocabularies/contrib/names/services.py +++ b/invenio_vocabularies/contrib/names/services.py @@ -42,10 +42,10 @@ def resolve(self, identity, id_, id_type, many=False): else: results = self._read_many(identity, search_query, max_records=1) - # cant use the results_item because it returns dicts intead of records + # cant use the results_item because it returns dicts instead of records total = results.hits.total["value"] if total == 0: - # Not a PID but trated as such + # Not a PID but treated as such raise PIDDoesNotExistError(pid_type=id_type, pid_value=id_) if many: for result in results: