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

Merge branch 'add-he-to-manuscript' into 'master'

Add he to manuscript

See merge request !2
parents c511b3fa 526c14ff
No related branches found
No related tags found
1 merge request!2Add he to manuscript
......@@ -8,10 +8,10 @@ module.exports = {
'http://localhost:3000/invite',
},
roles: {
global: ['admin', 'editorInChief', 'author'],
global: ['admin', 'editorInChief', 'author', 'handlingEditor'],
collection: ['handlingEditor', 'reviewer'],
inviteRights: {
admin: ['admin', 'editorInChief', 'author'],
admin: ['admin', 'editorInChief', 'author', 'handlingEditor'],
editorInChief: ['handlingEditor'],
handlingEditor: ['reviewer'],
},
......
......@@ -63,12 +63,19 @@ module.exports = async (
try {
let user = await models.User.findByEmail(email)
const team = await teamHelper.setupManuscriptTeam(
models,
user,
let team = teamHelper.getTeamByGroupAndCollection(
collectionId,
role,
models.Team,
)
if (team === undefined) {
team = await teamHelper.setupManuscriptTeam(
models,
user,
collectionId,
role,
)
}
// getting the updated user from the DB - creating a team also updates the user
user = await models.User.findByEmail(email)
......@@ -84,7 +91,7 @@ module.exports = async (
return res.status(200).json(user)
} catch (e) {
logger.error(e)
return res.status(500).json({ error: 'Mailing could not be sent.' })
return res.status(500).json({ error: 'Mail could not be sent.' })
}
} catch (e) {
const notFoundError = await helpers.handleNotFoundError(e, 'user')
......
......@@ -166,6 +166,16 @@ const getInviteData = (invitations, collectionId, role) => {
return { timestamp, status }
}
const getTeamByGroupAndCollection = async (collectionId, role, TeamModel) => {
const teams = await TeamModel.all()
return teams.find(
team =>
team.group === role &&
team.object.type === 'collection' &&
team.object.id === collectionId,
)
}
module.exports = {
createNewTeam,
setupEiCTeams,
......@@ -175,4 +185,5 @@ module.exports = {
removeTeamMember,
getTeamMembersByCollection,
getInviteData,
getTeamByGroupAndCollection,
}
......@@ -96,6 +96,7 @@ const createNewUser = async (
title,
editorInChief: role === 'editorInChief',
admin: role === 'admin',
handlingEditor: role === 'handlingEditor',
}
let newUser = new UserModel(userBody)
try {
......
......@@ -30,7 +30,7 @@ module.exports = models => async (req, res) => {
const collectionId = get(req, 'params.collectionId')
const url = `${req.protocol}://${req.get('host')}`
if (collectionId) {
if (collectionId)
return require('../controllers/assignCollectionRole')(
email,
role,
......@@ -40,7 +40,6 @@ module.exports = models => async (req, res) => {
models,
url,
)
}
if (reqUser.admin)
return require('../controllers/inviteGlobalRole')(
......
......@@ -6,6 +6,9 @@ const random = require('lodash/random')
const fixtures = require('./fixtures/fixtures')
const Chance = require('chance')
const Model = require('./helpers/Model')
const config = require('config')
const configRoles = config.get('roles')
const models = Model.build()
jest.mock('pubsweet-component-mail-service', () => ({
......@@ -13,9 +16,7 @@ jest.mock('pubsweet-component-mail-service', () => ({
setupAssignEmail: jest.fn(),
}))
const chance = new Chance()
const globalRoles = ['editorInChief', 'author', 'admin']
const manuscriptRoles = ['handlingEditor', 'reviewer']
const globalRoles = configRoles.global
const body = {
email: chance.email(),
role: globalRoles[random(0, globalRoles.length - 1)],
......@@ -48,7 +49,7 @@ describe('Post invite route handler', () => {
expect(data.email).toEqual(body.email)
expect(data.admin).toEqual(body.admin)
})
it('should return an error when the admin invites an user on a collection', async () => {
it('should return an error when the admin invites a user on a collection', async () => {
const req = httpMocks.createRequest({
body,
})
......@@ -62,8 +63,8 @@ describe('Post invite route handler', () => {
`admin cannot invite an ${body.role} to a collection`,
)
})
it('should return an error when the admin invites a manuscript role', async () => {
body.role = manuscriptRoles[random(0, manuscriptRoles.length - 1)]
it('should return an error when the admin invites a reviewer', async () => {
body.role = 'reviewer'
body.admin = false
const req = httpMocks.createRequest({
body,
......@@ -76,6 +77,7 @@ describe('Post invite route handler', () => {
expect(data.error).toEqual(
`admin tried to invite an invalid role: ${body.role}`,
)
body.role = globalRoles[random(0, globalRoles.length - 1)]
})
it('should return an error params are missing', async () => {
delete body.email
......
......@@ -48,10 +48,10 @@ module.exports = {
url: process.env.PUBSWEET_INVITE_PASSWORD_RESET_URL || '/invite',
},
roles: {
global: ['admin', 'editorInChief', 'author'],
global: ['admin', 'editorInChief', 'author', 'handlingEditor'],
collection: ['handlingEditor', 'reviewer'],
inviteRights: {
admin: ['admin', 'editorInChief', 'author'],
admin: ['admin', 'editorInChief', 'author', 'handlingEditor'],
editorInChief: ['handlingEditor'],
handlingEditor: ['reviewer'],
},
......
......@@ -97,6 +97,7 @@ module.exports = {
invitations: Joi.array(),
teams: Joi.array(),
editorInChief: Joi.boolean(),
handlingEditor: Joi.boolean(),
},
team: {
group: Joi.string(),
......
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