Skip to content
Snippets Groups Projects
Commit ba921a40 authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

feat(manuscript-manager): send proper emails on EQA accept

parent cc7f97e3
No related branches found
No related tags found
2 merge requests!110Sprint 21 Features,!92Hin 946
...@@ -60,7 +60,11 @@ module.exports = { ...@@ -60,7 +60,11 @@ module.exports = {
// the EiC recommends to publish so an email to the EQA needs to be sent, // the EiC recommends to publish so an email to the EQA needs to be sent,
// one requesting approval or one informing them that the manuscript has been published // one requesting approval or one informing them that the manuscript has been published
if (isEditorInChief && recommendation === 'publish') { if (
isEditorInChief &&
recommendation === 'publish' &&
collection.technicalChecks.token
) {
sendEQAEmail({ sendEQAEmail({
email, email,
eicName, eicName,
...@@ -77,7 +81,6 @@ module.exports = { ...@@ -77,7 +81,6 @@ module.exports = {
// send HE emails when a review is submitted // send HE emails when a review is submitted
// or when the EiC makes a recommendation after peer review // or when the EiC makes a recommendation after peer review
if ( if (
recommendationType === 'review' || recommendationType === 'review' ||
(isEditorInChief && (isEditorInChief &&
......
const config = require('config') const config = require('config')
const { get } = require('lodash')
const Email = require('@pubsweet/component-email-templating') const Email = require('@pubsweet/component-email-templating')
const { const {
...@@ -9,12 +8,10 @@ const { ...@@ -9,12 +8,10 @@ const {
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy') const { getEmailCopy } = require('./emailCopy')
const unsubscribeSlug = config.get('unsubscribe.url')
const { name: journalName, staffEmail } = config.get('journal') const { name: journalName, staffEmail } = config.get('journal')
module.exports = { module.exports = {
async sendNotifications({ async sendNotifications({
isEQA,
agree, agree,
baseUrl, baseUrl,
collection, collection,
...@@ -28,10 +25,7 @@ module.exports = { ...@@ -28,10 +25,7 @@ module.exports = {
handlingEditor: collection.handlingEditor, handlingEditor: collection.handlingEditor,
}) })
const { const { submittingAuthor } = await fragmentHelper.getAuthorData({
activeAuthors: authors,
submittingAuthor,
} = await fragmentHelper.getAuthorData({
UserModel, UserModel,
}) })
...@@ -60,42 +54,14 @@ module.exports = { ...@@ -60,42 +54,14 @@ module.exports = {
}, },
}) })
if (agree && isEQA) { sendEditorsEmail({
email.content.signatureName = await userHelper.getEiCName() email,
agree,
sendHandlingEditorEmail({ customId,
email, comments,
baseUrl, titleText,
titleText, userHelper,
subjectBaseText, })
handlingEditor: get(collection, 'handlingEditor', {}),
})
sendSubmittedReviewersEmail({
email,
baseUrl,
titleText,
UserModel,
fragmentHelper,
subjectBaseText,
})
sendAuthorsEmail({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors: authors,
})
} else {
sendEditorsEmail({
email,
agree,
customId,
comments,
titleText,
userHelper,
})
}
}, },
} }
...@@ -137,113 +103,3 @@ const sendEditorsEmail = async ({ ...@@ -137,113 +103,3 @@ const sendEditorsEmail = async ({
email.sendEmail({ html, text }) email.sendEmail({ html, text })
}) })
} }
const sendHandlingEditorEmail = ({
email,
baseUrl,
titleText,
handlingEditor,
subjectBaseText,
}) => {
email.content.subject = `${subjectBaseText} Decision`
const emailType = 'he-manuscript-published'
email.toUser = {
email: handlingEditor.email,
name: handlingEditor.name,
}
email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
id: handlingEditor.id,
})
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
emailType,
titleText,
}),
})
email.sendEmail({ html, text })
}
const sendSubmittedReviewersEmail = async ({
email,
baseUrl,
titleText,
UserModel,
fragmentHelper,
subjectBaseText,
}) => {
email.content.subject = `${subjectBaseText} Decision`
const reviewers = (await fragmentHelper.getReviewers({
UserModel,
type: 'submitted',
})).map(rev => ({
...rev,
...getEmailCopy({
emailType: 'submitted-reviewers-after-publish',
titleText,
}),
}))
reviewers.forEach(reviewer => {
email.toUser = {
email: reviewer.email,
name: `${reviewer.firstName} ${reviewer.lastName}`,
}
email.content.unsubscribeLink = services.createUrl(
baseUrl,
unsubscribeSlug,
{
id: reviewer.id,
},
)
const { html, text } = email.getNotificationBody({
emailBodyProps: {
paragraph: reviewer.paragraph,
hasLink: reviewer.hasLink,
},
})
email.sendEmail({ html, text })
})
}
const sendAuthorsEmail = ({
email,
baseUrl,
titleText,
subjectBaseText,
fragmentAuthors,
}) => {
const emailType = 'author-manuscript-published'
email.content.subject = `${subjectBaseText} Published`
const authors = fragmentAuthors.map(author => ({
...author,
...getEmailCopy({
emailType,
titleText,
}),
}))
authors.forEach(author => {
email.toUser = {
email: author.email,
name: `${author.firstName} ${author.lastName}`,
}
email.content.unsubscribeLink = services.createUrl(
baseUrl,
unsubscribeSlug,
{
id: author.id,
},
)
const { html, text } = email.getNotificationBody({
emailBodyProps: {
paragraph: author.paragraph,
hasLink: author.hasLink,
},
})
email.sendEmail({ html, text })
})
}
const { get, find, isEmpty } = require('lodash') const { get, find, isEmpty, has, last } = require('lodash')
const { services } = require('pubsweet-component-helper-service') const { services } = require('pubsweet-component-helper-service')
const { sendNotifications } = require('./notifications/notifications') const {
sendNotifications: sendEQSNotifications,
} = require('./notifications/notifications')
const {
sendNotifications: sendEQANotifications,
} = require('../fragmentsRecommendations/notifications/notifications')
const TECHNICAL_STEPS = { const TECHNICAL_STEPS = {
EQS: 'eqs', EQS: 'eqs',
...@@ -64,15 +70,33 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => { ...@@ -64,15 +70,33 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
collection.status = setNewStatus(step, agree) collection.status = setNewStatus(step, agree)
await collection.save() await collection.save()
sendNotifications({ const isEQA = get(collection, 'technicalChecks.eqa', false)
User, const baseUrl = services.getBaseUrl(req)
agree, if (isEQA) {
comments, const fragment = await Fragment.find(last(collection.fragments))
Fragment,
collection, sendEQANotifications({
baseUrl: services.getBaseUrl(req), baseUrl,
isEQA: step === TECHNICAL_STEPS.EQA, fragment,
}) collection,
hasEQA: true,
UserModel: User,
isEditorInChief: true,
newRecommendation: {
recommendation: 'publish',
recommendationType: 'editorRecommendation',
},
})
} else {
sendEQSNotifications({
User,
agree,
comments,
Fragment,
collection,
baseUrl,
})
}
return res.status(200).json(collection) return res.status(200).json(collection)
} catch (e) { } catch (e) {
......
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