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

Production deploy #2715

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# API
API_PORT=7002
API_URL_EXT=http://localhost:${API_PORT}
ENCRYPTION_KEY=👻

# JWT_SECRET must be at least 32 characters
JWT_SECRET=👻
Expand Down
113 changes: 67 additions & 46 deletions api.planx.uk/modules/gis/service/local_authorities/metadata/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,18 @@ const baseSchema: PlanningConstraintsBaseSchema = {
"digital-land-datasets": ["central-activities-zone"],
category: "General policy",
},
listed: {
brownfieldSite: {
active: true,
neg: "is not, or is not within, a Listed Building",
pos: "is, or is within, a Listed Building",
"digital-land-datasets": ["listed-building", "listed-building-outline"], // HE publishes points, LPAs publish polygons
category: "Heritage and conservation",
},
locallyListed: {
active: true,
neg: "is not, or is not within, a Locally Listed Building",
pos: "is, or is within, a Locally Listed Building",
"digital-land-datasets": ["locally-listed-building"],
category: "Heritage and conservation",
neg: "is not on Brownfield land",
pos: "is on Brownfield land",
"digital-land-datasets": ["brownfield-land", "brownfield-site"],
category: "General policy",
},
registeredPark: {
"designated.AONB": {
active: true,
neg: "is not in a Historic Park or Garden",
pos: "is in a Historic Park or Garden",
"digital-land-datasets": ["park-and-garden"],
neg: "is not in an Area of Outstanding Natural Beauty",
pos: "is in an Area of Outstanding Natural Beauty",
"digital-land-datasets": ["area-of-outstanding-natural-beauty"],
category: "Heritage and conservation",
},
"designated.conservationArea": {
Expand All @@ -55,11 +48,11 @@ const baseSchema: PlanningConstraintsBaseSchema = {
"digital-land-datasets": ["conservation-area"],
category: "Heritage and conservation",
},
"designated.AONB": {
"designated.greenBelt": {
active: true,
neg: "is not in an Area of Outstanding Natural Beauty",
pos: "is in an Area of Outstanding Natural Beauty",
"digital-land-datasets": ["area-of-outstanding-natural-beauty"],
neg: "is not in a Green Belt",
pos: "is in a Green Belt",
"digital-land-datasets": ["green-belt"],
category: "Heritage and conservation",
},
"designated.nationalPark": {
Expand All @@ -77,6 +70,13 @@ const baseSchema: PlanningConstraintsBaseSchema = {
"digital-land-entities": [520007], // https://www.planning.data.gov.uk/entity/520007
category: "Heritage and conservation",
},
"designated.SPA": {
active: true,
neg: "is not in a Special Protection Area (SPA)",
pos: "is in a Special Protection Area (SPA)",
"digital-land-datasets": ["special-protection-area"],
category: "Heritage and conservation",
},
"designated.WHS": {
active: true,
neg: "is not an UNESCO World Heritage Site",
Expand All @@ -87,11 +87,25 @@ const baseSchema: PlanningConstraintsBaseSchema = {
],
category: "Heritage and conservation",
},
"designated.SPA": {
flood: {
active: true,
neg: "is not in a Special Protection Area (SPA)",
pos: "is in a Special Protection Area (SPA)",
"digital-land-datasets": ["special-protection-area"],
neg: "is not in a Flood Risk Zone",
pos: "is in a Flood Risk Zone",
"digital-land-datasets": ["flood-risk-zone"],
category: "Flooding",
},
listed: {
active: true,
neg: "is not, or is not within, a Listed Building",
pos: "is, or is within, a Listed Building",
"digital-land-datasets": ["listed-building", "listed-building-outline"], // HE publishes points, LPAs publish polygons
category: "Heritage and conservation",
},
locallyListed: {
active: true,
neg: "is not, or is not within, a Locally Listed Building",
pos: "is, or is within, a Locally Listed Building",
"digital-land-datasets": ["locally-listed-building"],
category: "Heritage and conservation",
},
monument: {
Expand All @@ -101,22 +115,18 @@ const baseSchema: PlanningConstraintsBaseSchema = {
"digital-land-datasets": ["scheduled-monument"],
category: "Heritage and conservation",
},
tpo: {
"nature.ASNW": {
active: true,
neg: "is not in a Tree Preservation Order (TPO) Zone",
pos: "is in a Tree Preservation Order (TPO) Zone",
"digital-land-datasets": [
"tree",
"tree-preservation-order",
"tree-preservation-zone",
], // "tree" is points, "-zone" is polygons
category: "Trees",
neg: "is not in an Ancient Semi-Natural Woodland (ASNW)",
pos: "is in an Ancient Semi-Natural Woodland (ASNW)",
"digital-land-datasets": ["ancient-woodland"],
category: "Ecology",
},
"nature.SSSI": {
"nature.ramsarSite": {
active: true,
neg: "is not a Site of Special Scientific Interest (SSSI)",
pos: "is a Site of Special Scientific Interest (SSSI)",
"digital-land-datasets": ["site-of-special-scientific-interest"],
neg: "is not in a Ramsar Site",
pos: "is in a Ramsar Site",
"digital-land-datasets": ["ramsar"],
category: "Ecology",
},
"nature.SAC": {
Expand All @@ -126,19 +136,30 @@ const baseSchema: PlanningConstraintsBaseSchema = {
"digital-land-datasets": ["special-area-of-conservation"],
category: "Ecology",
},
"nature.ASNW": {
"nature.SSSI": {
active: true,
neg: "is not in an Ancient Semi-Natural Woodland (ASNW)",
pos: "is in an Ancient Semi-Natural Woodland (ASNW)",
"digital-land-datasets": ["ancient-woodland"],
neg: "is not a Site of Special Scientific Interest (SSSI)",
pos: "is a Site of Special Scientific Interest (SSSI)",
"digital-land-datasets": ["site-of-special-scientific-interest"],
category: "Ecology",
},
flood: {
registeredPark: {
active: true,
neg: "is not in a Flood Risk Zone",
pos: "is in a Flood Risk Zone",
"digital-land-datasets": ["flood-risk-zone"],
category: "Flooding",
neg: "is not in a Historic Park or Garden",
pos: "is in a Historic Park or Garden",
"digital-land-datasets": ["park-and-garden"],
category: "Heritage and conservation",
},
tpo: {
active: true,
neg: "is not in a Tree Preservation Order (TPO) Zone",
pos: "is in a Tree Preservation Order (TPO) Zone",
"digital-land-datasets": [
"tree",
"tree-preservation-order",
"tree-preservation-zone",
], // "tree" is points, "-zone" is polygons
category: "Trees",
},
"defence.explosives": {
active: false,
Expand Down
54 changes: 29 additions & 25 deletions api.planx.uk/modules/send/bops/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ describe(`sending an application to BOPS`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
bopsSecret: null,
},
},
],
Expand All @@ -72,15 +73,9 @@ describe(`sending an application to BOPS`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
teams: [],
},
variables: {
slug: "unsupported-team",
Expand Down Expand Up @@ -128,9 +123,11 @@ describe(`sending an application to BOPS`, () => {
.post("/bops/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(/not enabled for this local authority/);
expect(res.body.error).toMatch(
/No team matching "unsupported-team" found/,
);
});
});

Expand Down Expand Up @@ -187,12 +184,15 @@ describe(`sending an application to BOPS v2`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
// Decodes to "abc123"
bopsSecret:
"668514b455572ca39c46e49396506b29:6c6df14c7fd405dbf380533ba0dcae39",
},
},
],
Expand All @@ -203,15 +203,9 @@ describe(`sending an application to BOPS v2`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
teams: [],
},
variables: {
slug: "unsupported-team",
Expand All @@ -220,9 +214,14 @@ describe(`sending an application to BOPS v2`, () => {
});

it("successfully proxies request and returns hasura id", async () => {
nock(`${submissionURL}/api/v2/planning_applications`).post("").reply(200, {
application: "0000123",
});
const expectedHeaders = { authorization: "Bearer abc123" };
const nockScope = nock(`${submissionURL}/api/v2/planning_applications`, {
reqheaders: expectedHeaders,
})
.post("")
.reply(200, {
application: "0000123",
});

await supertest(app)
.post("/bops-v2/southwark")
Expand All @@ -233,6 +232,9 @@ describe(`sending an application to BOPS v2`, () => {
expect(res.body).toEqual({
application: { id: 22, bopsResponse: { application: "0000123" } },
});

// Check nock was called with expected headers
expect(nockScope.isDone()).toBe(true);
});
});

Expand All @@ -259,9 +261,11 @@ describe(`sending an application to BOPS v2`, () => {
.post("/bops-v2/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(/not enabled for this local authority/);
expect(res.body.error).toMatch(
/No team matching "unsupported-team" found/,
);
});
});

Expand Down
37 changes: 11 additions & 26 deletions api.planx.uk/modules/send/bops/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
const localAuthority = req.params.localAuthority;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,

const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
new ServerError({
status: 400,
message: `Back-office Planning System (BOPS) is not enabled for this local authority (${localAuthority})`,
}),
);
}
});
const target = `${bopsSubmissionURL}/api/v1/planning_applications`;
const exportData = await $api.export.bopsPayload(payload?.sessionId);

Expand All @@ -69,7 +62,7 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
adapter: "http",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.BOPS_API_TOKEN}`,
Authorization: `Bearer ${bopsToken || process.env.BOPS_API_TOKEN}`,
},
data: exportData,
})
Expand Down Expand Up @@ -181,19 +174,11 @@ const sendToBOPSV2 = async (
const localAuthority = req.params.localAuthority;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,
const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
new ServerError({
status: 400,
message: `Back-office Planning System (BOPS) is not enabled for this local authority (${localAuthority})`,
}),
);
}
});
const target = `${bopsSubmissionURL}/api/v2/planning_applications`;
const exportData = await $api.export.digitalPlanningDataPayload(
payload?.sessionId,
Expand All @@ -206,7 +191,7 @@ const sendToBOPSV2 = async (
adapter: "http",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.BOPS_API_TOKEN}`,
Authorization: `Bearer ${bopsToken || process.env.BOPS_API_TOKEN}`,
},
data: exportData,
})
Expand Down
3 changes: 2 additions & 1 deletion 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#d1a224c",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#aa93cbf",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand All @@ -18,6 +18,7 @@
"date-fns": "^2.29.3",
"dompurify": "^3.0.6",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"express-jwt": "^8.4.1",
"express-pino-logger": "^7.0.0",
"express-rate-limit": "^7.1.5",
Expand Down
Loading
Loading