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

feat(authsome): enhance authsome to hide editorial comments until decision

parent 2346fcdc
No related branches found
No related tags found
1 merge request!13Sprint #14
...@@ -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 = '',
  • Maintainer

    Default status should de 'draft'. That handles the case when fragment is still not submitted yet.

  • Please register or sign in to reply
user = {},
) => {
const { recommendations, files, authors } = fragment const { recommendations, files, authors } = fragment
  • Maintainer

    In my opinion, one useful thing for functions with more than two parameters is instead to define only one object parameter. Sebi talked about it at a Show&Tell session and he already applies this on the backend.

    More can be found here.

  • Please register or sign in to reply
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':
......
...@@ -132,9 +132,12 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ...@@ -132,9 +132,12 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
if (!permission) return false if (!permission) return false
const collectionId = get(object, 'fragment.collectionId')
const { status } = await context.models.Collection.find(collectionId)
  • Maintainer

    If the current fragment is still in draft mode there won't be a status property present. Should have 'draft' assigned by default.

  • Please register or sign in to reply
return { return {
filter: fragment => filter: fragment =>
helpers.stripeFragmentByRole(fragment, permission.role, user), helpers.stripeFragmentByRole(fragment, permission.role, user, status),
} }
} }
......
...@@ -112,6 +112,30 @@ describe('Authsome Helpers', () => { ...@@ -112,6 +112,30 @@ describe('Authsome Helpers', () => {
] ]
const result = ah.stripeFragmentByRole(fragment, 'author') const result = ah.stripeFragmentByRole(fragment, 'author')
const privateComments = get(result, 'recommendations[0].comments') const privateComments = get(result, 'recommendations[0].comments')
expect(privateComments).toHaveLength(0)
})
it('stripeFragment - author should see comments only if recommendation has been made', () => {
const { fragment } = testFixtures.fragments
fragment.recommendations = [
{
comments: [
{
content: 'private',
public: false,
},
{
content: 'public',
public: true,
},
],
},
]
const result = ah.stripeFragmentByRole(
fragment,
'author',
'revisionRequested',
)
const privateComments = get(result, 'recommendations[0].comments')
expect(privateComments).toHaveLength(1) expect(privateComments).toHaveLength(1)
}) })
}) })
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