From fdbe7b44a90315289cba53b3fa8877183709923b Mon Sep 17 00:00:00 2001
From: Sebastian Mihalache <sebastian.mihalache@gmail.con>
Date: Fri, 10 Aug 2018 10:37:54 +0300
Subject: [PATCH] fix(manuscript-manager): add proper signature name

---
 .../component-helper-service/src/services/User.js |  4 +++-
 .../notifications/notifications.js                | 15 ++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/packages/component-helper-service/src/services/User.js b/packages/component-helper-service/src/services/User.js
index 39d038968..cc5578b45 100644
--- a/packages/component-helper-service/src/services/User.js
+++ b/packages/component-helper-service/src/services/User.js
@@ -72,7 +72,9 @@ class User {
 
   async getEiCName() {
     const editorsInChief = await this.getEditorsInChief()
-    const { firstName, lastName } = editorsInChief[0]
+    const firstName = get(editorsInChief, '0.firstName', 'Editor')
+    const lastName = get(editorsInChief, '0.lastName', 'in Chief')
+
     return `${firstName} ${lastName}`
   }
 }
diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js
index b3f2e877a..df48f227d 100644
--- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js
+++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js
@@ -33,12 +33,15 @@ module.exports = {
       fragmentAuthors.submittingAuthor.firstName
     } ${fragmentAuthors.submittingAuthor.lastName}`
 
+    const userHelper = new User({ UserModel })
+    const eicName = await userHelper.getEiCName()
+
     const email = new Email({
       type: 'user',
       content: {
         unsubscribeLink: baseUrl,
         ctaText: 'MANUSCRIPT DETAILS',
-        signatureName: get(collection, 'handlingEditor.name', 'N/A'),
+        signatureName: eicName,
         ctaLink: services.createUrl(
           baseUrl,
           `/projects/${collection.id}/versions/${fragment.id}/details`,
@@ -46,8 +49,6 @@ module.exports = {
       },
     })
 
-    const userHelper = new User({ UserModel })
-
     let comments
     if (isEditorInChief) {
       const eicComments = chain(newRecommendation)
@@ -95,6 +96,7 @@ module.exports = {
           isEditorInChief,
           subjectBaseText,
           newRecommendation,
+          handlingEditorName: get(collection, 'handlingEditor.name', eicName),
         })
       }
       if (hasPeerReview(collection)) {
@@ -163,7 +165,7 @@ const sendHandlingEditorEmail = ({
   email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
     id: handlingEditor.id,
   })
-  email.content.signatureName = eicName
+
   const { html, text } = email.getBody({
     body: getEmailCopy({
       emailType,
@@ -183,6 +185,7 @@ const sendAuthorsEmail = async ({
   subjectBaseText,
   fragmentAuthors,
   newRecommendation,
+  handlingEditorName,
   parsedFragment: { heRecommendation },
 }) => {
   let emailType, authors, comments
@@ -216,7 +219,10 @@ const sendAuthorsEmail = async ({
     }))
   } else {
     emailType = 'author-request-to-revision'
+
     email.content.subject = `${subjectBaseText} Recommendation`
+    email.content.signatureName = handlingEditorName
+
     const authorNote = newRecommendation.comments.find(comm => comm.public)
     const content = get(authorNote, 'content')
     const authorNoteText = content ? `Reason & Details: "${content}"` : ''
@@ -285,7 +291,6 @@ const sendReviewersEmail = async ({
         titleText,
       }),
     }))
-    email.content.signatureName = eicName
   } else {
     email.content.signatureName = handlingEditorName
     email.content.subject = `${subjectBaseText} ${getSubjectByRecommendation(
-- 
GitLab