Skip to content

[CSM Portal] fix(cases): filter single-active-case check server-side - #1019

Merged
cloby99 merged 2 commits into
wso2-open-operations:v2from
rksk:csm-ongoing-case-server-filter
Jul 3, 2026
Merged

[CSM Portal] fix(cases): filter single-active-case check server-side#1019
cloby99 merged 2 commits into
wso2-open-operations:v2from
rksk:csm-ongoing-case-server-filter

Conversation

@rksk

@rksk rksk commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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_progress set and matched assignee + work-state on the client, because the case-search API had no assignee/work-state filter.

Now that POST /cases/search supports assignedUserIds and workStates, this issues one targeted query filtered by assignee + work_in_progress + ongoing and 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 check workState === "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:

  • compare workState case-insensitively (backstop against label casing), and
  • fall back to matching the JWT email when /users/me could not supply the caller's id (so the assignedUserIds filter 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) and tsc --noEmit pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the “my ongoing cases” lookup to return more accurate results.
    • Added more reliable server-side filtering for ongoing cases tied to the signed-in user.
    • Enhanced fallback behavior when user identity details are incomplete, using email-based matching.
    • Ensures the current case is excluded and applies tighter ongoing-state checks for better result consistency.

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.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c59a8f06-25f7-4b0e-a581-3581fec95b8d

📥 Commits

Reviewing files that changed from the base of the PR and between 16e8d2d and eb76182.

📒 Files selected for processing (1)
  • apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts

📝 Walkthrough

Walkthrough

useFindMyOngoingCases now fetches ongoing cases with server-side assignee filtering when a platform user id is available, and falls back to email-based matching when it is not. The hook also updates its ongoing-state checks, exclusion handling, and callback dependencies.

Changes

Ongoing cases hook refactor

Layer / File(s) Summary
Server-side filtering with assignee resolution
apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts
Adds useCurrentUser, conditionally sends assignedUserIds to /cases/search, updates the paging comment for the split server/fallback path, and adjusts client-side filtering to skip excludeCaseId, match workState case-insensitively, and use email only when myUserId is unavailable.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: Type/Improvement

Suggested reviewers: cloby99

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and testing, but it omits most required template sections like Purpose, Goals, User stories, Release note, Documentation, and Security checks. Rewrite it using the repository template and add the missing sections: Purpose, Goals, Approach, User stories, Release note, Documentation, Security checks, and the remaining fields.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: moving the single-active-case check to server-side filtering.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4d06a and 16e8d2d.

📒 Files selected for processing (1)
  • apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts

Comment thread apps/csm-portal/webapp/src/features/csm-cases/api/useFindMyOngoingCases.ts Outdated
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.
@rksk

rksk commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@cloby99
cloby99 merged commit e9694b8 into wso2-open-operations:v2 Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants