diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index 17e9e176354403406b6066cf5b09f589a9a93cfa..fb471ea96a51267573dcf00e32d8fe422379b18d 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', 'Unassigned')} + {get(handlingEditor, 'name', 'Undefined')} </Text> {canViewReports && ( <Fragment> diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js index f93e6c4c396f67836c8d1142000cc05682aac647..699edec06e90cfc92695a9cbec10bc2ca8e81d70 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js @@ -170,7 +170,7 @@ export default compose( </Button> ) } - return <Text ml={1}>Unassigned</Text> + return <Text ml={1}>Assigned</Text> }, }), setDisplayName('ManuscriptHeader'), diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index c43c00d912084c864261fd45e5c75fc05bd83a64..08e583c721fa6103de2f4729e0f2e64a348567a7 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -4,6 +4,8 @@ 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 ( @@ -70,6 +72,23 @@ const filterAuthorRecommendations = (recommendations, status, isLast) => { return [] } +const stripeCollectionByRole = ({ collection = {}, role = '' }) => { + if (role === 'author') { + const { handlingEditor } = collection + + if (authorCannotViewHENameStatuses.includes(collection.status)) { + return { + ...collection, + handlingEditor: handlingEditor && + !handlingEditor.isAccepted && { + ...omit(handlingEditor, keysToOmit), + name: 'Assigned', + }, + } + } + } + return collection +} const stripeFragmentByRole = ({ fragment = {}, role = '', @@ -142,23 +161,23 @@ const getCollections = async ({ user, models }) => { const userPermisssions = await getUserPermissions({ user, Team: models.Team }) const collections = (await Promise.all( - userPermisssions.map(async up => { + userPermisssions.map(async userPermission => { let fragment = {} let collection = {} try { - if (up.objectType === 'collection') { - collection = await models.Collection.find(up.objectId) + if (userPermission.objectType === 'collection') { + collection = await models.Collection.find(userPermission.objectId) const latestFragmentId = collection.fragments[collection.fragments.length - 1] collection.currentVersion = await models.Fragment.find( latestFragmentId, ) } else { - fragment = await models.Fragment.find(up.objectId) + fragment = await models.Fragment.find(userPermission.objectId) collection = await models.Collection.find(fragment.collectionId) collection.currentVersion = stripeFragmentByRole({ fragment, - role: up.role, + role: userPermission.role, user, }) } @@ -167,17 +186,25 @@ const getCollections = async ({ user, models }) => { return null } const status = get(collection, 'status', 'draft') - collection.visibleStatus = get(statuses, `${status}.${up.role}.label`) + collection.visibleStatus = get( + statuses, + `${status}.${userPermission.role}.label`, + ) - const role = get(up, 'role', 'author') + const role = get(userPermission, 'role', 'author') const parsedStatuses = await setCollectionStatus({ role, user, collection, FragmentModel: models.Fragment, }) + const stripedColl = stripeCollectionByRole({ + collection, + role: userPermission.role, + }) + return { - ...collection, + ...stripedColl, ...parsedStatuses, } }), @@ -275,5 +302,6 @@ module.exports = { setCollectionStatus, stripeFragmentByRole, getTeamsByPermissions, + stripeCollectionByRole, hasPermissionForObject, } diff --git a/packages/xpub-faraday/tests/config/authsome-helpers.test.js b/packages/xpub-faraday/tests/config/authsome-helpers.test.js index a15e1f9852337441114611dcc2a0e426bf904c5c..c5634168fdf6ab29134874c7c3fa9ee96183b2d0 100644 --- a/packages/xpub-faraday/tests/config/authsome-helpers.test.js +++ b/packages/xpub-faraday/tests/config/authsome-helpers.test.js @@ -10,6 +10,91 @@ describe('Authsome Helpers', () => { models = fixturesService.Model.build(testFixtures) }) + describe('stripeCollectionByRole', () => { + it('should return a collection', () => { + const { collection } = testFixtures.collections + const newCollection = ah.stripeCollectionByRole({ + collection, + }) + expect(newCollection).toBeTruthy() + }) + + it('Author should not see HE name on dashboard before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + + expect(handlingEditor.email).toBeFalsy() + expect(handlingEditor.name).toEqual('Assigned') + }) + + it('EIC and Admin should see HE name before HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: false, + } + collection.status = 'heInvited' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('EIC and Admin should see HE name after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.email).toBeTruthy() + expect(handlingEditor.name).not.toEqual('Assigned') + }) + + it('Atuhor should see HE name on dashboard after HE accepts invitation', () => { + const { collection } = testFixtures.collections + collection.handlingEditor = { + ...collection.handlingEditor, + isAccepted: true, + } + collection.status = 'heAssigned' + const role = 'author' + const newCollection = ah.stripeCollectionByRole({ + collection, + role, + }) + const { handlingEditor = {} } = newCollection + expect(handlingEditor.name).not.toEqual('Assigned') + }) + it('stripeCollection - returns if collection does not have HE', () => { + const { collection } = testFixtures.collections + delete collection.handlingEditor + const role = 'admin' + const newCollection = ah.stripeCollectionByRole({ collection, role }) + expect(newCollection.handlingEditor).toBeFalsy() + }) + }) + describe('stripeFragmentByRole', () => { it('reviewer should not see authors email', () => { const { fragment } = testFixtures.fragments