Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- You are about to drop the column `channel` on the `legacy_third_party_subscription` table. All the data in the column will be lost.
- You are about to drop the column `sensitivity` on the `legacy_third_party_subscription` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "legacy_third_party_subscription" DROP COLUMN "channel",
DROP COLUMN "sensitivity";
37 changes: 4 additions & 33 deletions libs/legacy-third-party-fulfilment/src/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,11 @@ describe("findSubscribersByListType", () => {
mockFindMany.mockResolvedValue([]);
});

it("filters PUBLIC publications to all sensitivity levels", async () => {
await findSubscribersByListType(42, "PUBLIC");
it("returns all subscribers for the given listTypeId regardless of sensitivity", async () => {
await findSubscribersByListType(42);

expect(mockFindMany).toHaveBeenCalledWith({
where: { listTypeId: 42, sensitivity: { in: ["PUBLIC", "PRIVATE", "CLASSIFIED"] } },
include: { user: true }
});
});

it("filters PRIVATE publications to PRIVATE and CLASSIFIED subscribers only", async () => {
await findSubscribersByListType(42, "PRIVATE");

expect(mockFindMany).toHaveBeenCalledWith({
where: { listTypeId: 42, sensitivity: { in: ["PRIVATE", "CLASSIFIED"] } },
include: { user: true }
});
});

it("filters CLASSIFIED publications to CLASSIFIED subscribers only", async () => {
await findSubscribersByListType(42, "CLASSIFIED");

expect(mockFindMany).toHaveBeenCalledWith({
where: { listTypeId: 42, sensitivity: { in: ["CLASSIFIED"] } },
include: { user: true }
});
});

it("treats unknown sensitivity as PUBLIC and includes all levels", async () => {
await findSubscribersByListType(42, "UNKNOWN");

expect(mockFindMany).toHaveBeenCalledWith({
where: { listTypeId: 42, sensitivity: { in: ["PUBLIC", "PRIVATE", "CLASSIFIED"] } },
where: { listTypeId: 42 },
include: { user: true }
});
});
Expand All @@ -58,14 +31,12 @@ describe("findSubscribersByListType", () => {
id: "sub-1",
userId: "user-1",
listTypeId: 42,
channel: "API",
sensitivity: "PRIVATE",
createdDate: new Date(),
user: { id: "user-1", name: "Courtel", createdDate: new Date() }
};
mockFindMany.mockResolvedValue([row]);

const result = await findSubscribersByListType(42, "PRIVATE");
const result = await findSubscribersByListType(42);

expect(result).toEqual([row]);
});
Expand Down
13 changes: 2 additions & 11 deletions libs/legacy-third-party-fulfilment/src/queries.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { prisma } from "@hmcts/postgres-prisma";

const SENSITIVITY_ORDER = ["PUBLIC", "PRIVATE", "CLASSIFIED"] as const;
type SensitivityLevel = (typeof SENSITIVITY_ORDER)[number];

function eligibleSensitivities(publicationSensitivity: string): SensitivityLevel[] {
const rank = SENSITIVITY_ORDER.indexOf(publicationSensitivity as SensitivityLevel);
const minRank = rank === -1 ? 0 : rank;
return SENSITIVITY_ORDER.filter((_, i) => i >= minRank);
}

export async function findSubscribersByListType(listTypeId: number, sensitivity: string) {
export async function findSubscribersByListType(listTypeId: number) {
return prisma.legacyThirdPartySubscription.findMany({
where: { listTypeId, sensitivity: { in: eligibleSensitivities(sensitivity) } },
where: { listTypeId },
include: { user: true }
});
}
4 changes: 2 additions & 2 deletions libs/legacy-third-party-fulfilment/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function sendThirdPartyPublications(params: ThirdPartyPushParams):
const secrets = resolveCourtelSecrets(logPrefix);
if (!secrets) return;

const subscribers = await findSubscribersByListType(listTypeId, sensitivity);
const subscribers = await findSubscribersByListType(listTypeId);
if (subscribers.length === 0) {
console.info(`${logPrefix} Third-party push skipped: no subscribers for listTypeId ${listTypeId}`);
return;
Expand All @@ -88,7 +88,7 @@ export async function sendThirdPartyDeletion(params: ThirdPartyDeletionParams):
const secrets = resolveCourtelSecrets(logPrefix);
if (!secrets) return;

const subscribers = await findSubscribersByListType(listTypeId, sensitivity);
const subscribers = await findSubscribersByListType(listTypeId);
if (subscribers.length === 0) {
console.info(`${logPrefix} Third-party deletion push skipped: no subscribers for listTypeId ${listTypeId}`);
return;
Expand Down
2 changes: 0 additions & 2 deletions libs/postgres-prisma/prisma/schema/base.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ model LegacyThirdPartySubscription {
id String @id @default(uuid()) @map("id") @db.Uuid
userId String @map("user_id") @db.Uuid
listTypeId Int @map("list_type_id")
channel String @default("API") @db.VarChar(20)
sensitivity String @db.VarChar(20)
createdDate DateTime @default(now()) @map("created_date")

user LegacyThirdPartyUser @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand Down
2 changes: 1 addition & 1 deletion libs/subscriptions/src/repository/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vi.mock("@hmcts/location", () => ({
getLocationsByIds: vi.fn()
}));

import { getLocationById, getLocationsByIds } from "@hmcts/location";
import { getLocationsByIds } from "@hmcts/location";

describe("Subscription Service", () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
export const cy = {
pageTitle: "Rheoli tanysgrifiadau trydydd parti",
channelLabel: "Dewiswch Sianel os gwelwch yn dda",
channelApiOption: "API",
sensitivityLabel: "Dewiswch sensitifrwydd os gwelwch yn dda",
sensitivityPublicOption: "Cyhoeddus",
sensitivityPrivateOption: "Preifat",
sensitivityClassifiedOption: "Cyfrinachol",
listTypesLabel: "Dewiswch fathau rhestr os gwelwch yn dda",
saveButtonText: "Cadarnhau tanysgrifiadau",
errorSummaryTitle: "Mae yna broblem",
sensitivityRequired: "Dewiswch lefel sensitifrwydd",
userNotFound: "Ni chanfuwyd defnyddiwr"
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
export const en = {
pageTitle: "Manage third party subscriptions",
channelLabel: "Please select a Channel",
channelApiOption: "API",
sensitivityLabel: "Please select sensitivity",
sensitivityPublicOption: "Public",
sensitivityPrivateOption: "Private",
sensitivityClassifiedOption: "Classified",
listTypesLabel: "Please select list types",
saveButtonText: "Save subscriptions",
errorSummaryTitle: "There is a problem",
sensitivityRequired: "Select a sensitivity level",
userNotFound: "User not found"
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
{% extends "layouts/base-template.njk" %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% from "govuk/components/checkboxes/macro.njk" import govukCheckboxes %}
{% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %}

{% macro getError(errors, fieldId) -%}
{%- if errors -%}
{%- for error in errors -%}
{%- if error.href == fieldId -%}{{ error.text }}{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand All @@ -27,52 +18,6 @@

<form method="post" novalidate>

{{ govukRadios({
name: "channel",
fieldset: {
legend: {
text: channelLabel,
classes: "govuk-fieldset__legend--m"
}
},
items: [
{
value: "API",
text: channelApiOption,
checked: currentChannel == "API"
}
]
}) }}

{% set sensitivityErrorText = getError(errors, "#sensitivity") %}
{{ govukRadios({
name: "sensitivity",
fieldset: {
legend: {
text: sensitivityLabel,
classes: "govuk-fieldset__legend--m"
}
},
errorMessage: { text: sensitivityErrorText } if sensitivityErrorText and sensitivityErrorText | length > 0 else undefined,
items: [
{
value: "PUBLIC",
text: sensitivityPublicOption,
checked: currentSensitivity == "PUBLIC"
},
{
value: "PRIVATE",
text: sensitivityPrivateOption,
checked: currentSensitivity == "PRIVATE"
},
{
value: "CLASSIFIED",
text: sensitivityClassifiedOption,
checked: currentSensitivity == "CLASSIFIED"
}
]
}) }}

{% if listTypes and listTypes.length > 0 %}
{% set checkboxItems = [] %}
{% for listType in listTypes %}
Expand Down
Loading
Loading