Skip to content

[PM-39833] Migrate POLICIES_NEW back to POLICIES - #24407

Merged
eliykat merged 4 commits into
mainfrom
ac/pm-39833/migrate-policies-new-state
Nov 5, 2026
Merged

eliykat merged 4 commits into
mainfrom
ac/pm-39833/migrate-policies-new-state

Conversation

@eliykat

@eliykat eliykat commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

🎟️ Tracking

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

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

📔 Objective

Current state:

  • POLICIES contains policies for confirmed organizations only, and is no longer used.
  • POLICIES_NEW contains policies for accepted and confirmed organizations, and is used by policyService.

This PR copies POLICIES_NEW back to POLICIES; updates consumers to read from POLICIES; and drops POLICIES_NEW. This closes the loop so that we have a single state definition without the NEW suffix.

📸 Screenshots

Clients kept two parallel policy states: POLICIES (confirmed only) and
POLICIES_NEW (accepted and confirmed). Consolidate on a single POLICIES
state holding the accepted and confirmed data.

- Add state migration 87 to copy policiesNew over policies when present
- Read and write POLICIES only in DefaultPolicyService
- Remove InternalNewPolicyService and DefaultNewPolicyService
- Sync policiesNew (falling back to policies) into POLICIES

POLICIES_NEW is deprecated but kept for removal in PM-45288.
Comment on lines 1339 to 1342
) =>
new DefaultPolicyService(
stateProvider,
organizationService,
accountService,
newPolicyService,
() => injector.get(SdkService),
new DefaultPolicyService(stateProvider, organizationService, accountService, () =>
injector.get(SdkService),
),

This comment was marked as low quality.

Comment on lines 457 to +458
const policies: { [id: string]: PolicyData } = {};
source.forEach((p) => {
source?.forEach((p) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When both response and fallback are absent, this builds an empty map that replaces stored policies, erasing existing data. Preserve the existing state when the sync response contains no policy data.

Show fix
Suggested change
const policies: { [id: string]: PolicyData } = {};
source.forEach((p) => {
source?.forEach((p) => {
if (source == null) {
return;
}
const policies: { [id: string]: PolicyData } = {};
source.forEach((p) => {
Details

✨ AI Reasoning
​Previously, when both policiesNew and policies were absent, the sync method returned without changing stored policies. The new optional iteration still calls replace with an empty map in that case, erasing existing policy state on a response that provides no policy data.

Reply on this comment to give feedback or ignore the issue.
More info

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They are never absent.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Ignored this finding.

@eliykat eliykat added t:tech-debt Change Type - Tech debt ai-review Request a Claude code review labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

This PR merges the policiesNew state back into POLICIES. It adds state migration 87, which copies policiesNew over policies for each account and then removes policiesNew. It also deletes InternalNewPolicyService and DefaultNewPolicyService, and points PolicyRecordMapper and the single syncPolicies path at POLICIES. Every read of POLICIES in DefaultPolicyService still scopes by organization: policies$ keeps only confirmed organizations, and policiesByType$ passes confirmed and accepted organization context to the SDK filter, so the wider stored set leaves consumer contracts unchanged. The constructor wiring in browser, CLI and jslib-services.module.ts matches the new signatures, and nothing in the repository still references the removed service or POLICIES_NEW outside the migration.

@eliykat
eliykat marked this pull request as ready for review November 4, 2026 03:40
@eliykat
eliykat requested review from a team as code owners November 4, 2026 03:40
@bw-ghapp

bw-ghapp Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Changes in this PR impact the Autofill experience of the browser client

BIT has tested the core experience with these changes and the feature flag configuration used by vault.bitwarden.com.

✅ Fortunately, these BIT tests have passed! 🎉

@bw-ghapp

bw-ghapp Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Changes in this PR impact the Autofill experience of the browser client

BIT has tested the core experience with these changes and all feature flags disabled.

✅ Fortunately, these BIT tests have passed! 🎉

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.74%. Comparing base (6017013) to head (8ece7aa).
⚠️ Report is 28 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/angular/src/services/jslib-services.module.ts 0.00% 2 Missing ⚠️
...c/admin-console/models/domain/policy-sdk-mapper.ts 50.00% 1 Missing ⚠️
...s/common/src/platform/sync/default-sync.service.ts 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24407   +/-   ##
=======================================
  Coverage   61.73%   61.74%           
=======================================
  Files        4900     4899    -1     
  Lines      158167   158148   -19     
  Branches    25350    25348    -2     
=======================================
- Hits        97652    97642   -10     
+ Misses      53784    53777    -7     
+ Partials     6731     6729    -2     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@djsmith85 djsmith85 added browser Browser Extension desktop Desktop Application cli CLI Application web labels Nov 5, 2026
@eliykat
eliykat merged commit c518013 into main Nov 5, 2026
284 of 290 checks passed
@eliykat
eliykat deleted the ac/pm-39833/migrate-policies-new-state branch November 5, 2026 23:05
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 browser Browser Extension cli CLI Application desktop Desktop Application t:tech-debt Change Type - Tech debt web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants