Skip to content
Snippets Groups Projects
Commit 2fca02c8 authored by Tania Fecheta's avatar Tania Fecheta
Browse files

fix(notifications): send the correct email when the admin creates a new...

fix(notifications): send the correct email when the admin creates a new manuscript and adds a new au
parent 924cb037
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!204Hin 1232 send correct email to new author
......@@ -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)
......
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()
})
},
}
......@@ -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,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment