[PM-38269] refactor: remove redundant permissions round-trip in OrganizationUserUserDetailsQuery - #8119
[PM-38269] refactor: remove redundant permissions round-trip in OrganizationUserUserDetailsQuery#8119r-tome wants to merge 3 commits into
Conversation
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE Reviewed the removal of the Code Review Details
The only behavioral delta is a Custom user whose PR Metadata Assessment
|
0f4bebe to
e0ba63b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8119 +/- ##
==========================================
- Coverage 68.12% 63.64% -4.49%
==========================================
Files 2373 2373
Lines 102846 102816 -30
Branches 9328 9325 -3
==========================================
- Hits 70068 65437 -4631
- Misses 30454 35150 +4696
+ Partials 2324 2229 -95 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…izationUserUserDetailsQuery For each Custom-role user the query was deserializing the Permissions JSON string then immediately re-serializing it back — a no-op before the string reaches the response model, which deserializes it once anyway. Remove the three identical if (Type == Custom) blocks and the now-unused CoreHelpers import.
e0ba63b to
ed04d6f
Compare
The method became a bare pass-through after the permissions round-trip was removed and has no callers in production code. Remove it from the interface and implementation, delete the unit tests that only covered it, and drop the stale stub from GetMany_Setup in the controller tests.
|
|
||
| sutProvider.GetDependency<IOrganizationUserUserDetailsQuery>().GetOrganizationUserUserDetails(Arg.Any<OrganizationUserUserDetailsQueryRequest>()).Returns(organizationUsers); | ||
|
|
||
| sutProvider.GetDependency<IAuthorizationService>().AuthorizeAsync( |
There was a problem hiding this comment.
♻️ DEBT: With the stub removed, GetMany_Setup no longer arranges anything GetAll reads, so GetMany_ReturnsUsers passes vacuously.
Details
OrganizationUsersController.GetAll resolves members through _organizationUserUserDetailsQuery.Get(request) (or GetAccountRecoveryEnrolledUsers), never IOrganizationUserRepository.GetManyDetailsByOrganizationAsync. That repository stub therefore has no effect, and the auto-mocked IOrganizationUserUserDetailsQuery returns an empty sequence, so response.Data is empty and Assert.True(response.Data.All(r => organizationUsers.Any(ou => ou.Id == r.Id))) is true regardless of the injected organizationUsers.
Since this PR is a dead-code cleanup, consider finishing the job in the setup: stub the query instead, e.g.
sutProvider.GetDependency<IOrganizationUserUserDetailsQuery>()
.Get(Arg.Any<OrganizationUserUserDetailsQueryRequest>())
.Returns(organizationUsers.Select(ou => (ou, false, false)));(or delete GetMany_ReturnsUsers if the coverage is not worth restoring). Note the vacuity predates this PR — the removed stub was on a method GetAll never called — so this is optional.
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-38269
📔 Objective
For each Custom-role user,
OrganizationUserUserDetailsQuerywas deserializing thePermissionsJSON string from the database and immediately re-serializing it back to a string — a no-op round-trip before the string reaches the API response model, which deserializes it once anyway.This PR removes the three identical
if (Type == Custom)blocks fromGetOrganizationUserUserDetails,Get, andGetAccountRecoveryEnrolledUsers, and drops the now-unusedusing Bit.Core.Utilitiesimport.An API integration test is added to
OrganizationUsersControllerGetTeststo verify that Custom-user permissions survive the full pipeline (DB → query → response model → JSON) correctly.