Skip to content

Commit

Permalink
Merge branch 'main' into jh/use-toast-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Sep 2, 2024
2 parents 287f3ba + b888daa commit 5173f4c
Show file tree
Hide file tree
Showing 29 changed files with 578 additions and 367 deletions.
4 changes: 2 additions & 2 deletions api.planx.uk/modules/send/downloadApplicationFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export async function downloadApplicationFiles(

try {
// Confirm that the provided email matches the stored team settings for the provided localAuthority
const { sendToEmail } = await getTeamEmailSettings(
const { notifyPersonalisation } = await getTeamEmailSettings(
req.query.localAuthority as string,
);
if (sendToEmail !== req.query.email) {
if (notifyPersonalisation.sendToEmail !== req.query.email) {
return next({
status: 403,
message:
Expand Down
22 changes: 16 additions & 6 deletions api.planx.uk/modules/send/email/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ describe(`sending an application by email to a planning office`, () => {
data: {
teams: [
{
sendToEmail: "[email protected]",
settings: { emailReplyToId: "abc123" },
notifyPersonalisation: {
emailReplyToId: "abc123",
sendToEmail: "[email protected]",
},
},
],
},
Expand Down Expand Up @@ -145,15 +147,17 @@ describe(`sending an application by email to a planning office`, () => {
});
});

it("errors if this team does not have a 'submission_email' configured in teams", async () => {
it("errors if this team does not have a 'submission_email' configured in team settings", async () => {
queryMock.mockQuery({
name: "GetTeamEmailSettings",
matchOnVariables: false,
data: {
teams: [
{
sendToEmail: null,
settings: { emailReplyToId: "abc123" },
notifyPersonalisation: {
emailReplyToId: "abc123",
sendToEmail: null,
},
},
],
},
Expand Down Expand Up @@ -200,7 +204,13 @@ describe(`downloading application data received by email`, () => {
name: "GetTeamEmailSettings",
matchOnVariables: false,
data: {
teams: [{ sendToEmail: "[email protected]" }],
teams: [
{
notifyPersonalisation: {
sendToEmail: "[email protected]",
},
},
],
},
variables: { slug: "southwark" },
});
Expand Down
19 changes: 12 additions & 7 deletions api.planx.uk/modules/send/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export async function sendToEmail(
}

try {
// Confirm this local authority (aka team) has an email configured in teams.submission_email
const { sendToEmail, notifyPersonalisation } =
// Confirm this local authority (aka team) has an email configured in team_settings.submission_email
const { notifyPersonalisation } =
await getTeamEmailSettings(localAuthority);
if (!sendToEmail) {

if (!notifyPersonalisation.sendToEmail) {
return next({
status: 400,
message: `Send to email is not enabled for this local authority (${localAuthority})`,
Expand All @@ -47,13 +48,17 @@ export async function sendToEmail(
serviceName: flowName,
sessionId: payload.sessionId,
applicantEmail: email,
downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${sendToEmail}&localAuthority=${localAuthority}`,
downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${notifyPersonalisation.sendToEmail}&localAuthority=${localAuthority}`,
...notifyPersonalisation,
},
};

// Send the email
const response = await sendEmail("submit", sendToEmail, config);
const response = await sendEmail(
"submit",
notifyPersonalisation.sendToEmail,
config,
);

// Mark session as submitted so that reminder and expiry emails are not triggered
markSessionAsSubmitted(payload.sessionId);
Expand All @@ -62,14 +67,14 @@ export async function sendToEmail(
insertAuditEntry(
payload.sessionId,
localAuthority,
sendToEmail,
notifyPersonalisation.sendToEmail,
config,
response,
);

return res.status(200).send({
message: `Successfully sent to email`,
inbox: sendToEmail,
inbox: notifyPersonalisation.sendToEmail,
govuk_notify_template: "Submit",
});
} catch (error) {
Expand Down
6 changes: 2 additions & 4 deletions api.planx.uk/modules/send/email/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js";

interface GetTeamEmailSettings {
teams: {
sendToEmail: string;
notifyPersonalisation: NotifyPersonalisation;
notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string };
}[];
}

Expand All @@ -18,12 +17,12 @@ export async function getTeamEmailSettings(localAuthority: string) {
gql`
query GetTeamEmailSettings($slug: String) {
teams(where: { slug: { _eq: $slug } }) {
sendToEmail: submission_email
notifyPersonalisation: team_settings {
helpEmail: help_email
helpPhone: help_phone
emailReplyToId: email_reply_to_id
helpOpeningHours: help_opening_hours
sendToEmail: submission_email
}
}
}
Expand All @@ -32,7 +31,6 @@ export async function getTeamEmailSettings(localAuthority: string) {
slug: localAuthority,
},
);

return response?.teams[0];
}

Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/api-driven/src/globalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export function createTeam(
$admin.team.create({
name: "E2E Test Team",
slug: "E2E",
submissionEmail: TEST_EMAIL,

settings: {
homepage: "http://www.planx.uk",
submissionEmail: TEST_EMAIL,
},
...args,
}),
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const contextDefaults: Context = {
},
settings: {
homepage: "planx.uk",
submissionEmail: "[email protected]",
},
submissionEmail: "[email protected]",
},
};

Expand All @@ -58,9 +58,9 @@ export async function setUpTestContext(
context.team.id = await $admin.team.create({
slug: context.team.slug,
name: context.team.name,
submissionEmail: context.team.submissionEmail,
settings: {
homepage: context.team.settings?.homepage,
submissionEmail: context.team.submissionEmail,
},
});
}
Expand Down
5 changes: 3 additions & 2 deletions editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"@ctrl/tinycolor": "^4.0.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@microlink/react-json-view": "^1.23.1",
"@mui/base": "5.0.0-beta.40",
"@mui/icons-material": "^5.15.10",
"@mui/lab": "5.0.0-alpha.170",
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.0",
"@opensystemslab/map": "1.0.0-alpha.1",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#d46df8d",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
Expand Down Expand Up @@ -169,7 +170,7 @@
},
"packageManager": "[email protected]",
"scripts": {
"start": "vite",
"start": "vite --open",
"build": "tsc && vite build",
"serve": "vite preview",
"test": "vitest",
Expand Down
Loading

0 comments on commit 5173f4c

Please sign in to comment.