From 1456436688fabf9e1f537525ec515b1837464cf1 Mon Sep 17 00:00:00 2001 From: Anika Churilova Date: Thu, 5 Dec 2024 11:42:08 +0100 Subject: [PATCH] doi: handle UI for optional DOI feature * closes https://github.com/CERNDocumentServer/cds-rdm/issues/163 --- invenio_app_rdm/ext.py | 13 ++++ invenio_app_rdm/records_ui/views/deposits.py | 60 ++++++++++++++++--- .../invenio_app_rdm/deposit/RDMDepositForm.js | 3 +- .../js/invenio_app_rdm/deposit/index.js | 1 + 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/invenio_app_rdm/ext.py b/invenio_app_rdm/ext.py index a6c6e20de..61e949e9f 100644 --- a/invenio_app_rdm/ext.py +++ b/invenio_app_rdm/ext.py @@ -33,6 +33,19 @@ def finalize_app(app): def init_config(app): """Initialize configuration.""" + record_doi_required = ( + app.config["RDM_PERSISTENT_IDENTIFIERS"].get("doi", {}).get("required") + ) + parent_doi_required = ( + app.config["RDM_PARENT_PERSISTENT_IDENTIFIERS"].get("doi", {}).get("required") + ) + + if record_doi_required != parent_doi_required: + raise Exception( + "Config variables RDM_PERSISTENT_IDENTIFIERS.doi.required and " + "RDM_PARENT_PERSISTENT_IDENTIFIERS.doi.required must be set to the same value." + ) + if "COMMUNITIES_GROUPS_ENABLED" in app.config: warnings.warn( "COMMUNITIES_GROUPS_ENABLED config variable is deprecated. Please use USERS_RESOURCES_GROUPS_ENABLED " diff --git a/invenio_app_rdm/records_ui/views/deposits.py b/invenio_app_rdm/records_ui/views/deposits.py index d9afc7487..79793b312 100644 --- a/invenio_app_rdm/records_ui/views/deposits.py +++ b/invenio_app_rdm/records_ui/views/deposits.py @@ -60,6 +60,12 @@ def get_form_pids_config(): continue record_pid_config = current_app.config["RDM_PERSISTENT_IDENTIFIERS"] scheme_label = record_pid_config.get(scheme, {}).get("label", scheme) + is_doi_required = record_pid_config.get(scheme, {}).get("required") + default_selected = ( + record_pid_config.get(scheme, {}).get("ui", {}).get("default_selected") + ) + if is_doi_required and default_selected == "not_needed": + default_selected = "yes" pids_provider = { "scheme": scheme, "field_label": "Digital Object Identifier", @@ -82,6 +88,7 @@ def get_form_pids_config(): "A {scheme_label} allows your upload to be easily and " "unambiguously cited. Example: 10.1234/foo.bar" ).format(scheme_label=scheme_label), + "default_selected": default_selected, } pids_providers.append(pids_provider) @@ -360,7 +367,16 @@ def new_record(): record = dump_empty(RDMRecordSchema) record["files"] = {"enabled": current_app.config.get("RDM_DEFAULT_FILES_ENABLED")} if "doi" in current_rdm_records.records_service.config.pids_providers: - record["pids"] = {"doi": {"provider": "external", "identifier": ""}} + if ( + current_app.config["RDM_PERSISTENT_IDENTIFIERS"] + .get("doi", {}) + .get("ui", {}) + .get("default_selected") + == "yes" # yes, no or not_needed + ): + record["pids"] = {"doi": {"provider": "external", "identifier": ""}} + else: + record["pids"] = {} else: record["pids"] = {} record["status"] = "draft" @@ -389,6 +405,11 @@ def deposit_create(community=None): community_use_jinja_header = bool(community_theme) dashboard_routes = current_app.config["APP_RDM_USER_DASHBOARD_ROUTES"] + is_doi_required = ( + current_app.config.get("RDM_PERSISTENT_IDENTIFIERS", {}) + .get("doi", {}) + .get("required") + ) return render_community_theme_template( current_app.config["APP_RDM_DEPOSIT_FORM_TEMPLATE"], theme=community_theme, @@ -397,6 +418,7 @@ def deposit_create(community=None): createUrl="/api/records", quota=get_files_quota(), hide_community_selection=community_use_jinja_header, + is_doi_required=is_doi_required, ), searchbar_config=dict(searchUrl=get_search_url()), record=new_record(), @@ -455,17 +477,37 @@ def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True): # communities community_use_jinja_header = bool(community_theme) dashboard_routes = current_app.config["APP_RDM_USER_DASHBOARD_ROUTES"] + is_doi_required = ( + current_app.config.get("RDM_PERSISTENT_IDENTIFIERS", {}) + .get("doi", {}) + .get("required") + ) + form_config = get_form_config( + apiUrl=f"/api/records/{pid_value}/draft", + dashboard_routes=dashboard_routes, + # maybe quota should be serialized into the record e.g for admins + quota=get_files_quota(draft._record), + # hide react community component + hide_community_selection=community_use_jinja_header, + is_doi_required=is_doi_required, + ) + + if is_doi_required and not record.get("pids", {}).get("doi"): + # if the DOI is required but there is no value, we set the default selected pid + # to no i.e. system should automatically mint a local DOI + if record["status"] == "new_version_draft": + doi_provider_config = [ + pid_config + for pid_config in form_config["pids"] + if pid_config.get("scheme") == "doi" + ] + if doi_provider_config: + doi_provider_config[0]["default_selected"] = "no" + return render_community_theme_template( current_app.config["APP_RDM_DEPOSIT_FORM_TEMPLATE"], theme=community_theme, - forms_config=get_form_config( - apiUrl=f"/api/records/{pid_value}/draft", - dashboard_routes=dashboard_routes, - # maybe quota should be serialized into the record e.g for admins - quota=get_files_quota(draft._record), - # hide react community component - hide_community_selection=community_use_jinja_header, - ), + forms_config=form_config, record=record, community=community, community_use_jinja_header=community_use_jinja_header, diff --git a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js index aa0eab5cd..ef0329622 100644 --- a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js +++ b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/RDMDepositForm.js @@ -221,7 +221,8 @@ export class RDMDepositForm extends Component { pidPlaceholder={pid.pid_placeholder} pidType={pid.scheme} unmanagedHelpText={pid.unmanaged_help_text} - required + doiDefaultSelection={pid.default_selected} + required={this.config.is_doi_required} record={record} /> diff --git a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/index.js b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/index.js index 2005fa220..3894697d5 100644 --- a/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/index.js +++ b/invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/index.js @@ -29,6 +29,7 @@ ReactDOM.render( allowRecordRestriction={getInputFromDOM("deposits-allow-record-restriction")} groupsEnabled={getInputFromDOM("config-groups-enabled")} allowEmptyFiles={getInputFromDOM("records-resources-allow-empty-files")} + isDoiRequired={getInputFromDOM("deposits-is-doi-required")} /> , document.getElementById("deposit-form")