Skip to content

Commit

Permalink
Merge pull request #7008 from opengovsg/chore/drop-encrypt-mode
Browse files Browse the repository at this point in the history
build: release 6.100.0
  • Loading branch information
tshuli committed Jan 9, 2024
2 parents 74b124b + b8e2acc commit 8817158
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 774 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.100.0](https://github.com/opengovsg/FormSG/compare/v6.99.0...v6.100.0)

- build: release v6.99.0 [`#7006`](https://github.com/opengovsg/FormSG/pull/7006)
- chore: remove old encrypt submission route [`02aacc2`](https://github.com/opengovsg/FormSG/commit/02aacc24a47d310dbc9aba51b69481ba41c2680c)
- chore: remove non encryption boundary fallback on frontend [`a1972f4`](https://github.com/opengovsg/FormSG/commit/a1972f4dd0106a0147be827e9fed0de57c84efe5)
- chore: remove feature flags [`0da0f61`](https://github.com/opengovsg/FormSG/commit/0da0f6143f32d9e33a9fcccda9900d031243fb97)

#### [v6.99.0](https://github.com/opengovsg/FormSG/compare/v6.98.0...v6.99.0)

> 8 January 2024

- chore: add advertising for Checkpoint [`#7005`](https://github.com/opengovsg/FormSG/pull/7005)
- chore(deps): update libphonenumber-js package [`#6904`](https://github.com/opengovsg/FormSG/pull/6904)
- fix(mrf): loading checkbox response, ui fixes [`#6997`](https://github.com/opengovsg/FormSG/pull/6997)
Expand All @@ -14,6 +23,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- build: merge release v6.98.0 into develop [`#6995`](https://github.com/opengovsg/FormSG/pull/6995)
- build: release v6.98.0 [`#6994`](https://github.com/opengovsg/FormSG/pull/6994)
- chore: bump version to v6.98.0 [`614d3a1`](https://github.com/opengovsg/FormSG/commit/614d3a1af0640525a9b0b66116230d1113431c2f)
- chore: bump version to v6.99.0 [`30cc270`](https://github.com/opengovsg/FormSG/commit/30cc270dc51adaead44a3446e19f642cf0280288)

#### [v6.98.0](https://github.com/opengovsg/FormSG/compare/v6.97.0...v6.98.0)

Expand Down
11 changes: 1 addition & 10 deletions __tests__/e2e/encrypt-submission.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import mongoose from 'mongoose'
import { featureFlags } from 'shared/constants/feature-flags'
import {
BasicField,
FormAuthType,
FormResponseMode,
MyInfoAttribute,
} from 'shared/types'

import { IFeatureFlagModel, IFormModel } from 'src/types'
import { IFormModel } from 'src/types'

import {
ALL_FIELDS as _ALL_FIELDS,
Expand Down Expand Up @@ -43,20 +42,12 @@ const runEncryptSubmissionTest = createSubmissionTestRunnerForResponseMode(

let db: mongoose.Connection
let Form: IFormModel
let FeatureFlags: IFeatureFlagModel

test.describe('Storage form submission', () => {
test.beforeAll(async () => {
// Create models
db = await makeMongooseFixtures()
Form = makeModel(db, 'form.server.model', 'Form')
// TODO(FRM-1232): Remove this once old storage submission endpoint (/submissions/encrypt) is removed
// Add feature flag model and set encryption boundary shift to true
FeatureFlags = makeModel(db, 'feature_flag.server.model', 'FeatureFlags')
await FeatureFlags.create({
name: featureFlags.encryptionBoundaryShift,
enabled: true,
})
})
test.afterAll(async () => {
// Clean up db
Expand Down
157 changes: 47 additions & 110 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SubmitHandler } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
import { useDisclosure } from '@chakra-ui/react'
import { datadogLogs } from '@datadog/browser-logs'
import { useFeatureIsOn, useGrowthBook } from '@growthbook/growthbook-react'
import { useGrowthBook } from '@growthbook/growthbook-react'
import { differenceInMilliseconds, isPast } from 'date-fns'
import get from 'lodash/get'
import simplur from 'simplur'
Expand Down Expand Up @@ -290,16 +290,11 @@ export const PublicFormProvider = ({
}
}, [data?.form.form_fields, toast, vfnToastIdRef])

const enableVirusScanner = useFeatureIsOn(
featureFlags.encryptionBoundaryShiftVirusScanner,
)

const {
submitEmailModeFormMutation,
submitEmailModeFormFetchMutation,
submitStorageModeClearFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeClearFormWithVirusScanningMutation,
submitStorageModeFormMutation,
submitStorageModeFormFetchMutation,
submitMultirespondentFormMutation,
updateMultirespondentSubmissionMutation,
} = usePublicFormMutations(formId, previousSubmissionId)
Expand Down Expand Up @@ -514,7 +509,7 @@ export const PublicFormProvider = ({
},
})

return submitStorageModeClearFormFetchMutation
return submitStorageModeFormFetchMutation
.mutateAsync(
{
...formData,
Expand Down Expand Up @@ -570,111 +565,55 @@ export const PublicFormProvider = ({
},
})

// TODO (FRM-1413): Move to main return statement once virus scanner has been fully rolled out
if (enableVirusScanner) {
return submitStorageModeClearFormWithVirusScanningMutation
.mutateAsync(
{
...formData,
...formPaymentData,
},
{
onSuccess: ({
submissionId,
return submitStorageModeFormMutation
.mutateAsync(
{
...formData,
...formPaymentData,
},
{
onSuccess: ({
submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
})
},
},
)
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error,
},
},
)

if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
}

return (
submitStorageModeClearFormMutation
.mutateAsync(
{
...formData,
...formPaymentData,
})
},
},
)
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
onSuccess: ({
submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
})
},
},
)
// Using catch since we are using mutateAsync and react-hook-form will continue bubbling this up.
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(`handleSubmitForm: ${error.message}`, {
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error: {
message: error.message,
stack: error.stack,
},
error,
},
})
},
)

if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
)
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
}
case FormResponseMode.Multirespondent:
return (
Expand Down Expand Up @@ -704,17 +643,15 @@ export const PublicFormProvider = ({
showErrorToast,
getCaptchaResponse,
previousSubmissionId,
submitMultirespondentFormMutation,
updateMultirespondentSubmissionMutation,
submitMultirespondentFormMutation,
submitEmailModeFormFetchMutation,
submitEmailModeFormMutation,
enableVirusScanner,
submitStorageModeClearFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeFormMutation,
submitStorageModeFormFetchMutation,
navigate,
formId,
storePaymentMemory,
submitStorageModeClearFormWithVirusScanningMutation,
],
)

Expand Down
68 changes: 16 additions & 52 deletions frontend/src/features/public-form/PublicFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PresignedPost } from 'aws-sdk/clients/s3'
import axios from 'axios'

import {
ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
MULTIRESPONDENT_FORM_SUBMISSION_VERSION,
VIRUS_SCANNER_SUBMISSION_VERSION,
} from '~shared/constants'
Expand Down Expand Up @@ -181,7 +180,9 @@ export const submitEmailModeForm = async ({
).then(({ data }) => data)
}

export const submitStorageModeClearForm = async ({
// TODO (#5826): Fallback mutation using Fetch. Remove once network error is resolved
// Submit storage mode form with virus scanning (storage v2.1+)
export const submitStorageModeFormWithFetch = async ({
formFields,
formLogics,
formInputs,
Expand All @@ -192,63 +193,26 @@ export const submitStorageModeClearForm = async ({
responseMetadata,
paymentProducts,
payments,
}: SubmitStorageFormClearArgs) => {
fieldIdToQuarantineKeyMap,
}: SubmitStorageFormWithVirusScanningArgs) => {
const filteredInputs = filterHiddenInputs({
formFields,
formInputs,
formLogics,
})

const formData = createClearSubmissionFormData({
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
})

return ApiService.post<SubmissionResponseDto>(
`${PUBLIC_FORMS_ENDPOINT}/${formId}/submissions/storage`,
formData,
const formData = createClearSubmissionWithVirusScanningFormData(
{
params: {
captchaResponse: String(captchaResponse),
captchaType: captchaType,
},
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: VIRUS_SCANNER_SUBMISSION_VERSION,
},
).then(({ data }) => data)
}

// TODO (#5826): Fallback mutation using Fetch. Remove once network error is resolved
export const submitStorageModeClearFormWithFetch = async ({
formFields,
formLogics,
formInputs,
formId,
captchaResponse = null,
captchaType = '',
paymentReceiptEmail,
responseMetadata,
paymentProducts,
payments,
}: SubmitStorageFormClearArgs) => {
const filteredInputs = filterHiddenInputs({
formFields,
formInputs,
formLogics,
})

const formData = createClearSubmissionFormData({
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
})
fieldIdToQuarantineKeyMap,
)

// Add captcha response to query string
const queryString = new URLSearchParams({
Expand All @@ -271,7 +235,7 @@ export const submitStorageModeClearFormWithFetch = async ({
}

// Submit storage mode form with virus scanning (storage v2.1+)
export const submitStorageModeClearFormWithVirusScanning = async ({
export const submitStorageModeForm = async ({
formFields,
formLogics,
formInputs,
Expand Down
Loading

0 comments on commit 8817158

Please sign in to comment.