[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
This commit is contained in:
Daniel James Smith 2022-08-25 19:09:27 +02:00 committed by GitHub
parent e0ae1bb738
commit 4c5a46ce13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 9 additions and 23 deletions

View File

@ -60,7 +60,7 @@ export default class CommandsBackground {
await this.openPopup(); await this.openPopup();
break; break;
case "lock_vault": case "lock_vault":
await this.vaultTimeoutService.lock(true); await this.vaultTimeoutService.lock();
break; break;
default: default:
break; break;

View File

@ -48,7 +48,7 @@ export default class IdleBackground {
if (action === "logOut") { if (action === "logOut") {
await this.vaultTimeoutService.logOut(); await this.vaultTimeoutService.logOut();
} else { } else {
await this.vaultTimeoutService.lock(true); await this.vaultTimeoutService.lock();
} }
} }
} }

View File

@ -302,7 +302,7 @@ export class SettingsComponent implements OnInit {
} }
async lock() { async lock() {
await this.vaultTimeoutService.lock(true); await this.vaultTimeoutService.lock();
} }
async logOut() { async logOut() {

View File

@ -323,7 +323,6 @@ export class Main {
this.apiService, this.apiService,
this.i18nService, this.i18nService,
this.collectionService, this.collectionService,
this.platformUtilsService,
this.cryptoService this.cryptoService
); );
this.exportService = new ExportService( this.exportService = new ExportService(

View File

@ -7,7 +7,6 @@ import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.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 { ImportService } from "@bitwarden/common/services/import.service";
import { LooseComponentsModule, SharedModule } from "../../../shared"; import { LooseComponentsModule, SharedModule } from "../../../shared";
@ -29,7 +28,6 @@ import { OrganizationImportComponent } from "./org-import.component";
ApiService, ApiService,
I18nService, I18nService,
CollectionService, CollectionService,
PlatformUtilsService,
CryptoService, CryptoService,
], ],
}, },

View File

@ -7,7 +7,6 @@ import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { ImportService as ImportServiceAbstraction } from "@bitwarden/common/abstractions/import.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 { ImportService } from "@bitwarden/common/services/import.service";
import { LooseComponentsModule, SharedModule } from "../../shared"; import { LooseComponentsModule, SharedModule } from "../../shared";
@ -29,7 +28,6 @@ import { ImportComponent } from "./import.component";
ApiService, ApiService,
I18nService, I18nService,
CollectionService, CollectionService,
PlatformUtilsService,
CryptoService, CryptoService,
], ],
}, },

View File

