diff --git a/packages/component-helper-service/src/services/User.js b/packages/component-helper-service/src/services/User.js index 1878092704ad027560176e161e3a526367ea3363..821528b4290bdb7baa2883615b64bca1b7b77f1f 100644 --- a/packages/component-helper-service/src/services/User.js +++ b/packages/component-helper-service/src/services/User.js @@ -64,6 +64,13 @@ class User { return eics } + async userIsAdmin(user) { + const { UserModel } = this + const users = await UserModel.all() + const admin = users.filter(user => user.admin) + return user === admin[0].id + } + async updateUserTeams({ userId, teamId }) { const user = await this.UserModel.find(userId) user.teams.push(teamId) diff --git a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js index bc2841276ba9300ce4c39b51068989b5b879b0ce..e37133b841c87adcd4b084dc152b959cec912aa6 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -1,5 +1,5 @@ const config = require('config') -const { get } = require('lodash') +const { get, isEmpty } = require('lodash') const Email = require('@pubsweet/component-email-templating') const { @@ -55,6 +55,11 @@ module.exports = { async sendAuthorsEmail({ baseUrl, fragment, UserModel, collection }) { const fragmentHelper = new Fragment({ fragment }) + const collectionOwners = get(collection, 'owners') + const userHelper = new User({ UserModel }) + const adminOwner = collectionOwners.find(owner => + userHelper.userIsAdmin(owner), + ) const handlingEditor = get(collection, 'handlingEditor') const parsedFragment = await fragmentHelper.getFragmentData({ handlingEditor, @@ -142,8 +147,7 @@ module.exports = { }) email.content.ctaText = 'CONFIRM ACCOUNT' } - - return email.sendEmail() + if (isEmpty(adminOwner)) return email.sendEmail() }) }, } 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 5e22345f88d873591ff1ab5a342d2e77f4b9444a..62945ecad929b3849d506e211f40af8b8bee789e 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js @@ -5,11 +5,7 @@ const unsubscribeSlug = config.get('unsubscribe.url') const { name: journalName, staffEmail } = config.get('journal') const Email = require('@pubsweet/component-email-templating') -const { - User, - services, - Fragment, -} = require('pubsweet-component-helper-service') +const { services, Fragment } = require('pubsweet-component-helper-service') const { getEmailCopy } = require('./emailCopy') @@ -26,10 +22,12 @@ module.exports = { handlingEditor: collection.handlingEditor, }) - const userHelper = new User({ UserModel }) - const eicName = await userHelper.getEiCName() + const titleText = `The manuscript titled "${title}" has been submitted to ${journalName} by Editorial Assistant.` - const titleText = `The manuscript titled "${title}" has been submitted to ${journalName} by ${eicName}.` + const { paragraph, ...bodyProps } = getEmailCopy({ + emailType: 'submitting-author-added-by-admin', + titleText, + }) const email = new Email({ type: 'user', @@ -43,17 +41,20 @@ module.exports = { signatureJournal: journalName, subject: `Manuscript submitted`, ctaLink: services.createUrl(baseUrl, ''), + paragraph, unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, { id: submittingAuthor.id, token: submittingAuthor.accessTokens.unsubscribe, }), }, + bodyProps, }) if (!submittingAuthor.isConfirmed) { email.content.ctaLink = services.createUrl(baseUrl, resetPath, { email: submittingAuthor.email, - title: submittingAuthor.title, + title: submittingAuthor.title.toLowerCase(), + country: submittingAuthor.country, firstName: submittingAuthor.firstName, lastName: submittingAuthor.lastName, affiliation: submittingAuthor.affiliation, @@ -62,7 +63,7 @@ module.exports = { email.content.ctaText = 'CONFIRM ACCOUNT' } - const { html, text } = email.getNotificationBody({ + const { html, text } = email._getNotificationBody({ emailBodyProps: getEmailCopy({ emailType: 'submitting-author-added-by-admin', titleText,