Skip to content

Commit

Permalink
updated styling, restore button scoped to teamEditors
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed May 6, 2024
2 parents 6503713 + f047472 commit 750d73e
Show file tree
Hide file tree
Showing 45 changed files with 2,257 additions and 1,451 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ jobs:
- uses: actions/checkout@v4
- name: Cache build assets
id: cache-react-build-assets
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**') }}
Expand Down Expand Up @@ -255,11 +255,11 @@ jobs:
working-directory: infrastructure/application
- name: Download React build assets
id: cache-react-build-assets
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**', '!editor.planx/build/**') }}
- uses: pulumi/actions@v4
- uses: pulumi/actions@v5
with:
command: preview
stack-name: staging
Expand Down Expand Up @@ -377,7 +377,7 @@ jobs:
- uses: actions/checkout@v4
- name: Download React build assets
id: cache-react-build-assets
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**', '!editor.planx/build/**') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
node-version: ${{ vars.NODE_VERSION }}
# https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows#using-the-cache-action
- name: NPM cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-npm
with:
Expand All @@ -34,7 +34,7 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: PNPM cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-pnpm
with:
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
with:
name: build
path: ./editor.planx.uk/build
- uses: pulumi/actions@v4
- uses: pulumi/actions@v5
with:
command: up
stack-name: staging
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
node-version: ${{ vars.NODE_VERSION }}
# https://docs.github.com/en/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows#using-the-cache-action
- name: NPM cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-npm
with:
Expand All @@ -34,7 +34,7 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: PNPM cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-pnpm
with:
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
with:
name: build
path: ./editor.planx.uk/build
- uses: pulumi/actions@v4
- uses: pulumi/actions@v5
with:
command: up
stack-name: production
Expand Down
34 changes: 32 additions & 2 deletions api.planx.uk/modules/send/s3/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import supertest from "supertest";
import app from "../../../server";
import { expectedPlanningPermissionPayload } from "../../../tests/mocks/digitalPlanningDataMocks";
import { queryMock } from "../../../tests/graphqlQueryMock";

jest.mock("../../saveAndReturn/service/utils", () => ({
markSessionAsSubmitted: jest.fn(),
Expand All @@ -25,6 +26,35 @@ jest.mock("@opensystemslab/planx-core", () => {
});

describe(`uploading an application to S3`, () => {
beforeEach(() => {
queryMock.mockQuery({
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
powerAutomateWebhookURL: "test.azure.com/whatever",
powerAutomateAPIKey: "secret",
},
},
],
},
variables: {
slug: "barnet",
},
});

queryMock.mockQuery({
name: "GetStagingIntegrations",
data: {
teams: [],
},
variables: {
slug: "unsupported-team",
},
});
});

it("requires auth", async () => {
await supertest(app)
.post("/upload-submission/barnet")
Expand All @@ -48,10 +78,10 @@ describe(`uploading an application to S3`, () => {
.post("/upload-submission/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.expect(500)
.then((res) => {
expect(res.body.error).toMatch(
"Send to S3 is not enabled for this local authority (unsupported-team)",
/No team matching "unsupported-team" found/,
);
});
});
Expand Down
45 changes: 39 additions & 6 deletions api.planx.uk/modules/send/s3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextFunction, Request, Response } from "express";
import { $api } from "../../../client";
import { uploadPrivateFile } from "../../file/service/uploadFile";
import { markSessionAsSubmitted } from "../../saveAndReturn/service/utils";
import axios from "axios";

export async function sendToS3(
req: Request,
Expand All @@ -11,6 +12,8 @@ export async function sendToS3(
// `/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;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";

if (!payload?.sessionId) {
return next({
Expand All @@ -22,9 +25,15 @@ export async function sendToS3(
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") {
// Fetch integration credentials for this team
const { powerAutomateWebhookURL, powerAutomateAPIKey } =
await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
});

if (!powerAutomateWebhookURL || !powerAutomateAPIKey) {
return next({
status: 400,
message: `Send to S3 is not enabled for this local authority (${localAuthority})`,
Expand All @@ -38,16 +47,40 @@ export async function sendToS3(
const { fileUrl } = await uploadPrivateFile(
exportData,
`${sessionId}.json`,
"barnet-prototype",
);

// Send a notification with the file URL to the Power Automate webook
let webhookResponseStatus: number | undefined;
await axios({
method: "POST",
url: powerAutomateWebhookURL,
adapter: "http",
headers: {
"Content-Type": "application/json",
apiKey: powerAutomateAPIKey,
},
data: {
message: "New submission from PlanX",
environment: env,
file: fileUrl,
},
})
.then((res) => {
// TODO Create & update audit table entry here
webhookResponseStatus = res.status;
})
.catch((error) => {
throw new Error(
`Failed to send submission notification to ${localAuthority}'s Power Automate Webhook (${sessionId}): ${error}`,
);
});

// Mark session as submitted so that reminder and expiry emails are not triggered
markSessionAsSubmitted(sessionId);

// TODO Create and update an audit table entry

return res.status(200).send({
message: `Successfully uploaded submission to S3: ${fileUrl}`,
webhookResponse: webhookResponseStatus,
});
} catch (error) {
return next({
Expand Down
9 changes: 8 additions & 1 deletion api.planx.uk/modules/send/uniform/uniform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export async function sendToUniform(
});
} catch (error) {
const errorMessage = isAxiosError(error)
? JSON.stringify(error.toJSON())
? JSON.stringify(error.response?.data)
: (error as Error).message;
return next({
error,
Expand Down Expand Up @@ -309,6 +309,13 @@ async function attachArchive(
const response = await axios.request(attachArchiveConfig);
// successful upload returns 204 No Content without body
const isSuccess = response.status === 204;

// Temp additional logging to debug failures
console.log("*** Uniform attachArchive response ***");
console.log({ status: response.status });
console.log(JSON.stringify(response.data, null, 2));
console.log("******");

return isSuccess;
}

Expand Down
8 changes: 4 additions & 4 deletions api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#4e67b2e",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#722e1c7",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand All @@ -16,7 +16,7 @@
"cors": "^2.8.5",
"csv-stringify": "^6.4.5",
"date-fns": "^3.3.1",
"dompurify": "^3.0.6",
"dompurify": "^3.1.2",
"express": "^4.19.2",
"express-async-errors": "^3.1.1",
"express-jwt": "^8.4.1",
Expand Down Expand Up @@ -45,8 +45,8 @@
"string-to-stream": "^3.0.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0",
"type-fest": "^4.10.3",
"zod": "^3.22.4"
"type-fest": "^4.18.1",
"zod": "^3.23.5"
},
"scripts": {
"dev": "ts-node-dev --files index.ts",
Expand Down
Loading

0 comments on commit 750d73e

Please sign in to comment.