Skip to content

Commit c0cfa50

Browse files
committed
feat(campaign): add password verification for "sendCampaignAnnouncement"
1 parent d98ca56 commit c0cfa50

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ input SendCampaignAnnouncementInput {
924924
campaign: ID!
925925
announcement: [TranslationInput!]!
926926
link: String!
927+
password: String!
927928
}
928929

929930
input CampaignStageInput {

src/definitions/schema.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,7 @@ export type GQLSendCampaignAnnouncementInput = {
32893289
announcement: Array<GQLTranslationInput>
32903290
campaign: Scalars['ID']['input']
32913291
link: Scalars['String']['input']
3292+
password: Scalars['String']['input']
32923293
}
32933294

32943295
export type GQLSendVerificationCodeInput = {

src/mutations/campaign/sendCampaignAnnouncement.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ import { fromGlobalId } from 'common/utils'
1010

1111
const resolver: GQLMutationResolvers['sendCampaignAnnouncement'] = async (
1212
_,
13-
{ input: { campaign: campaignGlobalId, announcement, link } },
14-
{ viewer, dataSources: { atomService, notificationService } }
13+
{ input: { campaign: campaignGlobalId, announcement, link, password } },
14+
{ viewer, dataSources: { userService, atomService, notificationService } }
1515
) => {
1616
if (!viewer.id) {
1717
throw new AuthenticationError('visitor has no permission')
1818
}
1919

20+
// validate password
21+
if (!password) {
22+
throw new UserInputError('`password` is required')
23+
} else {
24+
await userService.verifyPassword({ password, hash: viewer.passwordHash })
25+
}
26+
2027
// validate campaign
2128
const { type: campaignType, id: campaignId } = fromGlobalId(campaignGlobalId)
2229

src/types/campaign.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default /* GraphQL */ `
5757
campaign: ID!
5858
announcement: [TranslationInput!]!
5959
link: String! @constraint(format: "uri")
60+
password: String! # admin verification
6061
}
6162
6263
input CampaignStageInput {

0 commit comments

Comments
 (0)