mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
[AC-2248][PM-5352] Bugfix - Fix non-working policy state in autofill settings service (#8156)
* fix broken policy state in autofill settings service * cleanup and re-org * move toast display tracking value and update to autofill settings state
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
import { filter, switchMap, tap, firstValueFrom, map, Observable } from "rxjs";
|
||||
import { map, Observable } from "rxjs";
|
||||
|
||||
import {
|
||||
ClearClipboardDelaySetting,
|
||||
ClearClipboardDelay,
|
||||
} from "../../../../../apps/browser/src/autofill/constants";
|
||||
import {
|
||||
AutofillOverlayVisibility,
|
||||
InlineMenuVisibilitySetting,
|
||||
} from "../../../../../apps/browser/src/autofill/utils/autofill-overlay.enum";
|
||||
import { PolicyService } from "../../admin-console/abstractions/policy/policy.service.abstraction";
|
||||
import { PolicyType } from "../../admin-console/enums/index";
|
||||
import { Policy } from "../../admin-console/models/domain/policy";
|
||||
import { PolicyType } from "../../admin-console/enums";
|
||||
import {
|
||||
AUTOFILL_SETTINGS_DISK,
|
||||
AUTOFILL_SETTINGS_DISK_LOCAL,
|
||||
@@ -19,6 +10,8 @@ import {
|
||||
KeyDefinition,
|
||||
StateProvider,
|
||||
} from "../../platform/state";
|
||||
import { ClearClipboardDelay, AutofillOverlayVisibility } from "../constants";
|
||||
import { ClearClipboardDelaySetting, InlineMenuVisibilitySetting } from "../types";
|
||||
|
||||
const AUTOFILL_ON_PAGE_LOAD = new KeyDefinition(AUTOFILL_SETTINGS_DISK, "autofillOnPageLoad", {
|
||||
deserializer: (value: boolean) => value ?? false,
|
||||
@@ -32,10 +25,6 @@ const AUTOFILL_ON_PAGE_LOAD_DEFAULT = new KeyDefinition(
|
||||
},
|
||||
);
|
||||
|
||||
const AUTO_COPY_TOTP = new KeyDefinition(AUTOFILL_SETTINGS_DISK, "autoCopyTotp", {
|
||||
deserializer: (value: boolean) => value ?? false,
|
||||
});
|
||||
|
||||
const AUTOFILL_ON_PAGE_LOAD_CALLOUT_DISMISSED = new KeyDefinition(
|
||||
AUTOFILL_SETTINGS_DISK,
|
||||
"autofillOnPageLoadCalloutIsDismissed",
|
||||
@@ -44,14 +33,18 @@ const AUTOFILL_ON_PAGE_LOAD_CALLOUT_DISMISSED = new KeyDefinition(
|
||||
},
|
||||
);
|
||||
|
||||
const ACTIVATE_AUTOFILL_ON_PAGE_LOAD_FROM_POLICY = new KeyDefinition(
|
||||
AUTOFILL_SETTINGS_DISK_LOCAL,
|
||||
"activateAutofillOnPageLoadFromPolicy",
|
||||
const AUTOFILL_ON_PAGE_LOAD_POLICY_TOAST_HAS_DISPLAYED = new KeyDefinition(
|
||||
AUTOFILL_SETTINGS_DISK,
|
||||
"autofillOnPageLoadPolicyToastHasDisplayed",
|
||||
{
|
||||
deserializer: (value: boolean) => value ?? false,
|
||||
},
|
||||
);
|
||||
|
||||
const AUTO_COPY_TOTP = new KeyDefinition(AUTOFILL_SETTINGS_DISK, "autoCopyTotp", {
|
||||
deserializer: (value: boolean) => value ?? false,
|
||||
});
|
||||
|
||||
const INLINE_MENU_VISIBILITY = new KeyDefinition(
|
||||
AUTOFILL_SETTINGS_DISK_LOCAL,
|
||||
"inlineMenuVisibility",
|
||||
@@ -73,17 +66,17 @@ export abstract class AutofillSettingsServiceAbstraction {
|
||||
setAutofillOnPageLoad: (newValue: boolean) => Promise<void>;
|
||||
autofillOnPageLoadDefault$: Observable<boolean>;
|
||||
setAutofillOnPageLoadDefault: (newValue: boolean) => Promise<void>;
|
||||
autoCopyTotp$: Observable<boolean>;
|
||||
setAutoCopyTotp: (newValue: boolean) => Promise<void>;
|
||||
autofillOnPageLoadCalloutIsDismissed$: Observable<boolean>;
|
||||
setAutofillOnPageLoadCalloutIsDismissed: (newValue: boolean) => Promise<void>;
|
||||
activateAutofillOnPageLoadFromPolicy$: Observable<boolean>;
|
||||
setActivateAutofillOnPageLoadFromPolicy: (newValue: boolean) => Promise<void>;
|
||||
setAutofillOnPageLoadPolicyToastHasDisplayed: (newValue: boolean) => Promise<void>;
|
||||
autofillOnPageLoadPolicyToastHasDisplayed$: Observable<boolean>;
|
||||
autoCopyTotp$: Observable<boolean>;
|
||||
setAutoCopyTotp: (newValue: boolean) => Promise<void>;
|
||||
inlineMenuVisibility$: Observable<InlineMenuVisibilitySetting>;
|
||||
setInlineMenuVisibility: (newValue: InlineMenuVisibilitySetting) => Promise<void>;
|
||||
clearClipboardDelay$: Observable<ClearClipboardDelaySetting>;
|
||||
setClearClipboardDelay: (newValue: ClearClipboardDelaySetting) => Promise<void>;
|
||||
handleActivateAutofillPolicy: (policies: Observable<Policy[]>) => Observable<boolean[]>;
|
||||
}
|
||||
|
||||
export class AutofillSettingsService implements AutofillSettingsServiceAbstraction {
|
||||
@@ -93,15 +86,17 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
private autofillOnPageLoadDefaultState: ActiveUserState<boolean>;
|
||||
readonly autofillOnPageLoadDefault$: Observable<boolean>;
|
||||
|
||||
private autoCopyTotpState: ActiveUserState<boolean>;
|
||||
readonly autoCopyTotp$: Observable<boolean>;
|
||||
|
||||
private autofillOnPageLoadCalloutIsDismissedState: ActiveUserState<boolean>;
|
||||
readonly autofillOnPageLoadCalloutIsDismissed$: Observable<boolean>;
|
||||
|
||||
private activateAutofillOnPageLoadFromPolicyState: ActiveUserState<boolean>;
|
||||
readonly activateAutofillOnPageLoadFromPolicy$: Observable<boolean>;
|
||||
|
||||
private autofillOnPageLoadPolicyToastHasDisplayedState: ActiveUserState<boolean>;
|
||||
readonly autofillOnPageLoadPolicyToastHasDisplayed$: Observable<boolean>;
|
||||
|
||||
private autoCopyTotpState: ActiveUserState<boolean>;
|
||||
readonly autoCopyTotp$: Observable<boolean>;
|
||||
|
||||
private inlineMenuVisibilityState: GlobalState<InlineMenuVisibilitySetting>;
|
||||
readonly inlineMenuVisibility$: Observable<InlineMenuVisibilitySetting>;
|
||||
|
||||
@@ -110,7 +105,7 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
|
||||
constructor(
|
||||
private stateProvider: StateProvider,
|
||||
policyService: PolicyService,
|
||||
private policyService: PolicyService,
|
||||
) {
|
||||
this.autofillOnPageLoadState = this.stateProvider.getActive(AUTOFILL_ON_PAGE_LOAD);
|
||||
this.autofillOnPageLoad$ = this.autofillOnPageLoadState.state$.pipe(map((x) => x ?? false));
|
||||
@@ -122,20 +117,25 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
map((x) => x ?? true),
|
||||
);
|
||||
|
||||
this.autoCopyTotpState = this.stateProvider.getActive(AUTO_COPY_TOTP);
|
||||
this.autoCopyTotp$ = this.autoCopyTotpState.state$.pipe(map((x) => x ?? false));
|
||||
|
||||
this.autofillOnPageLoadCalloutIsDismissedState = this.stateProvider.getActive(
|
||||
AUTOFILL_ON_PAGE_LOAD_CALLOUT_DISMISSED,
|
||||
);
|
||||
this.autofillOnPageLoadCalloutIsDismissed$ =
|
||||
this.autofillOnPageLoadCalloutIsDismissedState.state$.pipe(map((x) => x ?? false));
|
||||
|
||||
this.activateAutofillOnPageLoadFromPolicyState = this.stateProvider.getActive(
|
||||
ACTIVATE_AUTOFILL_ON_PAGE_LOAD_FROM_POLICY,
|
||||
this.activateAutofillOnPageLoadFromPolicy$ = this.policyService.policyAppliesToActiveUser$(
|
||||
PolicyType.ActivateAutofill,
|
||||
);
|
||||
this.activateAutofillOnPageLoadFromPolicy$ =
|
||||
this.activateAutofillOnPageLoadFromPolicyState.state$.pipe(map((x) => x ?? false));
|
||||
|
||||
this.autofillOnPageLoadPolicyToastHasDisplayedState = this.stateProvider.getActive(
|
||||
AUTOFILL_ON_PAGE_LOAD_POLICY_TOAST_HAS_DISPLAYED,
|
||||
);
|
||||
this.autofillOnPageLoadPolicyToastHasDisplayed$ = this.autofillOnPageLoadState.state$.pipe(
|
||||
map((x) => x ?? false),
|
||||
);
|
||||
|
||||
this.autoCopyTotpState = this.stateProvider.getActive(AUTO_COPY_TOTP);
|
||||
this.autoCopyTotp$ = this.autoCopyTotpState.state$.pipe(map((x) => x ?? false));
|
||||
|
||||
this.inlineMenuVisibilityState = this.stateProvider.getGlobal(INLINE_MENU_VISIBILITY);
|
||||
this.inlineMenuVisibility$ = this.inlineMenuVisibilityState.state$.pipe(
|
||||
@@ -146,8 +146,6 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
this.clearClipboardDelay$ = this.clearClipboardDelayState.state$.pipe(
|
||||
map((x) => x ?? ClearClipboardDelay.Never),
|
||||
);
|
||||
|
||||
policyService.policies$.pipe(this.handleActivateAutofillPolicy.bind(this)).subscribe();
|
||||
}
|
||||
|
||||
async setAutofillOnPageLoad(newValue: boolean): Promise<void> {
|
||||
@@ -158,16 +156,16 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
await this.autofillOnPageLoadDefaultState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setAutoCopyTotp(newValue: boolean): Promise<void> {
|
||||
await this.autoCopyTotpState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setAutofillOnPageLoadCalloutIsDismissed(newValue: boolean): Promise<void> {
|
||||
await this.autofillOnPageLoadCalloutIsDismissedState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setActivateAutofillOnPageLoadFromPolicy(newValue: boolean): Promise<void> {
|
||||
await this.activateAutofillOnPageLoadFromPolicyState.update(() => newValue);
|
||||
async setAutofillOnPageLoadPolicyToastHasDisplayed(newValue: boolean): Promise<void> {
|
||||
await this.autofillOnPageLoadPolicyToastHasDisplayedState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setAutoCopyTotp(newValue: boolean): Promise<void> {
|
||||
await this.autoCopyTotpState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setInlineMenuVisibility(newValue: InlineMenuVisibilitySetting): Promise<void> {
|
||||
@@ -177,24 +175,4 @@ export class AutofillSettingsService implements AutofillSettingsServiceAbstracti
|
||||
async setClearClipboardDelay(newValue: ClearClipboardDelaySetting): Promise<void> {
|
||||
await this.clearClipboardDelayState.update(() => newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the ActivateAutofill policy is enabled, save a flag indicating if we need to
|
||||
* enable Autofill on page load.
|
||||
*/
|
||||
handleActivateAutofillPolicy(policies$: Observable<Policy[]>): Observable<boolean[]> {
|
||||
return policies$.pipe(
|
||||
map((policies) => policies.find((p) => p.type == PolicyType.ActivateAutofill && p.enabled)),
|
||||
filter((p) => p != null),
|
||||
switchMap(async (_) => [
|
||||
await firstValueFrom(this.activateAutofillOnPageLoadFromPolicy$),
|
||||
await firstValueFrom(this.autofillOnPageLoad$),
|
||||
]),
|
||||
tap(([activated, autofillEnabled]) => {
|
||||
if (activated === undefined) {
|
||||
void this.setActivateAutofillOnPageLoadFromPolicy(!autofillEnabled);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user