Skip to content

Commit

Permalink
identifiers: distinguish inspire id from legacy cds
Browse files Browse the repository at this point in the history
* identifiers: integrate internal_id
  • Loading branch information
kpsherva committed Dec 12, 2024
1 parent ed4747c commit c158621
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 41 deletions.
31 changes: 19 additions & 12 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ from invenio_cern_sync.users.profile import CERNUserProfileSchema
from invenio_oauthclient.views.client import auto_redirect_login
from invenio_cern_sync.sso import cern_remote_app_name, cern_keycloak

from invenio_vocabularies.config import VOCABULARIES_NAMES_SCHEMES as DEFAULT_VOCABULARIES_NAMES_SCHEMES
from invenio_vocabularies.config import \
VOCABULARIES_NAMES_SCHEMES as DEFAULT_VOCABULARIES_NAMES_SCHEMES


def _(x): # needed to avoid start time failure with lazy strings
return x
Expand Down Expand Up @@ -228,7 +230,6 @@ CERN_SYNC_KEYCLOAK_BASE_URL = "https://auth.cern.ch/"
CERN_SYNC_AUTHZ_BASE_URL = "https://authorization-service-api.web.cern.ch/"
INVENIO_CERN_SYNC_KEYCLOAK_BASE_URL = "https://auth.cern.ch/" # set env var when testing


OAUTHCLIENT_CERN_REALM_URL = cern_keycloak.realm_url
OAUTHCLIENT_CERN_USER_INFO_URL = cern_keycloak.user_info_url
OAUTHCLIENT_CERN_VERIFY_EXP = True
Expand Down Expand Up @@ -286,7 +287,7 @@ CDS_EOS_OFFLOAD_REDIRECT_BASE_PATH = ""

# CDS Migration
CDS_REDIRECTION_COLLECTIONS_MAPPING = {
"CERN Students Projects": "", # uuid
"CERN Students Projects": "", # uuid
}

RDM_PERMISSION_POLICY = CDSRDMRecordPermissionPolicy
Expand Down Expand Up @@ -476,8 +477,8 @@ RDM_CUSTOM_FIELDS_UI = [
]
}
]
RDM_FILES_DEFAULT_QUOTA_SIZE = 50 * 10**9 # 50GB
RDM_FILES_DEFAULT_MAX_FILE_SIZE = 50 * 10**9 # 50GB
RDM_FILES_DEFAULT_QUOTA_SIZE = 50 * 10 ** 9 # 50GB
RDM_FILES_DEFAULT_MAX_FILE_SIZE = 50 * 10 ** 9 # 50GB

JOBS_ADMINISTRATION_ENABLED = True

Expand All @@ -494,22 +495,28 @@ RDM_RECORDS_IDENTIFIERS_SCHEMES = {**RDM_RECORDS_IDENTIFIERS_SCHEMES,

RDM_RECORDS_PERSONORG_SCHEMES = {**RDM_RECORDS_PERSONORG_SCHEMES,
**{"inspire": {"label": _("Inspire"),
"validator": schemes.is_inspire,
"datacite": "INSPIRE"}}}
"validator": schemes.is_inspire_author,
"datacite": "INSPIRE"},
"lcds": {"label": _("CDS"),
"validator": schemes.is_cds,
"datacite": "CDS"}
}
}

### Do not require DOIs for record and parent
RDM_PERSISTENT_IDENTIFIERS["doi"]["required"] = False
RDM_PARENT_PERSISTENT_IDENTIFIERS["doi"]["required"] = False


# Invenio-Preservation-Sync
# =========================

PRESERVATION_SYNC_ENABLED = True


def resolve_record_pid(pid):
return record_service.record_cls.pid.resolve(pid).id


PRESERVATION_SYNC_PID_RESOLVER = resolve_record_pid

PRESERVATION_SYNC_PERMISSION_POLICY = CDSRDMPreservationSyncPermissionPolicy
Expand All @@ -529,9 +536,9 @@ APP_RDM_RECORD_LANDING_PAGE_EXTERNAL_LINKS = [
]
VOCABULARIES_NAMES_SCHEMES = {
**DEFAULT_VOCABULARIES_NAMES_SCHEMES,
"cern": {"label": _("CERN"), "validator": schemes.is_cern, "datacite": "CERN"},
"inspire": {"label": _("Inspire"),
"validator": schemes.is_inspire_author,
"datacite": "INSPIRE"},
"lcds": {"label": _("CDS"), "validator": schemes.is_cds, "datacite": "CDS"},
}
"""Names allowed identifier schemes."""

