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

fix(component-user): fix role in users added by admin emails

parent 6575f403
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!211Hin 1244 added users emails
......@@ -35,7 +35,9 @@
"precommit": "lint-staged",
"styleguide": "cd packages/styleguide && yarn styleguide",
"test": "lerna run test",
"start": "docker-compose up"
"start": "docker-compose up",
"start:services": "cd packages/xpub-faraday && yarn start:services",
"server": "cd packages/xpub-faraday && yarn server"
},
"lint-staged": {
"*.js": ["prettier --write"],
......
const config = require('config')
const journalName = config.get('journal.name')
const getEmailCopy = ({ emailType, role }) => {
const getEmailCopyForUsersAddedByAdmin = ({ role }) => {
let paragraph
let hasIntro = true
let hasSignature = true
switch (emailType) {
case 'user-signup':
paragraph = `Thank you for creating an account on Hindawi’s review system.
To submit a manuscript and access your dashboard, please confirm your account by clicking on the link below.`
break
case 'user-added-by-admin':
const hasSignature = true
switch (role) {
case 'admin':
hasIntro = false
hasSignature = false
paragraph = `You have been invited to join Hindawi as a ${role}.
paragraph = `You have been invited to join Hindawi as an Administrator.
Please confirm your account and set your account details by clicking on the link below.`
break
case 'editorInChief':
paragraph = `You have been invited to join Hindawi as an Editor in Chief.
Please confirm your account and set your account details by clicking on the link below.`
break
case 'he-added-by-admin':
case 'handlingEditor':
paragraph = `You have been invited to become an Academic Editor for the journal ${journalName}.
To begin performing your editorial duties, you will need to create an account on Hindawi’s review system.<br/><br/>
Please confirm your account details by clicking on the link below.`
break
default:
throw new Error(`The ${emailType} email type is not defined.`)
paragraph = `You have been invited to join Hindawi as an Author.
Please confirm your account and set your account details by clicking on the link below.`
}
return { paragraph, hasLink: true, hasIntro, hasSignature }
}
module.exports = {
getEmailCopy,
getEmailCopyForUsersAddedByAdmin,
}
......@@ -2,7 +2,7 @@ const config = require('config')
const Email = require('@pubsweet/component-email-templating')
const { services } = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy')
const { getEmailCopyForUsersAddedByAdmin } = require('./emailCopy')
const { name: journalName, staffEmail } = config.get('journal')
const unsubscribeSlug = config.get('unsubscribe.url')
......@@ -16,12 +16,9 @@ class Notification {
const resetPath = config.get('invite-reset-password.url')
const { user } = this
const baseUrl = config.get('pubsweet-client.baseUrl')
const emailType =
role === 'Handling Editor' ? 'he-added-by-admin' : 'user-added-by-admin'
const { paragraph, ...bodyProps } = getEmailCopy({
const { paragraph, ...bodyProps } = getEmailCopyForUsersAddedByAdmin({
role,
emailType,
})
const email = new Email({
......@@ -47,6 +44,7 @@ class Notification {
id: user.id,
token: user.accessTokens.unsubscribe,
}),
signatureJournal: journalName,
},
bodyProps,
})
......
......@@ -12,13 +12,14 @@ const {
const resolvers = {
Mutation: {
async addUserAsAdmin(_, { input }, ctx) {
ctx.parseUserFromAdmin = parseUserFromAdmin
return createUserAsAdmin
.initialize({
ctx,
Notification,
User: ctx.connectors.User,
})
.execute({ input: parseUserFromAdmin(input) })
.execute({ input })
},
async editUserAsAdmin(_, { id, input }, ctx) {
return editUser
......
......@@ -22,12 +22,13 @@ describe('create user', () => {
models = Model.build(testFixtures)
})
it('edit an user as admin', async () => {
it('create an user as admin', async () => {
const input = {
email: 'alexandrescu@gmail.com',
username: 'alexandrescu@gmail.com',
}
const ctx = {
parseUserFromAdmin: i => i,
user: {
admin: true,
},
......
......@@ -5,7 +5,7 @@ module.exports.initialize = ({ User, Notification, ctx }) => ({
throw new Error('Unauthorized')
}
const user = await User.create(input, ctx)
const user = await User.create(ctx.parseUserFromAdmin(input), ctx)
const notification = new Notification(user)
await notification.notifyUserAddedByAdmin(input.role)
......
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