[CSM Portal] fix(cases): filter single-active-case check server-side - #1019
Conversation
The single-active-case guard listed the engineer's other ongoing cases by scanning up to 20 pages of the cross-customer work_in_progress set and matching assignee + work-state on the client. Now that the case-search API supports assignee (assignedUserIds) and work-state (workStates) filters, issue one targeted query filtered by assignee + work_in_progress + ongoing instead of the paged client-side scan. A thin client-side re-check remains on the single returned page: it compares workState case-insensitively (the search view can return the raw label casing, unlike the lowercased detail view) and falls back to matching the JWT email when /users/me could not supply the caller's id (so the assignee filter was omitted). This makes the check correct regardless of label casing and keeps the pause-other-ongoing-cases prompt firing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesOngoing cases hook refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts`:
- Around line 34-38: The email fallback in useFindMyOngoingCases currently only
queries the first page when myUserId is missing, which can miss another ongoing
case and skip the pause prompt. Keep the existing single-page behavior for the
assignedUserIds path, but change the fallback path to iterate through pages
using offset until all matching results are exhausted, using the existing search
helper and SEARCH_LIMIT/BE_MAX_PAGE_LIMIT logic to locate the paging loop.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e5b1952f-519e-4007-a8d0-cde2d1b94ef3
📒 Files selected for processing (1)
apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts
When /users/me can't supply the caller's id, the search is not assignee-filtered server-side, so it returns every engineer's ongoing in-progress case. Checking only the first page could miss the caller's own ongoing case (beyond the first page) and skip the pause prompt. Page the loop until results are exhausted; the assignee-filtered path still exits after one page since its result set is tiny. MAX_PAGES bounds a pathological set.
|
@coderabbitai resume |
✅ Action performedReviews resumed. |
What
When an engineer starts (or resumes) work on a case, the portal enforces the single-active-case rule by listing the engineer's other ongoing cases and prompting to pause them. That lookup previously scanned up to 20 pages of the cross-customer
work_in_progressset and matched assignee + work-state on the client, because the case-search API had no assignee/work-state filter.Now that
POST /cases/searchsupportsassignedUserIdsandworkStates, this issues one targeted query filtered by assignee +work_in_progress+ongoingand drops the paged client-side scan.Why it also fixes a bug
The prompt was not firing even when the engineer had another ongoing case. The search view returns the work-state label in a different casing than the
GET /cases/{id}detail view (title-cased vs the lowercased enum), so the old client checkworkState === "ongoing"never matched. Filtering by work-state server-side sidesteps the label string entirely, and the retained re-check now compares case-insensitively.Behaviour of the retained client re-check
On the single returned page we still:
workStatecase-insensitively (backstop against label casing), and/users/mecould not supply the caller's id (so theassignedUserIdsfilter was omitted).Both are cheap on an already-narrowed page and keep the check correct even if the server-side filter is not yet honoured.
Scope
CSM webapp only. No API contract change; no customer-portal impact.
Testing
pnpm lint(file clean) andtsc --noEmitpass.Summary by CodeRabbit