1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 10:43:35 +00:00

[PM-24158] Add Premium Check (#16042)

* [PM-24158] Add initial premium check

* [PM-24158] Add premium membership dialog fix

* [PM-24158] Small updates

* [PM-24158] Set hasPremium to false upon initialization

* [PM-24158] Partial update to settings component tests

* [PM-24158] Fix billing mocked return value and add mac OS autotype test

* [PM-24158] Add missing premium checks

* [PM-24158] Update provider

* [PM-24158] Renamed autotype resolved value

* [PM-24158] Update missed resolvedAutotypeEnabled refactor

* [PM-24158] Fix tests
This commit is contained in:
Colton Hurst
2025-09-04 09:33:39 -07:00
committed by GitHub
parent 10a5eba05f
commit 896f54696b
7 changed files with 122 additions and 31 deletions

View File

@@ -17,6 +17,7 @@ import { UserVerificationService as UserVerificationServiceAbstraction } from "@
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions";
import { DeviceType } from "@bitwarden/common/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { PinServiceAbstraction } from "@bitwarden/common/key-management/pin/pin.service.abstraction";
@@ -50,6 +51,7 @@ import {
SelectModule,
ToastService,
TypographyModule,
BadgeComponent,
} from "@bitwarden/components";
import { KeyService, BiometricStateService, BiometricsStatus } from "@bitwarden/key-management";
import { PermitCipherDetailsPopoverComponent } from "@bitwarden/vault";
@@ -58,6 +60,7 @@ import { SetPinComponent } from "../../auth/components/set-pin.component";
import { SshAgentPromptType } from "../../autofill/models/ssh-agent-setting";
import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service";
import { DesktopAutotypeService } from "../../autofill/services/desktop-autotype.service";
import { PremiumComponent } from "../../billing/app/accounts/premium.component";
import { DesktopBiometricsService } from "../../key-management/biometrics/desktop.biometrics.service";
import { DesktopSettingsService } from "../../platform/services/desktop-settings.service";
import { NativeMessagingManifestService } from "../services/native-messaging-manifest.service";
@@ -67,6 +70,7 @@ import { NativeMessagingManifestService } from "../services/native-messaging-man
templateUrl: "settings.component.html",
standalone: true,
imports: [
BadgeComponent,
CheckboxModule,
CommonModule,
FormFieldModule,
@@ -130,6 +134,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
pinEnabled$: Observable<boolean> = of(true);
hasPremium: boolean = false;
form = this.formBuilder.group({
// Security
vaultTimeout: [null as VaultTimeout | null],
@@ -158,7 +164,10 @@ export class SettingsComponent implements OnInit, OnDestroy {
sshAgentPromptBehavior: SshAgentPromptType.Always,
allowScreenshots: false,
enableDuckDuckGoBrowserIntegration: false,
enableAutotype: false,
enableAutotype: this.formBuilder.control<boolean>({
value: false,
disabled: true,
}),
theme: [null as Theme | null],
locale: [null as string | null],
});
@@ -193,6 +202,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
private validationService: ValidationService,
private changeDetectorRef: ChangeDetectorRef,
private toastService: ToastService,
private billingAccountProfileStateService: BillingAccountProfileStateService,
) {
this.isMac = this.platformUtilsService.getDevice() === DeviceType.MacOsDesktop;
this.isLinux = this.platformUtilsService.getDevice() === DeviceType.LinuxDesktop;
@@ -268,10 +278,14 @@ export class SettingsComponent implements OnInit, OnDestroy {
// Autotype is for Windows initially
const isWindows = this.platformUtilsService.getDevice() === DeviceType.WindowsDesktop;
const windowsDesktopAutotypeFeatureFlag = await this.configService.getFeatureFlag(
FeatureFlag.WindowsDesktopAutotype,
);
this.showEnableAutotype = isWindows && windowsDesktopAutotypeFeatureFlag;
if (isWindows) {
this.configService
.getFeatureFlag$(FeatureFlag.WindowsDesktopAutotype)
.pipe(takeUntil(this.destroy$))
.subscribe((enabled) => {
this.showEnableAutotype = enabled;
});
}
this.userHasMasterPassword = await this.userVerificationService.hasMasterPassword();
@@ -377,7 +391,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
this.desktopSettingsService.sshAgentPromptBehavior$,
),
allowScreenshots: !(await firstValueFrom(this.desktopSettingsService.preventScreenshots$)),
enableAutotype: await firstValueFrom(this.desktopAutotypeService.autotypeEnabled$),
enableAutotype: await firstValueFrom(this.desktopAutotypeService.resolvedAutotypeEnabled$),
theme: await firstValueFrom(this.themeStateService.selectedTheme$),
locale: await firstValueFrom(this.i18nService.userSetLocale$),
};
@@ -402,6 +416,19 @@ export class SettingsComponent implements OnInit, OnDestroy {
this.form.controls.vaultTimeoutAction.setValue(action, { emitEvent: false });
});
if (isWindows) {
this.billingAccountProfileStateService
.hasPremiumFromAnySource$(activeAccount.id)
.pipe(takeUntil(this.destroy$))
.subscribe((hasPremium) => {
this.hasPremium = hasPremium;
if (this.hasPremium) {
this.form.controls.enableAutotype.enable();
}
});
}
// Form events
this.form.controls.vaultTimeout.valueChanges
.pipe(
@@ -865,6 +892,10 @@ export class SettingsComponent implements OnInit, OnDestroy {
}
}
async openPremiumDialog() {
await this.dialogService.open(PremiumComponent);
}
async saveEnableAutotype() {
await this.desktopAutotypeService.setAutotypeEnabledState(this.form.value.enableAutotype);
}