Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/mutations/comment/putComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const resolver: GQLMutationResolvers['putComment'] = async (
commentService,
paymentService,
articleService,
campaignService,
notificationService,
userService,
connections,
Expand Down Expand Up @@ -309,22 +308,9 @@ const resolver: GQLMutationResolvers['putComment'] = async (
}
}

// campaign discussion is public to read, but only succeeded participants
// (or the campaign organizers/managers) may comment
if (campaign) {
const isParticipant = await campaignService.isParticipant(
campaign.id,
viewer.id
)
const isOrganizer =
campaign.creatorId === viewer.id ||
(campaign.organizerIds ?? []).includes(viewer.id) ||
(campaign.managerIds ?? []).includes(viewer.id)

if (!isParticipant && !isOrganizer) {
throw new ForbiddenError('only campaign participants have the permission')
}
}
// campaign discussion is public to read; any logged-in user may comment.
// (relaxed from the previous participant-only restriction — basic user-state
// and campaign-state guards are still enforced above.)

// check whether viewer is blocked by target author (skip when no single author,
// e.g. campaign discussion)
Expand Down
29 changes: 20 additions & 9 deletions src/types/__test__/2/campaignComment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,22 +219,33 @@ describe('put campaignDiscussion comment', () => {
}
})

test('non-participant can not comment', async () => {
const { errors } = await putCampaignComment(
// the discussion is open to every logged-in user (the participant-only
// restriction was relaxed), so non-participant / pending / rejected may comment
test('non-participant can comment', async () => {
const { errors, data } = await putCampaignComment(
nonParticipantId,
campaignGlobalId
)
expect(errors?.[0].extensions.code).toBe('FORBIDDEN')
expect(errors).toBeUndefined()
expect(data.putComment.id).toBeDefined()
})

test('pending applicant can not comment', async () => {
const { errors } = await putCampaignComment(pendingId, campaignGlobalId)
expect(errors?.[0].extensions.code).toBe('FORBIDDEN')
test('pending applicant can comment', async () => {
const { errors, data } = await putCampaignComment(
pendingId,
campaignGlobalId
)
expect(errors).toBeUndefined()
expect(data.putComment.id).toBeDefined()
})

test('rejected applicant can not comment', async () => {
const { errors } = await putCampaignComment(rejectedId, campaignGlobalId)
expect(errors?.[0].extensions.code).toBe('FORBIDDEN')
test('rejected applicant can comment', async () => {
const { errors, data } = await putCampaignComment(
rejectedId,
campaignGlobalId
)
expect(errors).toBeUndefined()
expect(data.putComment.id).toBeDefined()
})

test('can not comment on archived campaign', async () => {
Expand Down
Loading