Skip to content

[PM-37486] Remove IPolicyService and associated dead code#7672

Open
r-tome wants to merge 10 commits into
mainfrom
ac/pm-37486/remove-unused-policy-methods-and-sprocs
Open

[PM-37486] Remove IPolicyService and associated dead code#7672
r-tome wants to merge 10 commits into
mainfrom
ac/pm-37486/remove-unused-policy-methods-and-sprocs

Conversation

@r-tome
Copy link
Copy Markdown
Contributor

@r-tome r-tome commented May 19, 2026

🎟️ Tracking

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

📔 Objective

Migrate remaining IPolicyService callers to use IPolicyRequirementQuery and subsequently delete IPolicyService and no longer used stored procedures.

r-tome added 5 commits May 19, 2026 10:16
…pendency and replace with IPolicyRequirementQuery for policy checks. Update related tests to reflect changes in policy validation logic.
…Service with IPolicyRequirementQuery for policy checks. Update tests accordingly to reflect changes in policy validation logic.
…updating PolicyServiceCollectionExtensions and deleting associated tests. This change streamlines policy management by relying on IPolicyRequirementQuery for policy checks.
…icyDetails and PolicyDetails_ReadByUserId, as they are no longer called in the codebase.
@r-tome r-tome added needs-qa ai-review Request a Claude code review labels May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR completes the migration from the legacy IPolicyService to IPolicyRequirementQuery, deletes the now-orphaned service, its OrganizationUserPolicyDetails model, the GetByUserIdWithPolicyDetailsAsync repository method on both Dapper and EF implementations, and the associated test fixtures and integration tests. Call sites in AccountsController, InitPendingOrganizationValidator, and the Identity request validators (BaseRequestValidator, CustomTokenRequestValidator, ResourceOwnerPasswordValidator, SsoRequestValidator, WebAuthnGrantValidator) have been switched over with semantically equivalent replacements — SingleOrganizationPolicyRequirement.CanCreateOrganization() for the SingleOrg check and MasterPasswordPolicyRequirement.EnforcedOptions for the master-password policy, both of which apply the same role/status/provider filtering as the deleted PolicyService once the underlying sproc-level org/policy-enabled checks are accounted for.

Prior reviewer concerns appear addressed: the orphaned EfPolicyApplicableToUser AutoFixture types are removed from PolicyFixtures.cs, and the stored-procedure DROP migration that risked a rollback-incompatible deployment has been reverted, leaving OrganizationUser_ReadByUserIdWithPolicyDetails and PolicyDetails_ReadByUserId in place for a later, safer cleanup PR.

Code Review Details

No new findings.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.45%. Comparing base (4a3c204) to head (99035ae).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/Api/Auth/Controllers/AccountsController.cs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7672      +/-   ##
==========================================
+ Coverage   59.98%   64.45%   +4.47%     
==========================================
  Files        2133     2130       -3     
  Lines       93731    93640      -91     
  Branches     8311     8314       +3     
==========================================
+ Hits        56226    60360    +4134     
+ Misses      35527    31213    -4314     
- Partials     1978     2067      +89     

☔ 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.

r-tome added 4 commits May 19, 2026 11:09
…es, as they are no longer needed in the codebase.
…licyRequirementQuery for SSO validation checks. Update related test logic to ensure accurate policy validation outcomes. Clean up unused test fixtures in PolicyFixtures.cs to streamline the codebase.
…ability by storing policy requirement results in local variables before returning values. This change enhances code clarity while maintaining existing functionality.
…of the policy requirement query in a local variable before returning the enforced options. This change enhances code readability while preserving existing functionality.
@r-tome r-tome marked this pull request as ready for review May 19, 2026 15:10
@r-tome r-tome requested review from a team as code owners May 19, 2026 15:10
@r-tome r-tome requested review from eliykat and rr-bw May 19, 2026 15:10
@rr-bw rr-bw requested review from JaredSnider-Bitwarden and removed request for rr-bw May 19, 2026 16:04
-- OrganizationUser_ReadByUserIdWithPolicyDetails was used by PolicyService (now deleted).
-- PolicyDetails_ReadByUserId was never called anywhere.

DROP PROCEDURE IF EXISTS [dbo].[OrganizationUser_ReadByUserIdWithPolicyDetails];
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.

It looks like the C# code that calls this proc is being removed in this PR. If the deployment requires a server code rollback, this DROP would cause issues since DB changes are not reverted. This DROP should be moved to another PR to be done at a later date once this server deployment is hardened.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for calling this out! I have reverted the SQL changes in this branch. I will create a separate task to drop the stored procedures in a future release.

…dWithPolicyDetails and PolicyDetails_ReadByUserId, as they are no longer called in the codebase."

This reverts commit 0f4fdca.
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

🧹

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 needs-qa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants