Skip to content

fix(#2395): prevent contact deletion when linked to other systems - #2402

Merged
mamartinezmejia merged 17 commits into
mainfrom
feat/2395
Aug 24, 2026
Merged

fix(#2395): prevent contact deletion when linked to other systems#2402
mamartinezmejia merged 17 commits into
mainfrom
feat/2395

Conversation

@mamartinezmejia

@mamartinezmejia mamartinezmejia commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Task Summary

Prevent deletion of a client contact when it is still referenced by another system (EMS, GAS2, LEXIS, or SCS), and surface a clear, actionable error message to the user instead of a silent or generic failure.

Background

Closes #2395. Users could delete a contact from the Forest Client Details page even when that contact was still tied to records in other downstream systems, leaving those systems with dangling references. The fix adds a server-side check against the SCALE_SITE_CONTACT table (used by EMS, GAS2, LEXIS, and SCS) before allowing a delete, and returns a 409 Conflict with a descriptive message when the contact is still in use.


Thanks for the PR!

Deployments, as required, will be available below:
Any successful deployments (not always required) will be available here

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

Copilot AI lite review requested due to automatic review settings August 12, 2026 22:49

Copilot AI 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.

Pull request overview

This PR addresses issue #2395 by introducing a backend “contact in use” check (based on THE.SCALE_SITE_CONTACT) to block deletion of contacts that are referenced by external systems, and by surfacing the backend’s conflict message to users in the frontend.

Changes:

  • Add SCALE_SITE_CONTACT support (entity + repository) and a /api/contacts/{contactId}/in-use endpoint in the legacy service.
  • Block contact deletion in the legacy JSON-patch remove operation by returning 409 Conflict when the contact is “in use”.
  • Update UI toast handling and add Cypress + integration tests to validate the error-message flow.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
legacy/src/test/resources/db/migration/V7.0.1__create_site_scale_contact.sql Adds test-schema DDL for THE.SCALE_SITE_CONTACT used by the new in-use checks.
legacy/src/test/resources/db/migration/V7.0.2__scale_site_contact_test_data.sql Seeds test data for “in use” vs “free” vs “deletable” contacts.
legacy/src/test/java/ca/bc/gov/app/controller/ClientContactControllerIntegrationTest.java Adds integration tests for the in-use endpoint and delete-blocking behavior.
legacy/src/main/java/ca/bc/gov/app/service/patch/PatchOperationContactRemoveService.java Adds pre-delete “in use” validation that throws ContactInUseException.
legacy/src/main/java/ca/bc/gov/app/service/ClientContactService.java Adds isContactInUse(contactId) service method.
legacy/src/main/java/ca/bc/gov/app/repository/ScaleSiteContactRepository.java Adds reactive repository method to check whether a contact is referenced in SCALE_SITE_CONTACT.
legacy/src/main/java/ca/bc/gov/app/exception/ContactInUseException.java Introduces a 409 Conflict exception with a user-facing message.
legacy/src/main/java/ca/bc/gov/app/entity/ScaleSiteContactEntity.java Adds entity mapping for THE.SCALE_SITE_CONTACT.
legacy/src/main/java/ca/bc/gov/app/controller/ClientContactController.java Adds /api/contacts/{contactId}/in-use endpoint.
frontend/src/pages/ClientDetailsPage.vue Displays backend 409 message string in the error toast when present.
frontend/cypress/e2e/pages/ClientDetailsPage.cy.ts Verifies the backend error message is shown in the toast on failed delete.
Suppressed comments (2)

legacy/src/test/resources/db/migration/V7.0.1__create_site_scale_contact.sql:31

  • Typo in the comment text: contact"s should be contact''s (SQL-escaped apostrophe).
COMMENT ON COLUMN THE.SCALE_SITE_CONTACT.CONTACT_ROLE_DESCRIPTION IS
    'Description of the contact"s role at the SCALE SITE. For example: - Bucking Contractor - Site Contact';

legacy/src/test/resources/db/migration/V7.0.1__create_site_scale_contact.sql:37

  • Typo in the comment text: site"s should be site''s (SQL-escaped apostrophe).
COMMENT ON COLUMN THE.SCALE_SITE_CONTACT.SITE_INFORMATION_ACCESS_IND IS
    'Indicates whether or not the SITE CONTACT has been granted the ability to view the site"s information via the SCS application system. The site contact must have: 1. Authentication via WebADE 2. Authorization to access specific SCS web services via ADAM';

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread legacy/src/test/resources/db/migration/V7.0.1__create_site_scale_contact.sql Outdated
@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@paulushcgcj paulushcgcj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change adds the requested server-side dependency check and carries the 409 explanation through to the contact toast. The end-to-end coverage also exercises the user-visible failure path.

Comment thread frontend/cypress/e2e/pages/ClientDetailsPage.cy.ts
@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@paulushcgcj paulushcgcj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change adds the requested cross-system contact dependency check and carries the 409 explanation through to the contact toast. The end-to-end coverage exercises the user-visible failure path. There is one remaining correctness concern around keeping validation and deletion atomic.

Comment thread frontend/cypress/e2e/pages/ClientDetailsPage.cy.ts
@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown
Contributor

There is no coverage information present for the Files changed

@mamartinezmejia
mamartinezmejia merged commit a888a6e into main Aug 24, 2026
32 of 34 checks passed
@mamartinezmejia
mamartinezmejia deleted the feat/2395 branch August 24, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contact deletion fails silently when contact has cross-application dependencies (EMS, GAS2, LEXIS, SCS)

3 participants