diff --git a/packages/component-user-manager/src/FragmentsUsers.js b/packages/component-user-manager/src/FragmentsUsers.js index 464e84743fc1f91dbe46ecea8ba7683ac9ced3a4..d1137db20a48689daffd320458b63185511b84c6 100644 --- a/packages/component-user-manager/src/FragmentsUsers.js +++ b/packages/component-user-manager/src/FragmentsUsers.js @@ -110,58 +110,6 @@ const FragmentsUsers = app => { * HTTP/1.1 404 Not Found */ app.get(basePath, authBearer, require(`${routePath}/get`)(app.locals.models)) - /** - * @api {patch} /api/collections/:collectionId/fragments/:fragmentId/users/:userId Update a user on a fragment - * @apiGroup FragmentsUsers - * @apiParam {collectionId} collectionId Collection id - * @apiParam {fragmentId} fragmentId Fragment id - * @apiParam {userId} userId User id - * @apiParamExample {json} Body - * { - * "isSubmitting": false, - * "isCorresponding": true, - * "firstName": "John", - * "lastName": "Smith", - * "affiliation": "UCLA" - * } - * @apiSuccessExample {json} Success - * HTTP/1.1 200 OK - * { - * "id": "c95a0f57-780d-4362-9964-7c1af566549b", - * "type": "fragment", - * "files": {}, - * "owners": [ - * { - * "id": "4be1d28d-4973-47bc-8732-16d4a1a735ef", - * "username": "admin" - * } - * ], - * "created": "2018-05-04T10:50:19.053Z", - * "version": 1, - * "metadata": { - * "title": "<p>Test Manuscript Title</p>", - * "abstract": "<p>Test manuscript abstract</p>" - * }, - * "fragmentType": "version", - * "authors": [ - * { - * "userId": "a6184463-b17a-42f8-b02b-ae1d755cdc6b", - * "isSubmitting": false, - * "isCorresponding": true - * } - * ], - * } - * @apiErrorExample {json} Update invitations errors - * HTTP/1.1 403 Forbidden - * HTTP/1.1 400 Bad Request - * HTTP/1.1 404 Not Found - * HTTP/1.1 500 Internal Server Error - */ - app.patch( - `${basePath}/:userId`, - authBearer, - require(`${routePath}/patch`)(app.locals.models), - ) } module.exports = FragmentsUsers diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/get.js b/packages/component-user-manager/src/routes/fragmentsUsers/get.js index 75385a1b54016c0a31d95371206bb9ca353f04c7..76ef6041615e728b141e04f537ae6b67e643dd86 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/get.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/get.js @@ -1,4 +1,4 @@ -const { Team, services } = require('pubsweet-component-helper-service') +const { services } = require('pubsweet-component-helper-service') module.exports = models => async (req, res) => { // TO DO: add authsome @@ -9,35 +9,9 @@ module.exports = models => async (req, res) => { return res.status(400).json({ error: `Fragment ${fragmentId} does not match collection ${collectionId}`, }) - const fragment = await models.Fragment.find(fragmentId) - if (fragment.authors === undefined) { - return res.status(200).json([]) - } - const teamHelper = new Team({ TeamModel: models.Team, fragmentId }) - const members = await teamHelper.getTeamMembers({ - role: 'author', - objectType: 'fragment', - }) - - if (members === undefined) - return res.status(400).json({ - error: 'The fragment does not have an author Team', - }) - - const membersData = members.map(async member => { - const user = await models.User.find(member) - const matchingAuthor = fragment.authors.find( - author => author.id === user.id, - ) - return { - ...user, - isSubmitting: matchingAuthor.isSubmitting, - isCorresponding: matchingAuthor.isCorresponding, - } - }) - const resBody = await Promise.all(membersData) - res.status(200).json(resBody) + const { authors = [] } = await models.Fragment.find(fragmentId) + return res.status(200).json(authors) } catch (e) { const notFoundError = await services.handleNotFoundError(e, 'item') return res.status(notFoundError.status).json({ diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/patch.js b/packages/component-user-manager/src/routes/fragmentsUsers/patch.js deleted file mode 100644 index dbdb663f478f095cfb24626dad95923cc427d62d..0000000000000000000000000000000000000000 --- a/packages/component-user-manager/src/routes/fragmentsUsers/patch.js +++ /dev/null @@ -1,57 +0,0 @@ -const logger = require('@pubsweet/logger') - -const { services } = require('pubsweet-component-helper-service') - -module.exports = models => async (req, res) => { - // TO DO: add authsome - const { collectionId, userId, fragmentId } = req.params - const { - isSubmitting, - isCorresponding, - firstName, - lastName, - affiliation, - } = req.body - - if (!services.checkForUndefinedParams(isSubmitting, isCorresponding)) { - res.status(400).json({ error: 'Missing parameters' }) - logger.error('some parameters are missing') - return - } - - try { - const collection = await models.Collection.find(collectionId) - if (!collection.fragments.includes(fragmentId)) - return res.status(400).json({ - error: `Fragment ${fragmentId} does not match collection ${collectionId}`, - }) - let fragment = await models.Fragment.find(fragmentId) - if (fragment.authors === undefined) { - return res.status(400).json({ - error: 'Collection does not have any authors', - }) - } - const user = await models.User.find(userId) - const matchingAuthor = fragment.authors.find( - author => author.id === user.id, - ) - if (matchingAuthor === undefined) { - return res.status(400).json({ - error: 'Fragment and user do not match', - }) - } - user.firstName = firstName - user.lastName = lastName - user.affiliation = affiliation - await user.save() - matchingAuthor.isSubmitting = isSubmitting - matchingAuthor.isCorresponding = isCorresponding - fragment = await fragment.save() - return res.status(200).json(fragment) - } catch (e) { - const notFoundError = await services.handleNotFoundError(e, 'item') - return res.status(notFoundError.status).json({ - error: notFoundError.message, - }) - } -} diff --git a/packages/components-faraday/src/components/AuthorList/AuthorEditor.js b/packages/components-faraday/src/components/AuthorList/AuthorEditor.js index dc60ebd8bb94bf07cab15b832fc51655c58fc1c5..5b6e09a194d1cf2ecb68e8edec397eff8593b27b 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorEditor.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorEditor.js @@ -108,25 +108,15 @@ export default compose( reduxForm({ form: 'edit', onSubmit: ( - values, + { edit: newAuthor }, dispatch, - { - index, - project, - version, - changeForm, - editAuthor, - setAuthors, - setAuthorEdit, - }, + { version: { authors = [] }, changeForm, setAuthorEdit }, ) => { - const newAuthor = values.edit - editAuthor(project.id, version.id, newAuthor.id, newAuthor).then( - authors => { - setAuthorEdit(-1)() - setAuthors(authors) - }, + const newAuthors = authors.map( + a => (a.id === newAuthor.id ? newAuthor : a), ) + changeForm('wizard', 'authors', newAuthors) + setAuthorEdit(-1)() }, }), )(AuthorEdit) diff --git a/packages/components-faraday/src/redux/authors.js b/packages/components-faraday/src/redux/authors.js index 34bfe9ce0b4386a1d90a083a7cbea567d6f12a62..d50c86c9d7ef458b66bfcec25554b50ba2989a14 100644 --- a/packages/components-faraday/src/redux/authors.js +++ b/packages/components-faraday/src/redux/authors.js @@ -1,10 +1,6 @@ import { get } from 'lodash' -import { - create, - remove, - update, - get as apiGet, -} from 'pubsweet-client/src/helpers/api' +import { create, remove, get as apiGet } from 'pubsweet-client/src/helpers/api' + import { handleError } from './utils' // constants @@ -29,26 +25,6 @@ export const authorSuccess = () => ({ export const getAuthors = (collectionId, fragmentId) => apiGet(`/collections/${collectionId}/fragments/${fragmentId}/users`) -export const editAuthor = ( - collectionId, - fragmentId, - userId, - body, -) => dispatch => { - dispatch(authorRequest()) - return update( - `/collections/${collectionId}/fragments/${fragmentId}/users/${userId}`, - body, - ).then( - () => - getAuthors(collectionId, fragmentId).then(authors => { - dispatch(authorSuccess()) - return authors - }, handleError(authorFailure, dispatch)), - handleError(authorFailure, dispatch), - ) -} - export const addAuthor = (author, collectionId, fragmentId) => dispatch => { dispatch(authorRequest()) return create(`/collections/${collectionId}/fragments/${fragmentId}/users`, {