Skip to content
Snippets Groups Projects
Commit c2d9daad authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

fix(manuscript-details): redirect on forbidden

parent d80100ea
No related branches found
No related tags found
1 merge request!10Sprint #12
import React, { Fragment } from 'react' import React, { Fragment } from 'react'
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import { Redirect } from 'react-router-dom'
import { import {
Root, Root,
...@@ -27,16 +26,13 @@ const ManuscriptLayout = ({ ...@@ -27,16 +26,13 @@ const ManuscriptLayout = ({
history, history,
currentUser, currentUser,
editorInChief, editorInChief,
pubsweetError,
updateManuscript, updateManuscript,
canSeeReviewersReports,
canSeeEditorialComments, canSeeEditorialComments,
editorialRecommendations, editorialRecommendations,
project = {}, project = {},
version = {}, version = {},
}) => ( }) => (
<Root> <Root>
{pubsweetError && <Redirect to="not-found" />}
{!isEmpty(project) && !isEmpty(version) ? ( {!isEmpty(project) && !isEmpty(version) ? (
<Fragment> <Fragment>
<Container flex={3}> <Container flex={3}>
...@@ -58,9 +54,7 @@ const ManuscriptLayout = ({ ...@@ -58,9 +54,7 @@ const ManuscriptLayout = ({
version={version} version={version}
/> />
<ManuscriptDetails collection={project} fragment={version} /> <ManuscriptDetails collection={project} fragment={version} />
{canSeeReviewersReports && ( <ReviewsAndReports project={project} version={version} />
<ReviewsAndReports project={project} version={version} />
)}
{canSeeEditorialComments && {canSeeEditorialComments &&
editorialRecommendations.length > 0 && ( editorialRecommendations.length > 0 && (
<EditorialComments <EditorialComments
......
...@@ -20,6 +20,10 @@ import { ...@@ -20,6 +20,10 @@ import {
} from 'recompose' } from 'recompose'
import { getSignedUrl } from 'pubsweet-components-faraday/src/redux/files' import { getSignedUrl } from 'pubsweet-components-faraday/src/redux/files'
import { reviewerDecision } from 'pubsweet-components-faraday/src/redux/reviewers' import { reviewerDecision } from 'pubsweet-components-faraday/src/redux/reviewers'
import {
hasManuscriptFailure,
clearCustomError,
} from 'pubsweet-components-faraday/src/redux/errors'
import { selectEditorialRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations' import { selectEditorialRecommendations } from 'pubsweet-components-faraday/src/redux/recommendations'
import { import {
getHandlingEditors, getHandlingEditors,
...@@ -28,11 +32,7 @@ import { ...@@ -28,11 +32,7 @@ import {
import ManuscriptLayout from './ManuscriptLayout' import ManuscriptLayout from './ManuscriptLayout'
import { parseSearchParams, redirectToError } from './utils' import { parseSearchParams, redirectToError } from './utils'
import { import { canSeeEditorialComments } from '../../../component-faraday-selectors'
getPubsweetError,
canSeeReviewersReports,
canSeeEditorialComments,
} from '../../../component-faraday-selectors'
export default compose( export default compose(
setDisplayName('ManuscriptPage'), setDisplayName('ManuscriptPage'),
...@@ -49,15 +49,11 @@ export default compose( ...@@ -49,15 +49,11 @@ export default compose(
connect( connect(
(state, { match }) => ({ (state, { match }) => ({
currentUser: selectCurrentUser(state), currentUser: selectCurrentUser(state),
pubsweetError: getPubsweetError(state),
handlingEditors: selectHandlingEditors(state), handlingEditors: selectHandlingEditors(state),
hasManuscriptFailure: hasManuscriptFailure(state),
version: selectFragment(state, match.params.version), version: selectFragment(state, match.params.version),
project: selectCollection(state, match.params.project), project: selectCollection(state, match.params.project),
editorialRecommendations: selectEditorialRecommendations(state), editorialRecommendations: selectEditorialRecommendations(state),
canSeeReviewersReports: canSeeReviewersReports(
state,
match.params.project,
),
canSeeEditorialComments: canSeeEditorialComments( canSeeEditorialComments: canSeeEditorialComments(
state, state,
match.params.project, match.params.project,
...@@ -66,6 +62,7 @@ export default compose( ...@@ -66,6 +62,7 @@ export default compose(
{ {
replace, replace,
getSignedUrl, getSignedUrl,
clearCustomError,
reviewerDecision, reviewerDecision,
getCollection: actions.getCollection, getCollection: actions.getCollection,
updateVersion: actions.updateFragment, updateVersion: actions.updateFragment,
...@@ -100,11 +97,19 @@ export default compose( ...@@ -100,11 +97,19 @@ export default compose(
const { const {
match, match,
replace, replace,
history,
location, location,
getCollection, getCollection,
reviewerDecision, reviewerDecision,
setEditorInChief, setEditorInChief,
clearCustomError,
hasManuscriptFailure,
} = this.props } = this.props
if (hasManuscriptFailure) {
history.push('/not-found')
clearCustomError()
}
const collectionId = match.params.project const collectionId = match.params.project
const { agree, invitationId } = parseSearchParams(location.search) const { agree, invitationId } = parseSearchParams(location.search)
if (agree === 'true') { if (agree === 'true') {
......
...@@ -16,7 +16,7 @@ import { selectRecommendations } from 'pubsweet-components-faraday/src/redux/rec ...@@ -16,7 +16,7 @@ import { selectRecommendations } from 'pubsweet-components-faraday/src/redux/rec
import { Tabs, Expandable } from '../molecules' import { Tabs, Expandable } from '../molecules'
import { ReviewReportCard, ReviewerReportForm } from './' import { ReviewReportCard, ReviewerReportForm } from './'
import { currentUserIs } from '../../../component-faraday-selectors' import { canSeeReviewersReports } from '../../../component-faraday-selectors'
const getTabSections = (collectionId, reviewers, recommendations = []) => [ const getTabSections = (collectionId, reviewers, recommendations = []) => [
{ {
...@@ -47,16 +47,16 @@ const ReviewsAndReports = ({ ...@@ -47,16 +47,16 @@ const ReviewsAndReports = ({
report, report,
project, project,
version, version,
isStaff,
isReviewer, isReviewer,
mappedReviewers, mappedReviewers,
mappedRecommendations, mappedRecommendations,
canSeeReviewersReports,
review = {}, review = {},
reviewers = [], reviewers = [],
recommendations = [], recommendations = [],
}) => ( }) => (
<Fragment> <Fragment>
{isStaff && ( {canSeeReviewersReports && (
<Root> <Root>
<Expandable <Expandable
label="Reviewers & Reports" label="Reviewers & Reports"
...@@ -102,10 +102,10 @@ export default compose( ...@@ -102,10 +102,10 @@ export default compose(
connect( connect(
(state, { project }) => ({ (state, { project }) => ({
reviewers: selectReviewers(state), reviewers: selectReviewers(state),
isStaff: currentUserIs(state, 'staff'),
recommendations: selectRecommendations(state), recommendations: selectRecommendations(state),
fetchingReviewers: selectFetchingReviewers(state), fetchingReviewers: selectFetchingReviewers(state),
isReviewer: currentUserIsReviewer(state, project.id), isReviewer: currentUserIsReviewer(state, project.id),
canSeeReviewersReports: canSeeReviewersReports(state, project.id),
}), }),
{ getCollectionReviewers }, { getCollectionReviewers },
), ),
...@@ -130,8 +130,8 @@ export default compose( ...@@ -130,8 +130,8 @@ export default compose(
})), })),
lifecycle({ lifecycle({
componentDidMount() { componentDidMount() {
const { getReviewers } = this.props const { getReviewers, canSeeReviewersReports } = this.props
getReviewers() canSeeReviewersReports && getReviewers()
}, },
}), }),
)(ReviewsAndReports) )(ReviewsAndReports)
......
...@@ -3,8 +3,9 @@ module.exports = { ...@@ -3,8 +3,9 @@ module.exports = {
components: [() => require('./components')], components: [() => require('./components')],
reducers: { reducers: {
authors: () => require('./redux/authors').default, authors: () => require('./redux/authors').default,
files: () => require('./redux/files').default, customError: () => require('./redux/errors').default,
editors: () => require('./redux/editors').default, editors: () => require('./redux/editors').default,
files: () => require('./redux/files').default,
reviewers: () => require('./redux/reviewers').default, reviewers: () => require('./redux/reviewers').default,
recommendations: () => require('./redux/recommendations').default, recommendations: () => require('./redux/recommendations').default,
}, },
......
export const hasManuscriptFailure = state =>
state.customError === 'manuscriptFailure'
export const clearCustomError = () => ({
type: 'CLEAR_CUSTOM_ERROR',
})
export default (state = '', action) => {
switch (action.type) {
case 'CLEAR_CUSTOM_ERROR':
return ''
case 'GET_FRAGMENT_FAILURE':
return 'manuscriptFailure'
default:
return state
}
}
export { default as files } from './files'
export { default as errors } from './errors'
export { default as authors } from './authors' export { default as authors } from './authors'
export { default as editors } from './editors' export { default as editors } from './editors'
export { default as files } from './files'
export { default as reviewers } from './reviewers' export { default as reviewers } from './reviewers'
export { default as recommendations } from './recommendations' export { default as recommendations } from './recommendations'
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