@ -6,7 +6,6 @@ import { CollectionService } from "@bitwarden/common/abstractions/collection.ser
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service"; import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction"; import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwardenPasswordProtectedImporter"; import { BitwardenPasswordProtectedImporter } from "@bitwarden/common/importers/bitwardenPasswordProtectedImporter";
import { Importer } from "@bitwarden/common/importers/importer"; import { Importer } from "@bitwarden/common/importers/importer";
import { Utils } from "@bitwarden/common/misc/utils"; import { Utils } from "@bitwarden/common/misc/utils";
@ -19,7 +18,6 @@ describe("ImportService", () => {
let apiService: SubstituteOf<ApiService>; let apiService: SubstituteOf<ApiService>;
let i18nService: SubstituteOf<I18nService>; let i18nService: SubstituteOf<I18nService>;
let collectionService: SubstituteOf<CollectionService>; let collectionService: SubstituteOf<CollectionService>;
let platformUtilsService: SubstituteOf<PlatformUtilsService>;
let cryptoService: SubstituteOf<CryptoService>; let cryptoService: SubstituteOf<CryptoService>;
beforeEach(() => { beforeEach(() => {
@ -28,7 +26,6 @@ describe("ImportService", () => {
apiService = Substitute.for<ApiService>(); apiService = Substitute.for<ApiService>();
i18nService = Substitute.for<I18nService>(); i18nService = Substitute.for<I18nService>();
collectionService = Substitute.for<CollectionService>(); collectionService = Substitute.for<CollectionService>();
platformUtilsService = Substitute.for<PlatformUtilsService>();
cryptoService = Substitute.for<CryptoService>(); cryptoService = Substitute.for<CryptoService>();
importService = new ImportService( importService = new ImportService(
@ -37,7 +34,6 @@ describe("ImportService", () => {
apiService, apiService,
i18nService, i18nService,
collectionService, collectionService,
platformUtilsService,
cryptoService cryptoService
); );
}); });

View File

@ -1,6 +1,6 @@
export abstract class VaultTimeoutService { export abstract class VaultTimeoutService {
checkVaultTimeout: () => Promise<void>; checkVaultTimeout: () => Promise<void>;
lock: (allowSoftLock?: boolean, userId?: string) => Promise<void>; lock: (userId?: string) => Promise<void>;
logOut: (userId?: string) => Promise<void>; logOut: (userId?: string) => Promise<void>;
setVaultTimeoutOptions: (vaultTimeout: number, vaultTimeoutAction: string) => Promise<void>; setVaultTimeoutOptions: (vaultTimeout: number, vaultTimeoutAction: string) => Promise<void>;
getVaultTimeout: () => Promise<number>; getVaultTimeout: () => Promise<number>;

View File

@ -72,7 +72,7 @@ export class Send extends Domain {
const model = new SendView(this); const model = new SendView(this);
let cryptoService: CryptoService; let cryptoService: CryptoService;
const containerService = (Utils.global as any).bitwardenContainerService; const containerService = Utils.global.bitwardenContainerService;
if (containerService) { if (containerService) {
cryptoService = containerService.getCryptoService(); cryptoService = containerService.getCryptoService();
} else { } else {

View File

@ -1,10 +1,7 @@
import { ApiService } from "../abstractions/api.service";
import { Utils } from "../misc/utils"; import { Utils } from "../misc/utils";
import { EncArrayBuffer } from "../models/domain/encArrayBuffer"; import { EncArrayBuffer } from "../models/domain/encArrayBuffer";
export class BitwardenFileUploadService { export class BitwardenFileUploadService {
constructor(private apiService: ApiService) {}
async upload( async upload(
encryptedFileName: string, encryptedFileName: string,
encryptedFileData: EncArrayBuffer, encryptedFileData: EncArrayBuffer,

View File

@ -16,7 +16,7 @@ export class FileUploadService implements FileUploadServiceAbstraction {
constructor(private logService: LogService, private apiService: ApiService) { constructor(private logService: LogService, private apiService: ApiService) {
this.azureFileUploadService = new AzureFileUploadService(logService); this.azureFileUploadService = new AzureFileUploadService(logService);
this.bitwardenFileUploadService = new BitwardenFileUploadService(apiService); this.bitwardenFileUploadService = new BitwardenFileUploadService();
} }
async uploadSendFile( async uploadSendFile(

View File

@ -26,7 +26,7 @@ export class FolderService implements InternalFolderServiceAbstraction {
private stateService: StateService private stateService: StateService
) { ) {
this.stateService.activeAccountUnlocked$.subscribe(async (unlocked) => { this.stateService.activeAccountUnlocked$.subscribe(async (unlocked) => {
if ((Utils.global as any).bitwardenContainerService == null) { if (Utils.global.bitwardenContainerService == null) {
return; return;
} }

View File

@ -5,7 +5,6 @@ import { CryptoService } from "../abstractions/crypto.service";
import { FolderService } from "../abstractions/folder/folder.service.abstraction"; import { FolderService } from "../abstractions/folder/folder.service.abstraction";
import { I18nService } from "../abstractions/i18n.service"; import { I18nService } from "../abstractions/i18n.service";
import { ImportService as ImportServiceAbstraction } from "../abstractions/import.service"; import { ImportService as ImportServiceAbstraction } from "../abstractions/import.service";
import { PlatformUtilsService } from "../abstractions/platformUtils.service";
import { CipherType } from "../enums/cipherType"; import { CipherType } from "../enums/cipherType";
import { import {
featuredImportOptions, featuredImportOptions,
@ -93,7 +92,6 @@ export class ImportService implements ImportServiceAbstraction {
private apiService: ApiService, private apiService: ApiService,
private i18nService: I18nService, private i18nService: I18nService,
private collectionService: CollectionService, private collectionService: CollectionService,
private platformUtilsService: PlatformUtilsService,
private cryptoService: CryptoService private cryptoService: CryptoService
) {} ) {}

View File

@ -62,7 +62,7 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
} }
} }
async lock(allowSoftLock = false, userId?: string): Promise<void> { async lock(userId?: string): Promise<void> {
const authed = await this.stateService.getIsAuthenticated({ userId: userId }); const authed = await this.stateService.getIsAuthenticated({ userId: userId });
if (!authed) { if (!authed) {
return; return;
@ -200,6 +200,6 @@ export class VaultTimeoutService implements VaultTimeoutServiceAbstraction {
private async executeTimeoutAction(userId: string): Promise<void> { private async executeTimeoutAction(userId: string): Promise<void> {
const timeoutAction = await this.stateService.getVaultTimeoutAction({ userId: userId }); 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);
} }
} }