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

fix(techChecks): fix EQA

parent a4b8e556
No related branches found
No related tags found
1 merge request!115Hin 1038
Showing
with 124 additions and 191 deletions
......@@ -119,6 +119,18 @@ const getEmailCopy = ({
Thank you for your submission, and please do consider submitting again in the future.`
hasLink = false
break
case 'eic-manuscript-accepted-by-eqs':
hasIntro = false
hasSignature = false
paragraph = `A new ${titleText} has been submitted to ${journalName}.<br/><br/>
To begin the review process, please visit the manuscript details page.`
break
case 'eic-manuscript-returned-by-eqa':
hasIntro = false
hasSignature = false
paragraph = `We regret to inform you that ${titleText} has been returned with comments. Please click the link below to access the manuscript.<br/><br/>
Comments: ${comments}<br/><br/>`
break
default:
throw new Error(`The ${emailType} email type is not defined.`)
}
......
......@@ -568,6 +568,85 @@ class Notification {
fragmentHelper,
}
}
async notifyEiCWhenEQSAcceptsManuscript() {
const { submittingAuthor } = await this.getNotificationProperties()
const userHelper = new User({ UserModel: this.UserModel })
const editors = await userHelper.getEditorsInChief()
const fragmentHelper = new Fragment({ fragment: this.fragment })
const parsedFragment = await fragmentHelper.getFragmentData({})
const emailBodyProps = getEmailCopy({
emailType: 'eic-manuscript-accepted-by-eqs',
titleText: `manuscript titled "${parsedFragment.title}" by ${
submittingAuthor.firstName
} ${submittingAuthor.lastName}`,
})
editors.forEach(eic => {
const email = new Email({
type: 'system',
toUser: {
email: eic.email,
},
fromEmail: `${journalName} <${staffEmail}>`,
content: {
subject: `${this.collection.customId}: New manuscript submitted`,
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: this.baseUrl,
ctaLink: services.createUrl(
this.baseUrl,
`/projects/${this.collection.id}/versions/${
this.fragment.id
}/details`,
),
},
})
const { html, text } = email.getNotificationBody({ emailBodyProps })
email.sendEmail({ html, text })
})
}
async notifyEiCWhenEQARejectsManuscript(comments) {
const { titleText } = await this.getNotificationProperties()
const userHelper = new User({ UserModel: this.UserModel })
const editors = await userHelper.getEditorsInChief()
const emailBodyProps = getEmailCopy({
comments,
titleText,
emailType: 'eic-manuscript-returned-by-eqa',
})
editors.forEach(eic => {
const email = new Email({
type: 'system',
toUser: {
email: eic.email,
},
fromEmail: `${journalName} <${staffEmail}>`,
content: {
subject: `${
this.collection.customId
}: Manuscript returned with comments`,
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: this.baseUrl,
ctaLink: services.createUrl(
this.baseUrl,
`/projects/${this.collection.id}/versions/${
this.fragment.id
}/details`,
),
},
})
const { html, text } = email.getNotificationBody({ emailBodyProps })
email.sendEmail({ html, text })
})
}
}
module.exports = Notification
......@@ -4,7 +4,7 @@ const {
Collection,
} = require('pubsweet-component-helper-service')
const Notification = require('./notifications/notification')
const Notification = require('../../notifications/notification')
module.exports = models => async (req, res) => {
const { collectionId, fragmentId, recommendationId } = req.params
......
......@@ -30,8 +30,7 @@ const sendMTSPackage = async (collection, fragment) => {
await MTS.sendPackage({ fragment: packageFragment })
}
// const notifications = require('./notifications/notifications')
const Notification = require('./notifications/notification')
const Notification = require('../../notifications/notification')
module.exports = models => async (req, res) => {
const { recommendation, comments, recommendationType } = req.body
......@@ -167,7 +166,10 @@ module.exports = models => async (req, res) => {
}
}
if (recommendation !== 'publish' || hasEQA) {
if (
recommendation !== 'return-to-handling-editor' &&
(recommendation !== 'publish' || hasEQA)
) {
notification.notifyAuthorsWhenEiCMakesDecision()
}
} else {
......
const config = require('config')
// const staffEmail = config.get('journal.staffEmail')
const journalName = config.get('journal.name')
const getEmailCopy = ({ emailType, titleText, comments }) => {
let paragraph
let hasLink = true
let hasIntro = true
let hasSignature = true
switch (emailType) {
case 'eqs-manuscript-accepted':
hasIntro = false
hasSignature = false
paragraph = `A new ${titleText} has been submitted to ${journalName}.<br/><br/>
To begin the review process, please visit the manuscript details page.`
break
case 'he-manuscript-published':
hasLink = false
paragraph = `Thank you for your recommendation to publish ${titleText} based on the reviews you received.<br/><br/>
I can confirm this article will now go through to publication.`
break
case 'author-manuscript-published':
paragraph = `I am delighted to inform you that ${titleText} has passed through the review process and will be published in Hindawi.<br/><br/>
Thanks again for choosing to publish with us.`
hasLink = false
break
case 'submitted-reviewers-after-publish':
hasLink = false
paragraph = `Thank you for your review on ${titleText}. After taking into account the reviews and the recommendation of the Handling Editor, I can confirm this article will now be published.<br/><br/>
If you have any queries about this decision, then please email them to Hindawi as soon as possible.`
break
case 'eqa-manuscript-returned-to-eic':
paragraph = `We regret to inform you that ${titleText} has been returned with comments. Please click the link below to access the manuscript.<br/><br/>
Comments: ${comments}<br/><br/>`
break
default:
throw new Error(`The ${emailType} email type is not defined.`)
}
return { paragraph, hasLink, hasIntro, hasSignature }
}
module.exports = {
getEmailCopy,
}
const config = require('config')
const Email = require('@pubsweet/component-email-templating')
const {
User,
services,
Fragment,
} = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy')
const { name: journalName, staffEmail } = config.get('journal')
module.exports = {
async sendNotifications({
agree,
baseUrl,
collection,
comments = '',
User: UserModel,
Fragment: FragmentModel,
}) {
const fragment = await FragmentModel.find(collection.fragments[0])
const fragmentHelper = new Fragment({ fragment })
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor,
})
const { submittingAuthor } = await fragmentHelper.getAuthorData({
UserModel,
})
const titleText = `manuscript titled "${parsedFragment.title}" by ${
submittingAuthor.firstName
} ${submittingAuthor.lastName}`
const subjectBaseText = `${collection.customId}: Manuscript`
const { customId } = collection
const userHelper = new User({ UserModel })
const subject = `${subjectBaseText} ${
agree ? '' : 'Not '
}Passed Technical Checks`
const email = new Email({
type: 'user',
fromEmail: `${journalName} <${staffEmail}>`,
content: {
subject,
signatureName: 'EQA Team',
ctaLink: services.createUrl(
baseUrl,
`/projects/${collection.id}/versions/${fragment.id}/details`,
),
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: baseUrl,
},
})
sendEditorsEmail({
email,
agree,
customId,
comments,
titleText,
userHelper,
})
},
}
const sendEditorsEmail = async ({
email,
agree,
titleText,
customId,
userHelper,
comments = '',
}) => {
email.content.subject = `${customId}: New manuscript submitted`
const emailType = agree
? 'eqs-manuscript-accepted'
: 'eqa-manuscript-returned-to-eic'
const editors = (await userHelper.getEditorsInChief()).map(eic => ({
...eic,
...getEmailCopy({
emailType,
titleText,
comments,
}),
}))
editors.forEach(eic => {
email.toUser = {
email: eic.email,
name: `${eic.firstName} ${eic.lastName}`,
}
const { html, text } = email.getNotificationBody({
emailBodyProps: {
paragraph: eic.paragraph,
hasLink: eic.hasLink,
hasIntro: eic.hasIntro,
hasSignature: eic.hasSignature,
},
})
email.sendEmail({ html, text })
})
}
const { get, find, isEmpty, last } = require('lodash')
const { services } = require('pubsweet-component-helper-service')
const {
sendNotifications: sendEQSNotifications,
} = require('./notifications/notifications')
const Notification = require('../fragmentsRecommendations/notifications/notification')
const Notification = require('../../notifications/notification')
const TECHNICAL_STEPS = {
EQS: 'eqs',
......@@ -68,36 +64,33 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
collection.status = setNewStatus(step, agree)
await collection.save()
const isEQA = get(collection, 'technicalChecks.eqa', false)
const baseUrl = services.getBaseUrl(req)
if (isEQA) {
// the EA accepted the manuscript so we need to notify users of the final publication
const fragment = await Fragment.find(last(collection.fragments))
const notification = new Notification({
fragment,
collection,
UserModel: User,
baseUrl: services.getBaseUrl(req),
newRecommendation: {
recommendation: 'publish',
recommendationType: 'editorRecommendation',
},
})
notification.notifyAuthorsWhenEiCMakesDecision()
const hasPeerReview = !isEmpty(collection.handlingEditor)
if (hasPeerReview) {
notification.notifyHEWhenEiCMakesDecision()
notification.notifyReviewersWhenEiCMakesDecision()
const fragment = await Fragment.find(last(collection.fragments))
const notification = new Notification({
fragment,
collection,
UserModel: User,
baseUrl: services.getBaseUrl(req),
newRecommendation: {
recommendation: 'publish',
recommendationType: 'editorRecommendation',
},
})
if (step === TECHNICAL_STEPS.EQA) {
const hasPassedEQA = get(collection, 'technicalChecks.eqa')
if (hasPassedEQA) {
// the EA accepted the manuscript so we need to notify users of the final publication decision
notification.notifyAuthorsWhenEiCMakesDecision()
const hasPeerReview = !isEmpty(collection.handlingEditor)
if (hasPeerReview) {
notification.notifyHEWhenEiCMakesDecision()
notification.notifyReviewersWhenEiCMakesDecision()
}
} else {
notification.notifyEiCWhenEQARejectsManuscript(comments)
}
} else {
sendEQSNotifications({
User,
agree,
comments,
Fragment,
collection,
baseUrl,
})
} else if (agree) {
notification.notifyEiCWhenEQSAcceptsManuscript()
}
return res.status(200).json(collection)
......
......@@ -306,8 +306,6 @@ describe('Post fragments recommendations route handler', () => {
delete fragment.recommendations
delete fragment.revision
delete fragment.invitations
delete collection.invitations
delete collection.handlingEditor
collection.technicalChecks.eqa = false
const res = await requests.sendRequest({
......
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