Skip to content

Commit

Permalink
fix(encrypt-submission): add missing ndi response fields
Browse files Browse the repository at this point in the history
  • Loading branch information
g-tejas committed Jun 27, 2024
1 parent 79106eb commit 2b5ddcb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/app/modules/submission/ParsedResponsesObject.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type NdiUserInfo =

export default class ParsedResponsesObject {
public ndiResponses: ProcessedFieldResponse[] = []
private constructor(public responses: ProcessedFieldResponse[]) {}
constructor(public responses: ProcessedFieldResponse[]) {}

addNdiResponses(info: NdiUserInfo): ParsedResponsesObject {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ import * as VerifiedContentService from '../../verified-content/verified-content
import * as EmailSubmissionService from '../email-submission/email-submission.service'
import { SubmissionEmailObj } from '../email-submission/email-submission.util'
import * as EncryptSubmissionMiddleware from '../encrypt-submission/encrypt-submission.middleware'
import ParsedResponsesObject from '../ParsedResponsesObject.class'
import * as ReceiverMiddleware from '../receiver/receiver.middleware'
import { SubmissionFailedError } from '../submission.errors'
import { uploadAttachments } from '../submission.service'
import { ProcessedFieldResponse } from '../submission.types'
import { mapRouteError } from '../submission.utils'
import { reportSubmissionResponseTime } from '../submissions.statsd-client'

Expand Down Expand Up @@ -132,6 +134,10 @@ const submitEncryptModeForm = async (
const { encryptedContent, responseMetadata, paymentProducts } =
encryptedPayload

// This is because NRIC masking is done in the controller, but we parse the fields in the
// middleware for encrypt forms
const parsedResponses = new ParsedResponsesObject(req.body.responses)

// Checks if user is SPCP-authenticated before allowing submission
let uinFin
let userInfo
Expand All @@ -157,6 +163,11 @@ const submitEncryptModeForm = async (
})
}
uinFin = jwtPayloadResult.value.userName
uinFin = form.isNricMaskEnabled ? maskNric(uinFin) : uinFin
parsedResponses.addNdiResponses({
authType,
uinFin,
})
break
}
case FormAuthType.CP: {
Expand All @@ -179,7 +190,13 @@ const submitEncryptModeForm = async (
})
}
uinFin = jwtPayloadResult.value.userName
uinFin = form.isNricMaskEnabled ? maskNric(uinFin) : uinFin
userInfo = jwtPayloadResult.value.userInfo
parsedResponses.addNdiResponses({
authType,
uinFin,
userInfo,
})
break
}
case FormAuthType.SGID_MyInfo:
Expand Down Expand Up @@ -219,6 +236,11 @@ const submitEncryptModeForm = async (
})
}
uinFin = jwtPayloadResult.value
uinFin = form.isNricMaskEnabled ? maskNric(uinFin) : uinFin
parsedResponses.addNdiResponses({
authType,
uinFin,
})
break
}
case FormAuthType.SGID: {
Expand All @@ -240,23 +262,15 @@ const submitEncryptModeForm = async (
})
}
uinFin = jwtPayloadResult.value.userName
uinFin = form.isNricMaskEnabled ? maskNric(uinFin) : uinFin
parsedResponses.addNdiResponses({
authType,
uinFin,
})
break
}
}

// Mask if Nric masking is enabled
if (
uinFin &&
form.isNricMaskEnabled &&
(form.authType === FormAuthType.SP ||
form.authType === FormAuthType.CP ||
form.authType === FormAuthType.SGID ||
form.authType === FormAuthType.MyInfo ||
form.authType === FormAuthType.SGID_MyInfo)
) {
uinFin = maskNric(uinFin)
}

// Encrypt Verified SPCP Fields
let verified
if (
Expand Down Expand Up @@ -351,6 +365,7 @@ const submitEncryptModeForm = async (
formId,
form,
responses: req.formsg.filteredResponses,
emailFields: parsedResponses.getAllResponses(),
responseMetadata,
submissionContent,
})
Expand Down Expand Up @@ -613,11 +628,13 @@ const _createSubmission = async ({
form,
responseMetadata,
responses,
emailFields,
}: {
req: Parameters<SubmitEncryptModeFormHandlerType>[0]
res: Parameters<SubmitEncryptModeFormHandlerType>[1]
responseMetadata: EncryptSubmissionDto['responseMetadata']
responses: ParsedClearFormFieldResponse[]
emailFields: ProcessedFieldResponse[]
formId: string
form: IPopulatedEncryptedForm
submissionContent: EncryptSubmissionContent
Expand Down Expand Up @@ -667,7 +684,7 @@ const _createSubmission = async ({
})

const emailData = new SubmissionEmailObj(
responses,
emailFields,
new Set(), // the MyInfo prefixes are already inserted in middleware
form.authType,
)
Expand All @@ -677,7 +694,7 @@ const _createSubmission = async ({
// stop the storage of the data in the db
if (((form as IEncryptedForm)?.emails || []).length > 0) {
void MailService.sendSubmissionToAdmin({
replyToEmails: EmailSubmissionService.extractEmailAnswers(responses),
replyToEmails: EmailSubmissionService.extractEmailAnswers(emailFields),
form,
submission: {
created: createdTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import * as FormService from '../../form/form.service'
import { MyInfoService } from '../../myinfo/myinfo.service'
import { extractMyInfoLoginJwt } from '../../myinfo/myinfo.util'
import * as PaymentsService from '../../payments/payments.service'
import { SGID_COOKIE_NAME } from '../../sgid/sgid.constants'

Check failure on line 30 in src/app/modules/submission/encrypt-submission/encrypt-submission.middleware.ts

View workflow job for this annotation

GitHub Actions / backend_lint

'SGID_COOKIE_NAME' is defined but never used
import { SgidService } from '../../sgid/sgid.service'

Check failure on line 31 in src/app/modules/submission/encrypt-submission/encrypt-submission.middleware.ts

View workflow job for this annotation

GitHub Actions / backend_lint

'SgidService' is defined but never used
import { getOidcService } from '../../spcp/spcp.oidc.service'

Check failure on line 32 in src/app/modules/submission/encrypt-submission/encrypt-submission.middleware.ts

View workflow job for this annotation

GitHub Actions / backend_lint

'getOidcService' is defined but never used
import { IPopulatedStorageFormWithResponsesAndHash } from '../email-submission/email-submission.types'
import ParsedResponsesObject from '../ParsedResponsesObject.class'
import { sharedSubmissionParams } from '../submission.constants'
Expand Down

0 comments on commit 2b5ddcb

Please sign in to comment.