diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js
index 71dafb704..c4413083b 100644
--- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js
+++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js
@@ -30,7 +30,11 @@ class PublishButtonComponent extends Component {
handlePublish = (event, handleSubmit, publishWithoutCommunity) => {
const { setSubmitContext } = this.context;
-
+ // const { formik } = this.props;
+ // const noINeedOne = formik?.values?.noINeedOne;
+ // if (noINeedOne && Object.keys(formik?.values?.pids).length === 0) {
+ // formik.setFieldError("pids", "EROROROROROOR");
+ // }
setSubmitContext(
publishWithoutCommunity
? DepositFormSubmitActions.PUBLISH_WITHOUT_COMMUNITY
diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js
index bd5b00cae..25afce880 100644
--- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js
+++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js
@@ -110,11 +110,13 @@ class ManagedUnmanagedSwitch extends Component {
handleChange = (e, { value }) => {
const { onManagedUnmanagedChange } = this.props;
const isManagedSelected = value === "managed";
- onManagedUnmanagedChange(isManagedSelected);
+ const isNoNeedSelected = value === "notNeeded";
+ onManagedUnmanagedChange(isManagedSelected, isNoNeedSelected);
};
render() {
- const { disabled, isManagedSelected, pidLabel } = this.props;
+ const { disabled, isManagedSelected, isNoNeedSelected, pidLabel, required } =
+ this.props;
return (
@@ -123,28 +125,41 @@ class ManagedUnmanagedSwitch extends Component {
pidLabel: pidLabel,
})}
-
+
-
+
+ {!required && (
+
+
+
+ )}
);
}
@@ -153,8 +168,10 @@ class ManagedUnmanagedSwitch extends Component {
ManagedUnmanagedSwitch.propTypes = {
disabled: PropTypes.bool,
isManagedSelected: PropTypes.bool.isRequired,
+ isNoNeedSelected: PropTypes.bool.isRequired,
onManagedUnmanagedChange: PropTypes.func.isRequired,
pidLabel: PropTypes.string,
+ required: PropTypes.bool.isRequired,
};
ManagedUnmanagedSwitch.defaultProps = {
@@ -307,7 +324,7 @@ class UnmanagedIdentifierCmp extends Component {
render() {
const { localIdentifier } = this.state;
- const { form, fieldPath, helpText, pidPlaceholder } = this.props;
+ const { form, fieldPath, helpText, pidPlaceholder, disabled } = this.props;
const fieldError = getFieldErrors(form, fieldPath);
return (
<>
@@ -318,6 +335,7 @@ class UnmanagedIdentifierCmp extends Component {
placeholder={pidPlaceholder}
width={16}
error={fieldError}
+ disabled={disabled}
/>
{helpText && }
@@ -333,10 +351,12 @@ UnmanagedIdentifierCmp.propTypes = {
identifier: PropTypes.string.isRequired,
onIdentifierChanged: PropTypes.func.isRequired,
pidPlaceholder: PropTypes.string.isRequired,
+ disabled: PropTypes.bool,
};
UnmanagedIdentifierCmp.defaultProps = {
helpText: null,
+ disabled: false,
};
/**
@@ -349,11 +369,17 @@ class CustomPIDField extends Component {
constructor(props) {
super(props);
- const { canBeManaged, canBeUnmanaged } = this.props;
+ const { canBeManaged, canBeUnmanaged, record, field } = this.props;
this.canBeManagedAndUnmanaged = canBeManaged && canBeUnmanaged;
-
+ const value = field?.value;
+ const isDraft = record?.is_draft;
this.state = {
- isManagedSelected: undefined,
+ isManagedSelected:
+ isDraft === true && value?.identifier && value?.provider !== PROVIDER_EXTERNAL
+ ? true
+ : undefined,
+ isNoNeedSelected:
+ isDraft === true && value?.identifier === undefined ? true : undefined,
};
}
@@ -373,7 +399,7 @@ class CustomPIDField extends Component {
};
render() {
- const { isManagedSelected } = this.state;
+ const { isManagedSelected, isNoNeedSelected } = this.state;
const {
btnLabelDiscardPID,
btnLabelGetPID,
@@ -392,6 +418,7 @@ class CustomPIDField extends Component {
pidType,
field,
record,
+ doiDefaultSelection,
} = this.props;
const value = field.value || {};
@@ -407,19 +434,36 @@ class CustomPIDField extends Component {
}
const hasManagedIdentifier = managedIdentifier !== "";
+ const hasUnmanagedIdentifier = unmanagedIdentifier !== "";
+
+ const isDraft = record.is_draft;
+ const _isUnmanagedSelected =
+ isManagedSelected === undefined
+ ? hasUnmanagedIdentifier ||
+ (currentIdentifier === "" && doiDefaultSelection === "yes")
+ : !isManagedSelected;
const _isManagedSelected =
isManagedSelected === undefined
- ? hasManagedIdentifier || currentProvider === "" // i.e pids: {}
+ ? hasManagedIdentifier ||
+ (currentIdentifier === "" && doiDefaultSelection === "no")
: isManagedSelected;
+ const _isNoNeedSelected =
+ isNoNeedSelected === undefined
+ ? (!_isManagedSelected && !_isUnmanagedSelected) ||
+ (isDraft !== true &&
+ currentIdentifier === "" &&
+ doiDefaultSelection === "not_needed")
+ : isNoNeedSelected;
+
const doi = record?.pids?.doi?.identifier || "";
const hasDoi = doi !== "";
const isDoiCreated = currentIdentifier !== "";
const fieldError = getFieldErrors(form, fieldPath);
return (
<>
-
+
@@ -427,20 +471,27 @@ class CustomPIDField extends Component {
{
+ isNoNeedSelected={_isNoNeedSelected}
+ onManagedUnmanagedChange={(userSelectedManaged, userSelectedNoNeed) => {
if (userSelectedManaged) {
form.setFieldValue("pids", {});
+ // form.setFieldValue("noINeedOne", true);
+ } else if (userSelectedNoNeed) {
+ // form.setFieldValue("noINeedOne", false);
} else {
this.onExternalIdentifierChanged("");
+ // form.setFieldValue("noINeedOne", false);
}
this.setState({
isManagedSelected: userSelectedManaged,
+ isNoNeedSelected: userSelectedNoNeed,
});
}}
pidLabel={pidLabel}
+ required={required}
/>
)}
@@ -458,7 +509,7 @@ class CustomPIDField extends Component {
/>
)}
- {canBeUnmanaged && !_isManagedSelected && (
+ {canBeUnmanaged && (!_isManagedSelected || _isNoNeedSelected) && (
{
@@ -468,6 +519,7 @@ class CustomPIDField extends Component {
fieldPath={fieldPath}
pidPlaceholder={pidPlaceholder}
helpText={unmanagedHelpText}
+ disabled={_isNoNeedSelected || isEditingPublishedRecord}
/>
)}
>
@@ -493,6 +545,7 @@ CustomPIDField.propTypes = {
required: PropTypes.bool.isRequired,
unmanagedHelpText: PropTypes.string,
record: PropTypes.object.isRequired,
+ doiDefaultSelection: PropTypes.object.isRequired,
};
CustomPIDField.defaultProps = {
@@ -542,6 +595,7 @@ PIDField.propTypes = {
required: PropTypes.bool,
unmanagedHelpText: PropTypes.string,
record: PropTypes.object.isRequired,
+ doiDefaultSelection: PropTypes.object.isRequired,
};
PIDField.defaultProps = {
diff --git a/invenio_rdm_records/config.py b/invenio_rdm_records/config.py
index 9ea88dddd..fdb96df32 100644
--- a/invenio_rdm_records/config.py
+++ b/invenio_rdm_records/config.py
@@ -391,6 +391,7 @@ def always_valid(identifier):
"validator": idutils.is_doi,
"normalizer": idutils.normalize_doi,
"is_enabled": providers.DataCitePIDProvider.is_enabled,
+ "ui": {"default_selected": "yes"}, # "yes", "no" or "not_needed"
},
"oai": {
"providers": ["oai"],
diff --git a/invenio_rdm_records/resources/serializers/datacite/schema.py b/invenio_rdm_records/resources/serializers/datacite/schema.py
index 82d685e41..6e8c00544 100644
--- a/invenio_rdm_records/resources/serializers/datacite/schema.py
+++ b/invenio_rdm_records/resources/serializers/datacite/schema.py
@@ -418,7 +418,7 @@ def get_related_identifiers(self, obj):
params={"_source_includes": "pids.doi"},
)
for version in record_versions:
- version_doi = version["pids"]["doi"]
+ version_doi = version.get("pids", {}).get("doi")
id_scheme = get_scheme_datacite(
"doi",
"RDM_RECORDS_IDENTIFIERS_SCHEMES",
diff --git a/invenio_rdm_records/services/components/pids.py b/invenio_rdm_records/services/components/pids.py
index 8a08a67b2..c41f68c41 100644
--- a/invenio_rdm_records/services/components/pids.py
+++ b/invenio_rdm_records/services/components/pids.py
@@ -172,6 +172,10 @@ def publish(self, identity, draft=None, record=None):
current_schemes = set(current_pids.keys())
required_schemes = set(self.service.config.parent_pids_required)
+ # if parent DOI is not required in the config, but record DOI is created, we need to create parent DOI as well
+ if "doi" not in required_schemes and draft and draft.get("pids", {}).get("doi"):
+ required_schemes.add("doi")
+
conditional_schemes = self.service.config.parent_pids_conditional
for scheme in set(required_schemes):
condition_func = conditional_schemes.get(scheme)