Skip to content

Commit

Permalink
feat(campaign): add password verification for "sendCampaignAnnouncement"
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwoz committed Oct 22, 2024
1 parent d98ca56 commit c0cfa50
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ input SendCampaignAnnouncementInput {
campaign: ID!
announcement: [TranslationInput!]!
link: String!
password: String!
}

input CampaignStageInput {
Expand Down
1 change: 1 addition & 0 deletions src/definitions/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3289,6 +3289,7 @@ export type GQLSendCampaignAnnouncementInput = {
announcement: Array<GQLTranslationInput>
campaign: Scalars['ID']['input']
link: Scalars['String']['input']
password: Scalars['String']['input']
}

export type GQLSendVerificationCodeInput = {
Expand Down
11 changes: 9 additions & 2 deletions src/mutations/campaign/sendCampaignAnnouncement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import { fromGlobalId } from 'common/utils'

const resolver: GQLMutationResolvers['sendCampaignAnnouncement'] = async (
_,
{ input: { campaign: campaignGlobalId, announcement, link } },
{ viewer, dataSources: { atomService, notificationService } }
{ input: { campaign: campaignGlobalId, announcement, link, password } },
{ viewer, dataSources: { userService, atomService, notificationService } }
) => {

Check warning on line 15 in src/mutations/campaign/sendCampaignAnnouncement.ts

View check run for this annotation

Codecov / codecov/patch

src/mutations/campaign/sendCampaignAnnouncement.ts#L15

Added line #L15 was not covered by tests
if (!viewer.id) {
throw new AuthenticationError('visitor has no permission')

Check warning on line 17 in src/mutations/campaign/sendCampaignAnnouncement.ts

View check run for this annotation

Codecov / codecov/patch

src/mutations/campaign/sendCampaignAnnouncement.ts#L17

Added line #L17 was not covered by tests
}

// validate password
if (!password) {
throw new UserInputError('`password` is required')
} else {
await userService.verifyPassword({ password, hash: viewer.passwordHash })

Check warning on line 24 in src/mutations/campaign/sendCampaignAnnouncement.ts

View check run for this annotation

Codecov / codecov/patch

src/mutations/campaign/sendCampaignAnnouncement.ts#L22-L24

Added lines #L22 - L24 were not covered by tests
}

// validate campaign
const { type: campaignType, id: campaignId } = fromGlobalId(campaignGlobalId)

Check warning on line 28 in src/mutations/campaign/sendCampaignAnnouncement.ts

View check run for this annotation

Codecov / codecov/patch

src/mutations/campaign/sendCampaignAnnouncement.ts#L28

Added line #L28 was not covered by tests

Expand Down
1 change: 1 addition & 0 deletions src/types/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default /* GraphQL */ `
campaign: ID!
announcement: [TranslationInput!]!
link: String! @constraint(format: "uri")
password: String! # admin verification
}
input CampaignStageInput {
Expand Down

0 comments on commit c0cfa50

Please sign in to comment.