From 0fa6a0b522466306f253cf1d0c87ce1141f3480f Mon Sep 17 00:00:00 2001
From: Tania Fecheta <tania.fecheta@thinslices.com>
Date: Wed, 7 Nov 2018 13:48:58 +0200
Subject: [PATCH] fix(responseToRevisionRequest): responseToRevisionRequest is
 not displayed for a new reviewer until

---
 .../component-faraday-selectors/src/index.js     | 16 +++++++++++++++-
 .../src/components/ManuscriptLayout.js           |  2 +-
 .../src/components/ManuscriptPage.js             | 13 +++++++------
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js
index efeb000e0..b693fa616 100644
--- a/packages/component-faraday-selectors/src/index.js
+++ b/packages/component-faraday-selectors/src/index.js
@@ -1,5 +1,5 @@
 import { selectCurrentUser } from 'xpub-selectors'
-import { get, has, last, chain, some } from 'lodash'
+import { get, has, last, chain, some, isEmpty } from 'lodash'
 
 export const isHEToManuscript = (state, collectionId = '') => {
   const { id = '', isAccepted = false } = chain(state)
@@ -181,6 +181,20 @@ export const canViewEditorialComments = (
   )
 }
 
+const cannotViewResponseFromAuthorStatuses = ['reviewersInvited']
+export const canViewResponseFromAuthor = (state, collection, fragmentId) => {
+  const authorResponseToRevisonRequest = getFragmentAuthorResponse(
+    state,
+    fragmentId,
+  )
+  return (
+    !isEmpty(authorResponseToRevisonRequest) &&
+    !cannotViewResponseFromAuthorStatuses.includes(
+      get(collection, 'status', 'draft'),
+    )
+  )
+}
+
 export const getUserToken = ({ currentUser }) =>
   get(currentUser, 'user.token', '')
 
diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js
index 6d08c78bb..900ae71b9 100644
--- a/packages/component-manuscript/src/components/ManuscriptLayout.js
+++ b/packages/component-manuscript/src/components/ManuscriptLayout.js
@@ -137,7 +137,7 @@ const ManuscriptLayout = ({
           />
         )}
 
-        {get(authorResponseToRevisonRequest, 'content', false) && (
+        {get(currentUser, 'permissions.canViewResponseFromAuthor', false) && (
           <ResponseToRevisionRequest
             authorReply={get(authorResponseToRevisonRequest, 'content', '')}
             expanded={responseToRevisionRequest}
diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js
index 685daeab9..7ef6a1164 100644
--- a/packages/component-manuscript/src/components/ManuscriptPage.js
+++ b/packages/component-manuscript/src/components/ManuscriptPage.js
@@ -40,6 +40,7 @@ import {
   isHEToManuscript,
   canSubmitRevision,
   canEditManuscript,
+  getVersionOptions,
   canInviteReviewers,
   pendingHEInvitation,
   currentUserIsReviewer,
@@ -48,7 +49,7 @@ import {
   canViewReviewersDetails,
   canViewEditorialComments,
   pendingReviewerInvitation,
-  getFragmentAuthorResponse,
+  canViewResponseFromAuthor,
   canOverrideTechnicalChecks,
   authorCanViewReportsDetails,
   getOwnPendingRecommendation,
@@ -56,7 +57,6 @@ import {
   canAuthorViewEditorialComments,
   getFragmentReviewerRecommendations,
   getInvitationsWithReviewersForFragment,
-  getVersionOptions,
 } from 'pubsweet-component-faraday-selectors'
 import {
   handleError,
@@ -129,10 +129,6 @@ export default compose(
         state,
         match.params.version,
       ),
-      authorResponseToRevisonRequest: getFragmentAuthorResponse(
-        state,
-        match.params.version,
-      ),
     }),
     {
       changeForm,
@@ -198,6 +194,11 @@ export default compose(
             collection,
             match.params.version,
           ),
+          canViewResponseFromAuthor: canViewResponseFromAuthor(
+            state,
+            collection,
+            match.params.version,
+          ),
         },
       },
       isFetchingData: {
-- 
GitLab