From 5ab05f63039bb6e37405bb9eea230fbcab23805f Mon Sep 17 00:00:00 2001
From: Bogdan Cochior <bogdan.cochior@thinslices.com>
Date: Wed, 15 Aug 2018 14:42:20 +0300
Subject: [PATCH] fix(user-manager): send 'Manuscript created' email only when
 admin adds author

---
 .../fragmentsUsers/emails/notifications.js    | 26 +++++++++++++------
 .../src/routes/fragmentsUsers/post.js         |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js
index 9a7af8dbc..140ec0d0f 100644
--- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js
+++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js
@@ -13,7 +13,14 @@ const {
 const { getEmailCopy } = require('./emailCopy')
 
 module.exports = {
-  async sendNotifications({ user, baseUrl, fragment, UserModel, collection }) {
+  async sendNotifications({
+    user,
+    baseUrl,
+    fragment,
+    UserModel,
+    collection,
+    reqUser,
+  }) {
     const fragmentHelper = new Fragment({ fragment })
     const { title } = await fragmentHelper.getFragmentData({
       handlingEditor: collection.handlingEditor,
@@ -48,13 +55,16 @@ module.exports = {
       })
     }
 
-    sendAddedToManuscriptEmail({
-      email,
-      baseUrl,
-      user,
-      titleText,
-      subjectBaseText,
-    })
+    const requestUser = await UserModel.find(reqUser)
+    if (requestUser.admin) {
+      sendAddedToManuscriptEmail({
+        email,
+        baseUrl,
+        user,
+        titleText,
+        subjectBaseText,
+      })
+    }
   },
 }
 
diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/post.js b/packages/component-user-manager/src/routes/fragmentsUsers/post.js
index 6a7546e6f..fa0b2b2f3 100644
--- a/packages/component-user-manager/src/routes/fragmentsUsers/post.js
+++ b/packages/component-user-manager/src/routes/fragmentsUsers/post.js
@@ -97,6 +97,7 @@ module.exports = models => async (req, res) => {
       baseUrl,
       fragment,
       collection,
+      reqUser: req.user,
       UserModel: models.User,
     })
 
-- 
GitLab