1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-09 21:20:27 +00:00

Rename to remove "view" and "default"

This commit is contained in:
Alec Rippberger
2025-04-10 15:35:19 -05:00
parent 116c4ec5ed
commit 92797c99c7
3 changed files with 33 additions and 33 deletions

View File

@@ -34,7 +34,7 @@ import { FakeAccountService, mockAccountServiceWith } from "@bitwarden/common/sp
import { UserId } from "@bitwarden/common/types/guid";
import { DialogService, ToastService } from "@bitwarden/components";
import { DefaultTwoFactorFormCacheService } from "../../common/services/auth-request/default-two-factor-form-cache.service";
import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service";
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
import { TwoFactorAuthComponentService } from "./two-factor-auth-component.service";
@@ -71,7 +71,7 @@ describe("TwoFactorAuthComponent", () => {
let anonLayoutWrapperDataService: MockProxy<AnonLayoutWrapperDataService>;
let mockEnvService: MockProxy<EnvironmentService>;
let mockLoginSuccessHandlerService: MockProxy<LoginSuccessHandlerService>;
let mockTwoFactorFormCacheService: MockProxy<DefaultTwoFactorFormCacheService>;
let mockTwoFactorAuthCacheService: MockProxy<TwoFactorAuthCacheService>;
let mockUserDecryptionOpts: {
noMasterPassword: UserDecryptionOptions;
@@ -112,9 +112,9 @@ describe("TwoFactorAuthComponent", () => {
anonLayoutWrapperDataService = mock<AnonLayoutWrapperDataService>();
mockTwoFactorFormCacheService = mock<DefaultTwoFactorFormCacheService>();
mockTwoFactorFormCacheService.getCachedTwoFactorFormData.mockReturnValue(null);
mockTwoFactorFormCacheService.init.mockResolvedValue();
mockTwoFactorAuthCacheService = mock<TwoFactorAuthCacheService>();
mockTwoFactorAuthCacheService.getCachedTwoFactorAuth.mockReturnValue(null);
mockTwoFactorAuthCacheService.init.mockResolvedValue();
mockUserDecryptionOpts = {
noMasterPassword: new UserDecryptionOptions({
@@ -200,7 +200,7 @@ describe("TwoFactorAuthComponent", () => {
{ provide: EnvironmentService, useValue: mockEnvService },
{ provide: AnonLayoutWrapperDataService, useValue: anonLayoutWrapperDataService },
{ provide: LoginSuccessHandlerService, useValue: mockLoginSuccessHandlerService },
{ provide: DefaultTwoFactorFormCacheService, useValue: mockTwoFactorFormCacheService },
{ provide: TwoFactorAuthCacheService, useValue: mockTwoFactorAuthCacheService },
],
});

View File

@@ -46,7 +46,7 @@ import {
ToastService,
} from "@bitwarden/components";
import { DefaultTwoFactorFormCacheService } from "../../common/services/auth-request/default-two-factor-form-cache.service";
import { TwoFactorAuthCacheService } from "../../common/services/auth-request/two-factor-auth-cache.service";
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
import {
TwoFactorAuthAuthenticatorIcon,
@@ -74,7 +74,7 @@ import {
/**
* Interface for the cache data structure
*/
interface TwoFactorFormCacheData {
interface TwoFactorCacheData {
token?: string;
remember?: boolean;
selectedProviderType?: TwoFactorProviderType;
@@ -103,7 +103,7 @@ interface TwoFactorFormCacheData {
],
providers: [
{
provide: DefaultTwoFactorFormCacheService,
provide: TwoFactorAuthCacheService,
},
],
})
@@ -180,7 +180,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
private anonLayoutWrapperDataService: AnonLayoutWrapperDataService,
private environmentService: EnvironmentService,
private loginSuccessHandlerService: LoginSuccessHandlerService,
private twoFactorFormCacheService: DefaultTwoFactorFormCacheService,
private twoFactorCacheService: TwoFactorAuthCacheService,
) {}
async ngOnInit() {
@@ -190,11 +190,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
this.listenForAuthnSessionTimeout();
// Initialize the cache
await this.twoFactorFormCacheService.init();
await this.twoFactorCacheService.init();
// Load persisted form data if available
let loadedCachedProviderType = false;
const persistedData = this.twoFactorFormCacheService.getCachedTwoFactorFormData();
const persistedData = this.twoFactorCacheService.getCachedTwoFactorAuth();
if (persistedData) {
if (persistedData.token) {
this.form.patchValue({ token: persistedData.token });
@@ -231,11 +231,11 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
/**
* Save specific form data fields to the cache
*/
async saveFormDataWithPartialData(data: Partial<TwoFactorFormCacheData>) {
async saveFormDataWithPartialData(data: Partial<TwoFactorCacheData>) {
// Get current cached data
const currentData = this.twoFactorFormCacheService.getCachedTwoFactorFormData();
const currentData = this.twoFactorCacheService.getCachedTwoFactorAuth();
this.twoFactorFormCacheService.cacheTwoFactorFormData({
this.twoFactorCacheService.cacheTwoFactorAuth({
token: data?.token ?? currentData?.token ?? "",
remember: data?.remember ?? currentData?.remember ?? false,
selectedProviderType:
@@ -250,7 +250,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
* Save all current form data to the cache
*/
async saveFormData() {
const formData: TwoFactorFormCacheData = {
const formData: TwoFactorCacheData = {
token: this.tokenFormControl.value || undefined,
remember: this.rememberFormControl.value ?? undefined,
selectedProviderType: this.selectedProviderType,
@@ -347,7 +347,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
const rememberValue = remember ?? this.rememberFormControl.value ?? false;
// Persist form data before submitting
this.twoFactorFormCacheService.cacheTwoFactorFormData({
this.twoFactorCacheService.cacheTwoFactorAuth({
token: tokenValue,
remember: rememberValue,
selectedProviderType: this.selectedProviderType,
@@ -375,7 +375,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
async selectOtherTwoFactorMethod() {
// Persist current form data before navigating to another method
this.twoFactorFormCacheService.cacheTwoFactorFormData({
this.twoFactorCacheService.cacheTwoFactorAuth({
token: "",
remember: false,
selectedProviderType: this.selectedProviderType,
@@ -396,7 +396,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
await this.setAnonLayoutDataByTwoFactorProviderType();
// Update the persisted provider type when a new one is chosen
this.twoFactorFormCacheService.cacheTwoFactorFormData({
this.twoFactorCacheService.cacheTwoFactorAuth({
token: "",
remember: false,
selectedProviderType: response.type,
@@ -481,7 +481,7 @@ export class TwoFactorAuthComponent implements OnInit, OnDestroy {
private async handleAuthResult(authResult: AuthResult) {
// Clear form cache
this.twoFactorFormCacheService.clearCachedTwoFactorFormData();
this.twoFactorCacheService.clearCachedTwoFactorAuth();
if (await this.handleMigrateEncryptionKey(authResult)) {
return; // stop login process

View File

@@ -22,7 +22,7 @@ export class TwoFactorAuthCache {
}
}
export interface TwoFactorFormData {
export interface TwoFactorAuthData {
token?: string;
remember?: boolean;
selectedProviderType?: TwoFactorProviderType;
@@ -36,7 +36,7 @@ export interface TwoFactorFormData {
* after 2 minutes.
*/
@Injectable()
export class DefaultTwoFactorFormCacheService {
export class TwoFactorAuthCacheService {
private viewCacheService: ViewCacheService = inject(ViewCacheService);
private configService: ConfigService = inject(ConfigService);
@@ -44,9 +44,9 @@ export class DefaultTwoFactorFormCacheService {
private featureEnabled: boolean = false;
/**
* Signal for the cached TwoFactorFormData.
* Signal for the cached TwoFactorAuthData.
*/
private defaultTwoFactorAuthCache: WritableSignal<TwoFactorAuthCache | null> =
private twoFactorAuthCache: WritableSignal<TwoFactorAuthCache | null> =
this.viewCacheService.signal<TwoFactorAuthCache | null>({
key: TWO_FACTOR_AUTH_CACHE_KEY,
initialValue: null,
@@ -65,14 +65,14 @@ export class DefaultTwoFactorFormCacheService {
}
/**
* Update the cache with the new TwoFactorFormData.
* Update the cache with the new TwoFactorAuthData.
*/
cacheTwoFactorFormData(data: TwoFactorFormData): void {
cacheTwoFactorAuth(data: TwoFactorAuthData): void {
if (!this.featureEnabled) {
return;
}
this.defaultTwoFactorAuthCache.set({
this.twoFactorAuthCache.set({
token: data.token,
remember: data.remember,
selectedProviderType: data.selectedProviderType,
@@ -81,24 +81,24 @@ export class DefaultTwoFactorFormCacheService {
}
/**
* Clears the cached TwoFactorFormData.
* Clears the cached TwoFactorAuthData.
*/
clearCachedTwoFactorFormData(): void {
clearCachedTwoFactorAuth(): void {
if (!this.featureEnabled) {
return;
}
this.defaultTwoFactorAuthCache.set(null);
this.twoFactorAuthCache.set(null);
}
/**
* Returns the cached TwoFactorFormData when available.
* Returns the cached TwoFactorAuthData when available.
*/
getCachedTwoFactorFormData(): TwoFactorAuthCache | null {
getCachedTwoFactorAuth(): TwoFactorAuthCache | null {
if (!this.featureEnabled) {
return null;
}
return this.defaultTwoFactorAuthCache();
return this.twoFactorAuthCache();
}
}