Skip to content

Commit

Permalink
Merge branch 'main' into jh/actual-or-work
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Dec 12, 2024
2 parents 919b408 + ea94f96 commit 3c313e5
Show file tree
Hide file tree
Showing 70 changed files with 3,773 additions and 2,711 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ FILE_API_KEY_NEXUS=👻
FILE_API_KEY_BARNET=👻
FILE_API_KEY_LAMBETH=👻
FILE_API_KEY_SOUTHWARK=👻
FILE_API_KEY_EPSOM_EWELL=👻
FILE_API_KEY_MEDWAY=👻

# Editor
EDITOR_URL_EXT=http://localhost:3000
Expand Down
2 changes: 2 additions & 0 deletions api.planx.uk/.env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ FILE_API_KEY_NEXUS=👻
FILE_API_KEY_BARNET=👻
FILE_API_KEY_LAMBETH=👻
FILE_API_KEY_SOUTHWARK=👻
FILE_API_KEY_EPSOM_EWELL=👻
FILE_API_KEY_MEDWAY=👻

# Editor
EDITOR_URL_EXT=example.com
Expand Down
8 changes: 8 additions & 0 deletions api.planx.uk/modules/auth/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export const useFilePermission: RequestHandler = (req, _res, next): void => {
isEqual(
req.headers["api-key"] as string,
process.env.FILE_API_KEY_SOUTHWARK!,
) ||
isEqual(
req.headers["api-key"] as string,
process.env.FILE_API_KEY_MEDWAY!,
) ||
isEqual(
req.headers["api-key"] as string,
process.env.FILE_API_KEY_EPSOM_EWELL!,
);
if (!isAuthenticated) return next({ status: 401, message: "Unauthorised" });
return next();
Expand Down
21 changes: 21 additions & 0 deletions api.planx.uk/modules/file/service/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { S3 } from "@aws-sdk/client-s3";
import { isLiveEnv } from "../../../helpers.js";
import { Readable } from "stream";

export function s3Factory() {
return new S3({
Expand Down Expand Up @@ -40,3 +41,23 @@ export function getS3KeyFromURL(fileURL: string): string {
const key = [folder, file].map(decodeURIComponent).join("/");
return key;
}

export const convertObjectToMulterJSONFile = (
data: Record<string, unknown>,
fileName: string,
): Express.Multer.File => {
const buffer = Buffer.from(JSON.stringify(data));

return {
buffer: buffer,
originalname: fileName,
mimetype: "application/json",
size: buffer.length,
fieldname: "file",
encoding: "7bit",
stream: Readable.from(buffer),
destination: "",
filename: "",
path: "",
};
};
12 changes: 10 additions & 2 deletions api.planx.uk/modules/flows/validate/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import * as jsondiffpatch from "jsondiffpatch";
import { dataMerged, getMostRecentPublishedFlow } from "../../../../helpers.js";
import { validateFileTypes } from "./fileTypes.js";
import { validateInviteToPay } from "./inviteToPay.js";
import { validateSections } from "./sections.js";
import { validatePlanningConstraints } from "./planningConstraints.js";
import { validateProjectTypes } from "./projectTypes.js";
import { validateSections } from "./sections.js";

type AlteredNode = {
id: string;
Expand Down Expand Up @@ -54,7 +55,14 @@ const validateAndDiffFlow = async (
const inviteToPay = validateInviteToPay(flattenedFlow);
const fileTypes = validateFileTypes(flattenedFlow);
const projectTypes = validateProjectTypes(flattenedFlow);
validationChecks.push(sections, inviteToPay, fileTypes, projectTypes);
const planningConstraints = validatePlanningConstraints(flattenedFlow);
validationChecks.push(
sections,
inviteToPay,
fileTypes,
projectTypes,
planningConstraints,
);

// Arrange list of validation checks in order of status: Fail, Warn, Pass, Not applicable
const failingChecks = validationChecks.filter((v) => v.status == "Fail");
Expand Down
15 changes: 0 additions & 15 deletions api.planx.uk/modules/flows/validate/service/inviteToPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,6 @@ const validateInviteToPay = (flowGraph: FlowGraph): FlowValidationResponse => {
};
}

if (
!hasComponentType(
flowGraph,
ComponentType.Checklist,
"proposal.projectType",
)
) {
return {
title: "Invite to Pay",
status: "Fail",
message:
"When using Invite to Pay, your flow must have a Checklist that sets `proposal.projectType`",
};
}

return {
title: "Invite to Pay",
status: "Pass",
Expand Down
38 changes: 38 additions & 0 deletions api.planx.uk/modules/flows/validate/service/planningConstraints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
ComponentType,
type FlowGraph,
} from "@opensystemslab/planx-core/types";
import { numberOfComponentType } from "../helpers.js";
import type { FlowValidationResponse } from "./index.js";

const validatePlanningConstraints = (
flowGraph: FlowGraph,
): FlowValidationResponse => {
const numberOfPlanningConstraintNodes = numberOfComponentType(
flowGraph,
ComponentType.PlanningConstraints,
);
if (numberOfPlanningConstraintNodes > 1) {
return {
title: "Planning Constraints",
status: "Fail",
message:
"When using Planning Constraints, your flow must have exactly ONE Planning Constraints component",
};
} else if (numberOfPlanningConstraintNodes === 1) {
// In future, add extra `hasPlanningData` validation step here to ensure integration is available for this team
return {
title: "Planning Constraints",
status: "Pass",
message: "Your flow has valid Planning Constraints",
};
} else {
return {
title: "Planning Constraints",
status: "Not applicable",
message: "Your flow is not using Planning Constraints",
};
}
};

export { validatePlanningConstraints };
Loading

0 comments on commit 3c313e5

Please sign in to comment.