Skip to content
Snippets Groups Projects
Commit ac9238f6 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into HIN-1244-added-users-emails

parents 20970d95 f900c13a
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!211Hin 1244 added users emails
......@@ -64,6 +64,13 @@ class User {
return eics
}
async isAdmin(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)
......
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true
const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service')
const { fixtures, Model } = fixturesService
const { User } = require('../Helper')
describe('User helper', () => {
let testFixtures = {}
let models
beforeEach(() => {
testFixtures = cloneDeep(fixtures)
models = Model.build(testFixtures)
})
describe('isAdmin', () => {
it('should return true if user is admin', async () => {
const { admin } = testFixtures.users
const adminId = admin.id
const UserModel = models.User
const userHelper = new User({ UserModel })
const isAdmin = await userHelper.isAdmin(adminId)
expect(isAdmin).toBe(true)
})
it('should return false if user is not admin', async () => {
const { reviewer } = testFixtures.users
const reviewerId = reviewer.id
const UserModel = models.User
const userHelper = new User({ UserModel })
const isAdmin = await userHelper.isAdmin(reviewerId)
expect(isAdmin).toBe(false)
})
})
})
......@@ -62,7 +62,7 @@ module.exports = models => async (req, res) => {
fragment.files.manuscripts,
fragment.files.coverLetter,
fragment.files.supplementary,
fragmentId,
{ id: fragmentId },
)
fileKeys = fileKeys.map(file => file.id)
......
const config = require('config')
const { get } = require('lodash')
const { get, tail } = require('lodash')
const Email = require('@pubsweet/component-email-templating')
const {
......@@ -55,6 +55,9 @@ 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.isAdmin(owner))
const handlingEditor = get(collection, 'handlingEditor')
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor,
......@@ -70,7 +73,7 @@ module.exports = {
submittingAuthor.lastName
}`
const userEmailData = await Promise.all(
let userEmailData = await Promise.all(
fragmentAuthors.map(async author => {
const { paragraph, ...bodyProps } = getEmailCopy({
emailType: author.isSubmitting
......@@ -95,6 +98,10 @@ module.exports = {
}),
)
if (adminOwner) {
userEmailData = tail(userEmailData)
}
userEmailData.forEach(({ author, paragraph, bodyProps }) => {
const email = new Email({
type: 'user',
......@@ -142,7 +149,6 @@ module.exports = {
})
email.content.ctaText = 'CONFIRM ACCOUNT'
}
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