Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: merge Release 5.5.0 into develop #1566

Merged
merged 10 commits into from
Apr 6, 2021
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
98 changes: 53 additions & 45 deletions CHANGELOG.md

Large diffs are not rendered by default.

202 changes: 101 additions & 101 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "5.4.1",
"version": "5.5.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down Expand Up @@ -63,7 +63,7 @@
"@opengovsg/formsg-sdk": "^0.8.4-beta.0",
"@opengovsg/myinfo-gov-client": "=4.0.0-beta.0",
"@opengovsg/ng-file-upload": "^12.2.15",
"@opengovsg/spcp-auth-client": "^1.4.4",
"@opengovsg/spcp-auth-client": "^1.4.5",
"@sentry/browser": "^6.2.5",
"@sentry/integrations": "^6.2.5",
"@stablelib/base64": "^1.0.0",
Expand Down Expand Up @@ -125,7 +125,7 @@
"lodash": "^4.17.21",
"moment-timezone": "0.5.33",
"mongodb-uri": "^0.9.7",
"mongoose": "^5.11.10",
"mongoose": "^5.12.3",
"multiparty": ">=4.2.2",
"neverthrow": "^4.2.1",
"ng-infinite-scroll": "^1.3.0",
Expand Down Expand Up @@ -179,7 +179,7 @@
"@types/ip": "^1.1.0",
"@types/jest": "^26.0.22",
"@types/json-stringify-safe": "^5.0.0",
"@types/mongodb": "^3.6.10",
"@types/mongodb": "^3.6.12",
"@types/mongodb-uri": "^0.9.0",
"@types/node": "^14.14.37",
"@types/nodemailer": "^6.4.1",
Expand All @@ -192,8 +192,8 @@
"@types/uid-generator": "^2.0.2",
"@types/uuid": "^8.3.0",
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"auto-changelog": "^2.2.1",
"axios-mock-adapter": "^1.19.0",
"babel-loader": "^8.2.2",
Expand All @@ -209,7 +209,7 @@
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-angular": "^4.0.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.3",
"eslint-plugin-jest": "^24.3.4",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-typesafe": "^0.5.2",
Expand All @@ -231,7 +231,7 @@
"mockdate": "^3.0.5",
"mockingoose": "^2.13.2",
"mongodb-memory-server-core": "^6.9.6",
"ngrok": "^4.0.0",
"ngrok": "^4.0.1",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"prettier": "^2.2.1",
"proxyquire": "^2.1.3",
Expand Down
5 changes: 4 additions & 1 deletion src/app/models/admin_verification.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { USER_SCHEMA_ID } from './user.server.model'

export const ADMIN_VERIFICATION_SCHEMA_ID = 'AdminVerification'

