feat(authsome): enhance authsome to hide editorial comments until decision
Showing
- packages/xpub-faraday/config/authsome-helpers.js 14 additions, 8 deletionspackages/xpub-faraday/config/authsome-helpers.js
- packages/xpub-faraday/config/authsome-mode.js 4 additions, 1 deletionpackages/xpub-faraday/config/authsome-mode.js
- packages/xpub-faraday/tests/authsome-helpers.test.js 24 additions, 0 deletionspackages/xpub-faraday/tests/authsome-helpers.test.js
... | @@ -126,12 +126,13 @@ const hasFragmentInDraft = async ({ object, Fragment }) => { | ... | @@ -126,12 +126,13 @@ const hasFragmentInDraft = async ({ object, Fragment }) => { |
return isInDraft(fragment) | return isInDraft(fragment) | ||
} | } | ||
const filterAuthorRecommendationData = recommendation => { | const filterAuthorRecommendationData = (recommendations, status) => { | ||
const { comments } = recommendation | const canViewComments = authorAllowedStatuses.includes(status) | ||
return { | return recommendations.map(r => ({ | ||
...recommendation, | ...r, | ||
comments: comments ? comments.filter(c => c.public) : [], | comments: | ||
} | r.comments && canViewComments ? r.comments.filter(c => c.public) : [], | ||
})) | |||
} | } | ||
const stripeCollectionByRole = (coll = {}, role = '') => { | const stripeCollectionByRole = (coll = {}, role = '') => { | ||
... | @@ -151,14 +152,19 @@ const stripeCollectionByRole = (coll = {}, role = '') => { | ... | @@ -151,14 +152,19 @@ const stripeCollectionByRole = (coll = {}, role = '') => { |
return coll | return coll | ||
} | } | ||
const stripeFragmentByRole = (fragment = {}, role = '', user = {}) => { | const stripeFragmentByRole = ( | ||
fragment = {}, | |||
role = '', | |||
status = '', | |||
user = {}, | |||
) => { | |||
const { recommendations, files, authors } = fragment | const { recommendations, files, authors } = fragment | ||
|
|||
switch (role) { | switch (role) { | ||
case 'author': | case 'author': | ||
return { | return { | ||
...fragment, | ...fragment, | ||
recommendations: recommendations | recommendations: recommendations | ||
? recommendations.map(filterAuthorRecommendationData) | ? filterAuthorRecommendationData(recommendations, status) | ||
: [], | : [], | ||
} | } | ||
case 'reviewer': | case 'reviewer': | ||
... | ... |