Skip to content

Commit 348de12

Browse files
zzacharojrcastro2
authored andcommitted
preview: do not mint parent doi if doi is not reserved and doi is optional
1 parent 832414c commit 348de12

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

invenio_app_rdm/records_ui/views/records.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def record_detail(
178178
)
179179
except ValidationError:
180180
abort(404)
181-
# inject parent doi format for new drafts so we can show in preview
181+
# inject parent doi format for new drafts so we can show in preview if parent doi is required
182182
if current_app.config["DATACITE_ENABLED"]:
183183
service = current_rdm_records.records_service
184184
datacite_provider = [
@@ -187,11 +187,27 @@ def record_detail(
187187
if p == "doi" and "datacite" in v
188188
]
189189
if datacite_provider:
190-
datacite_provider = datacite_provider[0]
191-
parent_doi = datacite_provider.client.generate_doi(
192-
record._record.parent
190+
should_mint_parent_doi = True
191+
is_doi_required = (
192+
current_app.config.get("RDM_PARENT_PERSISTENT_IDENTIFIERS", {})
193+
.get("doi", {})
194+
.get("required")
193195
)
194-
record_ui["ui"]["new_draft_parent_doi"] = parent_doi
196+
if not is_doi_required:
197+
# check if the draft has a reserved doi and mint parent doi only in that case
198+
record_doi = record._record.pids.get("doi", {})
199+
is_doi_reserved = record_doi.get(
200+
"provider", ""
201+
) == "datacite" and record_doi.get("identifier")
202+
if not is_doi_reserved:
203+
should_mint_parent_doi = False
204+
205+
if should_mint_parent_doi:
206+
datacite_provider = datacite_provider[0]
207+
parent_doi = datacite_provider.client.generate_doi(
208+
record._record.parent
209+
)
210+
record_ui["ui"]["new_draft_parent_doi"] = parent_doi
195211

196212
# emit a record view stats event
197213
emitter = current_stats.get_event_emitter("record-view")

0 commit comments

Comments
 (0)