const AdminVerificationSchema = new Schema<IAdminVerificationSchema>(
const AdminVerificationSchema = new Schema<
IAdminVerificationSchema,
IAdminVerificationModel
>(
{
admin: {
type: Schema.Types.ObjectId,
Expand Down
28 changes: 15 additions & 13 deletions src/app/models/form.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const EncryptedFormSchema = new Schema<IEncryptedFormSchema>({
},
})

const EmailFormSchema = new Schema<IEmailFormSchema>({
const EmailFormSchema = new Schema<IEmailFormSchema, IEmailFormModel>({
emails: {
type: [
{
Expand Down Expand Up @@ -159,7 +159,7 @@ const compileFormModel = (db: Mongoose): IFormModel => {
const User = getUserModel(db)

// Schema
const FormSchema = new Schema<IFormSchema>(
const FormSchema = new Schema<IFormSchema, IFormModel>(
{
title: {
type: String,
Expand Down Expand Up @@ -342,7 +342,7 @@ const compileFormModel = (db: Mongoose): IFormModel => {
// Add discriminators for the various field types.
const FormFieldPath = FormSchema.path(
'form_fields',
) as Schema.Types.DocumentArray
) as Schema.Types.DocumentArrayWithLooseDiscriminator

const TableFieldSchema = createTableFieldSchema()

Expand Down Expand Up @@ -376,7 +376,7 @@ const compileFormModel = (db: Mongoose): IFormModel => {
FormFieldPath.discriminator(BasicField.Table, TableFieldSchema)
const TableColumnPath = TableFieldSchema.path(
'columns',
) as Schema.Types.DocumentArray
) as Schema.Types.DocumentArrayWithLooseDiscriminator
TableColumnPath.discriminator(
BasicField.ShortText,
createShortTextFieldSchema(),
Expand All @@ -389,13 +389,13 @@ const compileFormModel = (db: Mongoose): IFormModel => {
// Discriminator defines all possible values of startPage.logo
const StartPageLogoPath = FormSchema.path(
'startPage.logo',
) as Schema.Types.DocumentArray
) as Schema.Types.DocumentArrayWithLooseDiscriminator
StartPageLogoPath.discriminator(FormLogoState.Custom, CustomFormLogoSchema)

// Discriminator defines different logic types
const FormLogicPath = FormSchema.path(
'form_logics',
) as Schema.Types.DocumentArray
) as Schema.Types.DocumentArrayWithLooseDiscriminator

FormLogicPath.discriminator(LogicType.ShowFields, ShowFieldsLogicSchema)
FormLogicPath.discriminator(LogicType.PreventSubmit, PreventSubmitLogicSchema)
Expand Down Expand Up @@ -458,12 +458,6 @@ const compileFormModel = (db: Mongoose): IFormModel => {
}
}

FormSchema.methods.getSettings = function (
this: IFormDocument,
): FormSettings {
return pick(this, FORM_SETTING_FIELDS)
}

// Archives form.
FormSchema.methods.archive = function (this: IFormSchema) {
// Return instantly when form is already archived.
Expand All @@ -475,8 +469,16 @@ const compileFormModel = (db: Mongoose): IFormModel => {
return this.save()
}

const FormDocumentSchema = (FormSchema as unknown) as Schema<IFormDocument>

FormDocumentSchema.methods.getSettings = function (
this: IFormDocument,
): FormSettings {
return pick(this, FORM_SETTING_FIELDS)
}

// Transfer ownership of the form to another user
FormSchema.methods.transferOwner = async function (
FormDocumentSchema.methods.transferOwner = async function (
this: IFormDocument,
currentOwner: IUserSchema,
newOwner: IUserSchema,
Expand Down
5 changes: 4 additions & 1 deletion src/app/models/form_statistics_total.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const FORM_STATS_TOTAL_SCHEMA_ID = 'FormStatisticsTotal'
const FORM_STATS_COLLECTION_NAME = 'formStatisticsTotal'

const compileFormStatisticsTotalModel = (db: Mongoose) => {
const FormStatisticsTotalSchema = new Schema<IFormStatisticsTotalSchema>(
const FormStatisticsTotalSchema = new Schema<
IFormStatisticsTotalSchema,
IFormStatisticsTotalModel
>(
{
formId: {
type: Schema.Types.ObjectId,
Expand Down
6 changes: 3 additions & 3 deletions src/app/models/login.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { USER_SCHEMA_ID } from './user.server.model'

export const LOGIN_SCHEMA_ID = 'Login'

const LoginSchema = new Schema<ILoginSchema>(
const LoginSchema = new Schema<ILoginSchema, ILoginModel>(
{
admin: {
type: Schema.Types.ObjectId,
Expand Down Expand Up @@ -133,7 +133,7 @@ LoginSchema.statics.aggregateLoginStats = function (
}

const compileLoginModel = (db: Mongoose) =>
db.model<ILoginSchema>(LOGIN_SCHEMA_ID, LoginSchema) as ILoginModel
db.model<ILoginSchema, ILoginModel>(LOGIN_SCHEMA_ID, LoginSchema)

/**
* Retrieves the Login model on the given Mongoose instance. If the model is
Expand All @@ -143,7 +143,7 @@ const compileLoginModel = (db: Mongoose) =>
*/
const getLoginModel = (db: Mongoose): ILoginModel => {
try {
return db.model(LOGIN_SCHEMA_ID) as ILoginModel
return db.model<ILoginSchema, ILoginModel>(LOGIN_SCHEMA_ID)
} catch {
return compileLoginModel(db)
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/models/submission.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { FORM_SCHEMA_ID } from './form.server.model'

export const SUBMISSION_SCHEMA_ID = 'Submission'

const SubmissionSchema = new Schema<ISubmissionSchema>(
const SubmissionSchema = new Schema<ISubmissionSchema, ISubmissionModel>(
{
form: {
type: Schema.Types.ObjectId,
Expand Down Expand Up @@ -143,7 +143,10 @@ const webhookResponseSchema = new Schema<IWebhookResponseSchema>(
},
)

const EncryptSubmissionSchema = new Schema<IEncryptedSubmissionSchema>({
const EncryptSubmissionSchema = new Schema<
IEncryptedSubmissionSchema,
IEncryptSubmissionModel
>({
encryptedContent: {
type: String,
trim: true,
Expand Down Expand Up @@ -347,15 +350,15 @@ const compileSubmissionModel = (db: Mongoose): ISubmissionModel => {
const Submission = db.model('Submission', SubmissionSchema)
Submission.discriminator(SubmissionType.Email, EmailSubmissionSchema)
Submission.discriminator(SubmissionType.Encrypt, EncryptSubmissionSchema)
return db.model<ISubmissionSchema>(
return db.model<ISubmissionSchema, ISubmissionModel>(
SUBMISSION_SCHEMA_ID,
SubmissionSchema,
) as ISubmissionModel
)
}

const getSubmissionModel = (db: Mongoose): ISubmissionModel => {
try {
return db.model(SUBMISSION_SCHEMA_ID) as ISubmissionModel
return db.model<ISubmissionSchema, ISubmissionModel>(SUBMISSION_SCHEMA_ID)
} catch {
return compileSubmissionModel(db)
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/token.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IToken, ITokenModel, ITokenSchema } from '../../types'

export const TOKEN_SCHEMA_ID = 'Token'

const TokenSchema = new Schema<ITokenSchema>({
const TokenSchema = new Schema<ITokenSchema, ITokenModel>({
email: {
type: String,
required: true,
Expand Down
5 changes: 3 additions & 2 deletions src/app/models/user.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const USER_SCHEMA_ID = 'User'
const compileUserModel = (db: Mongoose) => {
const Agency = getAgencyModel(db)

const UserSchema: Schema<IUserSchema> = new Schema(
const UserSchema: Schema<IUserSchema, IUserModel> = new Schema(
{
email: {
type: String,
Expand Down Expand Up @@ -59,7 +59,8 @@ const compileUserModel = (db: Mongoose) => {
if (!phoneNumber) return false
return phoneNumber.isValid()
},
message: (props) => `${props.value} is not a valid mobile number`,
message: (props: { value: string }) =>
`${props.value} is not a valid mobile number`,
},
},
lastAccessed: Date,
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/bounce/bounce.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IBounceModel extends Model<IBounceSchema> {
) => IBounceSchema
}

const BounceSchema = new Schema<IBounceSchema>({
const BounceSchema = new Schema<IBounceSchema, IBounceModel>({
formId: {
type: Schema.Types.ObjectId,
ref: FORM_SCHEMA_ID,
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/myinfo/myinfo_hash.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FORM_SCHEMA_ID } from '../../models/form.server.model'

export const MYINFO_HASH_SCHEMA_ID = 'MyInfoHash'

const MyInfoHashSchema = new Schema<IMyInfoHashSchema>(
const MyInfoHashSchema = new Schema<IMyInfoHashSchema, IMyInfoHashModel>(
{
// We stored a hashed uinFin using a salt stored as a env var
// Note: key name not updated to reflect this for backward compatibility purposes
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ export const getFormSubmissionsCount = (
* @returns ok(true) if all emails were sent successfully
* @returns err(SendEmailConfirmationError) if any email failed to be sent
*/
export const sendEmailConfirmations = ({
export const sendEmailConfirmations = <S extends ISubmissionSchema>({
form,
submission,
parsedResponses,
autoReplyData,
attachments,
}: {
form: IPopulatedForm
submission: ISubmissionSchema
submission: S
parsedResponses: ProcessedFieldResponse[]
autoReplyData?: EmailRespondentConfirmationField[]
attachments?: IAttachmentInfo[]
Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/verification/verification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SALT_ROUNDS } from '../../../shared/util/verification'
import { PublicTransaction } from '../../../types'
import { ErrorDto } from '../../../types/api'
import { generateOtpWithHash } from '../../utils/otp'
import { createReqMeta } from '../../utils/request'

import { VerificationFactory } from './verification.factory'
import { Transaction } from './verification.types'
Expand All @@ -30,6 +31,7 @@ export const handleCreateTransaction: RequestHandler<
const logMeta = {
action: 'handleCreateTransaction',
formId,
...createReqMeta(req),
}
return VerificationFactory.createTransaction(formId)
.map((transaction) => {
Expand Down Expand Up @@ -66,6 +68,7 @@ export const handleGetTransactionMetadata: RequestHandler<
const logMeta = {
action: 'handleGetTransactionMetadata',
transactionId,
...createReqMeta(req),
}
return VerificationFactory.getTransactionMetadata(transactionId)
.map((publicTransaction) =>
Expand Down Expand Up @@ -99,6 +102,7 @@ export const handleResetField: RequestHandler<
action: 'handleResetField',
transactionId,
fieldId,
...createReqMeta(req),
}
return VerificationFactory.resetFieldForTransaction(transactionId, fieldId)
.map(() => res.sendStatus(StatusCodes.OK))
Expand Down Expand Up @@ -130,6 +134,7 @@ export const handleGetOtp: RequestHandler<
action: 'handleGetOtp',
transactionId,
fieldId,
...createReqMeta(req),
}
return generateOtpWithHash(logMeta, SALT_ROUNDS)
.andThen(({ otp, hashedOtp }) =>
Expand Down Expand Up @@ -171,6 +176,7 @@ export const handleVerifyOtp: RequestHandler<
action: 'handleVerifyOtp',
transactionId,
fieldId,
...createReqMeta(req),
}
return VerificationFactory.verifyOtp(transactionId, fieldId, otp)
.map((signedData) => res.status(StatusCodes.OK).json(signedData))
Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/verification/verification.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ const VerificationFieldSchema = new Schema<IVerificationFieldSchema>({
})

const compileVerificationModel = (db: Mongoose): IVerificationModel => {
const VerificationSchema = new Schema<IVerificationSchema>({
const VerificationSchema = new Schema<
IVerificationSchema,
IVerificationModel
>({
formId: {
type: Schema.Types.ObjectId,
ref: FORM_SCHEMA_ID,
Expand Down
Loading