From 053e255a68bc7b9dd550161c7cc7af51e91c3b03 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:38:10 -0400 Subject: [PATCH 1/7] Delete Unused Bits of StateService (#9858) * Delete Unused Bits of StateService * Fix Tests --- .../notification.background.spec.ts | 3 - .../background/notification.background.ts | 2 - .../background/overlay.background.spec.ts | 3 - .../autofill/background/overlay.background.ts | 2 - .../browser/main-context-menu-handler.spec.ts | 5 +- .../browser/main-context-menu-handler.ts | 5 +- .../browser/src/background/idle.background.ts | 3 - .../browser/src/background/main.background.ts | 17 +- apps/browser/src/models/account.ts | 36 ---- .../abstractions/browser-state.service.ts | 5 - .../services/browser-state.service.spec.ts | 77 ------- .../services/default-browser-state.service.ts | 64 ------ apps/browser/src/popup/app.component.ts | 4 +- .../src/popup/services/init.service.ts | 4 +- .../src/popup/services/services.module.ts | 53 +---- .../popup/send/send-add-edit.component.ts | 4 +- apps/desktop/src/app/app.component.ts | 1 - .../app/layout/account-switcher.component.ts | 2 - .../src/app/services/services.module.ts | 37 ---- apps/desktop/src/models/account.ts | 20 -- .../services/electron-state.service.ts | 12 -- apps/web/src/app/core/core.module.ts | 16 +- apps/web/src/app/core/state/account.ts | 8 - apps/web/src/app/core/state/global-state.ts | 5 - apps/web/src/app/core/state/index.ts | 2 - apps/web/src/app/core/state/state.service.ts | 11 +- .../src/services/jslib-services.module.ts | 4 + .../platform/abstractions/state.service.ts | 31 --- .../models/domain/account-settings.spec.ts | 9 - .../platform/models/domain/account.spec.ts | 4 +- .../src/platform/models/domain/account.ts | 59 ----- .../src/platform/services/state.service.ts | 201 +----------------- .../src/platform/services/system.service.ts | 4 - 33 files changed, 32 insertions(+), 681 deletions(-) delete mode 100644 apps/browser/src/models/account.ts delete mode 100644 apps/browser/src/platform/services/abstractions/browser-state.service.ts delete mode 100644 apps/browser/src/platform/services/browser-state.service.spec.ts delete mode 100644 apps/browser/src/platform/services/default-browser-state.service.ts delete mode 100644 apps/desktop/src/models/account.ts delete mode 100644 apps/desktop/src/platform/services/electron-state.service.ts delete mode 100644 apps/web/src/app/core/state/account.ts delete mode 100644 apps/web/src/app/core/state/global-state.ts delete mode 100644 libs/common/src/platform/models/domain/account-settings.spec.ts diff --git a/apps/browser/src/autofill/background/notification.background.spec.ts b/apps/browser/src/autofill/background/notification.background.spec.ts index 5598c27dd6..9c2e63c1aa 100644 --- a/apps/browser/src/autofill/background/notification.background.spec.ts +++ b/apps/browser/src/autofill/background/notification.background.spec.ts @@ -17,7 +17,6 @@ import { CipherService } from "@bitwarden/common/vault/services/cipher.service"; import { FolderService } from "@bitwarden/common/vault/services/folder/folder.service"; import { BrowserApi } from "../../platform/browser/browser-api"; -import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service"; import { NotificationQueueMessageType } from "../enums/notification-queue-message-type.enum"; import { FormData } from "../services/abstractions/autofill.service"; import AutofillService from "../services/autofill.service"; @@ -49,7 +48,6 @@ describe("NotificationBackground", () => { const authService = mock(); const policyService = mock(); const folderService = mock(); - const stateService = mock(); const userNotificationSettingsService = mock(); const domainSettingsService = mock(); const environmentService = mock(); @@ -64,7 +62,6 @@ describe("NotificationBackground", () => { authService, policyService, folderService, - stateService, userNotificationSettingsService, domainSettingsService, environmentService, diff --git a/apps/browser/src/autofill/background/notification.background.ts b/apps/browser/src/autofill/background/notification.background.ts index 9b65e4db0b..179598a882 100644 --- a/apps/browser/src/autofill/background/notification.background.ts +++ b/apps/browser/src/autofill/background/notification.background.ts @@ -23,7 +23,6 @@ import { LoginView } from "@bitwarden/common/vault/models/view/login.view"; import { openUnlockPopout } from "../../auth/popup/utils/auth-popout-window"; import { BrowserApi } from "../../platform/browser/browser-api"; -import { BrowserStateService } from "../../platform/services/abstractions/browser-state.service"; import { openAddEditVaultItemPopout } from "../../vault/popup/utils/vault-popout-window"; import { NotificationQueueMessageType } from "../enums/notification-queue-message-type.enum"; import { AutofillService } from "../services/abstractions/autofill.service"; @@ -76,7 +75,6 @@ export default class NotificationBackground { private authService: AuthService, private policyService: PolicyService, private folderService: FolderService, - private stateService: BrowserStateService, private userNotificationSettingsService: UserNotificationSettingsServiceAbstraction, private domainSettingsService: DomainSettingsService, private environmentService: EnvironmentService, diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index df4867640f..7be93b11e6 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -33,7 +33,6 @@ import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { CipherService } from "@bitwarden/common/vault/services/cipher.service"; import { BrowserApi } from "../../platform/browser/browser-api"; -import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service"; import { BrowserPlatformUtilsService } from "../../platform/services/platform-utils/browser-platform-utils.service"; import { AutofillService } from "../services/abstractions/autofill.service"; import { @@ -73,7 +72,6 @@ describe("OverlayBackground", () => { urls: { icons: "https://icons.bitwarden.com/" }, }), ); - const stateService = mock(); const autofillSettingsService = mock(); const i18nService = mock(); const platformUtilsService = mock(); @@ -104,7 +102,6 @@ describe("OverlayBackground", () => { authService, environmentService, domainSettingsService, - stateService, autofillSettingsService, i18nService, platformUtilsService, diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index bf954c3419..2f80790134 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -9,7 +9,6 @@ import { InlineMenuVisibilitySetting } from "@bitwarden/common/autofill/types"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; @@ -101,7 +100,6 @@ class OverlayBackground implements OverlayBackgroundInterface { private authService: AuthService, private environmentService: EnvironmentService, private domainSettingsService: DomainSettingsService, - private stateService: StateService, private autofillSettingsService: AutofillSettingsServiceAbstraction, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, diff --git a/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts b/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts index 67637da2fd..21eadfaf66 100644 --- a/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts +++ b/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts @@ -6,16 +6,15 @@ import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/s import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { CipherType } from "@bitwarden/common/vault/enums"; import { Cipher } from "@bitwarden/common/vault/models/domain/cipher"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; -import { BrowserStateService } from "../../platform/services/abstractions/browser-state.service"; - import { MainContextMenuHandler } from "./main-context-menu-handler"; describe("context-menu", () => { - let stateService: MockProxy; + let stateService: MockProxy; let autofillSettingsService: MockProxy; let i18nService: MockProxy; let logService: MockProxy; diff --git a/apps/browser/src/autofill/browser/main-context-menu-handler.ts b/apps/browser/src/autofill/browser/main-context-menu-handler.ts index a02a3a84d4..7b074a566a 100644 --- a/apps/browser/src/autofill/browser/main-context-menu-handler.ts +++ b/apps/browser/src/autofill/browser/main-context-menu-handler.ts @@ -20,12 +20,11 @@ import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/s import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; -import { BrowserStateService } from "../../platform/services/abstractions/browser-state.service"; - import { InitContextMenuItems } from "./abstractions/main-context-menu-handler"; export class MainContextMenuHandler { @@ -143,7 +142,7 @@ export class MainContextMenuHandler { ]; constructor( - private stateService: BrowserStateService, + private stateService: StateService, private autofillSettingsService: AutofillSettingsServiceAbstraction, private i18nService: I18nService, private logService: LogService, diff --git a/apps/browser/src/background/idle.background.ts b/apps/browser/src/background/idle.background.ts index eef033b364..c0cd3a86aa 100644 --- a/apps/browser/src/background/idle.background.ts +++ b/apps/browser/src/background/idle.background.ts @@ -7,8 +7,6 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum"; import { VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type"; -import { BrowserStateService } from "../platform/services/abstractions/browser-state.service"; - const IdleInterval = 60 * 5; // 5 minutes export default class IdleBackground { @@ -18,7 +16,6 @@ export default class IdleBackground { constructor( private vaultTimeoutService: VaultTimeoutService, - private stateService: BrowserStateService, private notificationsService: NotificationsService, private accountService: AccountService, private vaultTimeoutSettingsService: VaultTimeoutSettingsService, diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 8de3014fb2..b1dbb8525f 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -86,6 +86,7 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { LogService as LogServiceAbstraction } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService, ObservableStorageService, @@ -101,6 +102,7 @@ import { Message, MessageListener, MessageSender } from "@bitwarden/common/platf import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; import { Lazy } from "@bitwarden/common/platform/misc/lazy"; import { clearCaches } from "@bitwarden/common/platform/misc/sequentialize"; +import { Account } from "@bitwarden/common/platform/models/domain/account"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key"; import { AppIdService } from "@bitwarden/common/platform/services/app-id.service"; @@ -116,6 +118,7 @@ import { FileUploadService } from "@bitwarden/common/platform/services/file-uplo import { KeyGenerationService } from "@bitwarden/common/platform/services/key-generation.service"; import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; +import { StateService } from "@bitwarden/common/platform/services/state.service"; import { SystemService } from "@bitwarden/common/platform/services/system.service"; import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; @@ -206,7 +209,6 @@ import { Fido2Background } from "../autofill/fido2/background/fido2.background"; import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service"; import AutofillService from "../autofill/services/autofill.service"; import { SafariApp } from "../browser/safariApp"; -import { Account } from "../models/account"; import { BrowserApi } from "../platform/browser/browser-api"; import { flagEnabled } from "../platform/flags"; import { UpdateBadge } from "../platform/listeners/update-badge"; @@ -215,13 +217,11 @@ import { ChromeMessageSender } from "../platform/messaging/chrome-message.sender /* eslint-enable no-restricted-imports */ import { OffscreenDocumentService } from "../platform/offscreen-document/abstractions/offscreen-document"; import { DefaultOffscreenDocumentService } from "../platform/offscreen-document/offscreen-document.service"; -import { BrowserStateService as StateServiceAbstraction } from "../platform/services/abstractions/browser-state.service"; import { BrowserCryptoService } from "../platform/services/browser-crypto.service"; import { BrowserEnvironmentService } from "../platform/services/browser-environment.service"; import BrowserLocalStorageService from "../platform/services/browser-local-storage.service"; import BrowserMemoryStorageService from "../platform/services/browser-memory-storage.service"; import { BrowserScriptInjectorService } from "../platform/services/browser-script-injector.service"; -import { DefaultBrowserStateService } from "../platform/services/default-browser-state.service"; import I18nService from "../platform/services/i18n.service"; import { LocalBackedSessionStorageService } from "../platform/services/local-backed-session-storage.service"; import { BackgroundPlatformUtilsService } from "../platform/services/platform-utils/background-platform-utils.service"; @@ -540,7 +540,7 @@ export default class MainBackground { ClientType.Browser, ); - this.stateService = new DefaultBrowserStateService( + this.stateService = new StateService( this.storageService, this.secureStorageService, this.memoryStorageService, @@ -968,7 +968,6 @@ export default class MainBackground { this.messagingService, this.platformUtilsService, systemUtilsServiceReloadCallback, - this.stateService, this.autofillSettingsService, this.vaultTimeoutSettingsService, this.biometricStateService, @@ -1028,7 +1027,6 @@ export default class MainBackground { this.authService, this.policyService, this.folderService, - this.stateService, this.userNotificationSettingsService, this.domainSettingsService, this.environmentService, @@ -1042,7 +1040,6 @@ export default class MainBackground { this.authService, this.environmentService, this.domainSettingsService, - this.stateService, this.autofillSettingsService, this.i18nService, this.platformUtilsService, @@ -1100,7 +1097,6 @@ export default class MainBackground { this.idleBackground = new IdleBackground( this.vaultTimeoutService, - this.stateService, this.notificationsService, this.accountService, this.vaultTimeoutSettingsService, @@ -1227,11 +1223,6 @@ export default class MainBackground { async switchAccount(userId: UserId) { let nextAccountStatus: AuthenticationStatus; try { - const currentlyActiveAccount = await firstValueFrom( - this.accountService.activeAccount$.pipe(map((account) => account?.id)), - ); - // can be removed once password generation history is migrated to state providers - await this.stateService.clearDecryptedData(currentlyActiveAccount); // HACK to ensure account is switched before proceeding const switchPromise = firstValueFrom( this.accountService.activeAccount$.pipe( diff --git a/apps/browser/src/models/account.ts b/apps/browser/src/models/account.ts deleted file mode 100644 index 519f1bda6b..0000000000 --- a/apps/browser/src/models/account.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Jsonify } from "type-fest"; - -import { Account as BaseAccount } from "@bitwarden/common/platform/models/domain/account"; - -import { BrowserComponentState } from "./browserComponentState"; -import { BrowserGroupingsComponentState } from "./browserGroupingsComponentState"; -import { BrowserSendComponentState } from "./browserSendComponentState"; - -export class Account extends BaseAccount { - groupings?: BrowserGroupingsComponentState; - send?: BrowserSendComponentState; - ciphers?: BrowserComponentState; - sendType?: BrowserComponentState; - - constructor(init: Partial) { - super(init); - - this.groupings = init?.groupings ?? new BrowserGroupingsComponentState(); - this.send = init?.send ?? new BrowserSendComponentState(); - this.ciphers = init?.ciphers ?? new BrowserComponentState(); - this.sendType = init?.sendType ?? new BrowserComponentState(); - } - - static fromJSON(json: Jsonify): Account { - if (json == null) { - return null; - } - - return Object.assign(new Account({}), json, super.fromJSON(json), { - groupings: BrowserGroupingsComponentState.fromJSON(json.groupings), - send: BrowserSendComponentState.fromJSON(json.send), - ciphers: BrowserComponentState.fromJSON(json.ciphers), - sendType: BrowserComponentState.fromJSON(json.sendType), - }); - } -} diff --git a/apps/browser/src/platform/services/abstractions/browser-state.service.ts b/apps/browser/src/platform/services/abstractions/browser-state.service.ts deleted file mode 100644 index c8e2c502e7..0000000000 --- a/apps/browser/src/platform/services/abstractions/browser-state.service.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; - -import { Account } from "../../../models/account"; - -export abstract class BrowserStateService extends BaseStateServiceAbstraction {} diff --git a/apps/browser/src/platform/services/browser-state.service.spec.ts b/apps/browser/src/platform/services/browser-state.service.spec.ts deleted file mode 100644 index 506f185b64..0000000000 --- a/apps/browser/src/platform/services/browser-state.service.spec.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { mock, MockProxy } from "jest-mock-extended"; - -import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"; -import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; -import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; -import { State } from "@bitwarden/common/platform/models/domain/state"; -import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; -import { mockAccountServiceWith } from "@bitwarden/common/spec"; -import { UserId } from "@bitwarden/common/types/guid"; - -import { Account } from "../../models/account"; - -import { DefaultBrowserStateService } from "./default-browser-state.service"; - -describe("Browser State Service", () => { - let secureStorageService: MockProxy; - let diskStorageService: MockProxy; - let logService: MockProxy; - let stateFactory: MockProxy>; - let environmentService: MockProxy; - let tokenService: MockProxy; - let migrationRunner: MockProxy; - - let state: State; - const userId = "userId" as UserId; - const accountService = mockAccountServiceWith(userId); - - let sut: DefaultBrowserStateService; - - beforeEach(() => { - secureStorageService = mock(); - diskStorageService = mock(); - logService = mock(); - stateFactory = mock(); - environmentService = mock(); - tokenService = mock(); - migrationRunner = mock(); - - state = new State(new GlobalState()); - state.accounts[userId] = new Account({ - profile: { userId: userId }, - }); - }); - - afterEach(() => { - jest.resetAllMocks(); - }); - - describe("state methods", () => { - let memoryStorageService: MockProxy; - - beforeEach(() => { - memoryStorageService = mock(); - const stateGetter = (key: string) => Promise.resolve(state); - memoryStorageService.get.mockImplementation(stateGetter); - - sut = new DefaultBrowserStateService( - diskStorageService, - secureStorageService, - memoryStorageService, - logService, - stateFactory, - accountService, - environmentService, - tokenService, - migrationRunner, - ); - }); - - it("exists", () => { - expect(sut).toBeDefined(); - }); - }); -}); diff --git a/apps/browser/src/platform/services/default-browser-state.service.ts b/apps/browser/src/platform/services/default-browser-state.service.ts deleted file mode 100644 index 92da28efa2..0000000000 --- a/apps/browser/src/platform/services/default-browser-state.service.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; -import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"; -import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; -import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; -import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; -import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; -import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options"; -import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; -import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service"; - -import { Account } from "../../models/account"; - -import { BrowserStateService } from "./abstractions/browser-state.service"; - -export class DefaultBrowserStateService - extends BaseStateService - implements BrowserStateService -{ - protected accountDeserializer = Account.fromJSON; - - constructor( - storageService: AbstractStorageService, - secureStorageService: AbstractStorageService, - memoryStorageService: AbstractStorageService, - logService: LogService, - stateFactory: StateFactory, - accountService: AccountService, - environmentService: EnvironmentService, - tokenService: TokenService, - migrationRunner: MigrationRunner, - ) { - super( - storageService, - secureStorageService, - memoryStorageService, - logService, - stateFactory, - accountService, - environmentService, - tokenService, - migrationRunner, - ); - } - - async addAccount(account: Account) { - // Apply browser overrides to default account values - account = new Account(account); - await super.addAccount(account); - } - - // Overriding the base class to prevent deleting the cache on save. We register a storage listener - // to delete the cache in the constructor above. - protected override async saveAccountToDisk( - account: Account, - options: StorageOptions, - ): Promise { - const storageLocation = options.useSecureStorage - ? this.secureStorageService - : this.storageService; - - await storageLocation.save(`${options.userId}`, account, options); - } -} diff --git a/apps/browser/src/popup/app.component.ts b/apps/browser/src/popup/app.component.ts index b70a5564ed..287e909668 100644 --- a/apps/browser/src/popup/app.component.ts +++ b/apps/browser/src/popup/app.component.ts @@ -8,6 +8,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { MessageListener } from "@bitwarden/common/platform/messaging"; import { UserId } from "@bitwarden/common/types/guid"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; @@ -19,7 +20,6 @@ import { } from "@bitwarden/components"; import { BrowserApi } from "../platform/browser/browser-api"; -import { BrowserStateService } from "../platform/services/abstractions/browser-state.service"; import { BrowserSendStateService } from "../tools/popup/services/browser-send-state.service"; import { VaultBrowserStateService } from "../vault/services/vault-browser-state.service"; @@ -45,7 +45,7 @@ export class AppComponent implements OnInit, OnDestroy { private authService: AuthService, private i18nService: I18nService, private router: Router, - private stateService: BrowserStateService, + private stateService: StateService, private browserSendStateService: BrowserSendStateService, private vaultBrowserStateService: VaultBrowserStateService, private cipherService: CipherService, diff --git a/apps/browser/src/popup/services/init.service.ts b/apps/browser/src/popup/services/init.service.ts index 63ce45c9b7..9e6471eaf2 100644 --- a/apps/browser/src/popup/services/init.service.ts +++ b/apps/browser/src/popup/services/init.service.ts @@ -6,16 +6,16 @@ import { TwoFactorService } from "@bitwarden/common/auth/abstractions/two-factor import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService as LogServiceAbstraction } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { BrowserApi } from "../../platform/browser/browser-api"; import BrowserPopupUtils from "../../platform/popup/browser-popup-utils"; -import { BrowserStateService as StateServiceAbstraction } from "../../platform/services/abstractions/browser-state.service"; @Injectable() export class InitService { constructor( private platformUtilsService: PlatformUtilsService, private i18nService: I18nService, - private stateService: StateServiceAbstraction, + private stateService: StateService, private twoFactorService: TwoFactorService, private logService: LogServiceAbstraction, private themingService: AbstractThemingService, diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 7c187d0051..47138842c8 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -32,7 +32,6 @@ import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction"; import { SsoLoginServiceAbstraction } from "@bitwarden/common/auth/abstractions/sso-login.service.abstraction"; -import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; import { AutofillSettingsService, @@ -57,20 +56,17 @@ import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platfor import { KeyGenerationService } from "@bitwarden/common/platform/abstractions/key-generation.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService, ObservableStorageService, } from "@bitwarden/common/platform/abstractions/storage.service"; import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; -import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { ContainerService } from "@bitwarden/common/platform/services/container.service"; -import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { StorageServiceProvider } from "@bitwarden/common/platform/services/storage-service.provider"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; import { @@ -94,7 +90,6 @@ import { UnauthGuardService } from "../../auth/popup/services"; import { AutofillService as AutofillServiceAbstraction } from "../../autofill/services/abstractions/autofill.service"; import AutofillService from "../../autofill/services/autofill.service"; import MainBackground from "../../background/main.background"; -import { Account } from "../../models/account"; import { BrowserApi } from "../../platform/browser/browser-api"; import { runInsideAngular } from "../../platform/browser/run-inside-angular.operator"; /* eslint-disable no-restricted-imports */ @@ -104,13 +99,11 @@ import { OffscreenDocumentService } from "../../platform/offscreen-document/abst import { DefaultOffscreenDocumentService } from "../../platform/offscreen-document/offscreen-document.service"; import BrowserPopupUtils from "../../platform/popup/browser-popup-utils"; import { BrowserFileDownloadService } from "../../platform/popup/services/browser-file-download.service"; -import { BrowserStateService as StateServiceAbstraction } from "../../platform/services/abstractions/browser-state.service"; import { ScriptInjectorService } from "../../platform/services/abstractions/script-injector.service"; import { BrowserCryptoService } from "../../platform/services/browser-crypto.service"; import { BrowserEnvironmentService } from "../../platform/services/browser-environment.service"; import BrowserLocalStorageService from "../../platform/services/browser-local-storage.service"; import { BrowserScriptInjectorService } from "../../platform/services/browser-script-injector.service"; -import { DefaultBrowserStateService } from "../../platform/services/default-browser-state.service"; import I18nService from "../../platform/services/i18n.service"; import { ForegroundPlatformUtilsService } from "../../platform/services/platform-utils/foreground-platform-utils.service"; import { BrowserStorageServiceProvider } from "../../platform/storage/browser-storage-service.provider"; @@ -219,7 +212,7 @@ const safeProviders: SafeProvider[] = [ encryptService: EncryptService, platformUtilsService: PlatformUtilsService, logService: LogService, - stateService: StateServiceAbstraction, + stateService: StateService, accountService: AccountServiceAbstraction, stateProvider: StateProvider, biometricStateService: BiometricStateService, @@ -250,7 +243,7 @@ const safeProviders: SafeProvider[] = [ EncryptService, PlatformUtilsService, LogService, - StateServiceAbstraction, + StateService, AccountServiceAbstraction, StateProvider, BiometricStateService, @@ -436,46 +429,6 @@ const safeProviders: SafeProvider[] = [ }, deps: [StateProvider], }), - safeProvider({ - provide: StateServiceAbstraction, - useFactory: ( - storageService: AbstractStorageService, - secureStorageService: AbstractStorageService, - memoryStorageService: AbstractStorageService, - logService: LogService, - accountService: AccountServiceAbstraction, - environmentService: EnvironmentService, - tokenService: TokenService, - migrationRunner: MigrationRunner, - ) => { - return new DefaultBrowserStateService( - storageService, - secureStorageService, - memoryStorageService, - logService, - new StateFactory(GlobalState, Account), - accountService, - environmentService, - tokenService, - migrationRunner, - ); - }, - deps: [ - AbstractStorageService, - SECURE_STORAGE, - MEMORY_STORAGE, - LogService, - AccountServiceAbstraction, - EnvironmentService, - TokenService, - MigrationRunner, - ], - }), - safeProvider({ - provide: BaseStateServiceAbstraction, - useExisting: StateServiceAbstraction, - deps: [], - }), safeProvider({ provide: FileDownloadService, useClass: BrowserFileDownloadService, diff --git a/apps/browser/src/tools/popup/send/send-add-edit.component.ts b/apps/browser/src/tools/popup/send/send-add-edit.component.ts index 7f17217816..697188e23a 100644 --- a/apps/browser/src/tools/popup/send/send-add-edit.component.ts +++ b/apps/browser/src/tools/popup/send/send-add-edit.component.ts @@ -13,12 +13,12 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; import { DialogService, ToastService } from "@bitwarden/components"; import BrowserPopupUtils from "../../../platform/popup/browser-popup-utils"; -import { BrowserStateService } from "../../../platform/services/abstractions/browser-state.service"; import { FilePopoutUtilsService } from "../services/file-popout-utils.service"; @Component({ @@ -37,7 +37,7 @@ export class SendAddEditComponent extends BaseAddEditComponent { constructor( i18nService: I18nService, platformUtilsService: PlatformUtilsService, - stateService: BrowserStateService, + stateService: StateService, messagingService: MessagingService, policyService: PolicyService, environmentService: EnvironmentService, diff --git a/apps/desktop/src/app/app.component.ts b/apps/desktop/src/app/app.component.ts index e01a11b8c7..625d1eea81 100644 --- a/apps/desktop/src/app/app.component.ts +++ b/apps/desktop/src/app/app.component.ts @@ -403,7 +403,6 @@ export class AppComponent implements OnInit, OnDestroy { // Clear sequentialized caches clearCaches(); if (message.userId != null) { - await this.stateService.clearDecryptedData(message.userId); await this.accountService.switchAccount(message.userId); } const locked = diff --git a/apps/desktop/src/app/layout/account-switcher.component.ts b/apps/desktop/src/app/layout/account-switcher.component.ts index ff27dacd96..14674ceb22 100644 --- a/apps/desktop/src/app/layout/account-switcher.component.ts +++ b/apps/desktop/src/app/layout/account-switcher.component.ts @@ -165,8 +165,6 @@ export class AccountSwitcherComponent { async addAccount() { this.close(); - const activeAccount = await firstValueFrom(this.accountService.activeAccount$); - await this.stateService.clearDecryptedData(activeAccount?.id as UserId); await this.accountService.switchAccount(null); await this.router.navigate(["/login"]); } diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index 7a2bc6cccc..dfea2e6f27 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -13,7 +13,6 @@ import { SUPPORTS_SECURE_STORAGE, SYSTEM_THEME_OBSERVABLE, SafeInjectionToken, - STATE_FACTORY, DEFAULT_VAULT_TIMEOUT, INTRAPROCESS_MESSAGING_SUBJECT, CLIENT_TYPE, @@ -25,13 +24,11 @@ import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/a import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service"; import { KdfConfigService as KdfConfigServiceAbstraction } from "@bitwarden/common/auth/abstractions/kdf-config.service"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/auth/abstractions/master-password.service.abstraction"; -import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"; import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service"; import { ClientType } from "@bitwarden/common/enums"; import { CryptoFunctionService as CryptoFunctionServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto-function.service"; import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto.service"; import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service"; -import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service"; import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service"; import { KeyGenerationService as KeyGenerationServiceAbstraction } from "@bitwarden/common/platform/abstractions/key-generation.service"; @@ -45,13 +42,10 @@ import { StateService as StateServiceAbstraction } from "@bitwarden/common/platf import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service"; import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service"; -import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging"; // eslint-disable-next-line no-restricted-imports -- Used for dependency injection import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal"; -import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service"; -import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { SystemService } from "@bitwarden/common/platform/services/system.service"; import { GlobalStateProvider, StateProvider } from "@bitwarden/common/platform/state"; // eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage @@ -63,7 +57,6 @@ import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legac import { PinServiceAbstraction } from "../../../../../libs/auth/src/common/abstractions"; import { DesktopAutofillSettingsService } from "../../autofill/services/desktop-autofill-settings.service"; -import { Account } from "../../models/account"; import { DesktopSettingsService } from "../../platform/services/desktop-settings.service"; import { ElectronCryptoService } from "../../platform/services/electron-crypto.service"; import { ElectronLogRendererService } from "../../platform/services/electron-log.renderer.service"; @@ -74,7 +67,6 @@ import { import { ElectronRendererMessageSender } from "../../platform/services/electron-renderer-message.sender"; import { ElectronRendererSecureStorageService } from "../../platform/services/electron-renderer-secure-storage.service"; import { ElectronRendererStorageService } from "../../platform/services/electron-renderer-storage.service"; -import { ElectronStateService } from "../../platform/services/electron-state.service"; import { I18nRendererService } from "../../platform/services/i18n.renderer.service"; import { fromIpcMessaging } from "../../platform/utils/from-ipc-messaging"; import { fromIpcSystemTheme } from "../../platform/utils/from-ipc-system-theme"; @@ -90,11 +82,6 @@ import { RendererCryptoFunctionService } from "./renderer-crypto-function.servic const RELOAD_CALLBACK = new SafeInjectionToken<() => any>("RELOAD_CALLBACK"); -// Desktop has its own Account definition which must be used in its StateService -const DESKTOP_STATE_FACTORY = new SafeInjectionToken>( - "DESKTOP_STATE_FACTORY", -); - /** * Provider definitions used in the ngModule. * Add your provider definition here using the safeProvider function as a wrapper. This will give you type safety. @@ -111,14 +98,6 @@ const safeProviders: SafeProvider[] = [ deps: [InitService], multi: true, }), - safeProvider({ - provide: DESKTOP_STATE_FACTORY, - useValue: new StateFactory(GlobalState, Account), - }), - safeProvider({ - provide: STATE_FACTORY, - useValue: null, - }), safeProvider({ provide: RELOAD_CALLBACK, useValue: null, @@ -194,28 +173,12 @@ const safeProviders: SafeProvider[] = [ MessagingServiceAbstraction, PlatformUtilsServiceAbstraction, RELOAD_CALLBACK, - StateServiceAbstraction, AutofillSettingsServiceAbstraction, VaultTimeoutSettingsService, BiometricStateService, AccountServiceAbstraction, ], }), - safeProvider({ - provide: StateServiceAbstraction, - useClass: ElectronStateService, - deps: [ - AbstractStorageService, - SECURE_STORAGE, - MEMORY_STORAGE, - LogService, - DESKTOP_STATE_FACTORY, - AccountServiceAbstraction, - EnvironmentService, - TokenService, - MigrationRunner, - ], - }), safeProvider({ provide: FileDownloadService, useClass: DesktopFileDownloadService, diff --git a/apps/desktop/src/models/account.ts b/apps/desktop/src/models/account.ts deleted file mode 100644 index b3d3128413..0000000000 --- a/apps/desktop/src/models/account.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { - Account as BaseAccount, - AccountSettings as BaseAccountSettings, -} from "@bitwarden/common/platform/models/domain/account"; - -export class AccountSettings extends BaseAccountSettings { - dismissedBiometricRequirePasswordOnStartCallout?: boolean; -} - -export class Account extends BaseAccount { - settings?: AccountSettings = new AccountSettings(); - - constructor(init: Partial) { - super(init); - Object.assign(this.settings, { - ...new AccountSettings(), - ...this.settings, - }); - } -} diff --git a/apps/desktop/src/platform/services/electron-state.service.ts b/apps/desktop/src/platform/services/electron-state.service.ts deleted file mode 100644 index 33c97f48af..0000000000 --- a/apps/desktop/src/platform/services/electron-state.service.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; -import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service"; - -import { Account } from "../../models/account"; - -export class ElectronStateService extends BaseStateService { - async addAccount(account: Account) { - // Apply desktop overides to default account values - account = new Account(account); - await super.addAccount(account); - } -} diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index 7dae8c07e5..93a5a9c00a 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -4,7 +4,6 @@ import { APP_INITIALIZER, NgModule, Optional, SkipSelf } from "@angular/core"; import { SafeProvider, safeProvider } from "@bitwarden/angular/platform/utils/safe-provider"; import { SECURE_STORAGE, - STATE_FACTORY, LOCALES_DIRECTORY, SYSTEM_LANGUAGE, MEMORY_STORAGE, @@ -30,10 +29,9 @@ import { FileDownloadService } from "@bitwarden/common/platform/abstractions/fil import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service"; -import { StateService as BaseStateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service"; +import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { ThemeType } from "@bitwarden/common/platform/enums"; -import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; import { MemoryStorageService } from "@bitwarden/common/platform/services/memory-storage.service"; // eslint-disable-next-line import/no-restricted-paths -- Implementation for memory storage import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service"; @@ -64,7 +62,7 @@ import { EventService } from "./event.service"; import { InitService } from "./init.service"; import { ModalService } from "./modal.service"; import { RouterService } from "./router.service"; -import { Account, GlobalState, StateService } from "./state"; +import { StateService as WebStateService } from "./state"; import { WebFileDownloadService } from "./web-file-download.service"; import { WebPlatformUtilsService } from "./web-platform-utils.service"; @@ -90,10 +88,6 @@ const safeProviders: SafeProvider[] = [ deps: [InitService], multi: true, }), - safeProvider({ - provide: STATE_FACTORY, - useValue: new StateFactory(GlobalState, Account), - }), safeProvider({ provide: I18nServiceAbstraction, useClass: I18nService, @@ -132,10 +126,10 @@ const safeProviders: SafeProvider[] = [ useClass: ModalService, useAngularDecorators: true, }), - safeProvider(StateService), + safeProvider(WebStateService), safeProvider({ - provide: BaseStateServiceAbstraction, - useExisting: StateService, + provide: StateService, + useExisting: WebStateService, }), safeProvider({ provide: FileDownloadService, diff --git a/apps/web/src/app/core/state/account.ts b/apps/web/src/app/core/state/account.ts deleted file mode 100644 index b6beafe31f..0000000000 --- a/apps/web/src/app/core/state/account.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Account as BaseAccount } from "@bitwarden/common/platform/models/domain/account"; - -// TODO: platform to clean up accounts in later PR -export class Account extends BaseAccount { - constructor(init: Partial) { - super(init); - } -} diff --git a/apps/web/src/app/core/state/global-state.ts b/apps/web/src/app/core/state/global-state.ts deleted file mode 100644 index 49e7608749..0000000000 --- a/apps/web/src/app/core/state/global-state.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { GlobalState as BaseGlobalState } from "@bitwarden/common/platform/models/domain/global-state"; - -export class GlobalState extends BaseGlobalState { - rememberEmail = true; -} diff --git a/apps/web/src/app/core/state/index.ts b/apps/web/src/app/core/state/index.ts index dd968df3a2..4fa4d160ac 100644 --- a/apps/web/src/app/core/state/index.ts +++ b/apps/web/src/app/core/state/index.ts @@ -1,3 +1 @@ -export * from "./account"; -export * from "./global-state"; export * from "./state.service"; diff --git a/apps/web/src/app/core/state/state.service.ts b/apps/web/src/app/core/state/state.service.ts index de47a69555..c60698acf6 100644 --- a/apps/web/src/app/core/state/state.service.ts +++ b/apps/web/src/app/core/state/state.service.ts @@ -11,13 +11,12 @@ import { EnvironmentService } from "@bitwarden/common/platform/abstractions/envi import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; +import { Account } from "@bitwarden/common/platform/models/domain/account"; +import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { StorageOptions } from "@bitwarden/common/platform/models/domain/storage-options"; import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner"; import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service"; -import { Account } from "./account"; -import { GlobalState } from "./global-state"; - @Injectable() export class StateService extends BaseStateService { constructor( @@ -44,12 +43,6 @@ export class StateService extends BaseStateService { ); } - async addAccount(account: Account) { - // Apply web overrides to default account values - account = new Account(account); - await super.addAccount(account); - } - override async getLastSync(options?: StorageOptions): Promise { options = this.reconcileOptions(options, await this.defaultInMemoryOptions()); return await super.getLastSync(options); diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index b956acb763..b4074988af 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -728,6 +728,10 @@ const safeProviders: SafeProvider[] = [ useClass: SsoLoginService, deps: [StateProvider], }), + safeProvider({ + provide: STATE_FACTORY, + useValue: new StateFactory(GlobalState, Account), + }), safeProvider({ provide: StateServiceAbstraction, useClass: StateService, diff --git a/libs/common/src/platform/abstractions/state.service.ts b/libs/common/src/platform/abstractions/state.service.ts index 6f69dca8a5..5c06fdda50 100644 --- a/libs/common/src/platform/abstractions/state.service.ts +++ b/libs/common/src/platform/abstractions/state.service.ts @@ -1,8 +1,4 @@ import { BiometricKey } from "../../auth/types/biometric-key"; -import { GeneratorOptions } from "../../tools/generator/generator-options"; -import { GeneratedPasswordHistory, PasswordGeneratorOptions } from "../../tools/generator/password"; -import { UsernameGeneratorOptions } from "../../tools/generator/username"; -import { UserId } from "../../types/guid"; import { Account } from "../models/domain/account"; import { StorageOptions } from "../models/domain/storage-options"; @@ -22,7 +18,6 @@ export type InitOptions = { export abstract class StateService { addAccount: (account: T) => Promise; - clearDecryptedData: (userId: UserId) => Promise; clean: (options?: StorageOptions) => Promise; init: (initOptions?: InitOptions) => Promise; @@ -73,36 +68,10 @@ export abstract class StateService { * @deprecated For migration purposes only, use setUserKeyBiometric instead */ setCryptoMasterKeyBiometric: (value: BiometricKey, options?: StorageOptions) => Promise; - getDecryptedPasswordGenerationHistory: ( - options?: StorageOptions, - ) => Promise; - setDecryptedPasswordGenerationHistory: ( - value: GeneratedPasswordHistory[], - options?: StorageOptions, - ) => Promise; getDuckDuckGoSharedKey: (options?: StorageOptions) => Promise; setDuckDuckGoSharedKey: (value: string, options?: StorageOptions) => Promise; - getEncryptedPasswordGenerationHistory: ( - options?: StorageOptions, - ) => Promise; - setEncryptedPasswordGenerationHistory: ( - value: GeneratedPasswordHistory[], - options?: StorageOptions, - ) => Promise; getIsAuthenticated: (options?: StorageOptions) => Promise; getLastSync: (options?: StorageOptions) => Promise; setLastSync: (value: string, options?: StorageOptions) => Promise; - getPasswordGenerationOptions: (options?: StorageOptions) => Promise; - setPasswordGenerationOptions: ( - value: PasswordGeneratorOptions, - options?: StorageOptions, - ) => Promise; - getUsernameGenerationOptions: (options?: StorageOptions) => Promise; - setUsernameGenerationOptions: ( - value: UsernameGeneratorOptions, - options?: StorageOptions, - ) => Promise; - getGeneratorOptions: (options?: StorageOptions) => Promise; - setGeneratorOptions: (value: GeneratorOptions, options?: StorageOptions) => Promise; getUserId: (options?: StorageOptions) => Promise; } diff --git a/libs/common/src/platform/models/domain/account-settings.spec.ts b/libs/common/src/platform/models/domain/account-settings.spec.ts deleted file mode 100644 index 525c878de6..0000000000 --- a/libs/common/src/platform/models/domain/account-settings.spec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { AccountSettings } from "./account"; - -describe("AccountSettings", () => { - describe("fromJSON", () => { - it("should deserialize to an instance of itself", () => { - expect(AccountSettings.fromJSON(JSON.parse("{}"))).toBeInstanceOf(AccountSettings); - }); - }); -}); diff --git a/libs/common/src/platform/models/domain/account.spec.ts b/libs/common/src/platform/models/domain/account.spec.ts index 77c242b6ff..307fde62f9 100644 --- a/libs/common/src/platform/models/domain/account.spec.ts +++ b/libs/common/src/platform/models/domain/account.spec.ts @@ -1,4 +1,4 @@ -import { Account, AccountKeys, AccountProfile, AccountSettings } from "./account"; +import { Account, AccountKeys, AccountProfile } from "./account"; describe("Account", () => { describe("fromJSON", () => { @@ -9,13 +9,11 @@ describe("Account", () => { it("should call all the sub-fromJSONs", () => { const keysSpy = jest.spyOn(AccountKeys, "fromJSON"); const profileSpy = jest.spyOn(AccountProfile, "fromJSON"); - const settingsSpy = jest.spyOn(AccountSettings, "fromJSON"); Account.fromJSON({}); expect(keysSpy).toHaveBeenCalled(); expect(profileSpy).toHaveBeenCalled(); - expect(settingsSpy).toHaveBeenCalled(); }); }); }); diff --git a/libs/common/src/platform/models/domain/account.ts b/libs/common/src/platform/models/domain/account.ts index 8e26e4ed30..79ba4058a4 100644 --- a/libs/common/src/platform/models/domain/account.ts +++ b/libs/common/src/platform/models/domain/account.ts @@ -1,14 +1,6 @@ import { Jsonify } from "type-fest"; -import { UriMatchStrategySetting } from "../../../models/domain/domain-service"; -import { GeneratorOptions } from "../../../tools/generator/generator-options"; -import { - GeneratedPasswordHistory, - PasswordGeneratorOptions, -} from "../../../tools/generator/password"; -import { UsernameGeneratorOptions } from "../../../tools/generator/username/username-generation-options"; import { DeepJsonify } from "../../../types/deep-jsonify"; -import { KdfType } from "../../enums"; import { Utils } from "../../misc/utils"; import { SymmetricCryptoKey } from "./symmetric-crypto-key"; @@ -51,26 +43,6 @@ export class EncryptionPair { } } -export class DataEncryptionPair { - encrypted?: Record; - decrypted?: TDecrypted[]; -} - -export class AccountData { - passwordGenerationHistory?: EncryptionPair< - GeneratedPasswordHistory[], - GeneratedPasswordHistory[] - > = new EncryptionPair(); - - static fromJSON(obj: DeepJsonify): AccountData { - if (obj == null) { - return null; - } - - return Object.assign(new AccountData(), obj); - } -} - export class AccountKeys { publicKey?: Uint8Array; @@ -127,10 +99,6 @@ export class AccountProfile { emailVerified?: boolean; lastSync?: string; userId?: string; - kdfIterations?: number; - kdfMemory?: number; - kdfParallelism?: number; - kdfType?: KdfType; static fromJSON(obj: Jsonify): AccountProfile { if (obj == null) { @@ -141,33 +109,12 @@ export class AccountProfile { } } -export class AccountSettings { - defaultUriMatch?: UriMatchStrategySetting; - passwordGenerationOptions?: PasswordGeneratorOptions; - usernameGenerationOptions?: UsernameGeneratorOptions; - generatorOptions?: GeneratorOptions; - - static fromJSON(obj: Jsonify): AccountSettings { - if (obj == null) { - return null; - } - - return Object.assign(new AccountSettings(), obj); - } -} - export class Account { - data?: AccountData = new AccountData(); keys?: AccountKeys = new AccountKeys(); profile?: AccountProfile = new AccountProfile(); - settings?: AccountSettings = new AccountSettings(); constructor(init: Partial) { Object.assign(this, { - data: { - ...new AccountData(), - ...init?.data, - }, keys: { ...new AccountKeys(), ...init?.keys, @@ -176,10 +123,6 @@ export class Account { ...new AccountProfile(), ...init?.profile, }, - settings: { - ...new AccountSettings(), - ...init?.settings, - }, }); } @@ -190,9 +133,7 @@ export class Account { return Object.assign(new Account({}), json, { keys: AccountKeys.fromJSON(json?.keys), - data: AccountData.fromJSON(json?.data), profile: AccountProfile.fromJSON(json?.profile), - settings: AccountSettings.fromJSON(json?.settings), }); } } diff --git a/libs/common/src/platform/services/state.service.ts b/libs/common/src/platform/services/state.service.ts index 122ade0510..e799471241 100644 --- a/libs/common/src/platform/services/state.service.ts +++ b/libs/common/src/platform/services/state.service.ts @@ -4,9 +4,6 @@ import { Jsonify, JsonValue } from "type-fest"; import { AccountService } from "../../auth/abstractions/account.service"; import { TokenService } from "../../auth/abstractions/token.service"; import { BiometricKey } from "../../auth/types/biometric-key"; -import { GeneratorOptions } from "../../tools/generator/generator-options"; -import { GeneratedPasswordHistory, PasswordGeneratorOptions } from "../../tools/generator/password"; -import { UsernameGeneratorOptions } from "../../tools/generator/username"; import { UserId } from "../../types/guid"; import { EnvironmentService } from "../abstractions/environment.service"; import { LogService } from "../abstractions/log.service"; @@ -17,8 +14,7 @@ import { import { AbstractStorageService } from "../abstractions/storage.service"; import { HtmlStorageLocation, StorageLocation } from "../enums"; import { StateFactory } from "../factories/state-factory"; -import { Utils } from "../misc/utils"; -import { Account, AccountData, AccountSettings } from "../models/domain/account"; +import { Account } from "../models/domain/account"; import { GlobalState } from "../models/domain/global-state"; import { State } from "../models/domain/state"; import { StorageOptions } from "../models/domain/storage-options"; @@ -306,29 +302,6 @@ export class StateService< await this.saveSecureStorageKey(partialKeys.biometricKey, value, options); } - @withPrototypeForArrayMembers(GeneratedPasswordHistory) - async getDecryptedPasswordGenerationHistory( - options?: StorageOptions, - ): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions())) - )?.data?.passwordGenerationHistory?.decrypted; - } - - async setDecryptedPasswordGenerationHistory( - value: GeneratedPasswordHistory[], - options?: StorageOptions, - ): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, await this.defaultInMemoryOptions()), - ); - account.data.passwordGenerationHistory.decrypted = value; - await this.saveAccount( - account, - this.reconcileOptions(options, await this.defaultInMemoryOptions()), - ); - } - async getDuckDuckGoSharedKey(options?: StorageOptions): Promise { options = this.reconcileOptions(options, await this.defaultSecureStorageOptions()); if (options?.userId == null) { @@ -370,29 +343,6 @@ export class StateService< )?.keys.cryptoSymmetricKey.encrypted; } - @withPrototypeForArrayMembers(GeneratedPasswordHistory) - async getEncryptedPasswordGenerationHistory( - options?: StorageOptions, - ): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions())) - )?.data?.passwordGenerationHistory?.encrypted; - } - - async setEncryptedPasswordGenerationHistory( - value: GeneratedPasswordHistory[], - options?: StorageOptions, - ): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, await this.defaultOnDiskOptions()), - ); - account.data.passwordGenerationHistory.encrypted = value; - await this.saveAccount( - account, - this.reconcileOptions(options, await this.defaultOnDiskOptions()), - ); - } - async getIsAuthenticated(options?: StorageOptions): Promise { return ( (await this.tokenService.getAccessToken(options?.userId as UserId)) != null && @@ -417,63 +367,6 @@ export class StateService< ); } - async getPasswordGenerationOptions(options?: StorageOptions): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) - )?.settings?.passwordGenerationOptions; - } - - async setPasswordGenerationOptions( - value: PasswordGeneratorOptions, - options?: StorageOptions, - ): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - account.settings.passwordGenerationOptions = value; - await this.saveAccount( - account, - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - } - - async getUsernameGenerationOptions(options?: StorageOptions): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) - )?.settings?.usernameGenerationOptions; - } - - async setUsernameGenerationOptions( - value: UsernameGeneratorOptions, - options?: StorageOptions, - ): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - account.settings.usernameGenerationOptions = value; - await this.saveAccount( - account, - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - } - - async getGeneratorOptions(options?: StorageOptions): Promise { - return ( - await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())) - )?.settings?.generatorOptions; - } - - async setGeneratorOptions(value: GeneratorOptions, options?: StorageOptions): Promise { - const account = await this.getAccount( - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - account.settings.generatorOptions = value; - await this.saveAccount( - account, - this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()), - ); - } - async getUserId(options?: StorageOptions): Promise { return ( await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions())) @@ -629,19 +522,6 @@ export class StateService< // TODO: There is a tech debt item for splitting up these methods - only Web uses multiple storage locations in its storageService. // For now these methods exist with some redundancy to facilitate this special web requirement. protected async scaffoldNewAccountLocalStorage(account: TAccount): Promise { - const storedAccount = await this.getAccount( - this.reconcileOptions( - { userId: account.profile.userId }, - await this.defaultOnDiskLocalOptions(), - ), - ); - if (storedAccount?.settings != null) { - account.settings = storedAccount.settings; - } else if (await this.storageService.has(keys.tempAccountSettings)) { - account.settings = await this.storageService.get(keys.tempAccountSettings); - await this.storageService.remove(keys.tempAccountSettings); - } - await this.saveAccount( account, this.reconcileOptions( @@ -652,15 +532,6 @@ export class StateService< } protected async scaffoldNewAccountMemoryStorage(account: TAccount): Promise { - const storedAccount = await this.getAccount( - this.reconcileOptions( - { userId: account.profile.userId }, - await this.defaultOnDiskMemoryOptions(), - ), - ); - if (storedAccount?.settings != null) { - account.settings = storedAccount.settings; - } await this.storageService.save( account.profile.userId, account, @@ -676,12 +547,6 @@ export class StateService< } protected async scaffoldNewAccountSessionStorage(account: TAccount): Promise { - const storedAccount = await this.getAccount( - this.reconcileOptions({ userId: account.profile.userId }, await this.defaultOnDiskOptions()), - ); - if (storedAccount?.settings != null) { - account.settings = storedAccount.settings; - } await this.storageService.save( account.profile.userId, account, @@ -830,20 +695,8 @@ export class StateService< // settings persist even on reset, and are not affected by this method protected resetAccount(account: TAccount) { - const persistentAccountInformation = { - settings: account.settings, - }; - return Object.assign(this.createAccount(), persistentAccountInformation); - } - - async clearDecryptedData(userId: UserId): Promise { - await this.updateState(async (state) => { - if (userId != null && state?.accounts[userId]?.data != null) { - state.accounts[userId].data = new AccountData(); - } - - return state; - }); + // All settings have been moved to StateProviders + return this.createAccount(); } protected createAccount(init: Partial = null): TAccount { @@ -904,51 +757,3 @@ export class StateService< }); } } - -function withPrototypeForArrayMembers( - memberConstructor: new (...args: any[]) => T, - memberConverter: (input: any) => T = (i) => i, -): ( - target: any, - propertyKey: string | symbol, - descriptor: PropertyDescriptor, -) => { value: (...args: any[]) => Promise } { - return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => { - const originalMethod = descriptor.value; - - return { - value: function (...args: any[]) { - const originalResult: Promise = originalMethod.apply(this, args); - - if (!Utils.isPromise(originalResult)) { - throw new Error( - `Error applying prototype to stored value -- result is not a promise for method ${String( - propertyKey, - )}`, - ); - } - - return originalResult.then((result) => { - if (result == null) { - return null; - } else if (!(result instanceof Array)) { - throw new Error( - `Attempted to retrieve non array type from state as an array for method ${String( - propertyKey, - )}`, - ); - } else { - return result.map((r) => { - return r == null || - r.constructor.name === memberConstructor.prototype.constructor.name - ? r - : memberConverter( - Object.create(memberConstructor.prototype, Object.getOwnPropertyDescriptors(r)), - ); - }); - } - }); - }, - }; - }; -} diff --git a/libs/common/src/platform/services/system.service.ts b/libs/common/src/platform/services/system.service.ts index b25898ab7c..a3927a3fb8 100644 --- a/libs/common/src/platform/services/system.service.ts +++ b/libs/common/src/platform/services/system.service.ts @@ -10,7 +10,6 @@ import { VaultTimeoutAction } from "../../enums/vault-timeout-action.enum"; import { UserId } from "../../types/guid"; import { MessagingService } from "../abstractions/messaging.service"; import { PlatformUtilsService } from "../abstractions/platform-utils.service"; -import { StateService } from "../abstractions/state.service"; import { SystemService as SystemServiceAbstraction } from "../abstractions/system.service"; import { BiometricStateService } from "../biometrics/biometric-state.service"; import { Utils } from "../misc/utils"; @@ -25,7 +24,6 @@ export class SystemService implements SystemServiceAbstraction { private messagingService: MessagingService, private platformUtilsService: PlatformUtilsService, private reloadCallback: () => Promise = null, - private stateService: StateService, private autofillSettingsService: AutofillSettingsServiceAbstraction, private vaultTimeoutSettingsService: VaultTimeoutSettingsService, private biometricStateService: BiometricStateService, @@ -90,8 +88,6 @@ export class SystemService implements SystemServiceAbstraction { const nextUser = await firstValueFrom( this.accountService.nextUpAccount$.pipe(map((account) => account?.id ?? null)), ); - // Can be removed once we migrate password generation history to state providers - await this.stateService.clearDecryptedData(activeUserId); await this.accountService.switchAccount(nextUser); } } From 1cb063689fd9cfc187bfd5df2b1e19c78ab23a40 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Mon, 8 Jul 2024 21:57:36 -0400 Subject: [PATCH 2/7] remove getBgService for auth request service (#10020) --- apps/browser/src/popup/services/services.module.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index 47138842c8..e82eb429a5 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -17,7 +17,7 @@ import { CLIENT_TYPE, } from "@bitwarden/angular/services/injection-tokens"; import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; -import { AuthRequestServiceAbstraction, PinServiceAbstraction } from "@bitwarden/auth/common"; +import { PinServiceAbstraction } from "@bitwarden/auth/common"; import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service"; import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service"; import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service"; @@ -255,11 +255,6 @@ const safeProviders: SafeProvider[] = [ useClass: TotpService, deps: [CryptoFunctionService, LogService], }), - safeProvider({ - provide: AuthRequestServiceAbstraction, - useFactory: getBgService("authRequestService"), - deps: [], - }), safeProvider({ provide: DeviceTrustServiceAbstraction, useFactory: getBgService("deviceTrustService"), From f9b623b37c72639761dce176f2ea5738b408afb2 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:33:07 +1000 Subject: [PATCH 3/7] Add AC Team eslint configuration (#9971) --- apps/cli/src/admin-console/.eslintrc.json | 3 +++ apps/web/src/app/admin-console/.eslintrc.json | 3 +++ .../guards/is-paid-org.guard.spec.ts | 4 ++-- .../nested-checkbox.component.ts | 4 +--- .../components/reset-password.component.ts | 4 ++-- .../members/members.component.ts | 2 +- .../policies/master-password.component.ts | 4 ++-- .../policies/policy-edit.component.ts | 11 ++++++++-- .../policies/reset-password.component.ts | 4 ++-- .../settings/account.component.ts | 4 ++-- .../settings/two-factor-setup.component.ts | 4 ++-- .../exposed-passwords-report.component.ts | 7 ++++-- .../inactive-two-factor-report.component.ts | 7 ++++-- .../reused-passwords-report.component.ts | 7 ++++-- .../unsecured-websites-report.component.ts | 7 ++++-- .../tools/weak-passwords-report.component.ts | 7 ++++-- .../bit-cli/src/admin-console/.eslintrc.json | 3 +++ .../src/app/admin-console/.eslintrc.json | 3 +++ .../providers/clients/clients.component.ts | 4 ++-- .../providers/manage/people.component.ts | 11 ++++++---- .../manage/user-add-edit.component.ts | 8 +++---- libs/admin-console/.eslintrc.json | 22 +++++++++++++++++++ 22 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 apps/cli/src/admin-console/.eslintrc.json create mode 100644 apps/web/src/app/admin-console/.eslintrc.json create mode 100644 bitwarden_license/bit-cli/src/admin-console/.eslintrc.json create mode 100644 bitwarden_license/bit-web/src/app/admin-console/.eslintrc.json create mode 100644 libs/admin-console/.eslintrc.json diff --git a/apps/cli/src/admin-console/.eslintrc.json b/apps/cli/src/admin-console/.eslintrc.json new file mode 100644 index 0000000000..3846718729 --- /dev/null +++ b/apps/cli/src/admin-console/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../../libs/admin-console/.eslintrc.json" +} diff --git a/apps/web/src/app/admin-console/.eslintrc.json b/apps/web/src/app/admin-console/.eslintrc.json new file mode 100644 index 0000000000..d55df3899e --- /dev/null +++ b/apps/web/src/app/admin-console/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../../../libs/admin-console/.eslintrc.json" +} diff --git a/apps/web/src/app/admin-console/organizations/guards/is-paid-org.guard.spec.ts b/apps/web/src/app/admin-console/organizations/guards/is-paid-org.guard.spec.ts index cf9a7b31dc..653651bf69 100644 --- a/apps/web/src/app/admin-console/organizations/guards/is-paid-org.guard.spec.ts +++ b/apps/web/src/app/admin-console/organizations/guards/is-paid-org.guard.spec.ts @@ -24,7 +24,7 @@ export class PaidOrganizationOnlyComponent {} @Component({ template: "

This is the organization upgrade screen!

", }) -export class OrganizationUpgradeScreen {} +export class OrganizationUpgradeScreenComponent {} const orgFactory = (props: Partial = {}) => Object.assign( @@ -62,7 +62,7 @@ describe("Is Paid Org Guard", () => { }, { path: "organizations/:organizationId/billing/subscription", - component: OrganizationUpgradeScreen, + component: OrganizationUpgradeScreenComponent, }, ]), ], diff --git a/apps/web/src/app/admin-console/organizations/members/components/member-dialog/nested-checkbox.component.ts b/apps/web/src/app/admin-console/organizations/members/components/member-dialog/nested-checkbox.component.ts index d823240fe6..69819d6981 100644 --- a/apps/web/src/app/admin-console/organizations/members/components/member-dialog/nested-checkbox.component.ts +++ b/apps/web/src/app/admin-console/organizations/members/components/member-dialog/nested-checkbox.component.ts @@ -1,5 +1,5 @@ import { KeyValue } from "@angular/common"; -import { Component, EventEmitter, Input, Output, OnInit, OnDestroy } from "@angular/core"; +import { Component, Input, OnInit, OnDestroy } from "@angular/core"; import { FormControl, FormGroup } from "@angular/forms"; import { Subject, takeUntil } from "rxjs"; @@ -14,8 +14,6 @@ export class NestedCheckboxComponent implements OnInit, OnDestroy { @Input() parentId: string; @Input() checkboxes: FormGroup>>; - @Output() onSavedUser = new EventEmitter(); - @Output() onDeletedUser = new EventEmitter(); get parentIndeterminate() { return ( diff --git a/apps/web/src/app/admin-console/organizations/members/components/reset-password.component.ts b/apps/web/src/app/admin-console/organizations/members/components/reset-password.component.ts index 291b026942..cbda3b2bdf 100644 --- a/apps/web/src/app/admin-console/organizations/members/components/reset-password.component.ts +++ b/apps/web/src/app/admin-console/organizations/members/components/reset-password.component.ts @@ -31,7 +31,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { @Input() email: string; @Input() id: string; @Input() organizationId: string; - @Output() onPasswordReset = new EventEmitter(); + @Output() passwordReset = new EventEmitter(); @ViewChild(PasswordStrengthComponent) passwordStrengthComponent: PasswordStrengthComponent; enforcedPolicyOptions: MasterPasswordPolicyOptions; @@ -156,7 +156,7 @@ export class ResetPasswordComponent implements OnInit, OnDestroy { null, this.i18nService.t("resetPasswordSuccess"), ); - this.onPasswordReset.emit(); + this.passwordReset.emit(); } catch (e) { this.logService.error(e); } diff --git a/apps/web/src/app/admin-console/organizations/members/members.component.ts b/apps/web/src/app/admin-console/organizations/members/members.component.ts index 1376dd5ec0..93827539f8 100644 --- a/apps/web/src/app/admin-console/organizations/members/members.component.ts +++ b/apps/web/src/app/admin-console/organizations/members/members.component.ts @@ -635,7 +635,7 @@ export class MembersComponent extends NewBasePeopleComponent { + comp.passwordReset.subscribe(() => { modal.close(); // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // eslint-disable-next-line @typescript-eslint/no-floating-promises diff --git a/apps/web/src/app/admin-console/organizations/policies/master-password.component.ts b/apps/web/src/app/admin-console/organizations/policies/master-password.component.ts index ff9caf557a..14dd708389 100644 --- a/apps/web/src/app/admin-console/organizations/policies/master-password.component.ts +++ b/apps/web/src/app/admin-console/organizations/policies/master-password.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { ControlsOf } from "@bitwarden/angular/types/controls-of"; @@ -21,7 +21,7 @@ export class MasterPasswordPolicy extends BasePolicy { selector: "policy-master-password", templateUrl: "master-password.component.html", }) -export class MasterPasswordPolicyComponent extends BasePolicyComponent { +export class MasterPasswordPolicyComponent extends BasePolicyComponent implements OnInit { MinPasswordLength = Utils.minimumPasswordLength; data: FormGroup> = this.formBuilder.group({ diff --git a/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.ts b/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.ts index dc3b667511..d84a7dec99 100644 --- a/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.ts +++ b/apps/web/src/app/admin-console/organizations/policies/policy-edit.component.ts @@ -1,5 +1,12 @@ import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog"; -import { ChangeDetectorRef, Component, Inject, ViewChild, ViewContainerRef } from "@angular/core"; +import { + AfterViewInit, + ChangeDetectorRef, + Component, + Inject, + ViewChild, + ViewContainerRef, +} from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction"; @@ -28,7 +35,7 @@ export enum PolicyEditDialogResult { selector: "app-policy-edit", templateUrl: "policy-edit.component.html", }) -export class PolicyEditComponent { +export class PolicyEditComponent implements AfterViewInit { @ViewChild("policyForm", { read: ViewContainerRef, static: true }) policyFormRef: ViewContainerRef; diff --git a/apps/web/src/app/admin-console/organizations/policies/reset-password.component.ts b/apps/web/src/app/admin-console/organizations/policies/reset-password.component.ts index fbf338ac1f..6307ee13fa 100644 --- a/apps/web/src/app/admin-console/organizations/policies/reset-password.component.ts +++ b/apps/web/src/app/admin-console/organizations/policies/reset-password.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { FormBuilder } from "@angular/forms"; import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction"; @@ -22,7 +22,7 @@ export class ResetPasswordPolicy extends BasePolicy { selector: "policy-reset-password", templateUrl: "reset-password.component.html", }) -export class ResetPasswordPolicyComponent extends BasePolicyComponent { +export class ResetPasswordPolicyComponent extends BasePolicyComponent implements OnInit { data = this.formBuilder.group({ autoEnrollEnabled: false, }); diff --git a/apps/web/src/app/admin-console/organizations/settings/account.component.ts b/apps/web/src/app/admin-console/organizations/settings/account.component.ts index 82f9a24993..c53a4991d5 100644 --- a/apps/web/src/app/admin-console/organizations/settings/account.component.ts +++ b/apps/web/src/app/admin-console/organizations/settings/account.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild, ViewContainerRef } from "@angular/core"; +import { Component, OnDestroy, OnInit, ViewChild, ViewContainerRef } from "@angular/core"; import { FormBuilder, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; import { combineLatest, from, lastValueFrom, of, Subject, switchMap, takeUntil } from "rxjs"; @@ -27,7 +27,7 @@ import { DeleteOrganizationDialogResult, openDeleteOrganizationDialog } from "./ selector: "app-org-account", templateUrl: "account.component.html", }) -export class AccountComponent { +export class AccountComponent implements OnInit, OnDestroy { @ViewChild("apiKeyTemplate", { read: ViewContainerRef, static: true }) apiKeyModalRef: ViewContainerRef; @ViewChild("rotateApiKeyTemplate", { read: ViewContainerRef, static: true }) diff --git a/apps/web/src/app/admin-console/organizations/settings/two-factor-setup.component.ts b/apps/web/src/app/admin-console/organizations/settings/two-factor-setup.component.ts index 0e00c31a69..39d29741e7 100644 --- a/apps/web/src/app/admin-console/organizations/settings/two-factor-setup.component.ts +++ b/apps/web/src/app/admin-console/organizations/settings/two-factor-setup.component.ts @@ -1,5 +1,5 @@ import { DialogRef } from "@angular/cdk/dialog"; -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { concatMap, takeUntil, map, lastValueFrom } from "rxjs"; import { first, tap } from "rxjs/operators"; @@ -24,7 +24,7 @@ import { TwoFactorVerifyComponent } from "../../../auth/settings/two-factor-veri templateUrl: "../../../auth/settings/two-factor-setup.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent { +export class TwoFactorSetupComponent extends BaseTwoFactorSetupComponent implements OnInit { tabbedHeader = false; constructor( dialogService: DialogService, diff --git a/apps/web/src/app/admin-console/organizations/tools/exposed-passwords-report.component.ts b/apps/web/src/app/admin-console/organizations/tools/exposed-passwords-report.component.ts index cab6189c45..3ea2a8f43e 100644 --- a/apps/web/src/app/admin-console/organizations/tools/exposed-passwords-report.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/exposed-passwords-report.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; @@ -19,7 +19,10 @@ import { ExposedPasswordsReportComponent as BaseExposedPasswordsReportComponent templateUrl: "../../../tools/reports/pages/exposed-passwords-report.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class ExposedPasswordsReportComponent extends BaseExposedPasswordsReportComponent { +export class ExposedPasswordsReportComponent + extends BaseExposedPasswordsReportComponent + implements OnInit +{ manageableCiphers: Cipher[]; constructor( diff --git a/apps/web/src/app/admin-console/organizations/tools/inactive-two-factor-report.component.ts b/apps/web/src/app/admin-console/organizations/tools/inactive-two-factor-report.component.ts index abfbd45f38..6eb8889dc2 100644 --- a/apps/web/src/app/admin-console/organizations/tools/inactive-two-factor-report.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/inactive-two-factor-report.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; @@ -18,7 +18,10 @@ import { InactiveTwoFactorReportComponent as BaseInactiveTwoFactorReportComponen templateUrl: "../../../tools/reports/pages/inactive-two-factor-report.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class InactiveTwoFactorReportComponent extends BaseInactiveTwoFactorReportComponent { +export class InactiveTwoFactorReportComponent + extends BaseInactiveTwoFactorReportComponent + implements OnInit +{ constructor( cipherService: CipherService, modalService: ModalService, diff --git a/apps/web/src/app/admin-console/organizations/tools/reused-passwords-report.component.ts b/apps/web/src/app/admin-console/organizations/tools/reused-passwords-report.component.ts index 76d783b666..0fea1f0a58 100644 --- a/apps/web/src/app/admin-console/organizations/tools/reused-passwords-report.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/reused-passwords-report.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; @@ -18,7 +18,10 @@ import { ReusedPasswordsReportComponent as BaseReusedPasswordsReportComponent } templateUrl: "../../../tools/reports/pages/reused-passwords-report.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class ReusedPasswordsReportComponent extends BaseReusedPasswordsReportComponent { +export class ReusedPasswordsReportComponent + extends BaseReusedPasswordsReportComponent + implements OnInit +{ manageableCiphers: Cipher[]; constructor( diff --git a/apps/web/src/app/admin-console/organizations/tools/unsecured-websites-report.component.ts b/apps/web/src/app/admin-console/organizations/tools/unsecured-websites-report.component.ts index 7f6f08fb96..559d2f417a 100644 --- a/apps/web/src/app/admin-console/organizations/tools/unsecured-websites-report.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/unsecured-websites-report.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; @@ -17,7 +17,10 @@ import { UnsecuredWebsitesReportComponent as BaseUnsecuredWebsitesReportComponen templateUrl: "../../../tools/reports/pages/unsecured-websites-report.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class UnsecuredWebsitesReportComponent extends BaseUnsecuredWebsitesReportComponent { +export class UnsecuredWebsitesReportComponent + extends BaseUnsecuredWebsitesReportComponent + implements OnInit +{ constructor( cipherService: CipherService, modalService: ModalService, diff --git a/apps/web/src/app/admin-console/organizations/tools/weak-passwords-report.component.ts b/apps/web/src/app/admin-console/organizations/tools/weak-passwords-report.component.ts index 0ac2129478..06e6fdf0a7 100644 --- a/apps/web/src/app/admin-console/organizations/tools/weak-passwords-report.component.ts +++ b/apps/web/src/app/admin-console/organizations/tools/weak-passwords-report.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ModalService } from "@bitwarden/angular/services/modal.service"; @@ -19,7 +19,10 @@ import { WeakPasswordsReportComponent as BaseWeakPasswordsReportComponent } from templateUrl: "../../../tools/reports/pages/weak-passwords-report.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class WeakPasswordsReportComponent extends BaseWeakPasswordsReportComponent { +export class WeakPasswordsReportComponent + extends BaseWeakPasswordsReportComponent + implements OnInit +{ manageableCiphers: Cipher[]; constructor( diff --git a/bitwarden_license/bit-cli/src/admin-console/.eslintrc.json b/bitwarden_license/bit-cli/src/admin-console/.eslintrc.json new file mode 100644 index 0000000000..3846718729 --- /dev/null +++ b/bitwarden_license/bit-cli/src/admin-console/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../../libs/admin-console/.eslintrc.json" +} diff --git a/bitwarden_license/bit-web/src/app/admin-console/.eslintrc.json b/bitwarden_license/bit-web/src/app/admin-console/.eslintrc.json new file mode 100644 index 0000000000..d55df3899e --- /dev/null +++ b/bitwarden_license/bit-web/src/app/admin-console/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../../../libs/admin-console/.eslintrc.json" +} diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/clients/clients.component.ts b/bitwarden_license/bit-web/src/app/admin-console/providers/clients/clients.component.ts index 2e422b8136..88f125a65a 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/clients/clients.component.ts +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/clients/clients.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { firstValueFrom, from, map } from "rxjs"; import { switchMap, takeUntil } from "rxjs/operators"; @@ -33,7 +33,7 @@ const DisallowedPlanTypes = [ @Component({ templateUrl: "clients.component.html", }) -export class ClientsComponent extends BaseClientsComponent { +export class ClientsComponent extends BaseClientsComponent implements OnInit, OnDestroy { providerId: string; addableOrganizations: Organization[]; loading = true; diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/people.component.ts b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/people.component.ts index 97dd4d3e0a..564808d005 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/people.component.ts +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/people.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild, ViewContainerRef } from "@angular/core"; +import { Component, OnInit, ViewChild, ViewContainerRef } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { lastValueFrom } from "rxjs"; import { first } from "rxjs/operators"; @@ -34,7 +34,10 @@ import { UserAddEditComponent } from "./user-add-edit.component"; templateUrl: "people.component.html", }) // eslint-disable-next-line rxjs-angular/prefer-takeuntil -export class PeopleComponent extends BasePeopleComponent { +export class PeopleComponent + extends BasePeopleComponent + implements OnInit +{ @ViewChild("addEdit", { read: ViewContainerRef, static: true }) addEditModalRef: ViewContainerRef; @ViewChild("groupsTemplate", { read: ViewContainerRef, static: true }) groupsModalRef: ViewContainerRef; @@ -154,11 +157,11 @@ export class PeopleComponent extends BasePeopleComponent { + comp.savedUser.subscribe(() => { modal.close(); this.load(); }); - comp.onDeletedUser.subscribe(() => { + comp.deletedUser.subscribe(() => { modal.close(); this.removeUser(user); }); diff --git a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/user-add-edit.component.ts b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/user-add-edit.component.ts index b1513a79fc..664e399660 100644 --- a/bitwarden_license/bit-web/src/app/admin-console/providers/manage/user-add-edit.component.ts +++ b/bitwarden_license/bit-web/src/app/admin-console/providers/manage/user-add-edit.component.ts @@ -18,8 +18,8 @@ export class UserAddEditComponent implements OnInit { @Input() name: string; @Input() providerUserId: string; @Input() providerId: string; - @Output() onSavedUser = new EventEmitter(); - @Output() onDeletedUser = new EventEmitter(); + @Output() savedUser = new EventEmitter(); + @Output() deletedUser = new EventEmitter(); loading = true; editMode = false; @@ -82,7 +82,7 @@ export class UserAddEditComponent implements OnInit { null, this.i18nService.t(this.editMode ? "editedUserId" : "invitedUsers", this.name), ); - this.onSavedUser.emit(); + this.savedUser.emit(); } catch (e) { this.logService.error(e); } @@ -111,7 +111,7 @@ export class UserAddEditComponent implements OnInit { null, this.i18nService.t("removedUserId", this.name), ); - this.onDeletedUser.emit(); + this.deletedUser.emit(); } catch (e) { this.logService.error(e); } diff --git a/libs/admin-console/.eslintrc.json b/libs/admin-console/.eslintrc.json new file mode 100644 index 0000000000..d8aa8f64a8 --- /dev/null +++ b/libs/admin-console/.eslintrc.json @@ -0,0 +1,22 @@ +{ + "overrides": [ + { + "files": ["*.ts"], + "extends": ["plugin:@angular-eslint/recommended"], + "rules": { + "@angular-eslint/component-class-suffix": "error", + "@angular-eslint/contextual-lifecycle": "error", + "@angular-eslint/directive-class-suffix": "error", + "@angular-eslint/no-empty-lifecycle-method": "error", + "@angular-eslint/no-input-rename": "error", + "@angular-eslint/no-inputs-metadata-property": "error", + "@angular-eslint/no-output-native": "error", + "@angular-eslint/no-output-on-prefix": "error", + "@angular-eslint/no-output-rename": "error", + "@angular-eslint/no-outputs-metadata-property": "error", + "@angular-eslint/use-lifecycle-interface": "error", + "@angular-eslint/use-pipe-transform-interface": "error" + } + } + ] +} From 830c1297f221dee82b0da3e1e01defb4e26e786f Mon Sep 17 00:00:00 2001 From: Nick Krantz <125900171+nick-livefront@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:02:41 -0500 Subject: [PATCH 4/7] do not allow wrapping on choose file button (#10025) --- .../cipher-attachments/cipher-attachments.component.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/browser/src/vault/popup/components/vault-v2/attachments/cipher-attachments/cipher-attachments.component.html b/apps/browser/src/vault/popup/components/vault-v2/attachments/cipher-attachments/cipher-attachments.component.html index 46e8092d90..159cab31e8 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/attachments/cipher-attachments/cipher-attachments.component.html +++ b/apps/browser/src/vault/popup/components/vault-v2/attachments/cipher-attachments/cipher-attachments.component.html @@ -47,7 +47,13 @@ (change)="onFileChange($event)" />