VOCABULARIES_NAMES_RESTRICTED_SCHEMES = ['cern']
"""Names restricted names schemes [not visible in search endpoint]."""
37 changes: 24 additions & 13 deletions site/cds_rdm/schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def cds_reference_number():


aleph_regexp = re.compile(r"\d+CER$", flags=re.I)
inspire_regexp = re.compile(r"\d+$", flags=re.I)
inspire_author_regexp = re.compile(r"INSPIRE-\d+$", flags=re.I)


def is_aleph(val):
Expand All @@ -44,16 +46,23 @@ def aleph():
}


inspire_regexp = re.compile(r"\d+$", flags=re.I)
def is_inspire(val):
"""Test if argument is an inspire ID
Warning: INSPIRE IDs are just integers, with no structure, so this function will
say any integer is an INSPIRE id
"""
return inspire_regexp.match(val)

def is_inspire(val):

def is_inspire_author(val):
"""Test if argument is a PubMed ID.
Warning: PMID are just integers, with no structure, so this function will
say any integer is a PubMed ID
"""
return inspire_regexp.match(val)
return inspire_author_regexp.match(val)



def inspire():
Expand All @@ -66,17 +75,19 @@ def inspire():
}


def is_cern(val):
"""Test if argument is a valid CERN person ID."""
pattern = r"^\d+$"
return bool(re.match(pattern, val))


def cern_person_id():
"""Define validator for CERN person ID."""
def inspire_author():
"""Define validator for inspire author."""
return {
"validator": is_cern,
"validator": is_inspire_author,
"normalizer": lambda value: value,
"filter": [""],
"filter": ["inspire"],
"url_generator": None,
}




def is_cds(val):
"""Test if argument is a valid CERN person ID."""
pattern = r"^\d+$"
return bool(re.match(pattern, val))
19 changes: 4 additions & 15 deletions site/cds_rdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import idutils
from flask import current_app
from invenio_access.permissions import system_identity
from invenio_records_resources.proxies import current_service_registry
from invenio_records_resources.services.errors import ValidationError


Expand Down Expand Up @@ -119,17 +118,8 @@ def add_person_id(self, user, name, updated_name, updated=False):
:return: Boolean indicating if the name was updated.
"""
person_id = user.user_profile.get("person_id")
cern_values = [
identifier["identifier"]
for identifier in name.get("identifiers", [])
if identifier["scheme"] == "cern"
]
if person_id and person_id not in cern_values:
if "identifiers" not in updated_name:
updated_name["identifiers"] = []
updated_name["identifiers"].append(
{"scheme": "cern", "identifier": person_id}
)
if person_id and not name.get("internal_id"):
updated_name["internal_id"] = person_id
updated = True
return updated

Expand Down Expand Up @@ -201,10 +191,9 @@ def create_new_name(self, user, uow=None):
default_props = self.get_default_props(user.id)
name = {
"id": str(user.user_profile["person_id"]),
"internal_id": str(user.user_profile["person_id"]),
"props": default_props,
"identifiers": [
{"scheme": "cern", "identifier": str(user.user_profile["person_id"])}
],
"identifiers": [],
}

if user.user_profile.get("given_name"):
Expand Down
2 changes: 1 addition & 1 deletion site/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ invenio_pidstore.minters =
legacy = cds_rdm.minters:legacy_recid_minter
idutils.custom_schemes =
cds_ref = cds_rdm.schemes:cds_reference_number
cern_person_id = cds_rdm.schemes:cern_person_id
aleph = cds_rdm.schemes:aleph
inspire = cds_rdm.schemes:inspire
inspire_author = cds_rdm.schemes:inspire_author
invenio_db.alembic =
cds_rdm = cds_rdm:alembic
invenio_db.models =
Expand Down

0 comments on commit c158621

Please sign in to comment.