Skip to content
Snippets Groups Projects
Commit bbce4b59 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

Merge branch 'HIN-1127' into 'develop'

fix(authsome-helpers): In manuscript status 'HE Invited', the Author shouldn't…

See merge request !152
parents 2fb3e5ba 6109bf28
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!152fix(authsome-helpers): In manuscript status 'HE Invited', the Author shouldn't…
......@@ -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>
......
......@@ -170,7 +170,7 @@ export default compose(
</Button>
)
}
return <Text ml={1}>Unassigned</Text>
return <Text ml={1}>Assigned</Text>
},
}),
setDisplayName('ManuscriptHeader'),
......
......@@ -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,
}
......@@ -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
......
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