diff --git a/package.json b/package.json index e7ff3374fc518d9ee9c31f4960b3dfac930108c0..c6af25494be78f560fb5c7e213d7bd15b8399235 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/packages/component-user/server/notifications/emailCopy.js b/packages/component-user/server/notifications/emailCopy.js index b8c618a83b4b1a6cddea14520e5aa142adfc1cf4..d326488857808d4c38f5a5a40138f575af831506 100644 --- a/packages/component-user/server/notifications/emailCopy.js +++ b/packages/component-user/server/notifications/emailCopy.js @@ -1,33 +1,33 @@ 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, } diff --git a/packages/component-user/server/notifications/notification.js b/packages/component-user/server/notifications/notification.js index c32282a6e7cbd60bd91ec4eb24add9254fa4fc95..876e0c24df8d40e6e8e5e0f8a188751f138486ae 100644 --- a/packages/component-user/server/notifications/notification.js +++ b/packages/component-user/server/notifications/notification.js @@ -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, }) diff --git a/packages/component-user/server/resolvers.js b/packages/component-user/server/resolvers.js index dd914063955f0aeee31ef236bb7dd79e82f63aa7..832987e887a511d08d4c0da5b50d7dc69fcf4ede 100644 --- a/packages/component-user/server/resolvers.js +++ b/packages/component-user/server/resolvers.js @@ -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 diff --git a/packages/component-user/server/tests/createUserAsAdmin.test.js b/packages/component-user/server/tests/createUserAsAdmin.test.js index 80c3155a6d7fbbf00043cf714312d256e3146c97..148e99acf1d454450b16e4f179480332a54525a9 100644 --- a/packages/component-user/server/tests/createUserAsAdmin.test.js +++ b/packages/component-user/server/tests/createUserAsAdmin.test.js @@ -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, }, diff --git a/packages/component-user/server/use-cases/createUserAsAdmin.js b/packages/component-user/server/use-cases/createUserAsAdmin.js index 6a46215e4067744cd558983c6bd8aed3be95aacb..ec32a6680a137cc1b90bb1ed08d14c16a080a3d3 100644 --- a/packages/component-user/server/use-cases/createUserAsAdmin.js +++ b/packages/component-user/server/use-cases/createUserAsAdmin.js @@ -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)