Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

names: restrict specified identifiers from search endpoint #450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions invenio_vocabularies/contrib/names/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
15 changes: 13 additions & 2 deletions invenio_vocabularies/contrib/names/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in invenio_vocabularies/contrib/names/schema.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.9, postgresql14, opensearch2)

pydocstyle-check /home/runner/work/invenio-vocabularies/invenio-vocabularies/invenio_vocabularies/contrib/names/schema.py:109 in public method `filter_exposed_identifiers`: D102: Missing docstring in public method

Check failure on line 1 in invenio_vocabularies/contrib/names/schema.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.12, postgresql14, opensearch2)

pydocstyle-check /home/runner/work/invenio-vocabularies/invenio-vocabularies/invenio_vocabularies/contrib/names/schema.py:109 in public method `filter_exposed_identifiers`: D102: Missing docstring in public method
#
# Copyright (C) 2021-2024 CERN.
#
Expand All @@ -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 @@
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 @@
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
Loading