fix(#2395): prevent contact deletion when linked to other systems - #2402
Conversation
There was a problem hiding this comment.
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_CONTACTsupport (entity + repository) and a/api/contacts/{contactId}/in-useendpoint in the legacy service. - Block contact deletion in the legacy JSON-patch remove operation by returning
409 Conflictwhen 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"sshould becontact''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"sshould besite''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.
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
|
|
|
|
paulushcgcj
left a comment
There was a problem hiding this comment.
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.
|
|
|
…explicitly use the THE
|
paulushcgcj
left a comment
There was a problem hiding this comment.
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.
|
|
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: