Skip to content

Commit

Permalink
doi: handle UI for optional DOI feature
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova committed Dec 5, 2024
1 parent 399ebb4 commit b28c934
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions invenio_app_rdm/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def finalize_app(app):

def init_config(app):
"""Initialize configuration."""
record_doi_required = app.config["RDM_PERSISTENT_IDENTIFIERS"]["doi"]["required"]
parent_doi_required = app.config["RDM_PARENT_PERSISTENT_IDENTIFIERS"]["doi"]["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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
value='{{ permissions | tojson }}'>
{%- endif %}

{%- if is_doi_required != None %}
<input id="deposits-is-doi-required" type="hidden"
name="deposits-is-doi-required"
value='{{ is_doi_required | tojson }}'>
{%- endif %}

<div id="deposit-form"></div>

{%- endblock page_body %}
Expand Down
10 changes: 9 additions & 1 deletion invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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": record_pid_config.get(scheme, {}).get("ui", {}).get("default_selected", "yes")
}
pids_providers.append(pids_provider)

Expand Down Expand Up @@ -360,7 +361,10 @@ 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.get("DOI_DEFAULT_SELECTION", {}) is True:
record["pids"] = {"doi": {"provider": "external", "identifier": ""}}
else:
record["pids"] = {}
else:
record["pids"] = {}
record["status"] = "draft"
Expand Down Expand Up @@ -389,6 +393,7 @@ 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 @@ -413,6 +418,7 @@ def deposit_create(community=None):
"manage_record_access",
]
),
is_doi_required=is_doi_required,
)


Expand Down Expand Up @@ -455,6 +461,7 @@ 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")
return render_community_theme_template(
current_app.config["APP_RDM_DEPOSIT_FORM_TEMPLATE"],
theme=community_theme,
Expand All @@ -481,6 +488,7 @@ def deposit_edit(pid_value, draft=None, draft_files=None, files_locked=True):
"manage_record_access",
]
),
is_doi_required=is_doi_required,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class RDMDepositForm extends Component {
allowRecordRestriction,
groupsEnabled,
allowEmptyFiles,
isDoiRequired,
} = this.props;
const customFieldsUI = this.config.custom_fields.ui;
return (
Expand Down Expand Up @@ -221,7 +222,8 @@ export class RDMDepositForm extends Component {
pidPlaceholder={pid.pid_placeholder}
pidType={pid.scheme}
unmanagedHelpText={pid.unmanaged_help_text}
required
doiDefaultSelection={pid.default_selected}
required={isDoiRequired}
record={record}
/>
</Fragment>
Expand Down Expand Up @@ -724,6 +726,7 @@ RDMDepositForm.propTypes = {
permissions: PropTypes.object,
filesLocked: PropTypes.bool,
allowEmptyFiles: PropTypes.bool,
isDoiRequired: PropTypes.bool.isRequired,
};

RDMDepositForm.defaultProps = {
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

0 comments on commit b28c934

Please sign in to comment.