Skip to content

Commit

Permalink
Merge branch 'master' into subcom-invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
slint authored Nov 28, 2024
2 parents bae253f + 0355acb commit aae2bc1
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 185 deletions.
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ sphinx = ">=4.5"
isort = "<6.0" # Unpin when isort==6.0.0 is released

[packages]
invenio-app-rdm = {version = "~=13.0.0b1.dev17", extras = ["opensearch2"]}
invenio-app-rdm = {version = "~=13.0.0b1.dev18", extras = ["opensearch2"]}

invenio-logging = {extras = ["sentry_sdk"], version = "~=2.0"}
sentry-sdk = ">=1.45,<2.0.0"
zenodo_rdm = {editable="True", path="./site"}
zenodo_legacy = {editable="True", path="./legacy"}
# TODO: Remove once we fix PyPI package issues
invenio-swh = {git = "https://github.com/inveniosoftware/invenio-swh", ref = "v0.10.2"}
invenio-swh = {git = "https://github.com/inveniosoftware/invenio-swh", ref = "v0.10.3"}
jsonschema = ">=4.17.0,<4.18.0" # due to compatibility issues with alpha
ipython = "!=8.1.0"
uwsgi = ">=2.0"
Expand Down
244 changes: 122 additions & 122 deletions Pipfile.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react";
import { Header, Grid } from "semantic-ui-react";
import { makeIdEntry, makeSubheader } from "react-invenio-forms";


export const CustomAffiliationsSuggestions = (creatibutors) => {
// Ensure creatibutors is always an array
const creatibutorsArray = Array.isArray(creatibutors) ? creatibutors : [creatibutors];

return creatibutorsArray.map((creatibutor) => {
const { creatibutor: creatibutorData } = creatibutor;
const { name, acronym, identifiers = [], id } = creatibutorData;

const subheader = makeSubheader(creatibutorData, creatibutor.isOrganization);
const displayName = acronym ? `${name} (${acronym})` : name;

const sources = [];
const idStrings = [];

identifiers.forEach((identifier) => {
const { scheme, identifier: value } = identifier;

if (scheme === "ror") {
sources.push(
<span key={value}>
Source: {scheme.toUpperCase()} <span>(Preferred)</span>
</span>
);
} else if (scheme === "edmo") {
sources.push(
<span key={value}>Source: {scheme.toUpperCase()}</span>
);
} else {
const idEntry = makeIdEntry(identifier);
if (idEntry) idStrings.push(idEntry);
}
});

return (
<Grid key={id}>
<Grid.Row columns={2} verticalAlign="middle">
<Grid.Column width={12}>
<Header>
{displayName} {idStrings.length > 0 && <>({idStrings})</>}
{subheader && <Header.Subheader>{subheader}</Header.Subheader>}
</Header>
</Grid.Column>
<Grid.Column width={4} textAlign="right">
{sources.length > 0 && (
<Header as="h6" color="grey" style={{ margin: 0 }}>
{sources}
</Header>
)}
</Grid.Column>
</Grid.Row>
</Grid>
);
});
};
2 changes: 2 additions & 0 deletions assets/js/invenio_app_rdm/overridableRegistry/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import { UpgradeLegacyRecordButton } from "../../components/landing_page/overrides/UpgradeLegacyRecordButton";
import { FileUploaderNewVersion } from "../../components/landing_page/overrides/FileUploaderNewVersion";
import SubcommunityCreateForm from "../../components/community/overrides/SubcommunityCreateForm";
import { CustomAffiliationsSuggestions } from "../../components/react_invenio_forms/CustomAffiliationsSuggestions";

