Skip to content

Feature/511 Remove sensitivity and channel from legacy third party functionality - #691

Merged
junaidiqbalmoj merged 6 commits into
masterfrom
feature/511-Remove-sensitivity-from-legacy-third-party
Jun 18, 2026
Merged

Feature/511 Remove sensitivity and channel from legacy third party functionality#691
junaidiqbalmoj merged 6 commits into
masterfrom
feature/511-Remove-sensitivity-from-legacy-third-party

Conversation

@KianKwa

@KianKwa KianKwa commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Jira link

#511

Change description

Remove sensitivity and channel from legacy third party functionality

Testing done

Security Vulnerability Assessment

CVE Suppression: Are there any CVEs present in the codebase (either newly introduced or pre-existing) that are being intentionally suppressed or ignored by this commit?

  • Yes
  • No

Checklist

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)
  • Does this PR introduce a breaking change

Summary by CodeRabbit

  • Refactor
    • Removed channel and sensitivity selection options from third-party subscriptions management interface
    • Simplified subscription management to filter and store list type identifiers only
    • Removed sensitivity classification information and display from third-party user management views

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request removes the channel and sensitivity fields from the third-party subscription management system. The changes span the database schema, query layer, service integrations, and all related user-facing management pages, simplifying subscriptions to track only listTypeId per user.

Changes

Third-party subscription field removal

