Skip to content

[PM-31364] Discard edit bug fixes#20511

Open
JaredScar wants to merge 13 commits intomainfrom
ac/pm-31364-discard-edit-bug-fixes
Open

[PM-31364] Discard edit bug fixes#20511
JaredScar wants to merge 13 commits intomainfrom
ac/pm-31364-discard-edit-bug-fixes

Conversation

@JaredScar
Copy link
Copy Markdown
Contributor

JaredScar added 11 commits May 4, 2026 17:14
…fore state clearance. This allows canDeactivate guards to function properly, preventing state changes if the user cancels the logout. Refactor logout logic to improve user experience during logout flow.
…g logout and navigation. Removed unused canDeactivate registration in PoliciesComponent and streamlined the PoliciesDeactivateGuard to directly check user authentication status. This ensures smoother transitions when locking the vault or logging out, preventing unnecessary warnings and enhancing overall functionality.
…dle null active accounts during logout. This change improves user experience by ensuring that the guards disarm correctly when the active account is null, preventing unnecessary warnings and enhancing navigation flow during logout and policy editing.
…. Removed unused initial value signals and streamlined the dirty state checks for form components, enhancing clarity and maintainability of the code.
…gComponent to simplify the component and improve code maintainability.
…ity for dialog interactions. Updated button actions to call close method, ensuring proper dialog closure and integration with the discard-edits dialog when there are unsaved changes. Enhanced MultiStepPolicyEditDialogComponent to reset dirty state on step advancement, improving user experience during policy editing.
@JaredScar JaredScar requested a review from a team as a code owner May 5, 2026 17:35
@JaredScar JaredScar added the ai-review Request a Claude code review label May 5, 2026
@JaredScar JaredScar requested a review from a team as a code owner May 5, 2026 17:35
@JaredScar JaredScar requested review from BTreston and vleague2 May 5, 2026 17:35
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🤖 Bitwarden Claude Code Review

Overall Assessment: REQUEST CHANGES

This PR fixes several bugs in the policy edit Discard Edits dialog: the policies route deactivation guard now skips its dirty-check when the user is locked or logged out; the modal/drawer dialog disarms its discard guard during a lock/logout transition; the dialog X button no longer bypasses closePredicate; the auto-confirm policy footer routes its cancel/close buttons through the close predicate; the multi-step policy dialog resets dirty state when advancing steps. Behavior changes look reasonable, but two issues should be addressed before merge.

Code Review Details
  • ⚠️ : New required AuthService constructor dependency breaks existing tests (PolicyEditDialogComponent and MultiStepPolicyEditDialogComponent specs do not provide it, so TestBed.createComponent will throw NullInjectorError)
    • apps/web/src/app/admin-console/organizations/policies/policy-edit-dialog.component.ts:90
  • ♻️ : Comments at lines 152–166 reference a beforeunload handler that this same PR removes; the discardGuardEnabled.set(false) it justifies is now effectively dead code on the discard-confirm path
    • apps/web/src/app/admin-console/organizations/policies/policy-edit-dialog.component.ts:152

JaredScar and others added 2 commits May 5, 2026 13:40
…lock functionality. Removed unused Injector dependency in AppComponent and streamlined logout process to ensure canDeactivate guards are respected. Updated AccountMenuComponent to utilize LockService for locking the vault, improving user experience during state transitions.
Remove navigate-before-logout change; no net changes to this file should be on this branch.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

protected readonly dialogService: DialogService,
protected readonly cdkDialogRef: CdkDialogRef,
protected readonly configService: ConfigService,
private readonly authService: AuthService,
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.

⚠️ IMPORTANT: New required AuthService constructor dependency breaks existing tests.

Details and fix

PolicyEditDialogComponent and MultiStepPolicyEditDialogComponent now require AuthService via constructor injection (not @Optional()), but neither policy-edit-dialog.component.spec.ts nor multi-step-policy-edit-dialog.component.spec.ts provides one in TestBed.configureTestingModule. TestBed.createComponent(...) in the existing beforeEach blocks will throw NullInjectorError: No provider for AuthService!, failing every test in both spec files.

Fix: add a mock provider in both spec files, e.g.:

import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
// ...
{ provide: AuthService, useValue: mock<AuthService>() },

Also consider provisioning authService.authStatusFor$ to return a non-emitting observable (e.g. NEVER or of(AuthenticationStatus.Unlocked)) so the new subscription in setupDiscardGuard doesn't disrupt other tests if ngAfterViewInit runs.

Comment on lines +152 to +158
if (confirmed) {
// Disarm the beforeunload handler immediately. Angular won't destroy this component
// until its next change-detection cycle, but a lock/logout can trigger
// window.location.reload() before that cycle runs. Clearing the flag here ensures
// the handler doesn't block the reload after the user has already confirmed discard.
this.discardGuardEnabled.set(false);
}
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.

♻️ DEBT: Comment references a beforeunload handler that no longer exists.

Details

This same PR removes the @HostListener("window:beforeunload") handler, so the rationale "Disarm the beforeunload handler immediately" no longer applies. After this point, discardGuardEnabled is read only by cancel(), which won't be invoked again on this close path since closePredicate is about to resolve true and tear down the dialog. Either drop discardGuardEnabled.set(false) here or update the comment to reflect the actual reason for the assignment (currently it appears load-bearing, but isn't).

The same stale rationale appears at lines 162–166 ("so the browser's beforeunload dialog cannot block the lock/logout reload") for the auth-status subscription — worth aligning that comment too.

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.

1 participant