From 6f9755c986e24aab9241f34f772e8ec76e22b548 Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Wed, 7 Feb 2024 17:43:23 +0000 Subject: [PATCH 1/3] chore: setup deletion of feedback created before retention policy date - Add deleteFeedback operation - Grant delete and select permissions of the feedback table to the API - Update Hasura test with new permissions --- .../sanitiseApplicationData/mocks/queries.ts | 10 ++++++++ .../operations.test.ts | 6 +++++ .../sanitiseApplicationData/operations.ts | 23 +++++++++++++++++++ hasura.planx.uk/metadata/tables.yaml | 23 +++++++++++++++++++ hasura.planx.uk/tests/feedback.test.js | 17 ++++++++++---- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts index 73be6c851a..a78ae11377 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/mocks/queries.ts @@ -67,3 +67,13 @@ export const mockGetExpiredSessionIdsQuery = { lowcal_sessions: [{ id: "id1" }, { id: "id2" }, { id: "id3" }], }, }; + +export const mockDeleteFeedbackMutation = { + name: "DeleteFeedback", + matchOnVariables: false, + data: { + feedback: { + returning: mockIds, + }, + }, +}; diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts index bf406d3a3a..cec0532097 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts @@ -9,6 +9,7 @@ import { mockSanitiseUniformApplicationsMutation, mockGetExpiredSessionIdsQuery, mockDeletePaymentRequests, + mockDeleteFeedbackMutation, } from "./mocks/queries"; import { deleteHasuraEventLogs, @@ -23,6 +24,7 @@ import { deleteApplicationFiles, deletePaymentRequests, deleteHasuraScheduledEventsForSubmittedSessions, + deleteFeedback, } from "./operations"; jest.mock("../../../../lib/hasura/schema"); @@ -142,6 +144,10 @@ describe("Data sanitation operations", () => { operation: deletePaymentRequests, query: mockDeletePaymentRequests, }, + { + operation: deleteFeedback, + query: mockDeleteFeedbackMutation, + }, ]; for (const { operation, query } of testCases) { diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts index 9bd6b8b7ab..189f8956cc 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts @@ -32,6 +32,9 @@ export const getOperations = (): Operation[] => [ // Queued up scheduled events (backup method to PG function/trigger) deleteHasuraScheduledEventsForSubmittedSessions, + + // Feedback records + deleteFeedback, ]; export const operationHandler = async ( @@ -291,3 +294,23 @@ export const deleteHasuraScheduledEventsForSubmittedSessions: Operation = const [_column_name, ...ids] = response?.result?.flat() || []; return ids; }; + +export const deleteFeedback: Operation = async () => { + const mutation = gql` + mutation DeleteFeedback($retentionPeriod: timestamptz) { + feedback: delete_feedback( + where: { created_at: { _lt: $retentionPeriod } } + ) { + returning { + id + } + } + } + `; + const { + feedback: { returning: result }, + } = await $api.client.request<{ feedback: Result }>(mutation, { + retentionPeriod: getRetentionPeriod(), + }); + return result; +}; diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index b4cd51a1bf..13c00166ea 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -248,6 +248,29 @@ - user_context - user_data comment: Allow users who want to leave feedback on their experience to write to the table + select_permissions: + - role: api + permission: + columns: + - id + - team_id + - device + - user_data + - feedback_type + - node_id + - created_at + - flow_id + - node_type + - status + - user_comment + - user_context + filter: {} + comment: "" + delete_permissions: + - role: api + permission: + filter: {} + comment: "" - table: name: feedback_status_enum schema: public diff --git a/hasura.planx.uk/tests/feedback.test.js b/hasura.planx.uk/tests/feedback.test.js index e83df7537d..07d5e4b4da 100644 --- a/hasura.planx.uk/tests/feedback.test.js +++ b/hasura.planx.uk/tests/feedback.test.js @@ -80,12 +80,21 @@ describe("feedback", () => { i = await introspectAs("api"); }); - test("cannot query feedback", () => { - expect(i.queries).not.toContain("feedback"); + test("can query feedback", () => { + expect(i.queries).toContain("feedback"); }); - test("cannot create, update, or delete teams", () => { - expect(i).toHaveNoMutationsFor("feedback"); + test("cannot update feedback", () => { + expect(i.mutations).not.toContain("update_feedback"); + expect(i.mutations).not.toContain("update_feedback_by_pk"); + }); + + test("can delete feedback", async () => { + expect(i.mutations).toContain("delete_feedback"); + }); + + test("cannot insert feedback", async () => { + expect(i.mutations).not.toContain("insert_feedback"); }); }); }); From 9705b7fc2781a03f4d785d5add328b3da7407d23 Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Thu, 8 Feb 2024 16:59:28 +0000 Subject: [PATCH 2/3] chore: rename "development" to "local" for slack notifications --- api.planx.uk/helpers.test.ts | 2 +- api.planx.uk/helpers.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api.planx.uk/helpers.test.ts b/api.planx.uk/helpers.test.ts index 953bfdb4f1..5c275e1437 100644 --- a/api.planx.uk/helpers.test.ts +++ b/api.planx.uk/helpers.test.ts @@ -38,7 +38,7 @@ describe("getEnvironment function", () => { test("Development env", () => { process.env.NODE_ENV = "development"; - expect(getFormattedEnvironment()).toBe("Development"); + expect(getFormattedEnvironment()).toBe("Local"); }); }); diff --git a/api.planx.uk/helpers.ts b/api.planx.uk/helpers.ts index 7e09603aa4..624fa5169b 100644 --- a/api.planx.uk/helpers.ts +++ b/api.planx.uk/helpers.ts @@ -247,6 +247,10 @@ const getFormattedEnvironment = (): string => { const pizzaNumber = new URL(process.env.API_URL_EXT!).href.split(".")[1]; environment += ` ${pizzaNumber}`; } + // For readability redefine development as local for slack warnings + if (environment === "development") { + environment = "local"; + } return capitalize(environment); }; From b259adcb7545487aab16b61284acaf0a5e87ae5c Mon Sep 17 00:00:00 2001 From: Mike Heneghan Date: Fri, 9 Feb 2024 12:56:53 +0000 Subject: [PATCH 3/3] chore: remove unnecessary columns from api select permission --- hasura.planx.uk/metadata/tables.yaml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index 13c00166ea..557eefa0e7 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -252,18 +252,8 @@ - role: api permission: columns: - - id - - team_id - - device - - user_data - - feedback_type - - node_id - created_at - - flow_id - - node_type - - status - - user_comment - - user_context + - id filter: {} comment: "" delete_permissions: