Skip to content

Commit

Permalink
names: restrict specified identifiers from search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Dec 10, 2024
1 parent ca6e3ae commit 0f926fe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions invenio_vocabularies/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 2 additions & 0 deletions invenio_vocabularies/contrib/names/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

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."""
Expand Down
15 changes: 13 additions & 2 deletions invenio_vocabularies/contrib/names/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions invenio_vocabularies/contrib/names/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0f926fe

Please sign in to comment.