Skip to content

[PM-39237] fix: Handle mismatched and orphaned migration cohort assignments in admin dropdown#7836

Open
cyprain-okeke wants to merge 5 commits into
mainfrom
billing/pm-39237/fix-mismatched-cohort-dropdown
Open

[PM-39237] fix: Handle mismatched and orphaned migration cohort assignments in admin dropdown#7836
cyprain-okeke wants to merge 5 commits into
mainfrom
billing/pm-39237/fix-mismatched-cohort-dropdown

Conversation

@cyprain-okeke

Copy link
Copy Markdown
Contributor

🎟️ Tracking

PM-39237

📔 Objective

The admin organization edit page builds the migration cohort dropdown by listing
only cohorts whose migration path matches the organization's current plan. When
an organization's existing assignment points to a cohort outside that filtered
set, the selected value was silently dropped — the dropdown rendered as
"(Not assigned)" or with the wrong selection, hiding the real assignment from
admins.

This PR ensures the currently-assigned cohort is always present in the dropdown
and clearly labeled:

  • Plan mismatch — when the assigned cohort's migration path no longer matches
    the organization's plan (including a null/retired path id during a multi-stage
    rollout), the option is appended and labeled (plan mismatch). The POST
    resolver already mirrors this guard, blocking a switch to a null-path cohort
    while letting the current value round-trip unchanged.
  • Orphaned assignment — when the assigned cohort no longer exists in the
    repository, the dropdown shows (assigned cohort no longer exists) and a
    warning is logged (org id and cohort id only, no sensitive data).

Covered by 52 unit tests in OrganizationsControllerTests (all passing).

📸 Screenshots

…nments in admin dropdown

The cohort dropdown only listed cohorts whose migration path matched the
organization's current plan. When an assignment pointed to a cohort outside
that filtered set, the selected value silently dropped, making the dropdown
appear unassigned or showing the wrong selection. Now the assigned cohort is
always included and labeled "(plan mismatch)" when its path no longer matches
the plan, or "(assigned cohort no longer exists)" when the cohort is missing.
@cyprain-okeke cyprain-okeke added the ai-review Request a Claude code review label Jun 18, 2026
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the admin migration-cohort dropdown fix (PM-39237). The change ensures a currently-assigned cohort that falls outside the plan-filtered set is still rendered and labeled, covering both plan-mismatch and orphaned-cohort states. Verified the GET fallback is correctly mirrored by the POST resolver's NoChange short-circuit, so a no-touch save round-trips the id instead of silently deleting the assignment.

Code Review Details

No blocking findings.

Correctness verified:

  • GET fallback (OrganizationsController.cs:261-283) appends the assigned cohort and the POST resolver's NoChange guard (OrganizationsController.cs:705) prevents silent deletion on resubmit — the core fix is consistent across both request paths.
  • Null/retired MigrationPathId handling matches between GET mismatch detection (OrganizationsController.cs:273-274) and the POST compatibility guard (OrganizationsController.cs:726-734).
  • Orphan warning logs only organization id and cohort id, no sensitive data (OrganizationsController.cs:279-281).
  • View renders the assigned cohort once in the mismatch case and appends a separate item only in the orphan case, with no duplicate options (_OrganizationForm.cshtml:81-99).

Test coverage is thorough: regression tests assert no-delete on resubmit for both mismatch and orphan, correct delete-then-create ordering on a valid switch, lock-guard precedence, and the compatibility guard rejecting a mismatch-to-mismatch switch.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.23%. Comparing base (408002d) to head (f367c18).

Files with missing lines Patch % Lines
...AdminConsole/Views/Shared/_OrganizationForm.cshtml 0.00% 17 Missing ⚠️
...dminConsole/Controllers/OrganizationsController.cs 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7836   +/-   ##
=======================================
  Coverage   61.23%   61.23%           
=======================================
  Files        2209     2209           
  Lines       97743    97779   +36     
  Branches     8815     8823    +8     
=======================================
+ Hits        59849    59873   +24     
- Misses      35770    35781   +11     
- Partials     2124     2125    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cyprain-okeke cyprain-okeke marked this pull request as ready for review June 19, 2026 12:25
@cyprain-okeke cyprain-okeke requested a review from a team as a code owner June 19, 2026 12:25
if (currentAssignment?.CohortId is { } assignedId
&& visibleCohorts.All(c => c.Id != assignedId))
{
var assignedCohort = await _organizationPlanMigrationCohortRepository.GetByIdAsync(assignedId);

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.

Do we need to go to the database for this, or can we use the migrationCohorts list above? I assume the list would have the one we're looking for

@sven-bitwarden sven-bitwarden 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.

Approving with one comment that might be a minor optimization, but could also be unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants