From 1c1389c76393b3525b75c177b6d321a211fa8150 Mon Sep 17 00:00:00 2001 From: Milo Thurston Date: Thu, 21 Nov 2024 13:43:04 +0000 Subject: [PATCH] Fixes crash when DOI for wrong object type used. #2429 --- src/components/Editor/EditPublications.vue | 78 ++++++++++++---------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/src/components/Editor/EditPublications.vue b/src/components/Editor/EditPublications.vue index 1dfedc71b..063ce9bc8 100644 --- a/src/components/Editor/EditPublications.vue +++ b/src/components/Editor/EditPublications.vue @@ -523,51 +523,59 @@ export default { } else { let dataPublication; if (Array.isArray(data)) { + console.log("Array!"); dataPublication = data[0]; } else { + console.log("Object!"); dataPublication = data; } - if ( - dataPublication.metadata.upload_type === "publication" || - (dataPublication.metadata.resource_type && - dataPublication.metadata.resource_type.type && - dataPublication.metadata.resource_type.type === "publication") - ) { - this.newPublication = { - journal: null, - doi: null, - title: null, - url: null, - year: null, - authors: null, - }; - if (dataPublication.metadata.journal_title) { - this.newPublication.journal = - dataPublication.metadata.journal_title; - } else { - if (dataPublication.metadata.meeting) { + if (dataPublication.metadata !== undefined) { + if (dataPublication.metadata.upload_type === "publication" || + (dataPublication.metadata.resource_type && + dataPublication.metadata.resource_type.type && + dataPublication.metadata.resource_type.type === "publication") + ) { + this.newPublication = { + journal: null, + doi: null, + title: null, + url: null, + year: null, + authors: null, + }; + if (dataPublication.metadata.journal_title) { this.newPublication.journal = - dataPublication.metadata.meeting.title; + dataPublication.metadata.journal_title; + } else { + if (dataPublication.metadata.meeting) { + this.newPublication.journal = + dataPublication.metadata.meeting.title; + } } + this.newPublication.doi = dataPublication.doi; + this.newPublication.title = dataPublication.metadata.title; + this.newPublication.url = dataPublication.links.doi; + this.newPublication.year = Number( + dataPublication.metadata.publication_date.split("-")[0] + ); + let authors = []; + dataPublication.metadata.creators.forEach(function (a) { + authors.push(a.name + "; "); + }); + this.newPublication.authors = authors.join(""); + this.newPublication.isCitation = false; + this.openEditor = true; } - this.newPublication.doi = dataPublication.doi; - this.newPublication.title = dataPublication.metadata.title; - this.newPublication.url = dataPublication.links.doi; - this.newPublication.year = Number( - dataPublication.metadata.publication_date.split("-")[0] - ); - let authors = []; - dataPublication.metadata.creators.forEach(function (a) { - authors.push(a.name + "; "); - }); - this.newPublication.authors = authors.join(""); - this.newPublication.isCitation = false; - this.openEditor = true; - } else { + else { + this.errors.doi = true; + } + } + else { this.errors.doi = true; } } - } else { + } + else { /* istanbul ignore next */ this.newPublication.journal = data["container-title-short"] || data["container-title"];