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

Merge branch 'HIN-1244-added-users-emails' into 'develop'

Hin 1244 added users emails

See merge request !211
parents 67a7daae ac9238f6
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!211Hin 1244 added users emails
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
"precommit": "lint-staged", "precommit": "lint-staged",
"styleguide": "cd packages/styleguide && yarn styleguide", "styleguide": "cd packages/styleguide && yarn styleguide",
"test": "lerna run test", "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": { "lint-staged": {
"*.js": [ "*.js": [
......
const config = require('config') const config = require('config')
const journalName = config.get('journal.name') const journalName = config.get('journal.name')
const getEmailCopy = ({ emailType, role }) => { const getEmailCopyForUsersAddedByAdmin = ({ role }) => {
let paragraph let paragraph
let hasIntro = true let hasIntro = true
let hasSignature = true const hasSignature = true
switch (emailType) { switch (role) {
case 'user-signup': case 'admin':
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':
hasIntro = false hasIntro = false
hasSignature = false paragraph = `You have been invited to join Hindawi as an Administrator.
paragraph = `You have been invited to join Hindawi as a ${role}. 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.` Please confirm your account and set your account details by clicking on the link below.`
break break
case 'he-added-by-admin': case 'handlingEditor':
paragraph = `You have been invited to become an Academic Editor for the journal ${journalName}. 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/> 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.` Please confirm your account details by clicking on the link below.`
break break
default: 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 } return { paragraph, hasLink: true, hasIntro, hasSignature }
} }
module.exports = { module.exports = {
getEmailCopy, getEmailCopyForUsersAddedByAdmin,
} }
...@@ -2,7 +2,7 @@ const config = require('config') ...@@ -2,7 +2,7 @@ const config = require('config')
const Email = require('@pubsweet/component-email-templating') const Email = require('@pubsweet/component-email-templating')
const { services } = require('pubsweet-component-helper-service') const { services } = require('pubsweet-component-helper-service')
const { getEmailCopy } = require('./emailCopy') const { getEmailCopyForUsersAddedByAdmin } = require('./emailCopy')
const { name: journalName, staffEmail } = config.get('journal') const { name: journalName, staffEmail } = config.get('journal')
const unsubscribeSlug = config.get('unsubscribe.url') const unsubscribeSlug = config.get('unsubscribe.url')
...@@ -16,12 +16,9 @@ class Notification { ...@@ -16,12 +16,9 @@ class Notification {
const resetPath = config.get('invite-reset-password.url') const resetPath = config.get('invite-reset-password.url')
const { user } = this const { user } = this
const baseUrl = config.get('pubsweet-client.baseUrl') 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, role,
emailType,
}) })
const email = new Email({ const email = new Email({
...@@ -47,6 +44,7 @@ class Notification { ...@@ -47,6 +44,7 @@ class Notification {
id: user.id, id: user.id,
token: user.accessTokens.unsubscribe, token: user.accessTokens.unsubscribe,
}), }),
signatureJournal: journalName,
}, },
bodyProps, bodyProps,
}) })
......
...@@ -12,13 +12,14 @@ const { ...@@ -12,13 +12,14 @@ const {
const resolvers = { const resolvers = {
Mutation: { Mutation: {
async addUserAsAdmin(_, { input }, ctx) { async addUserAsAdmin(_, { input }, ctx) {
ctx.parseUserFromAdmin = parseUserFromAdmin
return createUserAsAdmin return createUserAsAdmin
.initialize({ .initialize({
ctx, ctx,
Notification, Notification,
User: ctx.connectors.User, User: ctx.connectors.User,
}) })
.execute({ input: parseUserFromAdmin(input) }) .execute({ input })
}, },
async editUserAsAdmin(_, { id, input }, ctx) { async editUserAsAdmin(_, { id, input }, ctx) {
return editUser return editUser
......
...@@ -22,12 +22,13 @@ describe('create user', () => { ...@@ -22,12 +22,13 @@ describe('create user', () => {
models = Model.build(testFixtures) models = Model.build(testFixtures)
}) })
it('edit an user as admin', async () => { it('create an user as admin', async () => {
const input = { const input = {
email: 'alexandrescu@gmail.com', email: 'alexandrescu@gmail.com',
username: 'alexandrescu@gmail.com', username: 'alexandrescu@gmail.com',
} }
const ctx = { const ctx = {
parseUserFromAdmin: i => i,
user: { user: {
admin: true, admin: true,
}, },
......
...@@ -5,7 +5,7 @@ module.exports.initialize = ({ User, Notification, ctx }) => ({ ...@@ -5,7 +5,7 @@ module.exports.initialize = ({ User, Notification, ctx }) => ({
throw new Error('Unauthorized') 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) const notification = new Notification(user)
await notification.notifyUserAddedByAdmin(input.role) 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