Skip to content

[PM-35624] Fix EF GetCountByOnlyOwnerAsync - #7586

Merged
JimmyVo16 merged 2 commits into
mainfrom
ac/pm-35624/fix-ef-getcountbyonlyownerasync
May 7, 2026
Merged

JimmyVo16 merged 2 commits into
mainfrom
ac/pm-35624/fix-ef-getcountbyonlyownerasync

Conversation

@JimmyVo16

@JimmyVo16 JimmyVo16 commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-35624

📔 Objective

  1. Fix the EF query to mirror the stored procedure behavior.
  2. Add unit tests to cover edge cases.

Added test cases

  1. A user with no org memberships at all.
  2. A user who is the only confirmed owner of one org.
  3. A user who shares ownership with another confirmed owner in the same org.
  4. A user who is the sole owner of one org but shares ownership in another org.
  5. A user who is an Owner but has only been invited, not confirmed.
  6. A user who is the sole confirmed owner of two separate orgs.

📸 Screenshots

I ran a sanity check by executing the tests against the old code to confirm they fail, which validates that this change is the fix.

image

@JimmyVo16 JimmyVo16 self-assigned this May 5, 2026
@JimmyVo16 JimmyVo16 added the ai-review Request a Claude code review label May 5, 2026
@github-actions

github-actions Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR fixes the EF Core implementation of GetCountByOnlyOwnerAsync so it correctly mirrors the SQL stored procedure semantics: counting the number of organizations where a user is the sole confirmed owner. The previous EF query grouped by UserId and produced an incorrect count (e.g., a user who was the sole owner of two organizations was counted as zero). The fix groups by OrganizationId with Count() == 1 && Any(ou.UserId == userId), which translates cleanly under EF Core 8 to a GROUP BY ... HAVING COUNT(*) = 1 AND EXISTS (...) query and matches the Dapper/MSSQL CTE behavior. New integration tests cover the previously-broken multi-org case along with no-org, single-org, multi-owner, and unconfirmed-status scenarios. Drive-by cleanup migrates [DatabaseTheory] to [Theory], consistent with the obsolete-attribute guidance.

Code Review Details

No findings.

@codecov

codecov Bot commented May 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.14%. Comparing base (f835212) to head (c23f611).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7586      +/-   ##
==========================================
+ Coverage   59.73%   64.14%   +4.40%     
==========================================
  Files        2102     2102              
  Lines       92691    92687       -4     
  Branches     8257     8257              
==========================================
+ Hits        55371    59450    +4079     
+ Misses      35366    31197    -4169     
- Partials     1954     2040      +86     

☔ View full report in Codecov by Sentry.
📢 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.

@JimmyVo16
JimmyVo16 marked this pull request as ready for review May 5, 2026 20:37
@JimmyVo16
JimmyVo16 requested a review from a team as a code owner May 5, 2026 20:37
@JimmyVo16
JimmyVo16 requested a review from eliykat May 5, 2026 20:37
@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

@eliykat eliykat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No notes!

@JimmyVo16
JimmyVo16 merged commit f2a3555 into main May 7, 2026
47 checks passed
@JimmyVo16
JimmyVo16 deleted the ac/pm-35624/fix-ef-getcountbyonlyownerasync branch May 7, 2026 18:23
@djsmith85 djsmith85 added the t:bugfix Change Type - Bugfix label May 29, 2026
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 t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants