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

doi: handle UI for optional DOI feature #2933

Merged
Merged
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
13 changes: 13 additions & 0 deletions invenio_app_rdm/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
60 changes: 51 additions & 9 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
/>
</OverridableContext.Provider>,
document.getElementById("deposit-form")
Expand Down