Skip to content
Snippets Groups Projects
Commit 7ec69d53 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Merge branch 'develop' of https://gitlab.coko.foundation/xpub/xpub-faraday into develop

parents dd2c0097 d4dd91c6
No related branches found
No related tags found
1 merge request!58Sprint #20 - Goal - Reviewers submit report
...@@ -76,7 +76,9 @@ class Fragment { ...@@ -76,7 +76,9 @@ class Fragment {
) )
const userHelper = new User({ UserModel }) const userHelper = new User({ UserModel })
const activeAuthors = await userHelper.getActiveAuthors(authors) const activeAuthors = await userHelper.getActiveAuthors({
fragmentAuthors: authors,
})
return { return {
activeAuthors, activeAuthors,
......
...@@ -62,15 +62,25 @@ class User { ...@@ -62,15 +62,25 @@ class User {
user.save() user.save()
} }
async getActiveAuthors(authors) { async getActiveAuthors({ fragmentAuthors }) {
const activeUsers = (await Promise.all( const userData = (await Promise.all(
authors.map(author => this.UserModel.find(author.id)), fragmentAuthors.map(author => this.UserModel.find(author.id)),
)) ))
.filter(user => user.isActive) .filter(user => user.isActive && get(user, 'notifications.email.user'))
.filter(user => get(user, 'notifications.email.user')) .map(user => ({ id: user.id, accessTokens: user.accessTokens }))
.map(user => user.id)
return authors.filter(author => activeUsers.includes(author.id)) return fragmentAuthors
.map(fAuthor => {
const matchingAuthor = userData.find(user => user.id === fAuthor.id)
if (matchingAuthor) {
return {
...fAuthor,
accessTokens: matchingAuthor.accessTokens,
}
}
return false
})
.filter(Boolean)
} }
async getEiCName() { async getEiCName() {
......
...@@ -85,9 +85,7 @@ class Email { ...@@ -85,9 +85,7 @@ class Email {
logger.info( logger.info(
`EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`, `EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`,
) )
logger.debug(
`EMAIL: Sent email from ${from} to ${to} with subject '${subject}'`,
)
SendEmail.send(mailData) SendEmail.send(mailData)
} }
} }
......
...@@ -109,6 +109,12 @@ const getEmailCopy = ({ ...@@ -109,6 +109,12 @@ const getEmailCopy = ({
paragraph = `${titleText} has been accepted for publication by ${eicName}. <br/><br/> paragraph = `${titleText} has been accepted for publication by ${eicName}. <br/><br/>
Please complete QA screening so that manuscript can be sent to production.` Please complete QA screening so that manuscript can be sent to production.`
break break
case 'authors-manuscript-rejected-before-review':
paragraph = `I regret to inform you that your manuscript has been rejected for publication in ${journalName} for the following reason:<br/><br/>
${comments}<br/><br/>
Thank you for your submission, and please do consider submitting again in the future.`
hasLink = false
break
default: default:
throw new Error(`The ${emailType} email type is not defined.`) throw new Error(`The ${emailType} email type is not defined.`)
} }
......
...@@ -378,14 +378,19 @@ module.exports = { ...@@ -378,14 +378,19 @@ module.exports = {
return email return email
}, },
getEmailTypeByRecommendationForAuthors: ({ recommendation }) => { getEmailTypeByRecommendationForAuthors: ({
recommendation,
hasPeerReview,
}) => {
let emailType let emailType
switch (recommendation) { switch (recommendation) {
case 'publish': case 'publish':
emailType = 'author-manuscript-published' emailType = 'author-manuscript-published'
break break
case 'reject': case 'reject':
emailType = 'author-manuscript-rejected' emailType = hasPeerReview
? 'author-manuscript-rejected'
: 'authors-manuscript-rejected-before-review'
break break
default: default:
throw new Error(`Undefined recommendation: ${recommendation}`) throw new Error(`Undefined recommendation: ${recommendation}`)
......
...@@ -68,8 +68,7 @@ module.exports = { ...@@ -68,8 +68,7 @@ module.exports = {
}) })
} }
const hasPeerReview = (collection = {}) => const hasPeerReview = !isEmpty(collection.handlingEditor)
!isEmpty(collection.handlingEditor)
const { customId } = collection const { customId } = collection
const collHelper = new Collection({ collection }) const collHelper = new Collection({ collection })
...@@ -77,7 +76,7 @@ module.exports = { ...@@ -77,7 +76,7 @@ module.exports = {
// or when the EiC makes a recommendation after peer review // or when the EiC makes a recommendation after peer review
if ( if (
(isEditorInChief || recommendationType === 'review') && (isEditorInChief || recommendationType === 'review') &&
hasPeerReview(collection) && hasPeerReview &&
(recommendation !== 'publish' || hasEQA) (recommendation !== 'publish' || hasEQA)
) { ) {
const handlingEditor = get(collection, 'handlingEditor', {}) const handlingEditor = get(collection, 'handlingEditor', {})
...@@ -118,10 +117,18 @@ module.exports = { ...@@ -118,10 +117,18 @@ module.exports = {
// send all authors email // send all authors email
const emailType = helpers.getEmailTypeByRecommendationForAuthors({ const emailType = helpers.getEmailTypeByRecommendationForAuthors({
recommendation, recommendation,
hasPeerReview,
}) })
const comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation, let comments
}) if (hasPeerReview) {
comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
} else {
comments = newRecommendation.comments[0].content
}
const authors = helpers.getAllAuthors({ const authors = helpers.getAllAuthors({
comments, comments,
emailType, emailType,
...@@ -156,7 +163,7 @@ module.exports = { ...@@ -156,7 +163,7 @@ module.exports = {
helpers.sendSubmittingAuthorEmail({ email, author, baseUrl }) helpers.sendSubmittingAuthorEmail({ email, author, baseUrl })
} }
if (!hasPeerReview(collection)) { if (!hasPeerReview) {
return return
} }
......
...@@ -13,7 +13,9 @@ module.exports = models => async (req, res) => { ...@@ -13,7 +13,9 @@ module.exports = models => async (req, res) => {
const { authors = [] } = await models.Fragment.find(fragmentId) const { authors = [] } = await models.Fragment.find(fragmentId)
const userHelper = new User({ UserModel: models.User }) const userHelper = new User({ UserModel: models.User })
const activeAuthors = await userHelper.getActiveAuthors(authors) const activeAuthors = await userHelper.getActiveAuthors({
fragmentAuthors: authors,
})
return res.status(200).json(activeAuthors) return res.status(200).json(activeAuthors)
} 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