diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index fb471ea96a51267573dcf00e32d8fe422379b18d..17e9e176354403406b6066cf5b09f589a9a93cfa 100644 --- a/packages/component-faraday-ui/src/ManuscriptCard.js +++ b/packages/component-faraday-ui/src/ManuscriptCard.js @@ -76,7 +76,7 @@ const ManuscriptCard = ({ <Row alignItems="center" justify="flex-start" mb={1}> <H4>Handling editor</H4> <Text ml={1} mr={3} whiteSpace="nowrap"> - {get(handlingEditor, 'name', 'Undefined')} + {get(handlingEditor, 'name', 'Unassigned')} </Text> {canViewReports && ( <Fragment> diff --git a/packages/component-faraday-ui/src/PersonInvitation.js b/packages/component-faraday-ui/src/PersonInvitation.js index 17ed1e3ac350499eb5c2660c697b48c4b2d94e22..492d7cbdab15ab168f2a84f8c470105d1b24bb15 100644 --- a/packages/component-faraday-ui/src/PersonInvitation.js +++ b/packages/component-faraday-ui/src/PersonInvitation.js @@ -66,7 +66,7 @@ const PersonInvitation = ({ isFetching={isFetching} modalKey={`remove-${id}`} onConfirm={revokeInvitation} - subtitle={`Are you sure you want to remove ${email}? This decision will erase all data from the current fragment.`} + subtitle="Deleting the handling editor at this moment will also remove all his work." title="Revoke invitation?" > {showModal => ( diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js index 9c6f5b851a29553f89aae6ee59db2647f1ee58f6..296bebafcfc99f9f765f677a90d97d74f630b3e1 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js @@ -1,5 +1,5 @@ import React, { Fragment } from 'react' -import { get, chain } from 'lodash' +import { get, chain, isEmpty } from 'lodash' import { H2, H4, DateParser, Button } from '@pubsweet/ui' import { compose, @@ -135,22 +135,22 @@ export default compose( if (pendingInvitation.userId === currentUserId) { return <Text ml={1}>Invited</Text> } - if ( - (get(pendingInvitation, 'userId', false) || - get(heInvitation, 'userId', false)) && - (admin || editorInChief) - ) { + const invitedHeId = + get(pendingInvitation, 'userId', false) || + get(heInvitation, 'userId', false) + + if (invitedHeId && (admin || editorInChief)) { const person = chain(handlingEditors) - .filter(he => he.id === get(heInvitation, 'userId', false)) + .filter(he => he.id === invitedHeId) .map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` })) .first() .value() - let invitedPerson = {} + let invitedHe = {} if (get(pendingInvitation, 'userId', false)) { - invitedPerson = pendingInvitation + invitedHe = pendingInvitation } else if (get(heInvitation, 'userId', false)) { - invitedPerson = heInvitation + invitedHe = heInvitation } return ( <PersonInvitation @@ -158,14 +158,16 @@ export default compose( isLatestVersion={isLatestVersion} ml={1} withName - {...invitedPerson} + {...invitedHe} onResend={resendInvitation} onRevoke={revokeInvitation} person={person} /> ) } - + if (!isEmpty(pendingInvitation)) { + return <Text ml={1}>{handlingEditor.name}</Text> + } if (heInvitation) { return <Text ml={1}>{handlingEditor.name}</Text> } @@ -183,7 +185,7 @@ export default compose( </Button> ) } - return <Text ml={1}>Assigned</Text> + return <Text ml={1}>Unassigned</Text> }, }), setDisplayName('ManuscriptHeader'), diff --git a/packages/component-invite/src/routes/collectionsInvitations/delete.js b/packages/component-invite/src/routes/collectionsInvitations/delete.js index 75bc11393f4356d744d9f38f7c4e997db0f129ab..3119458018dec661b6da2c2e20e3b9433aa7e3c1 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/delete.js +++ b/packages/component-invite/src/routes/collectionsInvitations/delete.js @@ -71,6 +71,21 @@ module.exports = models => async (req, res) => { last(get(collection, 'fragments', [])), ) + const fragmentId = fragment.id + const teamHelperForFragment = new Team({ + TeamModel: models.Team, + collectionId, + fragmentId, + }) + + const teams = await teamHelperForFragment.getTeams('fragment') + const reviewerTeam = teams.find( + team => team.object.id === fragmentId && team.group === 'reviewer', + ) + if (reviewerTeam) { + reviewerTeam.delete() + } + const fileKeys = [] fragment.recommendations && fragment.recommendations.forEach(recommendation => { diff --git a/packages/component-manuscript-manager/src/routes/fragments/patch.js b/packages/component-manuscript-manager/src/routes/fragments/patch.js index acd037254ddb9ada6417d99980a2a30588799d08..6a3e11ef06411ccd3868b8da6aca8389289f0d6a 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/patch.js +++ b/packages/component-manuscript-manager/src/routes/fragments/patch.js @@ -24,7 +24,8 @@ module.exports = models => async (req, res) => { fragment = await models.Fragment.find(fragmentId) if (!fragment.revision) { return res.status(400).json({ - error: 'No revision has been found.', + error: + 'Your Handling Editor was changed. A new handling editor will be assigned to your manuscript soon. Sorry for the inconvenience.', }) } diff --git a/packages/component-manuscript-manager/src/tests/fragments/patch.test.js b/packages/component-manuscript-manager/src/tests/fragments/patch.test.js index f4e2147a5604bf4f77e0782fdd1f33cb28ec9f58..be867cbe7df7674d91c619d7837a94ed08e808e6 100644 --- a/packages/component-manuscript-manager/src/tests/fragments/patch.test.js +++ b/packages/component-manuscript-manager/src/tests/fragments/patch.test.js @@ -148,7 +148,9 @@ describe('Patch fragments route handler', () => { expect(res.statusCode).toBe(400) const data = JSON.parse(res._getData()) - expect(data.error).toEqual('No revision has been found.') + expect(data.error).toEqual( + 'Your Handling Editor was changed. A new handling editor will be assigned to your manuscript soon. Sorry for the inconvenience.', + ) }) it('should return an error when the user is inactive', async () => { const { inactiveUser } = testFixtures.users diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index af24148066d5dc53764e440da68fb2c965436f2d..39f753c539a754d22829a00a0397277236eb40b1 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -4,8 +4,6 @@ const { omit, get, last, chain } = require('lodash') const statuses = config.get('statuses') -const keysToOmit = [`email`, `id`] -const authorCannotViewHENameStatuses = ['heInvited'] const authorAllowedStatuses = ['revisionRequested', 'rejected', 'accepted'] const getTeamsByPermissions = async ( @@ -102,21 +100,27 @@ const filterRecommendationsFromOlderVersions = (recommendations, user) => { const stripeCollectionByRole = ({ collection = {}, role = '' }) => { if (role === 'author') { - const { handlingEditor } = collection - - if (authorCannotViewHENameStatuses.includes(collection.status)) { + if (collection.status === 'heInvited') { return { ...collection, - handlingEditor: handlingEditor && - !handlingEditor.isAccepted && { - ...omit(handlingEditor, keysToOmit), - name: 'Assigned', - }, + handlingEditor: { + name: 'Assigned', + }, + } + } + if (collection.status === 'submitted') { + return { + ...collection, + handlingEditor: { + name: 'Unassigned', + }, } } } + return collection } + const stripeFragmentByRole = ({ fragment = {}, role = '', diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js index fe678f981257b9e3a67647f062f3f15ef0f87f31..c9df55d68c485557d2c6031a4a5a35e6f9f752a9 100644 --- a/packages/xpub-faraday/config/authsome-mode.js +++ b/packages/xpub-faraday/config/authsome-mode.js @@ -93,8 +93,13 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { FragmentModel: context.models.Fragment, }) + const parsedCollection = helpers.stripeCollectionByRole({ + collection, + role, + }) + return { - ...collection, + ...parsedCollection, ...parsedStatuses, fragments: role !== 'reviewer' diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index de16758af67242c6ab707a10a6f0f31f2cb24876..41fa760afb11a7bb0cb7896549aa19151e3ce79a 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -19,7 +19,7 @@ describe('Authsome Helpers', () => { expect(newCollection).toBeTruthy() }) - it('Author should not see HE name on dashboard before HE accepts invitation', () => { + it('Author should see Assigned instead of HE name on dashboard before HE accepts invitation', () => { const { collection } = testFixtures.collections collection.handlingEditor = { ...collection.handlingEditor, @@ -86,6 +86,19 @@ describe('Authsome Helpers', () => { const { handlingEditor = {} } = newCollection expect(handlingEditor.name).not.toEqual('Assigned') }) + + it('Author should see Unassigned insted of HE name before HE is invited', () => { + const { collection } = testFixtures.collections + collection.status = 'submitted' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.name).toEqual('Unassigned') + }) + it('stripeCollection - returns if collection does not have HE', () => { const { collection } = testFixtures.collections delete collection.handlingEditor