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

feat: add send events and API endpoint for uploading submissions to S3 #3003

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Apr 10, 2024

These are the backend changes following on from #2999:

  • Adds API endpoint /upload-submisison/:localAuthority within Send module to generate digital planning payload JSON & upload as a private file to a specified/static S3 folder within our main user data bucket
  • Hooks up Hasura send events for this destination

Testing:

  • Go to a supported submission service flow in Barnet's editor workspace (eg Prior Approval)
    • Update Send component to select S3 option and publish
  • Open /published link and fill out application (note that Pay is not enabled for Barnet and will show error, but you can "Continue" through without paying for this test and still generate a valid payload)
  • After reaching Confirmation page, check Hasura events for successful audit log
    • The success message will include a link the uploaded submission on S3 like below
    • Confirm that JSON file is private and you can download successfully if authenticated
    • The lowcal_session database record should also be marked as submitted

Screenshot from 2024-04-11 09-43-39

Copy link

github-actions bot commented Apr 10, 2024

Removed vultr server and associated DNS entries

ContentDisposition: `inline;filename="${filename}"`,
ContentType: file.mimetype,
ContentType: file?.mimetype || "application/json",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit surprisingly, exportData (our DigitalPlanningApplication typed object) satisfies type Express.Multer.File expected by these functions. It won't have a buffer & mimetype properties, but the S3.PutObjectRequest.Body accepts any string so I've just defined this simple JSON.stringify() fallback here.

Would be a good one to more intentionally revisit in a follow-up PR if this grows beyond a proof-of-concept!

@jessicamcinchak jessicamcinchak marked this pull request as ready for review April 11, 2024 08:08
@jessicamcinchak jessicamcinchak requested a review from a team April 11, 2024 08:08
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-only review looks great! Going onto manual testing now (thanks for notes!) and I'll follow up shortly 👍

});
});

it.todo("succeeds"); // mock uploadPrivateFile ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure there are examples of this (mocking aws-sdk/clients/s3 basically) in file.test.ts 👍

Comment on lines +11 to +32
// `/upload-submission/:localAuthority` is only called via Hasura's scheduled event webhook, so body is wrapped in a "payload" key
const { payload } = req.body;
const localAuthority = req.params.localAuthority;

if (!payload?.sessionId) {
return next({
status: 400,
message: `Missing application payload data to send to email`,
});
}

try {
const { sessionId } = payload;

// Only prototyping with Barnet to begin
// In future, confirm this local authority has an S3 bucket/folder configured in team_integrations or similar
if (localAuthority !== "barnet") {
return next({
status: 400,
message: `Send to S3 is not enabled for this local authority (${localAuthority})`,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: /send is one of the modules that still doesn't have the validation layer finished.

It could be nice to call validate() as a middleware in the route before getting here which would save us some of this manual checking.

Totally fair if this is a follow up, post-prototype tidy up tbh (I think there's shared validation logic between various /send routes so this might be nice to tackle in one go).

Comment on lines +118 to +127
if (
value === Destination.S3 &&
newCheckedValues.includes(value) &&
teamSlug !== "barnet"
) {
alert(
"AWS S3 uploads are currently being prototyped with Barnet only. Please do not select this option for other councils yet.",
);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit / no action needed): As this grows it looks like a good case for a formik validation schema, similar to how we handle logic for other forms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these validation reminders - will address all in followup PRs - going to merge this initial work so I can get test links over to Kev sooner than later 👍

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The success message will include a link the uploaded submission on S3 like below
  • Confirm that JSON file is private and you can download successfully if authenticated
  • The lowcal_session database record should also be marked as submitted

Tested and working as expected! ✅

@jessicamcinchak jessicamcinchak merged commit 18ab668 into main Apr 11, 2024
12 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/barnet-prototype-api branch April 11, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants