Skip to content

Commit

Permalink
feat: display draft updates if user is a collaborator
Browse files Browse the repository at this point in the history
  • Loading branch information
mariojsnunes committed May 24, 2024
1 parent 1d4379f commit 57fa969
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/pages/Research/researchHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,18 @@ describe('Research Helpers', () => {
// assert
expect(show).toEqual(true)
})

it('should show when draft and current user is a collaborator', async () => {
// prepare
const authorId = 'author'
const item = { collaborators: [authorId] } as IResearch.Item
const update = { status: ResearchUpdateStatus.DRAFT } as IResearch.Update

// act
const show = researchUpdateStatusFilter(item, update, authorId)

// assert
expect(show).toEqual(true)
})
})
})
15 changes: 10 additions & 5 deletions src/pages/Research/researchHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export const researchUpdateStatusFilter = (
update: IResearch.Update,
currentUserId?: string,
) => {
return (
(item._createdBy === currentUserId ||
update.status !== ResearchUpdateStatus.DRAFT) &&
!update._deleted
)
const isCollaborator =
currentUserId &&
item.collaborators &&
item.collaborators.includes(currentUserId)

const isAuthor = item._createdBy === currentUserId
const isUpdateDraft = update.status === ResearchUpdateStatus.DRAFT
const isUpdateDeleted = update._deleted

return (isAuthor || isCollaborator || !isUpdateDraft) && !isUpdateDeleted
}

export const getPublicUpdates = (
Expand Down

0 comments on commit 57fa969

Please sign in to comment.