GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(consultant): exclude soft-deleted agencies from consultant profiles (#1125) by shazia-k · Pull Request #1129 · OpenResilienceInitiative/ORISO-UserService Conversation
|
| Caller | Where | Effect |
|---|---|---|
ConsultantService.findConsultantsByAgencyIds |
service/ConsultantService.java:131,135 |
agency-scoped consultant lookups no longer return ex-members |
ConsultantService.findConsultantsByAgencyId |
service/ConsultantService.java:144,145 |
same, single-agency variant |
AgencySilentMembershipService.joinAgencyConsultants |
service/session/AgencySilentMembershipService.java:59,65 |
Matrix room fan-out: removed counsellors are no longer silently joined to new rooms |
UnauthorizedMembersProvider |
facade/assignsession/UnauthorizedMembersProvider.java:78,80 |
the "authorized members" allow-list shrinks, so removed counsellors are now removed from the room on reassignment |
ChatService.getChatModerators |
service/ChatService.java:130,141 |
group-chat moderator list no longer includes removed counsellors |
ConsultantAgencyAdminService.removeConsultantsFromTeamSessionsByAgencyId |
admin/service/agency/ConsultantAgencyAdminService.java:188,196-197 |
the team-consultant flag is now cleared for consultants whose only remaining relations are soft-deleted |
All six are directionally correct — every one of them is asking "who currently belongs to this agency?", and the honest answer excludes soft-deleted relations. But the change is real, it is visible to users, and it is broader than a profile page. Worth flagging on the last row: ConsultantAgencyAdminService deliberately uses the repository query rather than consultant.getConsultantAgencies() (see its comment at :209-213, because open-in-view is disabled) — so it only gets the corrected behaviour through this PR.
Written for a colleague who does not read code. Two effects are visible the moment this deploys — both are the intended semantics, but both will read as an incident if they are not announced first.
(a) Removing a counsellor from an agency now takes effect immediately and completely.
Until now, a counsellor who was removed from an agency kept seeing that agency's work. From this deploy on, the removal is real: they immediately lose that agency's
service/session/SessionService.java:313-317)service/session/SessionService.java:383-388)service/session/SessionService.java:983-990)service/ChatService.java:74)This includes a team session they were actively working on but do not own. Such a session does not disappear from the system — it stays visible to its owner and to everyone still in the agency — but it disappears from the removed counsellor's list without warning. If someone is removed from an agency mid-conversation, their in-flight work needs a hand-over.
(b) Assigning or re-assigning a session to such a counsellor now returns 403.
Session (re)assignment checks whether the target counsellor belongs to the session's agency, and whether they cover its consulting type (facade/assignsession/SessionToConsultantConditionProvider.java:76-84 and :107-118, enforced by SessionToConsultantVerifier.java:86-110 and :112-125). Both checks read the same collection. A counsellor whose relation to the agency is soft-deleted now fails them, and the API answers HTTP 403 Forbidden where it previously succeeded — unless the session's main topic is one the counsellor owns, which is an explicit escape hatch in the same check (SessionToConsultantVerifier.java:93 → isConsultantAssignedToSessionTopic).
Assigning sessions is a daily admin workflow. It will start throwing 403 for exactly those counsellors who were previously removed from the agency and were, until now, still assignable by accident. Again: correct, but it needs to be said out loud before the deploy, not diagnosed afterwards.
Each of these was checked; none of them is a blocker.
ON clause of a LEFT JOIN, not in the WHERE (emitted SQL quoted above). A consultant with only soft-deleted agency relations still loads; their agency collection is simply empty.workflow/delete/action/consultant/DeleteDatabaseConsultantAgencyAction.java:34-37 uses consultantAgencyRepository.findByConsultantId(...), which has no deleteDate predicate (ConsultantAgencyRepository.java:27), so GDPR deletion still removes the history rows. No orphans.admin/service/consultant/querybuilder/ConsultantFilterSpecification.java already filtered the consultant at :21 and already added isNull(agencyJoin.get("deleteDate")) on the agency join at :37-41. Unchanged by this PR.port/out/AdminStatisticsRepository.java:106-115 is native SQL that already said ca.delete_date IS NULL (line 113). The ORM path now agrees with it instead of contradicting it.ConsultantFilterQueryBuilder has no callers anywhere in src/main or src/test; ConsultantReindexer carries no stereotype annotation and is never registered as a bean, so its afterPropertiesSet() never runs; and the index backend is local-heap (src/main/resources/hibernate.properties:1), i.e. per-instance and rebuilt on restart. Nothing durable can drift.dev apart from the two tests added here. The only local red is 3 failures + 19 errors, all in UserControllerE2EIT and all rooted in org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis — no local Redis, because Docker is not running on the dev machine. Unrelated to this change; CI covers it.Run locally against dev in a clean worktree, JDK 21. Both regression tests were confirmed red first.
Red — test 1, the mapped collection. With only the test applied and Consultant.java still on the dev version:
ConsultantRepositoryIT.loginProfileShouldExcludeSoftDeletedAgencyRelationsWithoutDeletingHistory
expected: <[1, 1731, 900001]> but was: <[1, 1731, 900001, 900002]>
Tests run: 23, Failures: 1
Agency 900002 is the soft-deleted one, and it was still there.
Red — test 2, the derived queries. Same procedure (git checkout origin/dev -- src/main/java/.../model/Consultant.java, restoring @Where):
ConsultantRepositoryIT.findByAgencyIdShouldExcludeConsultantsWhoseAgencyRelationIsSoftDeleted:130
expected: <false> but was: <true>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
Line 130 is the assertion that findByConsultantAgenciesAgencyIdAndDeleteDateIsNull(900004L) must not return the consultant whose relation to agency 900004 is soft-deleted. On dev it did.
Green after the change:
| What was run | Result |
|---|---|
mvn integration-test -Dtest=ConsultantRepositoryIT#findByAgencyIdShouldExcludeConsultantsWhoseAgencyRelationIsSoftDeleted |
1 test, 0 failures |
mvn integration-test -Dtest=ConsultantRepositoryIT |
24 tests, 0 failures, 0 errors |
mvn integration-test on the 4 consultant repository ITs |
27 tests, 0 failures, 0 errors |
mvn test (full unit suite) |
4295 tests, 0 failures, 0 errors |
mvn integration-test (full IT suite, 102 classes) |
932 tests; the only red is 22 UserControllerE2EIT cases failing on RedisConnectionFailureException — no local Redis, environmental |
mvn spotless:apply / spotless check at compile |
clean |
The ITs run against the in-memory H2 database used by the testing profile, so they need no Docker and run in CI as-is.
No schema change, no migration, no config change, no API contract change — but see Blast radius and Release note above: this is not a silent fix. Announce it.
Please size the blast radius on Dev before approving, and paste the results into a comment:
-- 1. How many soft-deleted agency relations exist at all? SELECT COUNT(*) FROM consultant_agency WHERE delete_date IS NOT NULL; -- 2. How many consultants go from "has agencies" to "has none"? SELECT COUNT(DISTINCT consultant_id) FROM consultant_agency ca WHERE delete_date IS NOT NULL AND NOT EXISTS (SELECT 1 FROM consultant_agency x WHERE x.consultant_id = ca.consultant_id AND x.delete_date IS NULL);
____________Query 2 is the one that matters. It counts the consultants who currently appear to have agencies and will have none after this deploys — the population that hits both effects in the release note (loses their session/enquiry/chat lists, and becomes un-assignable with a 403). If that number is 0 on Dev, the change is invisible there and the release note is precautionary. If it is not 0, those accounts should be looked at by hand before this goes to Prod.
consultant_agency row still exists with a non-null delete_date — history must be retained, not deleted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
A consultant's agency list still contained agencies that had been removed. The removal is a soft delete (delete_date is set, the row is kept for audit), and the collection mapping was supposed to filter those rows out. Consultant.consultantAgencies was annotated with the Hibernate 5 annotation @where(clause = "delete_date IS NULL"). That class no longer exists in Hibernate ORM 7.2.19 (the version this project actually runs on); it is still on the compile classpath only because hibernate-search-orm 5.11.12.Final drags in hibernate-core 5.4.33.Final transitively. So the annotation compiled but the ORM never read it, and the restriction was silently a no-op. Replaced with the supported @SQLRestriction, which Hibernate 7 does apply. Soft-deleted rows are still retained in the database. Refs #1125. Split out of #1124. Co-Authored-By: Claude Opus 5 <[email protected]>
There was an error while loading. Please reload this page.
|
Warning Review limit reachedNext included review available in 28 minutes. View limit detailsLimit details: You’ve used the included review currently available. This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The change is narrowly scoped to the intended association filter, and the added integration test validates the exact persistence reload scenario that previously exposed the bug.
This PR fixes a data-correctness issue in the consultant profile domain model where soft-deleted consultant_agency relations were still being returned via Consultant.consultantAgencies, by replacing an unsupported Hibernate annotation with the Hibernate ORM 7 equivalent and adding an integration test to prevent regressions.
Changes:
@Where(clause = "delete_date IS NULL") with Hibernate ORM 7 @SQLRestriction("delete_date IS NULL") on Consultant.consultantAgencies.| File | Description |
|---|---|
| src/main/java/de/caritas/cob/userservice/api/model/Consultant.java | Updates the ORM mapping to enforce delete_date IS NULL filtering on the consultant’s agency relation collection using Hibernate 7 supported annotation. |
| src/test/java/de/caritas/cob/userservice/api/port/out/ConsultantRepositoryIT.java | Adds a persistence-context-reload regression test ensuring soft-deleted agency relations do not appear in reloaded consultant profiles while the soft-deleted row remains. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…iction @SQLRestriction on Consultant.consultantAgencies is not limited to the mapped collection: Hibernate also applies it to the join Spring Data generates for derived queries that navigate the collection path. So ConsultantRepository.findByConsultantAgenciesAgencyIdAndDeleteDateIsNull and its ...AgencyIdInAndDeleteDateIsNull variant now exclude consultants whose relation to the agency was soft-deleted. That half of the change was untested. The new IT asserts both queries against a fixture with one live and one soft-deleted ConsultantAgency on the same consultant. Confirmed red first: with the origin/dev version of Consultant.java restored (the inert @where), the assertion that the soft-deleted agency must not match fails with "expected: <false> but was: <true>". Green on this branch. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The change is minimal, correct for Hibernate 7, and is backed by regression integration tests that reproduce the prior failure via persistence-context reload.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed at d39831e against dev. The Hibernate 7 mapping change and both regression paths are consistent with the intended soft-delete semantics. CodeRabbit CLI reported no findings; ConsultantRepositoryIT passed locally on Java 21 (24 tests, 0 failures). The Dev data blast-radius queries documented in the PR remain a separate pre-merge operational check.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.