export const overriddenComponents = {
"InvenioAppRdm.RecordLandingPage.RecordManagement.container":
UpgradeLegacyRecordButton,
"ReactInvenioDeposit.FileUploader.NewVersionButton.container": FileUploaderNewVersion,
"ReactInvenioForms.AffiliationsSuggestions.content": CustomAffiliationsSuggestions,
"InvenioCommunities.CommunityCreateForm.layout": SubcommunityCreateForm
};
1 change: 0 additions & 1 deletion docker-compose.full.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2.2'
services:
cache:
extends:
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '2.2'
services:
cache:
extends:
Expand Down
1 change: 0 additions & 1 deletion docker-services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "2.2"
services:
app:
build:
Expand Down
94 changes: 42 additions & 52 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,68 +20,48 @@ from datetime import timedelta
from celery.schedules import crontab
from flask_resources import create_error_handler
from invenio_administration.permissions import administration_permission
from invenio_app_rdm.config import (
APP_RDM_DEPOSIT_FORM_DEFAULTS as DEPOSIT_FORM_DEFAULTS,
)
from invenio_app_rdm.config import (
APP_RDM_ROUTES,
CELERY_BEAT_SCHEDULE,
)
from invenio_app_rdm.config import (
COMMUNITIES_ERROR_HANDLERS as BASE_COMMUNITIES_ERROR_HANDLERS,
)
from invenio_app_rdm.config import \
APP_RDM_DEPOSIT_FORM_DEFAULTS as DEPOSIT_FORM_DEFAULTS
from invenio_app_rdm.config import APP_RDM_ROUTES, CELERY_BEAT_SCHEDULE, APP_RDM_IDENTIFIER_SCHEMES_UI
from invenio_app_rdm.config import \
COMMUNITIES_ERROR_HANDLERS as BASE_COMMUNITIES_ERROR_HANDLERS
from invenio_communities.communities.services import facets as community_facets
from invenio_github.oauth.remote_app import github_app as github_remote_app
from invenio_i18n import lazy_gettext as _
from invenio_oauthclient.contrib.keycloak import KeycloakSettingsHelper
from invenio_oauthclient.contrib.orcid import (
REMOTE_MEMBER_APP,
REMOTE_SANDBOX_MEMBER_APP,
)
from invenio_oauthclient.contrib.orcid import (REMOTE_MEMBER_APP,
REMOTE_SANDBOX_MEMBER_APP)
from invenio_oauthclient.views.client import auto_redirect_login
from invenio_rdm_records.config import (
RDM_FACETS,
)
from invenio_rdm_records.config import (
RDM_SORT_OPTIONS as BASE_SORT_OPTIONS,
)
from invenio_rdm_records.config import (RDM_FACETS,
RDM_RECORDS_PERSONORG_SCHEMES)
from invenio_rdm_records.config import RDM_SORT_OPTIONS as BASE_SORT_OPTIONS
from invenio_rdm_records.contrib.journal import JOURNAL_SORT_OPTIONS
from invenio_rdm_records.contrib.meeting import MEETING_SORT_OPTIONS
from invenio_rdm_records.resources.config import (
error_handlers as base_records_error_handlers,
)
from invenio_rdm_records.resources.config import \
error_handlers as base_records_error_handlers
from invenio_rdm_records.resources.errors import HTTPJSONException
from invenio_rdm_records.services.components import DefaultRecordsComponents
from invenio_rdm_records.services.components.signal import SignalComponent
from invenio_records_resources.services.records.queryparser import (
FieldValueMapper,
QueryParser,
SearchFieldTransformer,
)
from invenio_vocabularies.services.custom_fields import (
SUBJECT_FIELDS,
SUBJECT_FIELDS_UI,
)
FieldValueMapper, QueryParser, SearchFieldTransformer)
from invenio_vocabularies.services.custom_fields import (SUBJECT_FIELDS,
SUBJECT_FIELDS_UI)
from zenodo_rdm import facets as zenodo_community_facets
from zenodo_rdm import providers as zenodo_providers
from zenodo_rdm.api import ZenodoRDMDraft, ZenodoRDMRecord
from zenodo_rdm.custom_fields import (
CUSTOM_FIELDS,
CUSTOM_FIELDS_FACETS,
CUSTOM_FIELDS_UI,
NAMESPACES,
)
from zenodo_rdm.custom_fields import (CUSTOM_FIELDS, CUSTOM_FIELDS_FACETS,
CUSTOM_FIELDS_UI, NAMESPACES)
from zenodo_rdm.custom_schemes import is_edmo
from zenodo_rdm.files import storage_factory
from zenodo_rdm.github.schemas import CitationMetadataSchema
from zenodo_rdm.legacy.resources import record_serializers
from zenodo_rdm.metrics.config import METRICS_CACHE_UPDATE_INTERVAL
from zenodo_rdm.moderation.errors import UserBlockedException
from zenodo_rdm.moderation.handlers import CommunityScoreHandler, RecordScoreHandler
from zenodo_rdm.moderation.handlers import (CommunityScoreHandler,
RecordScoreHandler)
from zenodo_rdm.openaire.records.components import OpenAIREComponent
from zenodo_rdm.permissions import (
ZenodoCommunityPermissionPolicy,
ZenodoRDMRecordPermissionPolicy,
)
from zenodo_rdm.permissions import (ZenodoCommunityPermissionPolicy,
ZenodoRDMRecordPermissionPolicy)
from zenodo_rdm.queryparser import word_communities, word_doi
from zenodo_rdm.subcommunities import (
ZenodoSubCommunityRequest,
Expand Down Expand Up @@ -740,16 +720,10 @@ USERPROFILES_READ_ONLY = (
THEME_SHOW_FRONTPAGE_INTRO_SECTION = False
APP_RDM_RECORD_LANDING_PAGE_TEMPLATE = "zenodo_rdm/records/detail.html"

from zenodo_rdm.utils import (
annostor_link_render,
blr_link_render,
briefideas_link_render,
f1000_link_render,
github_link_render,
openaire_link_render,
reana_link_render,
swh_link_render,
)
from zenodo_rdm.utils import (annostor_link_render, blr_link_render,
briefideas_link_render, f1000_link_render,
github_link_render, openaire_link_render,
reana_link_render, swh_link_render)

APP_RDM_RECORD_LANDING_PAGE_EXTERNAL_LINKS = [
{"id": "f1000", "render": f1000_link_render},
Expand Down Expand Up @@ -926,6 +900,22 @@ OAISERVER_XSL_URL = "/static/oai2.xsl"
RDM_DATACITE_FUNDER_IDENTIFIERS_PRIORITY = ("doi", "ror", "grid", "isni", "gnd")
"""Priority of funder identifiers types for Datacite serialization, prioritize DOI."""

RDM_RECORDS_PERSONORG_SCHEMES = {
**RDM_RECORDS_PERSONORG_SCHEMES,
"edmo": {"label": _("EDMO"), "validator": is_edmo, "datacite": "URL"},
}
"""Person and Organization Schemes."""

APP_RDM_IDENTIFIER_SCHEMES_UI = {
**APP_RDM_IDENTIFIER_SCHEMES_UI,
"edmo": {
"url_prefix": "https://edmo.seadatanet.org/report/",
"icon": "images/edmo-icon.svg",
"label": "EDMO",
}
}
"""Identifier Schemes UI config."""

RECORDS_RESOURCES_ALLOW_EMPTY_FILES = False
"""Disable empty files for Zenodo."""

Expand Down
13 changes: 8 additions & 5 deletions scripts/run_script.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# Invenio-RDM is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
"""Script to run a Python script in a job on OpenShift."""
#!/usr/bin/env python

import json
import subprocess
import sys
Expand All @@ -22,9 +23,9 @@ def _abort(message):

if len(sys.argv) < 1:
print(f"Usage: {PROGRAM} <file> <image>\n")
print(f" file: the path to the script to run")
print(" file: the path to the script to run")
print(
f" image: the image version to be used by the job. If not provided, the script will try to infer it from the deployed image."
" image: the image version to be used by the job. If not provided, the script will try to infer it from the deployed image."
)
print(f" Example: {PROGRAM} /home/script.py 7.3.0")
sys.exit(1)
Expand Down Expand Up @@ -60,7 +61,9 @@ def infer_deployed_version():


script_path = sys.argv[1]
image_version = sys.argv[2].removeprefix("v") if len(sys.argv) > 2 else infer_deployed_version()
image_version = (
sys.argv[2].removeprefix("v") if len(sys.argv) > 2 else infer_deployed_version()
)

# verify the file exists in local filesystem
if not Path(script_path).is_file():
Expand Down Expand Up @@ -103,7 +106,7 @@ def infer_deployed_version():
- copy the script {script_path} to {terminal_pod_name}
- run a pod with Zenodo {image_version}
- execute the script inside the created pod
Proceed? (y/n):
Proceed? (y/n):
"""
if input(str_) != "y":
_abort("Aborted.")
Expand Down
2 changes: 2 additions & 0 deletions site/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ invenio_previewer.previewers =
image_previewer = zenodo_rdm.previewer.image_previewer
invenio_search.index_templates =
zenodo_rdm = zenodo_rdm.index_templates
idutils.custom_schemes =
edmo = zenodo_rdm.custom_schemes:get_scheme_config_func

[bdist_wheel]
universal = 1
Expand Down
57 changes: 57 additions & 0 deletions site/zenodo_rdm/custom_schemes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# ZenodoRDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Custom scheme config."""

import re

# Regular expression to validate EDMO identifiers in the format "edmo:<ID>"
edmo_regexp = re.compile(r"^edmo:(\d+)$")

# Regular expression to match the EDMO URL format
edmo_url_regexp = re.compile(
r"(?:https?://)?(?:edmo\.seadatanet\.org/report/)?(\d+)$", re.IGNORECASE
)


def is_edmo(val):
"""
Validate and normalize an EDMO identifier or URL.
Returns the normalized 'edmo:<ID>' format if valid, otherwise None.
"""
# Match against the URL or the edmo:<ID> format
match = edmo_url_regexp.match(val) or edmo_regexp.match(val)
if match:
# Extract the numeric ID from the matched group
return f"edmo:{match.group(1)}"
return None


def normalize_edmo(val):
"""Normalize an EDMO identifier or URL to the 'edmo:<ID>' format."""
return is_edmo(val)


def generate_edmo_url(_, normalized_pid):
"""
Generate a URL for a given normalized EDMO identifier.
Assumes the input is in the form 'edmo:<ID>'.
"""
edmo_id = normalized_pid.split(":")[1]
return f"https://edmo.seadatanet.org/report/{edmo_id}"


def get_scheme_config_func():
"""Return the configuration for the EDMO custom scheme."""
return {
"validator": is_edmo,
"normalizer": normalize_edmo,
"filter": [],
"url_generator": generate_edmo_url,
}
2 changes: 1 addition & 1 deletion site/zenodo_rdm/legacy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class LegacyRecordServiceConfig(RDMRecordServiceConfig):
),
"doi": RecordPIDLink("https://doi.org/{+pid_doi}", when=has_doi),
"parent_doi": RecordParentPIDLink(
"{+ui}/doi/{+pid_doi}",
"https://doi.org/{+pid_doi}",
when=is_record_and_has_parent_doi,
),
"badge": RecordPIDLink("{+ui}/badge/doi/{pid_doi}.svg"),
Expand Down
3 changes: 3 additions & 0 deletions static/images/edmo-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions templates/semantic-ui/zenodo_rdm/macros/creators.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
{% set link = "https://ror.org/{identifier}".format(identifier=id.identifier) %}
{% set link_title = _("ROR profile") %}
{% set icon = "/static/images/ror-icon.svg" %}

{% elif id.scheme == "edmo" %}
{% set link = "https://edmo.seadatanet.org/report/{identifier}".format(identifier=id.identifier) %}
{% set link_title = _("EDMO profile") %}
{% set icon = "/static/images/edmo-icon.svg" %}

{% elif id.scheme == "gnd" %}
{% set link = "https://d-nb.info/gnd/{identifier}".format(identifier=id.identifier) %}
Expand Down

0 comments on commit aae2bc1

Please sign in to comment.