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

Merge branch 'hin-1036' into 'develop'

Hin 1036

See merge request !89
parents df203100 912c7905
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!150Develop,!89Hin 1036
Showing
with 519 additions and 195 deletions
......@@ -47,3 +47,9 @@ Contact us at technology@hindawi.com for help getting setup.
## Community
Join [the Mattermost channel](https://mattermost.coko.foundation/coko/channels/xpub) for discussion of xpub.
## Migrations
1. use folder `./packages/xpub-faraday/migrations`
2. add file named `${number}-${name}(.sql/.js)` e.g. `001-user-add-name-field.sql`
......@@ -254,11 +254,11 @@ export const currentUserIsAuthor = (state, id) => {
.includes(id)
}
export const getUserPermissions = ({ currentUser }) =>
get(currentUser, 'user.teams', []).map(t => ({
objectId: t.object.id,
objectType: t.object.type,
role: t.teamType.permissions,
export const getUserPermissions = ({ teams = [] }) =>
teams.map(t => ({
objectId: get(t, 'object.id', ''),
objectType: get(t, 'object.type', ''),
role: get(t, 'teamType.permissions', ''),
}))
export const userNotConfirmed = ({ currentUser }) =>
......
......@@ -9,7 +9,14 @@ class User {
async createUser({ role, body }) {
const { UserModel } = this
const { email, firstName, lastName, affiliation, title, country } = body
const {
email,
firstName,
lastName,
affiliation,
title = 'Dr',
country,
} = body
const username = email
const password = uuid.v4()
const userBody = {
......@@ -33,7 +40,7 @@ class User {
},
},
accessTokens: {
invitation: role === 'reviewer' ? services.generateHash() : undefined,
invitation: role === 'reviewer' ? services.generateHash() : null,
unsubscribe: services.generateHash(),
passwordReset: services.generateHash(),
},
......
const logger = require('@pubsweet/logger')
const {
Team,
User,
......@@ -14,11 +12,19 @@ const emailInvitations = require('./emails/invitations')
const { last } = require('lodash')
module.exports = models => async (req, res) => {
const { email, role } = req.body
if (!services.checkForUndefinedParams(email, role)) {
res.status(400).json({ error: 'Email and role are required.' })
logger.error('User ID and role are missing')
const { email, role, firstName, lastName, affiliation, country } = req.body
if (
!services.checkForUndefinedParams(
email,
role,
firstName,
lastName,
affiliation,
country,
)
) {
res.status(400).json({ error: 'Missing parameters.' })
return
}
......@@ -130,7 +136,7 @@ module.exports = models => async (req, res) => {
const userHelper = new User({ UserModel })
const userData = req.body
const { firstName = '', lastName = '', isPublons } = userData
const { firstName, lastName, isPublons } = userData
if (!services.checkForUndefinedParams(firstName, lastName)) {
return res
.status(400)
......
......@@ -21,6 +21,7 @@ const reqBody = {
title: 'Mr',
affiliation: chance.company(),
admin: false,
country: chance.country(),
}
const route = {
path: '/api/collections/:collectionId/fragments/:fragmentId/invitations',
......@@ -49,17 +50,18 @@ describe('Post fragments invitations route handler', () => {
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Email and role are required.')
expect(data.error).toEqual('Missing parameters.')
})
it('should return success when a reviewer is invited', async () => {
const { user, editorInChief } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
body = {
body = Object.assign(body, {
email: user.email,
role: 'reviewer',
}
})
const res = await requests.sendRequest({
body,
userId: editorInChief.id,
......@@ -109,10 +111,12 @@ describe('Post fragments invitations route handler', () => {
const { answerReviewer, handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
body = {
body = Object.assign(body, {
email: answerReviewer.email,
role: 'reviewer',
}
})
const res = await requests.sendRequest({
body,
userId: handlingEditor.id,
......@@ -155,10 +159,12 @@ describe('Post fragments invitations route handler', () => {
const { inactiveUser, handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
body = {
body = Object.assign(body, {
email: inactiveUser.email,
role: 'reviewer',
}
})
const res = await requests.sendRequest({
body,
userId: handlingEditor.id,
......
......@@ -95,6 +95,7 @@ export default compose(
actions.getCollection({ id: match.params.project }),
actions.getFragments({ id: match.params.project }),
actions.getUsers(),
actions.getTeams(),
]),
connect(
(state, { match }) => ({
......
......@@ -17,7 +17,11 @@ import { Dashboard } from './'
import { priorityFilter, orderFilter, withFiltersHOC } from '../Filters'
export default compose(
ConnectPage(() => [actions.getCollections(), actions.getUsers()]),
ConnectPage(() => [
actions.getCollections(),
actions.getUsers(),
actions.getTeams(),
]),
connect(
state => {
const { collections, conversion } = state
......
const logger = require('@pubsweet/logger')
const startServer = require('pubsweet-server')
const { startServer } = require('pubsweet-server')
require('dotenv').config()
startServer().catch(err => {
......
......@@ -158,6 +158,12 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
models: context.models,
})
}
if (get(object, 'path', '') === '/teams') {
return {
filter: teams => teams.filter(t => user.teams.includes(t.id)),
}
}
}
if (operation === 'POST') {
......@@ -197,12 +203,12 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
}
if (operation === 'PATCH') {
if (get(object, 'type') === 'collection') {
return helpers.isOwner({ user, object })
if (get(object.current, 'type') === 'collection') {
return helpers.isOwner({ user, object: object.current })
}
if (get(object, 'type') === 'fragment') {
return helpers.isOwner({ user, object })
if (get(object.current, 'type') === 'fragment') {
return helpers.isOwner({ user, object: object.current })
}
// allow reviewer to patch (accept/decline) his invitation
......
......@@ -35,6 +35,9 @@ module.exports = {
pubsweet: {
components,
},
dbManager: {
migrationsPath: path.join(process.cwd(), 'migrations'),
},
'pubsweet-server': {
db: getDbConfig(),
port: 3000,
......
......@@ -166,10 +166,13 @@ module.exports = {
confirmation: Joi.string().allow(''),
passwordReset: Joi.string().allow(''),
unsubscribe: Joi.string().allow(''),
invitation: Joi.string().allow(''),
invitation: Joi.string().allow(null),
}),
},
team: {
name: Joi.string(),
type: Joi.string(),
group: Joi.string(),
teamType: Joi.object(),
},
}
......@@ -26,11 +26,11 @@
"moment": "^2.18.1",
"nodemailer-ses-transport": "^1.5.1",
"prop-types": "^15.5.10",
"pubsweet": "^2.2.1",
"pubsweet": "3.0.6",
"pubsweet-client": "^4.0.4",
"pubsweet-component-login": "^1.1.0",
"pubsweet-component-signup": "^1.0.0",
"pubsweet-server": "2.0.3",
"pubsweet-server": "10.0.1",
"react": "^16.4.2",
"react-dnd": "^2.5.4",
"react-dnd-html5-backend": "^2.5.4",
......@@ -81,8 +81,7 @@
"start": "pubsweet start",
"start:services": "docker-compose up postgres",
"server": "pubsweet server",
"start-now":
"echo $secret > config/local-development.json && npm run server",
"start-now": "echo $secret > config/local-development.json && npm run server",
"build": "NODE_ENV=production pubsweet build",
"clean": "rm -rf node_modules",
"debug": "pgrep -f startup/start.js | xargs kill -sigusr1",
......
This diff is collapsed.
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