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: release v5.15.0 - webhook attachments #2176

Merged
merged 2 commits into from
Jun 17, 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
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ 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).

#### [v5.15.0](https://github.com/opengovsg/FormSG/compare/v5.14.1...v5.15.0)

- feat: Add webhook support for storage mode attachments [`#1713`](https://github.com/opengovsg/FormSG/pull/1713)

#### [v5.14.1](https://github.com/opengovsg/FormSG/compare/v5.14.0...v5.14.1)

> 15 June 2021

- chore: bump version to v5.14.1 [`d7a612e`](https://github.com/opengovsg/FormSG/commit/d7a612e55ed56aac1d7784d25a8b894b924f3401)
- fix: allow read key in permissionList when updating collaborators [`6ae1af6`](https://github.com/opengovsg/FormSG/commit/6ae1af6859e8b9be275204f4274ba396a6769ff4)

#### [v5.14.0](https://github.com/opengovsg/FormSG/compare/v5.13.1...v5.14.0)
Expand Down Expand Up @@ -166,7 +173,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- fix(verification): loosen OTP waiting time by 2 seconds [`#1957`](https://github.com/opengovsg/FormSG/pull/1957)
- chore: bump version to 5.12.0 [`85759bc`](https://github.com/opengovsg/FormSG/commit/85759bc9dc01f73da3cbd0ec73c636e58e983948)

#### [v5.11.0](https://github.com/opengovsg/FormSG/compare/v5.10.1...v5.11.0)
#### [v5.11.0](https://github.com/opengovsg/FormSG/compare/v5.10.0...v5.11.0)

> 25 May 2021

Expand Down Expand Up @@ -234,11 +241,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- chore(deps-dev): bump @typescript-eslint/eslint-plugin [`#1868`](https://github.com/opengovsg/FormSG/pull/1868)
- fix(deps): bump @sentry/integrations from 6.3.5 to 6.3.6 [`#1850`](https://github.com/opengovsg/FormSG/pull/1850)
- chore: bump version to 5.11.0 [`54b1958`](https://github.com/opengovsg/FormSG/commit/54b1958d0968e670ef145461d9d7859384d573ef)

#### [v5.10.1](https://github.com/opengovsg/FormSG/compare/v5.10.0...v5.10.1)

> 17 May 2021

- chore: bump version to v5.10.1 [`0442cd7`](https://github.com/opengovsg/FormSG/commit/0442cd72637019fb1e43bce5f8f5abe14ee79f8c)
- fix: allow for unknown keys in updateEndPage validator [`617d86a`](https://github.com/opengovsg/FormSG/commit/617d86a28910eec6ebd3249a2de636086429d6a6)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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.14.1",
"version": "5.15.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down
6 changes: 6 additions & 0 deletions src/app/models/__tests__/submission.server.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('Submission Model', () => {
isRetryEnabled: true,
webhookView: {
data: {
attachmentDownloadUrls: {},
formId: String(form._id),
submissionId: String(submission._id),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
Expand Down Expand Up @@ -120,6 +121,7 @@ describe('Submission Model', () => {
isRetryEnabled: false,
webhookView: {
data: {
attachmentDownloadUrls: {},
formId: String(form._id),
submissionId: String(submission._id),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('Submission Model', () => {
isRetryEnabled: false,
webhookView: {
data: {
attachmentDownloadUrls: {},
formId: String(form._id),
submissionId: String(submission._id),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
Expand Down Expand Up @@ -268,6 +271,7 @@ describe('Submission Model', () => {
created: expect.any(Date),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: undefined,
attachmentDownloadUrls: {},
version: 1,
},
})
Expand All @@ -294,6 +298,7 @@ describe('Submission Model', () => {
// Assert
expect(actualWebhookView).toEqual({
data: {
attachmentDownloadUrls: {},
formId: expect.any(String),
submissionId: expect.any(String),
created: expect.any(Date),
Expand Down Expand Up @@ -336,6 +341,7 @@ describe('Submission Model', () => {
// Assert
expect(actualWebhookView).toEqual({
data: {
attachmentDownloadUrls: {},
formId: expect.any(String),
submissionId: expect.any(String),
created: expect.any(Date),
Expand Down
23 changes: 1 addition & 22 deletions src/app/models/field/attachmentField.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Document, Schema } from 'mongoose'

import {
AttachmentSize,
IAttachmentField,
IFormSchema,
ResponseMode,
} from '../../../types'
import { AttachmentSize, IAttachmentField, IFormSchema } from '../../../types'

// Manual override since mongoose types don't have generics yet.
interface IAttachmentFieldSchema extends IAttachmentField, Document {
Expand All @@ -24,22 +19,6 @@ const createAttachmentFieldSchema = () => {
},
})

// Prevent attachments from being saved on a webhooked form.
AttachmentFieldSchema.pre<IAttachmentFieldSchema>(
'validate',
function (next) {
const { webhook, responseMode } = this.parent()

if (responseMode === ResponseMode.Encrypt && webhook?.url) {
return next(
Error('Attachments are not allowed when a form has a webhook url'),
)
}

return next()
},
)

return AttachmentFieldSchema
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/models/submission.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,18 @@ EncryptSubmissionSchema.methods.getWebhookView = function (
const formId = this.populated('form')
? String(this.form._id)
: String(this.form)
const attachmentRecords = Object.fromEntries(
this.attachmentMetadata ?? new Map(),
)

const webhookData: WebhookData = {
formId,
submissionId: String(this._id),
encryptedContent: this.encryptedContent,
verifiedContent: this.verifiedContent,
version: this.version,
created: this.created,
attachmentDownloadUrls: attachmentRecords,
}

return {
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/webhook/__tests__/webhook.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ describe('webhook.service', () => {
formId: MOCK_FORM_ID,
submissionId: MOCK_SUBMISSION_ID,
verifiedContent: 'mockVerifiedContent',
attachmentDownloadUrls: {
'some-field-id': 'https://mock.s3.url/some/s3/url/timeout=3600',
},
version: 1,
},
}
Expand Down
14 changes: 14 additions & 0 deletions src/app/modules/webhook/webhook.errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ export class WebhookValidationError extends ApplicationError {
}
}

/**
* Webhook failed to generate S3 presigned URLs for attachments
*/
export class WebhookFailedWithPresignedUrlGenerationError extends ApplicationError {
meta: {
originalError: unknown
}

constructor(error: unknown, message = 'Presigned Url Generation failed') {
super(message)
this.meta = { originalError: error }
}
}

/**
* Webhook returned non-200 status, but error is not instance of AxiosError
*/
Expand Down
Loading