Skip to content

Commit

Permalink
Merge pull request #1629 from opengovsg/release-v5.5.1
Browse files Browse the repository at this point in the history
chore: merge release v5.5.1 to master
  • Loading branch information
karrui authored Apr 13, 2021
2 parents 4556b00 + aca5c20 commit 4f0194c
Show file tree
Hide file tree
Showing 57 changed files with 4,942 additions and 1,707 deletions.
104 changes: 59 additions & 45 deletions CHANGELOG.md

Large diffs are not rendered by default.

694 changes: 366 additions & 328 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 13 additions & 15 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.1",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down Expand Up @@ -63,9 +63,9 @@
"@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",
"@sentry/browser": "^6.2.3",
"@sentry/integrations": "^6.2.3",
"@opengovsg/spcp-auth-client": "^1.4.5",
"@sentry/browser": "^6.2.5",
"@sentry/integrations": "^6.2.5",
"@stablelib/base64": "^1.0.0",
"JSONStream": "^1.3.5",
"abortcontroller-polyfill": "^1.7.1",
Expand All @@ -84,7 +84,7 @@
"angular-ui-bootstrap": "~2.5.6",
"angular-ui-router": "~1.0.29",
"aws-info": "^1.2.0",
"aws-sdk": "^2.874.0",
"aws-sdk": "^2.879.0",
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"bluebird": "^3.5.2",
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 All @@ -134,7 +134,6 @@
"nocache": "^2.1.0",
"node-cache": "^5.1.2",
"nodemailer": "^6.5.0",
"nodemailer-direct-transport": "~3.3.2",
"opossum": "^6.0.0",
"p-queue": "^6.6.2",
"promise-retry": "^2.0.1",
Expand All @@ -158,7 +157,7 @@
"winston-cloudwatch": "^2.5.0"
},
"devDependencies": {
"@babel/core": "^7.13.13",
"@babel/core": "^7.13.14",
"@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.12",
"@opengovsg/mockpass": "^2.6.8",
Expand All @@ -180,11 +179,10 @@
"@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",
"@types/nodemailer-direct-transport": "^1.0.31",
"@types/opossum": "^4.1.1",
"@types/promise-retry": "^1.1.3",
"@types/puppeteer-core": "^5.4.0",
Expand All @@ -194,8 +192,8 @@
"@types/uid-generator": "^2.0.2",
"@types/uuid": "^8.3.0",
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.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 @@ -211,15 +209,15 @@
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-angular": "^4.0.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.2",
"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",
"form-data": "^4.0.0",
"google-fonts-plugin": "4.1.0",
"html-loader": "~0.5.5",
"htmlhint": "^0.14.2",
"husky": "^5.2.0",
"husky": "^6.0.0",
"jasmine": "^3.7.0",
"jasmine-core": "^3.7.1",
"jasmine-sinon": "^0.4.0",
Expand All @@ -233,7 +231,7 @@
"mockdate": "^3.0.5",
"mockingoose": "^2.13.2",
"mongodb-memory-server-core": "^6.9.6",
"ngrok": "^3.4.1",
"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
10 changes: 10 additions & 0 deletions src/app/modules/core/core.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export class DatabasePayloadSizeError extends ApplicationError {
super(message)
}
}

/**
* Union of all possible database errors
*/
export type PossibleDatabaseError =
| DatabaseError
| DatabaseValidationError
| DatabaseConflictError
| DatabasePayloadSizeError

export class MalformedParametersError extends ApplicationError {
constructor(message: string, meta?: unknown) {
super(message, meta)
Expand Down
7 changes: 6 additions & 1 deletion src/app/modules/form/__tests__/form.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ describe('FormService', () => {
)

// Assert
expect(actual._unsafeUnwrapErr()).toEqual(new PrivateFormError())
expect(actual._unsafeUnwrapErr()).toEqual(
new PrivateFormError(
'Submission made after form submission limit was reached',
form.title,
),
)
const updated = await Form.findById(form._id)
expect(updated!.status).toBe('PRIVATE')
})
Expand Down
Loading

0 comments on commit 4f0194c

Please sign in to comment.