Layer / File(s) Summary
Database schema and legacy subscription migration
apps/postgres/prisma/migrations/*, libs/postgres-prisma/prisma/schema/base.prisma, libs/legacy-third-party-fulfilment/src/queries.ts, libs/legacy-third-party-fulfilment/src/queries.test.ts, libs/legacy-third-party-fulfilment/src/service.ts
Database migration drops channel and sensitivity columns from legacy_third_party_subscription table; Prisma schema updated; legacy subscription queries simplified to filter by listTypeId only without sensitivity constraints.
Third-party user query layer refactoring
libs/system-admin-pages/src/third-party-user/queries.ts, libs/system-admin-pages/src/third-party-user/queries.test.ts
Query functions findAllThirdPartyUsers, findThirdPartyUserById, and updateThirdPartySubscriptions updated to remove channel and sensitivity from subscription data; Prisma select statements narrowed to id, userId, and listTypeId only; function signatures reflect subscription shape changes.
Manage subscriptions page refactoring
libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.ts, libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.njk, libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.test.ts, libs/system-admin-pages/src/pages/manage-third-party-subscriptions/cy.ts, libs/system-admin-pages/src/pages/manage-third-party-subscriptions/en.ts
Subscription management page removes sensitivity and channel selection from forms and handlers; GET handler renders only list types, POST handler accepts only list type selections; translation files updated to remove channel/sensitivity labels; tests simplified to reflect new subscription structure.
User detail and list pages refactoring
libs/system-admin-pages/src/pages/manage-third-party-user/, libs/system-admin-pages/src/pages/manage-third-party-users/
Manage-third-party-user and manage-third-party-users pages remove sensitivity display and highest-sensitivity calculations; templates no longer render sensitivity columns, handlers remove getHighestSensitivity calls; test fixtures updated to exclude sensitivity values.
Validation cleanup
libs/system-admin-pages/src/third-party-user/validation.ts, libs/system-admin-pages/src/third-party-user/validation.test.ts, libs/system-admin-pages/src/user-management/validation.ts, libs/subscriptions/src/repository/service.test.ts
Removed validateSensitivity function and its test suite; deleted unused ALPHANUMERIC_REGEX constant; test imports adjusted to remove references to deleted validation functions.

Possibly related PRs

  • hmcts/cath-service#344: Originally introduced the LegacyThirdPartySubscription model with channel and sensitivity fields and sensitivity-based subscription management; this PR removes those same fields and associated logic.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the primary objective of this changeset: removing sensitivity and channel fields from legacy third-party functionality across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/511-Remove-sensitivity-from-legacy-third-party

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright E2E Test Results

84 tests   52 ✅  6m 1s ⏱️
33 suites  32 💤
 1 files     0 ❌

Results for commit c895039.

♻️ This comment has been updated with latest results.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
libs/subscriptions/src/repository/service.test.ts (1)

21-24: 💤 Low value

Remove unused getLocationById from mock factory.

The mock defines getLocationById but it's no longer imported (line 26) or used anywhere in this test file. Consider removing it for cleanliness.

♻️ Proposed cleanup
 vi.mock("`@hmcts/location`", () => ({
-  getLocationById: vi.fn(),
   getLocationsByIds: vi.fn()
 }));
libs/system-admin-pages/src/third-party-user/queries.test.ts (1)

128-144: ⚡ Quick win

Strengthen transaction assertions for subscription updates.

These tests only check that $transaction was called, so they can miss regressions in deleteMany/createMany payloads (especially the removed fields contract). Assert the inner calls and exact createMany.data shape.

Suggested test tightening
   it("should delete existing subscriptions and create new ones", async () => {
+    const deleteMany = vi.fn();
+    const createMany = vi.fn();
     const mockTransaction = vi.fn(async (callback) => {
       return callback({
         legacyThirdPartySubscription: {
-          deleteMany: vi.fn(),
-          createMany: vi.fn()
+          deleteMany,
+          createMany
         }
       });
     });
     vi.mocked(prisma.$transaction).mockImplementation(mockTransaction);

     const subscriptions = [{ listTypeId: 1 }, { listTypeId: 2 }];

     await updateThirdPartySubscriptions("user-1", subscriptions);

     expect(prisma.$transaction).toHaveBeenCalled();
+    expect(deleteMany).toHaveBeenCalledWith({ where: { userId: "user-1" } });
+    expect(createMany).toHaveBeenCalledWith({
+      data: [{ userId: "user-1", listTypeId: 1 }, { userId: "user-1", listTypeId: 2 }]
+    });
   });

Also applies to: 146-160


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0d96fe09-e472-4f52-95cc-1cee0514b5fe

📥 Commits

Reviewing files that changed from the base of the PR and between 4d66356 and 91bc1cb.

📒 Files selected for processing (26)
  • apps/postgres/prisma/migrations/20260608155746_remove_channel_sensitivity_from_legacy_third_party_subscription/migration.sql
  • libs/legacy-third-party-fulfilment/src/queries.test.ts
  • libs/legacy-third-party-fulfilment/src/queries.ts
  • libs/legacy-third-party-fulfilment/src/service.ts
  • libs/postgres-prisma/prisma/schema/base.prisma
  • libs/subscriptions/src/repository/service.test.ts
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/cy.ts
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/en.ts
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.njk
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.test.ts
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.ts
  • libs/system-admin-pages/src/pages/manage-third-party-user/cy.ts
  • libs/system-admin-pages/src/pages/manage-third-party-user/en.ts
  • libs/system-admin-pages/src/pages/manage-third-party-user/index.njk
  • libs/system-admin-pages/src/pages/manage-third-party-user/index.test.ts
  • libs/system-admin-pages/src/pages/manage-third-party-user/index.ts
  • libs/system-admin-pages/src/pages/manage-third-party-users/cy.ts
  • libs/system-admin-pages/src/pages/manage-third-party-users/en.ts
  • libs/system-admin-pages/src/pages/manage-third-party-users/index.njk
  • libs/system-admin-pages/src/pages/manage-third-party-users/index.test.ts
  • libs/system-admin-pages/src/pages/manage-third-party-users/index.ts
  • libs/system-admin-pages/src/third-party-user/queries.test.ts
  • libs/system-admin-pages/src/third-party-user/queries.ts
  • libs/system-admin-pages/src/third-party-user/validation.test.ts
  • libs/system-admin-pages/src/third-party-user/validation.ts
  • libs/system-admin-pages/src/user-management/validation.ts
💤 Files with no reviewable changes (7)
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/en.ts
  • libs/system-admin-pages/src/user-management/validation.ts
  • libs/system-admin-pages/src/third-party-user/validation.ts
  • libs/system-admin-pages/src/pages/manage-third-party-users/index.njk
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/index.njk
  • libs/postgres-prisma/prisma/schema/base.prisma
  • libs/system-admin-pages/src/pages/manage-third-party-subscriptions/cy.ts

Comment on lines 61 to 66
const listTypeIds = Array.isArray(req.body.listTypes) ? req.body.listTypes.map(Number) : req.body.listTypes ? [Number(req.body.listTypes)] : [];
const listTypes = await findAllListTypes();

const validationError = validateSensitivity(sensitivity);
if (validationError) {
return res.render("manage-third-party-subscriptions/index", {
...content,
listTypes,
currentChannel: channel || "API",
currentSensitivity: sensitivity || "",
currentListTypeIds: listTypeIds,
errors: [{ ...validationError, text: content.sensitivityRequired }]
});
}

const subscriptions = listTypeIds.map((listTypeId: number) => ({
listTypeId,
channel: channel || "API",
sensitivity: sensitivity!
}));
const subscriptions = listTypeIds.map((listTypeId: number) => ({ listTypeId }));

await updateThirdPartySubscriptions(session.manageThirdPartyUser.userId, subscriptions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reject invalid listTypes values before DB update.

Number(...) can produce NaN (or out-of-domain IDs), and those values are sent straight to updateThirdPartySubscriptions, which can fail at persistence time and surface as a server error.

Suggested hardening
-  const listTypeIds = Array.isArray(req.body.listTypes) ? req.body.listTypes.map(Number) : req.body.listTypes ? [Number(req.body.listTypes)] : [];
-  const listTypes = await findAllListTypes();
+  const rawListTypeIds = Array.isArray(req.body.listTypes) ? req.body.listTypes : req.body.listTypes ? [req.body.listTypes] : [];
+  const parsedListTypeIds = rawListTypeIds.map((value: string) => Number(value));
+  const listTypes = await findAllListTypes();
+  const allowedListTypeIds = new Set(listTypes.map((listType) => listType.id));
+  const hasInvalidListType = parsedListTypeIds.some((id) => !Number.isInteger(id) || !allowedListTypeIds.has(id));
+  if (hasInvalidListType) {
+    return res.status(400).render("manage-third-party-subscriptions/index", {
+      ...(language === "cy" ? cy : en),
+      listTypes,
+      currentListTypeIds: session.manageThirdPartyUser.originalSubscriptions,
+      errors: [{ text: "Invalid list type selection" }]
+    });
+  }
+  const listTypeIds = parsedListTypeIds;

As per coding guidelines: “All API endpoints must include input validation.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const listTypeIds = Array.isArray(req.body.listTypes) ? req.body.listTypes.map(Number) : req.body.listTypes ? [Number(req.body.listTypes)] : [];
const listTypes = await findAllListTypes();
const validationError = validateSensitivity(sensitivity);
if (validationError) {
return res.render("manage-third-party-subscriptions/index", {
...content,
listTypes,
currentChannel: channel || "API",
currentSensitivity: sensitivity || "",
currentListTypeIds: listTypeIds,
errors: [{ ...validationError, text: content.sensitivityRequired }]
});
}
const subscriptions = listTypeIds.map((listTypeId: number) => ({
listTypeId,
channel: channel || "API",
sensitivity: sensitivity!
}));
const subscriptions = listTypeIds.map((listTypeId: number) => ({ listTypeId }));
await updateThirdPartySubscriptions(session.manageThirdPartyUser.userId, subscriptions);
const rawListTypeIds = Array.isArray(req.body.listTypes) ? req.body.listTypes : req.body.listTypes ? [req.body.listTypes] : [];
const parsedListTypeIds = rawListTypeIds.map((value: string) => Number(value));
const listTypes = await findAllListTypes();
const allowedListTypeIds = new Set(listTypes.map((listType) => listType.id));
const hasInvalidListType = parsedListTypeIds.some((id) => !Number.isInteger(id) || !allowedListTypeIds.has(id));
if (hasInvalidListType) {
return res.status(400).render("manage-third-party-subscriptions/index", {
...(language === "cy" ? cy : en),
listTypes,
currentListTypeIds: session.manageThirdPartyUser.originalSubscriptions,
errors: [{ text: "Invalid list type selection" }]
});
}
const listTypeIds = parsedListTypeIds;
const subscriptions = listTypeIds.map((listTypeId: number) => ({ listTypeId }));
await updateThirdPartySubscriptions(session.manageThirdPartyUser.userId, subscriptions);

Source: Coding guidelines

Comment on lines 80 to 84
req.auditMetadata = {
shouldLog: true,
action: AuditLogAction.UPDATE_THIRD_PARTY_SUBSCRIPTIONS,
entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Name: ${session.manageThirdPartyUser.userName}, Sensitivity: ${sensitivity}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Name: ${session.manageThirdPartyUser.userName}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid logging user names in audit metadata.

entityInfo currently includes userName, which is personal data and should be excluded from logs.

Suggested change
-    entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Name: ${session.manageThirdPartyUser.userName}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
+    entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`

As per coding guidelines: “Never include sensitive data in logs.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
req.auditMetadata = {
shouldLog: true,
action: AuditLogAction.UPDATE_THIRD_PARTY_SUBSCRIPTIONS,
entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Name: ${session.manageThirdPartyUser.userName}, Sensitivity: ${sensitivity}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Name: ${session.manageThirdPartyUser.userName}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
};
req.auditMetadata = {
shouldLog: true,
action: AuditLogAction.UPDATE_THIRD_PARTY_SUBSCRIPTIONS,
entityInfo: `ID: ${session.manageThirdPartyUser.userId}, Previous List Types: [${previousListTypes}], Current List Types: [${currentListTypes}]`
};

Source: Coding guidelines

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Preview Deployment Successful 🚀

Your preview environment is ready:

The environment will be automatically cleaned up when this PR is closed.

@ashwini-mv ashwini-mv linked an issue Jun 12, 2026 that may be closed by this pull request
KianKwa added 3 commits June 16, 2026 12:18
…sensitivity-from-legacy-third-party

# Conflicts:
#	apps/web/src/pages/(system-admin)/manage-third-party-subscriptions/index.test.ts
#	apps/web/src/pages/(system-admin)/manage-third-party-subscriptions/index.ts
#	apps/web/src/pages/(system-admin)/manage-third-party-user/index.test.ts
#	apps/web/src/pages/(system-admin)/manage-third-party-user/index.ts
#	apps/web/src/pages/(system-admin)/manage-third-party-users/index.test.ts
#	apps/web/src/pages/(system-admin)/manage-third-party-users/index.ts
#	libs/system-admin-pages/src/user-management/validation.ts
@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment Successful 🚀

Your preview environment is ready:

The environment will be automatically cleaned up when this PR is closed.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Preview Deployment Successful 🚀

Your preview environment is ready:

The environment will be automatically cleaned up when this PR is closed.

@junaidiqbalmoj
junaidiqbalmoj merged commit b5e9528 into master Jun 18, 2026
26 checks passed
junaidiqbalmoj added a commit that referenced this pull request Jun 18, 2026
Resolved conflicts by taking master's removal of channel/sensitivity
from legacy third-party subscriptions (PR #691) and adopting the `t`
variable naming convention and `{% block content %}` template pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove List Sensitivity - Third Party Courtel

2 participants