From 4c5a46ce13307f6c4c18dae5bdea7bbedb9f87e2 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 25 Aug 2022 19:09:27 +0200 Subject: [PATCH] [PS-1363] Tech debt and small refactorings (#3377) * Remove cast to any as Utils.gobal got typed with #3131 * BitwardenFileUploadService: Remove unneeded dependency * Remove allowSoftLock from vaultTimeoutService * ImportService: Remove dependency on PlatformUtilsSvc --- apps/browser/src/background/commands.background.ts | 2 +- apps/browser/src/background/idle.background.ts | 2 +- apps/browser/src/popup/settings/settings.component.ts | 2 +- apps/cli/src/bw.ts | 1 - .../tools/import-export/org-import-export.module.ts | 2 -- apps/web/src/app/tools/import-export/import-export.module.ts | 2 -- libs/common/spec/services/import.service.spec.ts | 4 ---- libs/common/src/abstractions/vaultTimeout.service.ts | 2 +- libs/common/src/models/domain/send.ts | 2 +- libs/common/src/services/bitwardenFileUpload.service.ts | 3 --- libs/common/src/services/fileUpload.service.ts | 2 +- libs/common/src/services/folder/folder.service.ts | 2 +- libs/common/src/services/import.service.ts | 2 -- libs/common/src/services/vaultTimeout.service.ts | 4 ++-- 14 files changed, 9 insertions(+), 23 deletions(-) diff --git a/apps/browser/src/background/commands.background.ts b/apps/browser/src/background/commands.background.ts index 860f1bf077..4d85c91c0b 100644 --- a/apps/browser/src/background/commands.background.ts +++ b/apps/browser/src/background/commands.background.ts @@ -60,7 +60,7 @@ export default class CommandsBackground { await this.openPopup(); break; case "lock_vault": - await this.vaultTimeoutService.lock(true); + await this.vaultTimeoutService.lock(); break; default: break; diff --git a/apps/browser/src/background/idle.background.ts b/apps/browser/src/background/idle.background.ts index 65712f5df2..aecadd31fc 100644 --- a/apps/browser/src/background/idle.background.ts +++ b/apps/browser/src/background/idle.background.ts @@ -48,7 +48,7 @@ export default class IdleBackground { if (action === "logOut") { await this.vaultTimeoutService.logOut(); } else { - await this.vaultTimeoutService.lock(true); + await this.vaultTimeoutService.lock(); } } } diff --git a/apps/browser/src/popup/settings/settings.component.ts b/apps/browser/src/popup/settings/settings.component.ts index 3d9603a48e..f691128311 100644 --- a/apps/browser/src/popup/settings/settings.component.ts +++ b/apps/browser/src/popup/settings/settings.component.ts @@ -302,7 +302,7 @@ export class SettingsComponent implements OnInit { } async lock() { - await this.vaultTimeoutService.lock(true); + await this.vaultTimeoutService.lock(); } async logOut() { diff --git a/apps/cli/src/bw.ts b/apps/cli/src/bw.ts index 2813ed589d..9f9998af89 100644 --- a/apps/cli/src/bw.ts +++ b/apps/cli/src/bw.ts @@ -323,7 +323,6 @@ export class Main { this.apiService, this.i18nService, this.collectionService, - this.platformUtilsService, this.cryptoService ); this.exportService = new ExportService( diff --git a/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts b/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts index 527ac69bdd..650363300b 100644 --- a/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts +++ b/apps/web/src/app/organizations/tools/import-export/org-import-export.module.ts @@ -7,7 +7,6 @@ import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.service"; -import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ImportService } from "@bitwarden/common/services/import.service"; import { LooseComponentsModule, SharedModule } from "../../../shared"; @@ -29,7 +28,6 @@ import { OrganizationImportComponent } from "./org-import.component"; ApiService, I18nService, CollectionService, - PlatformUtilsService, CryptoService, ], }, diff --git a/apps/web/src/app/tools/import-export/import-export.module.ts b/apps/web/src/app/tools/import-export/import-export.module.ts index 7d87c2fbe1..90a09f2aa0 100644 --- a/apps/web/src/app/tools/import-export/import-export.module.ts +++ b/apps/web/src/app/tools/import-export/import-export.module.ts @@ -7,7 +7,6 @@ import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.service"; -import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { ImportService } from "@bitwarden/common/services/import.service"; import { LooseComponentsModule, SharedModule } from "../../shared"; @@ -29,7 +28,6 @@ import { ImportComponent } from "./import.component"; ApiService, I18nService, CollectionService, - PlatformUtilsService, CryptoService, ], }, diff --git a/libs/common/spec/services/import.service.spec.ts b/libs/common/spec/services/import.service.spec.ts index 3464656568..654c1b6124 100644 --- a/libs/common/spec/services/import.service.spec.ts +++ b/libs/common/spec/services/import.service.spec.ts @@ -6,7 +6,6 @@ import { CollectionService } from "@bitwarden/common/abstractions/collection.ser import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwardenPasswordProtectedImporter"; import { Importer } from "@bitwarden/common/importers/importer"; import { Utils } from "@bitwarden/common/misc/utils"; @@ -19,7 +18,6 @@ describe("ImportService", () => { let apiService: SubstituteOf; let i18nService: SubstituteOf; let collectionService: SubstituteOf; - let platformUtilsService: SubstituteOf; let cryptoService: SubstituteOf; beforeEach(() => { @@ -28,7 +26,6 @@ describe("ImportService", () => { apiService = Substitute.for(); i18nService = Substitute.for(); collectionService = Substitute.for(); - platformUtilsService = Substitute.for(); cryptoService = Substitute.for(); importService = new ImportService( @@ -37,7 +34,6 @@ describe("ImportService", () => { apiService, i18nService, collectionService, - platformUtilsService, cryptoService ); }); diff --git a/libs/common/src/abstractions/vaultTimeout.service.ts b/libs/common/src/abstractions/vaultTimeout.service.ts index 317fbca86d..4fb474fd03 100644 --- a/libs/common/src/abstractions/vaultTimeout.service.ts +++ b/libs/common/src/abstractions/vaultTimeout.service.ts @@ -1,6 +1,6 @@ export abstract class VaultTimeoutService { checkVaultTimeout: () => Promise; - lock: (allowSoftLock?: boolean, userId?: string) => Promise; + lock: (userId?: string) => Promise; logOut: (userId?: string) => Promise; setVaultTimeoutOptions: (vaultTimeout: number, vaultTimeoutAction: string) => Promise; getVaultTimeout: () => Promise; diff --git a/libs/common/src/models/domain/send.ts b/libs/common/src/models/domain/send.ts index a398ac2dbf..8bf56acbee 100644 --- a/libs/common/src/models/domain/send.ts +++ b/libs/common/src/models/domain/send.ts @@ -72,7 +72,7 @@ export class Send extends Domain { const model = new SendView(this); let cryptoService: CryptoService; - const containerService = (Utils.global as any).bitwardenContainerService; + const containerService = Utils.global.bitwardenContainerService; if (containerService) { cryptoService = containerService.getCryptoService(); } else { diff --git a/libs/common/src/services/bitwardenFileUpload.service.ts b/libs/common/src/services/bitwardenFileUpload.service.ts index dd189e3e54..64432e13cb 100644 --- a/libs/common/src/services/bitwardenFileUpload.service.ts +++ b/libs/common/src/services/bitwardenFileUpload.service.ts @@ -1,10 +1,7 @@ -import { ApiService } from "../abstractions/api.service"; import { Utils } from "../misc/utils"; import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; export class BitwardenFileUploadService { - constructor(private apiService: ApiService) {} - async upload( encryptedFileName: string, encryptedFileData: EncArrayBuffer, diff --git a/libs/common/src/services/fileUpload.service.ts b/libs/common/src/services/fileUpload.service.ts index 6fc0af35f7..b7837a2d64 100644 --- a/libs/common/src/services/fileUpload.service.ts +++ b/libs/common/src/services/fileUpload.service.ts @@ -16,7 +16,7 @@ export class FileUploadService implements FileUploadServiceAbstraction { constructor(private logService: LogService, private apiService: ApiService) { this.azureFileUploadService = new AzureFileUploadService(logService); - this.bitwardenFileUploadService = new BitwardenFileUploadService(apiService); + this.bitwardenFileUploadService = new BitwardenFileUploadService(); } async uploadSendFile( diff --git a/libs/common/src/services/folder/folder.service.ts b/libs/common/src/services/folder/folder.service.ts index 2c598a70c1..9b3647a8d6 100644 --- a/libs/common/src/services/folder/folder.service.ts +++ b/libs/common/src/services/folder/folder.service.ts @@ -26,7 +26,7 @@ export class FolderService implements InternalFolderServiceAbstraction { private stateService: StateService ) { this.stateService.activeAccountUnlocked$.subscribe(async (unlocked) => { - if ((Utils.global as any).bitwardenContainerService == null) { + if (Utils.global.bitwardenContainerService == null) { return; } diff --git a/libs/common/src/services/import.service.ts b/libs/common/src/services/import.service.ts index 2b1b7bd567..acb45f7ebb 100644 --- a/libs/common/src/services/import.service.ts +++ b/libs/common/src/services/import.service.ts @@ -5,7 +5,6 @@ import { CryptoService } from "../abstractions/crypto.service"; import { FolderService } from "../abstractions/folder/folder.service.abstraction"; import { I18nService } from "../abstractions/i18n.service"; import { ImportService as ImportServiceAbstraction } from "../abstractions/import.service"; -import { PlatformUtilsService } from "../abstractions/platformUtils.service"; import { CipherType } from "../enums/cipherType"; import { featuredImportOptions, @@ -93,7 +92,6 @@ export class ImportService implements ImportServiceAbstraction { private apiService: ApiService, private i18nService: I18nService, private collectionService: CollectionService, - private platformUtilsService: PlatformUtilsService, private cryptoService: CryptoService ) {} diff --git a/libs/common/src/services/vaultTimeout.service.ts b/libs/common/src/services/vaultTimeout.service.ts index 95ee8ded48..55e347484d 100644 --- a/libs/common/src/services/vaultTimeout.service.ts +++ b/libs/common/src/services/vaultTimeout.service.ts @@ -62,7 +62,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { } } - async lock(allowSoftLock = false, userId?: string): Promise { + async lock(userId?: string): Promise { const authed = await this.stateService.getIsAuthenticated({ userId: userId }); if (!authed) { return; @@ -200,6 +200,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction { private async executeTimeoutAction(userId: string): Promise { const timeoutAction = await this.stateService.getVaultTimeoutAction({ userId: userId }); - timeoutAction === "logOut" ? await this.logOut(userId) : await this.lock(true, userId); + timeoutAction === "logOut" ? await this.logOut(userId) : await this.lock(userId); } }