diff --git a/packages/component-faraday-ui/src/manuscriptDetails/DeleteManuscriptModal.js b/packages/component-faraday-ui/src/manuscriptDetails/DeleteManuscriptModal.js index 4d8fa28b80607985d271e757e43fc0e8b5ecabc1..514a206200203e8dc3fd17da0763e4e7337caf91 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/DeleteManuscriptModal.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/DeleteManuscriptModal.js @@ -77,9 +77,9 @@ const DeleteManuscriptModal = props => ( onClick={showModal} paddingBottom={2} paddingRight={0} - size={1.6} + size={1.65} > - DELETE + Delete </DeleteIcon> )} </OpenModal> diff --git a/packages/component-manuscript-manager/src/routes/collections/patch.js b/packages/component-manuscript-manager/src/routes/collections/patch.js index fd8dba25c96b34f4d7e0a3b818369b516dc38184..ce752b64e6898079a20a31e63c9d4054ecf88aa1 100644 --- a/packages/component-manuscript-manager/src/routes/collections/patch.js +++ b/packages/component-manuscript-manager/src/routes/collections/patch.js @@ -1,6 +1,7 @@ -const { has, get } = require('lodash') +const { get } = require('lodash') const { services, + Collection, authsome: authsomeHelper, } = require('pubsweet-component-helper-service') @@ -9,37 +10,36 @@ module.exports = models => async (req, res) => { try { const collection = await models.Collection.find(collectionId) + const collectionStatus = get(collection, 'status') const authsome = authsomeHelper.getAuthsome(models) const target = { path: req.route.path, } const canArchive = await authsome.can(req.user, 'PATCH', target) - if (!collection) - return res.status(404).json({ - error: `Collection not found`, - }) - - if (!canArchive) + if (!canArchive) { return res.status(403).json({ error: 'Unauthorized', }) + } - if (!has(collection, 'status')) { + if (!collectionStatus) { return res.status(400).json({ error: 'You cannot delete manuscripts while in draft.', }) } - if (get(collection, 'status') === 'deleted') { + if (collectionStatus === 'deleted') { return res.status(400).json({ error: 'Manuscript already deleted', }) } - if (has(collection, 'status')) { + if (collectionStatus) { collection.status = 'deleted' await collection.save() + const collectionHelper = new Collection({ collection }) + collectionHelper.updateStatus({ newStatus: 'deleted' }) } return res.status(200).json(collection) } catch (e) { diff --git a/packages/component-manuscript-manager/src/tests/collections/patch.test.js b/packages/component-manuscript-manager/src/tests/collections/patch.test.js index 7a0ed8ad318aefaca14da77a939c44ef68ac11d6..77767d8f92f509a54d3434ab7632c964e45af0e4 100644 --- a/packages/component-manuscript-manager/src/tests/collections/patch.test.js +++ b/packages/component-manuscript-manager/src/tests/collections/patch.test.js @@ -28,8 +28,6 @@ describe('Patch colection route handler', () => { it('should return an error if the manuscript does not exist', async () => { const { admin } = testFixtures.users - const { collection } = testFixtures.collections - collection.status = 'underReview' const res = await requests.sendRequest({ userId: admin.id, body, diff --git a/packages/components-faraday/src/components/Dashboard/DashboardPage.js b/packages/components-faraday/src/components/Dashboard/DashboardPage.js index e103791cd21b6bb479c6b4dcd778025b188ebc67..689623146e2eda389d53679b13cbc8079221a5a8 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardPage.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardPage.js @@ -3,6 +3,7 @@ import { connect } from 'react-redux' import { actions } from 'pubsweet-client' import { withJournal } from 'xpub-journal' import { ConnectPage } from 'xpub-connect' +import { get } from 'lodash' import { withRouter } from 'react-router-dom' import { selectCurrentUser } from 'xpub-selectors' import { handleError, withFetching } from 'pubsweet-component-faraday-ui' @@ -38,7 +39,7 @@ export default compose( collections, currentUser, userPermissions, - isAdmin: state.currentUser.user.admin, + isAdmin: get(state, 'currentUser.user.admin', 'false'), } }, {