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