GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@shazia-k

@shazia-k shazia-k commented Sep 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

The bug (#1125)

When an agency is removed from a consultant, the removal is a soft delete: the consultant_agency row is kept and its delete_date is set, so the assignment history stays auditable. The consultant's profile is supposed to hide those rows.

It did not. After an agency was removed, it still appeared in the consultant's agency list on profile reload — so a consultant looked like they were still assigned to an agency they had been taken off.

Cause — one annotation

Consultant.consultantAgencies was annotated with the Hibernate 5 annotation:

@Where(clause = "delete_date IS NULL")

org.hibernate.annotations.Where does not exist in Hibernate ORM 7.2.19, the version this project actually runs on (via Spring Boot 4.0.7). It is still on the compile classpath only because hibernate-search-orm:5.11.12.Final transitively pulls in hibernate-core:5.4.33.Final.

So the annotation compiled fine, but the running ORM never looked at it — the restriction was silently a no-op. No compiler warning, no runtime error, just an unfiltered collection.

The fix replaces it with the supported Hibernate 7 equivalent:

@SQLRestriction("delete_date IS NULL")

Soft-deleted rows are still retained in the database; they are only excluded from the mapped collection. @Where was deprecated in Hibernate 6.3 in favour of @SQLRestriction and removed in Hibernate 7 — verified that SQLRestriction.class is present and Where.class is absent in hibernate-core-7.2.19.Final.jar.

This was the last remaining org.hibernate.annotations.Where in src/main — grep -rn "org.hibernate.annotations.Where\|@Where(" src/main/ now returns nothing.

Why this is split out of #1124

The fix was written on emails-v2 (commit c053740f) and is currently carried by draft PR #1124, which is an 8,183-line email rework. This is a Medium data-correctness bug that should not wait on a large draft to be finished and reviewed. This PR is the two-line production change plus its regression tests, cherry-picked onto dev. #1124 is untouched and can drop or keep the commit when it rebases.

Blast radius — this is NOT limited to the profile collection

An earlier revision of this description said the behaviour change is "limited to the Consultant.consultantAgencies collection". That was wrong, and it understated the change. Correction:

@SQLRestriction is applied by Hibernate wherever the mapped collection is used — including the join that Spring Data generates for derived queries that navigate the collection path. Two such queries exist:

  • ConsultantRepository.findByConsultantAgenciesAgencyIdAndDeleteDateIsNull (port/out/ConsultantRepository.java:38)
  • ConsultantRepository.findByConsultantAgenciesAgencyIdInAndDeleteDateIsNull (port/out/ConsultantRepository.java:36)

Note the DeleteDateIsNull in those names refers to the Consultant, not to the consultant_agency row. Before this PR nothing filtered the relation row; now the restriction lands in the ON clause of the generated join. Emitted SQL, captured from the new IT:

... from consultant c1_0
     left join consultant_agency ca1_0
            on c1_0.consultant_id = ca1_0.consultant_id
           and (ca1_0.delete_date IS NULL)
   where ca1_0.agency_id = ? and c1_0.delete_date is null

Both queries therefore now exclude consultants whose relation to that agency was soft-deleted. Behaviour changes for these callers:

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.

Release note / behaviour change

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

  • team sessions (service/session/SessionService.java:313-317)
  • registered enquiries (service/session/SessionService.java:383-388)
  • archived team sessions (service/session/SessionService.java:983-990)
  • group chats (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.

Cleared risks — please do not re-litigate these

Each of these was checked; none of them is a blocker.

  • No consultant disappears from a profile or listing. The restriction lands in the 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.
  • The deletion workflow still hard-deletes soft-deleted rows. 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 listing / search / update were already correct. 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.
  • Statistics get more consistent, not less. 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.
  • Hibernate Search index divergence is a dead path. 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.
  • The rest of the suite is unaffected. The full integration-test suite is 102 IT classes / 932 tests on this branch, identical to 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.

Verification

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.

Deploy impact

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.

Before merging

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 1 result pasted: ______
  • Query 2 result pasted: ______

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.

Reviewer test plan

  • Open a consultant who is assigned to at least two agencies and note the agency list on their profile.
  • Remove one of those agencies from the consultant (admin agency assignment).
  • Reload the consultant's profile — the removed agency should no longer be listed.
  • The remaining agency (or agencies) should still be listed, unchanged.
  • Confirm the consultant can still be found by a search filtered on an agency they are still assigned to.
  • Confirm the consultant is not returned by a search filtered on the agency they were just removed from.
  • Try to assign a session of the removed agency to that consultant — expect 403 (this is the new behaviour from the release note, not a bug).
  • Confirm a consultant still in the agency can still be assigned that session.
  • Optional, DB: confirm the removed consultant_agency row still exists with a non-null delete_date — history must be retained, not deleted.

Refs #1125. Split out of #1124.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Shazia Kausar @claude @shazia-k
fix(consultant): exclude soft-deleted agencies from consultant profiles
0c59b9f
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]>
@shazia-k
shazia-k requested review from Shirloin, Storypapst and kiodreambau and a lite review from Copilot September 8, 2026 11:23
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 5229941b-4a0c-4548-8249-f95f1e2f26fd

📥 Commits

Reviewing files that changed from the base of the PR and between 10a29ac and d39831e.

📒 Files selected for processing (2)
  • src/main/java/de/caritas/cob/userservice/api/model/Consultant.java
  • src/test/java/de/caritas/cob/userservice/api/port/out/ConsultantRepositoryIT.java

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of shazia-k September 8, 2026 11:23
View session
Copilot AI reviewed Sep 8, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟢 Approval recommended

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.

Pull request overview

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:

  • Replace legacy @Where(clause = "delete_date IS NULL") with Hibernate ORM 7 @SQLRestriction("delete_date IS NULL") on Consultant.consultantAgencies.
  • Add an integration test that soft-deletes a consultant-agency relation, flushes + clears the persistence context, reloads the consultant, and verifies the soft-deleted relation is excluded while history remains in the DB.
File summaries
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.
Review details
  • Files reviewed: 1/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Shazia Kausar @claude
test(consultant): cover the derived-query half of the agency SQLRestr…
d39831e
…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]>
Copilot AI review requested due to automatic review settings September 8, 2026 11:54
Copilot started reviewing on behalf of shazia-k September 8, 2026 11:54
View session
Copilot AI reviewed Sep 8, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is minimal, correct for Hibernate 7, and is backed by regression integration tests that reproduce the prior failure via persistence-context reload.

Review details
  • Files reviewed: 1/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Storypapst Storypapst assigned shazia-k Sep 8, 2026
Storypapst
Storypapst approved these changes Sep 8, 2026
View reviewed changes

@Storypapst Storypapst left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shazia-k
shazia-k merged commit 14c8309 into dev Sep 9, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@shazia-k
shazia-k deleted the fix/1125-removed-agency-sqlrestriction branch September 9, 2026 13:05
@shazia-k shazia-k mentioned this pull request Sep 9, 2026
Removed agency remains in consultant profile after soft deletion #1125
Closed
4 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@Storypapst Storypapst Storypapst approved these changes
@kiodreambau kiodreambau Awaiting requested review from kiodreambau
@Shirloin Shirloin Awaiting requested review from Shirloin

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@shazia-k shazia-k

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@shazia-k @Storypapst
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.