diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index 728b2e28a08eb1572980a1879a27e4a6e5eb98f5..049383e6bd1305d61ca5534a9810c9b06d13a224 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -1,6 +1,16 @@ import { selectCurrentUser } from 'xpub-selectors' -// eslint-disable-next-line no-unused-vars -import { get, has, last, chain, some, isEmpty, flatten } from 'lodash' +import { + get, + has, + last, + chain, + some, + isEmpty, + // eslint-disable-next-line no-unused-vars + flatten, + slice, + find, +} from 'lodash' export const isHEToManuscript = (state, collectionId = '') => { const { id = '', isAccepted = false } = chain(state) @@ -49,6 +59,18 @@ export const canInviteReviewers = (state, collection = {}) => { return isAccepted && (userId === heId || isAdminEiC) } +const canViewContextualBoxOnOldVersionStatuses = ['submitted', 'heAssigned'] +const canViewContextualBoxOnOldVersion = (collection, fragmentId) => { + const fragments = get(collection, 'fragments', []) + const oldVersions = slice(fragments, 0, fragments.length - 1) + const isOldVersion = !!find(oldVersions, fragment => fragment === fragmentId) + return ( + isOldVersion && + canViewContextualBoxOnOldVersionStatuses.includes( + get(collection, 'status', 'draft'), + ) + ) +} const cannotViewReviewersDetails = [ 'draft', 'technicalChecks', @@ -83,9 +105,11 @@ export const authorCanViewReportsDetails = ( ) => { const isAuthor = currentUserIsAuthor(state, fragmentId) return ( - authorCanViewReportsDetailsStatuses.includes( + isAuthor && + (authorCanViewReportsDetailsStatuses.includes( get(collection, 'status', 'draft'), - ) && isAuthor + ) || + canViewContextualBoxOnOldVersion(collection, fragmentId)) ) } @@ -177,7 +201,8 @@ export const canViewEditorialComments = ( fragmentId, ) return ( - (canHeViewEditorialComments(state, collection) || + (canViewContextualBoxOnOldVersion(collection, fragmentId) || + canHeViewEditorialComments(state, collection) || canEICViewEditorialComments(state, collection) || canReviewerViewEditorialComments(state, collection, fragment) || canAuthorViewEditorialComments(state, collection, fragmentId)) && diff --git a/packages/component-faraday-ui/src/PersonInvitation.js b/packages/component-faraday-ui/src/PersonInvitation.js index a168270be1e1dd2f10049476640ff993b46070ed..8c5e7526da145dc84aefe6ac6bf6d76336d96d3e 100644 --- a/packages/component-faraday-ui/src/PersonInvitation.js +++ b/packages/component-faraday-ui/src/PersonInvitation.js @@ -3,6 +3,7 @@ import styled from 'styled-components' import { compose, withHandlers, defaultProps, setDisplayName } from 'recompose' import { Text, OpenModal, IconButton, marginHelper, withFetching } from './' +import { isLatestVersion } from '../../component-manuscript/src/components/utils' const PersonInvitation = ({ id, @@ -57,28 +58,29 @@ const PersonInvitation = ({ </OpenModal> </Fragment> )} - {hasAnswer && ( - <Fragment> - <OpenModal - confirmText="Revoke" - 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.`} - title="Revoke invitation?" - > - {showModal => ( - <IconButton - icon="x-circle" - iconSize={2} - ml={2} - onClick={showModal} - secondary - /> - )} - </OpenModal> - </Fragment> - )} + {hasAnswer && + isLatestVersion( + <Fragment> + <OpenModal + confirmText="Revoke" + 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.`} + title="Revoke invitation?" + > + {showModal => ( + <IconButton + icon="x-circle" + iconSize={2} + ml={2} + onClick={showModal} + secondary + /> + )} + </OpenModal> + </Fragment>, + )} </Root> ) diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js index 63ec143f1c888b8a99e05aa48a827d8c4c01bc2f..98e4738ddc6f475d9fe923b41907a54f8c542d6d 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js @@ -121,6 +121,7 @@ export default compose( revokeInvitation, pendingInvitation = {}, handlingEditors = [], + isLatestVersion, currentUser: { permissions: { canAssignHE }, id: currentUserId, @@ -128,6 +129,7 @@ export default compose( editorInChief, }, collection: { handlingEditor }, + collection, currentUser, }) => () => { if (pendingInvitation.userId === currentUserId) { @@ -157,6 +159,7 @@ export default compose( return ( <PersonInvitation isFetching={isFetching} + isLatestVersion={isLatestVersion} ml={1} withName {...invitedPerson} diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index 4953fa278e884980a5bfe28168c62a6a0e97a455..98ef1c4823bc77a1e4868da6cb87a65b4e42d0a4 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -185,14 +185,16 @@ const ManuscriptLayout = ({ /> )} - <ManuscriptAssignHE - assignHE={inviteHandlingEditor.assignHE} - currentUser={currentUser} - expanded={heExpanded} - handlingEditors={handlingEditors} - isFetching={isFetchingData.editorsFetching} - toggle={toggleAssignHE} - /> + {isLatestVersion && ( + <ManuscriptAssignHE + assignHE={inviteHandlingEditor.assignHE} + currentUser={currentUser} + expanded={heExpanded} + handlingEditors={handlingEditors} + isFetching={isFetchingData.editorsFetching} + toggle={toggleAssignHE} + /> + )} {get(currentUser, 'permissions.canViewReviewersDetails', false) && ( <ReviewerDetails diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js index 89b5dadefcc611d56684ad1b442b326f2f3870ab..49431eac63aad495e794a5c5a5b6e749323191df 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -177,7 +177,11 @@ export default compose( collection, statuses: get(journal, 'statuses', {}), }), - canAssignHE: canAssignHE(state, collection), + canAssignHE: canAssignHE( + state, + collection, + isLatestVersion(collection, fragment), + ), canViewReports: canViewReports(state, match.params.project), canViewEditorialComments: canViewEditorialComments( state, diff --git a/packages/component-manuscript/src/redux/editors.js b/packages/component-manuscript/src/redux/editors.js index e28c0dd29ff392776fa2092639ec8fceda19026a..2ff500a7c82c6d94db4b74faaa837b961b6c1b04 100644 --- a/packages/component-manuscript/src/redux/editors.js +++ b/packages/component-manuscript/src/redux/editors.js @@ -24,13 +24,14 @@ export const selectHandlingEditors = state => .value() const canAssignHEStatuses = ['submitted'] -export const canAssignHE = (state, collection = {}) => { +export const canAssignHE = (state, collection = {}, isLatestVersion) => { const isEIC = currentUserIs(state, 'adminEiC') const hasHE = get(collection, 'handlingEditor', false) return ( isEIC && !hasHE && + isLatestVersion && canAssignHEStatuses.includes(get(collection, 'status', 'draft')) ) }