mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
[PM-329] Detangle SearchService & CipherService (#4838)
* Remove Circular Dependency * Fix Vault Searching * Remove Unused cipherServiceOptions * Add searchService Parameter to CipherService * Fix instantiation of CipherService in test
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { StateFactory } from "@bitwarden/common/factories/stateFactory";
|
||||
@@ -14,7 +13,6 @@ import {
|
||||
AuthServiceInitOptions,
|
||||
} from "../../auth/background/service-factories/auth-service.factory";
|
||||
import { CachedServices } from "../../background/service_factories/factory-options";
|
||||
import { searchServiceFactory } from "../../background/service_factories/search-service.factory";
|
||||
import { BrowserApi } from "../../browser/browserApi";
|
||||
import { Account } from "../../models/account";
|
||||
import {
|
||||
@@ -45,14 +43,10 @@ export class CipherContextMenuHandler {
|
||||
|
||||
static async create(cachedServices: CachedServices) {
|
||||
const stateFactory = new StateFactory(GlobalState, Account);
|
||||
let searchService: SearchService | null = null;
|
||||
const serviceOptions: AuthServiceInitOptions & CipherServiceInitOptions = {
|
||||
apiServiceOptions: {
|
||||
logoutCallback: NOT_IMPLEMENTED,
|
||||
},
|
||||
cipherServiceOptions: {
|
||||
searchServiceFactory: () => searchService,
|
||||
},
|
||||
cryptoFunctionServiceOptions: {
|
||||
win: self,
|
||||
},
|
||||
@@ -80,7 +74,6 @@ export class CipherContextMenuHandler {
|
||||
stateFactory: stateFactory,
|
||||
},
|
||||
};
|
||||
searchService = await searchServiceFactory(cachedServices, serviceOptions);
|
||||
return new CipherContextMenuHandler(
|
||||
await MainContextMenuHandler.mv3Create(cachedServices),
|
||||
await authServiceFactory(cachedServices, serviceOptions),
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { TotpService } from "@bitwarden/common/abstractions/totp.service";
|
||||
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
@@ -19,7 +18,6 @@ import LockedVaultPendingNotificationsItem from "../../background/models/lockedV
|
||||
import { eventCollectionServiceFactory } from "../../background/service_factories/event-collection-service.factory";
|
||||
import { CachedServices } from "../../background/service_factories/factory-options";
|
||||
import { passwordGenerationServiceFactory } from "../../background/service_factories/password-generation-service.factory";
|
||||
import { searchServiceFactory } from "../../background/service_factories/search-service.factory";
|
||||
import { stateServiceFactory } from "../../background/service_factories/state-service.factory";
|
||||
import { BrowserApi } from "../../browser/browserApi";
|
||||
import { Account } from "../../models/account";
|
||||
@@ -63,14 +61,10 @@ export class ContextMenuClickedHandler {
|
||||
|
||||
static async mv3Create(cachedServices: CachedServices) {
|
||||
const stateFactory = new StateFactory(GlobalState, Account);
|
||||
let searchService: SearchService | null = null;
|
||||
const serviceOptions: AuthServiceInitOptions & CipherServiceInitOptions = {
|
||||
apiServiceOptions: {
|
||||
logoutCallback: NOT_IMPLEMENTED,
|
||||
},
|
||||
cipherServiceOptions: {
|
||||
searchServiceFactory: () => searchService,
|
||||
},
|
||||
cryptoFunctionServiceOptions: {
|
||||
win: self,
|
||||
},
|
||||
@@ -98,7 +92,6 @@ export class ContextMenuClickedHandler {
|
||||
stateFactory: stateFactory,
|
||||
},
|
||||
};
|
||||
searchService = await searchServiceFactory(cachedServices, serviceOptions);
|
||||
|
||||
const generatePasswordToClipboardCommand = new GeneratePasswordToClipboardCommand(
|
||||
await passwordGenerationServiceFactory(cachedServices, serviceOptions),
|
||||
|
||||
@@ -303,12 +303,14 @@ export default class MainBackground {
|
||||
this.apiService,
|
||||
this.fileUploadService
|
||||
);
|
||||
this.searchService = new SearchService(this.logService, this.i18nService);
|
||||
|
||||
this.cipherService = new CipherService(
|
||||
this.cryptoService,
|
||||
this.settingsService,
|
||||
this.apiService,
|
||||
this.i18nService,
|
||||
() => this.searchService,
|
||||
this.searchService,
|
||||
this.stateService,
|
||||
this.encryptService,
|
||||
this.cipherFileUploadService
|
||||
@@ -325,7 +327,6 @@ export default class MainBackground {
|
||||
this.i18nService,
|
||||
this.stateService
|
||||
);
|
||||
this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService);
|
||||
this.syncNotifierService = new SyncNotifierService();
|
||||
this.organizationService = new BrowserOrganizationService(this.stateService);
|
||||
this.policyService = new BrowserPolicyService(this.stateService, this.organizationService);
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { SearchService as AbstractSearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { SearchService } from "@bitwarden/common/services/search.service";
|
||||
|
||||
import {
|
||||
cipherServiceFactory,
|
||||
CipherServiceInitOptions,
|
||||
} from "../../vault/background/service_factories/cipher-service.factory";
|
||||
|
||||
import { CachedServices, factory, FactoryOptions } from "./factory-options";
|
||||
import { i18nServiceFactory, I18nServiceInitOptions } from "./i18n-service.factory";
|
||||
import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory";
|
||||
@@ -13,7 +8,6 @@ import { logServiceFactory, LogServiceInitOptions } from "./log-service.factory"
|
||||
type SearchServiceFactoryOptions = FactoryOptions;
|
||||
|
||||
export type SearchServiceInitOptions = SearchServiceFactoryOptions &
|
||||
CipherServiceInitOptions &
|
||||
LogServiceInitOptions &
|
||||
I18nServiceInitOptions;
|
||||
|
||||
@@ -26,10 +20,6 @@ export function searchServiceFactory(
|
||||
"searchService",
|
||||
opts,
|
||||
async () =>
|
||||
new SearchService(
|
||||
await cipherServiceFactory(cache, opts),
|
||||
await logServiceFactory(cache, opts),
|
||||
await i18nServiceFactory(cache, opts)
|
||||
)
|
||||
new SearchService(await logServiceFactory(cache, opts), await i18nServiceFactory(cache, opts))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||
import { StateFactory } from "@bitwarden/common/factories/stateFactory";
|
||||
import { GlobalState } from "@bitwarden/common/models/domain/global-state";
|
||||
@@ -60,9 +59,6 @@ const doAutoFillLogin = async (tab: chrome.tabs.Tab): Promise<void> => {
|
||||
i18nServiceOptions: {
|
||||
systemLanguage: BrowserApi.getUILanguage(self),
|
||||
},
|
||||
cipherServiceOptions: {
|
||||
searchServiceFactory: null as () => SearchService, // No dependence on search service
|
||||
},
|
||||
};
|
||||
const logService = await logServiceFactory(cachedServices, opts);
|
||||
const authService = await authServiceFactory(cachedServices, opts);
|
||||
|
||||
@@ -9,7 +9,6 @@ import { ContainerService } from "@bitwarden/common/services/container.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
|
||||
import { authServiceFactory } from "../auth/background/service-factories/auth-service.factory";
|
||||
import { searchServiceFactory } from "../background/service_factories/search-service.factory";
|
||||
import { stateServiceFactory } from "../background/service_factories/state-service.factory";
|
||||
import { BrowserApi } from "../browser/browserApi";
|
||||
import { Account } from "../models/account";
|
||||
@@ -279,12 +278,7 @@ export class UpdateBadge {
|
||||
};
|
||||
this.stateService = await stateServiceFactory(serviceCache, opts);
|
||||
this.authService = await authServiceFactory(serviceCache, opts);
|
||||
const searchService = await searchServiceFactory(serviceCache, opts);
|
||||
|
||||
this.cipherService = await cipherServiceFactory(serviceCache, {
|
||||
...opts,
|
||||
cipherServiceOptions: { searchServiceFactory: () => searchService },
|
||||
});
|
||||
this.cipherService = await cipherServiceFactory(serviceCache, opts);
|
||||
|
||||
// Needed for cipher decryption
|
||||
if (!self.bitwardenContainerService) {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { ConsoleLogService } from "@bitwarden/common/services/consoleLog.service";
|
||||
import { SearchService } from "@bitwarden/common/services/search.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
|
||||
export class PopupSearchService extends SearchService {
|
||||
constructor(
|
||||
private mainSearchService: SearchService,
|
||||
cipherService: CipherService,
|
||||
consoleLogService: ConsoleLogService,
|
||||
i18nService: I18nService
|
||||
) {
|
||||
super(cipherService, consoleLogService, i18nService);
|
||||
super(consoleLogService, i18nService);
|
||||
}
|
||||
|
||||
clearIndex() {
|
||||
|
||||
@@ -164,19 +164,14 @@ function getBgService<T>(service: keyof MainBackground) {
|
||||
},
|
||||
{
|
||||
provide: SearchServiceAbstraction,
|
||||
useFactory: (
|
||||
cipherService: CipherService,
|
||||
logService: ConsoleLogService,
|
||||
i18nService: I18nServiceAbstraction
|
||||
) => {
|
||||
useFactory: (logService: ConsoleLogService, i18nService: I18nServiceAbstraction) => {
|
||||
return new PopupSearchService(
|
||||
getBgService<SearchService>("searchService")(),
|
||||
cipherService,
|
||||
logService,
|
||||
i18nService
|
||||
);
|
||||
},
|
||||
deps: [CipherService, LogServiceAbstraction, I18nServiceAbstraction],
|
||||
deps: [LogServiceAbstraction, I18nServiceAbstraction],
|
||||
},
|
||||
{ provide: AuditService, useFactory: getBgService<AuditService>("auditService"), deps: [] },
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { CipherService as AbstractCipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/services/cipher.service";
|
||||
|
||||
@@ -27,6 +26,10 @@ import {
|
||||
i18nServiceFactory,
|
||||
I18nServiceInitOptions,
|
||||
} from "../../../background/service_factories/i18n-service.factory";
|
||||
import {
|
||||
searchServiceFactory,
|
||||
SearchServiceInitOptions,
|
||||
} from "../../../background/service_factories/search-service.factory";
|
||||
import {
|
||||
SettingsServiceInitOptions,
|
||||
settingsServiceFactory,
|
||||
@@ -36,11 +39,7 @@ import {
|
||||
StateServiceInitOptions,
|
||||
} from "../../../background/service_factories/state-service.factory";
|
||||
|
||||
type CipherServiceFactoryOptions = FactoryOptions & {
|
||||
cipherServiceOptions?: {
|
||||
searchServiceFactory?: () => SearchService;
|
||||
};
|
||||
};
|
||||
type CipherServiceFactoryOptions = FactoryOptions;
|
||||
|
||||
export type CipherServiceInitOptions = CipherServiceFactoryOptions &
|
||||
CryptoServiceInitOptions &
|
||||
@@ -48,6 +47,7 @@ export type CipherServiceInitOptions = CipherServiceFactoryOptions &
|
||||
ApiServiceInitOptions &
|
||||
CipherFileUploadServiceInitOptions &
|
||||
I18nServiceInitOptions &
|
||||
SearchServiceInitOptions &
|
||||
StateServiceInitOptions &
|
||||
EncryptServiceInitOptions;
|
||||
|
||||
@@ -65,9 +65,7 @@ export function cipherServiceFactory(
|
||||
await settingsServiceFactory(cache, opts),
|
||||
await apiServiceFactory(cache, opts),
|
||||
await i18nServiceFactory(cache, opts),
|
||||
opts.cipherServiceOptions?.searchServiceFactory === undefined
|
||||
? () => cache.searchService as SearchService
|
||||
: opts.cipherServiceOptions.searchServiceFactory,
|
||||
await searchServiceFactory(cache, opts),
|
||||
await stateServiceFactory(cache, opts),
|
||||
await encryptServiceFactory(cache, opts),
|
||||
await cipherFileUploadServiceFactory(cache, opts)
|
||||
|
||||
@@ -66,10 +66,10 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnIn
|
||||
private folderService: FolderService,
|
||||
private collectionService: CollectionService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
private cipherService: CipherService,
|
||||
cipherService: CipherService,
|
||||
private vaultFilterService: VaultFilterService
|
||||
) {
|
||||
super(searchService);
|
||||
super(searchService, cipherService);
|
||||
this.applySavedState =
|
||||
(window as any).previousPopupUrl != null &&
|
||||
!(window as any).previousPopupUrl.startsWith("/ciphers");
|
||||
|
||||
@@ -239,12 +239,14 @@ export class Main {
|
||||
this.sendService
|
||||
);
|
||||
|
||||
this.searchService = new SearchService(this.logService, this.i18nService);
|
||||
|
||||
this.cipherService = new CipherService(
|
||||
this.cryptoService,
|
||||
this.settingsService,
|
||||
this.apiService,
|
||||
this.i18nService,
|
||||
null,
|
||||
this.searchService,
|
||||
this.stateService,
|
||||
this.encryptService,
|
||||
this.cipherFileUploadService
|
||||
@@ -267,8 +269,6 @@ export class Main {
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService);
|
||||
|
||||
this.providerService = new ProviderService(this.stateService);
|
||||
|
||||
this.organizationService = new OrganizationService(this.stateService);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component } from "@angular/core";
|
||||
|
||||
import { VaultItemsComponent as BaseVaultItemsComponent } from "@bitwarden/angular/vault/components/vault-items.component";
|
||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
|
||||
import { SearchBarService } from "../../../app/layout/search/search-bar.service";
|
||||
@@ -12,8 +13,12 @@ import { SearchBarService } from "../../../app/layout/search/search-bar.service"
|
||||
})
|
||||
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
||||
export class VaultItemsComponent extends BaseVaultItemsComponent {
|
||||
constructor(searchService: SearchService, searchBarService: SearchBarService) {
|
||||
super(searchService);
|
||||
constructor(
|
||||
searchService: SearchService,
|
||||
searchBarService: SearchBarService,
|
||||
cipherService: CipherService
|
||||
) {
|
||||
super(searchService, cipherService);
|
||||
|
||||
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
||||
searchBarService.searchText$.subscribe((searchText) => {
|
||||
|
||||
@@ -118,7 +118,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
|
||||
protected i18nService: I18nService,
|
||||
protected platformUtilsService: PlatformUtilsService,
|
||||
protected vaultFilterService: VaultFilterService,
|
||||
protected cipherService: CipherService,
|
||||
cipherService: CipherService,
|
||||
protected eventCollectionService: EventCollectionService,
|
||||
protected totpService: TotpService,
|
||||
protected stateService: StateService,
|
||||
@@ -129,7 +129,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
|
||||
private organizationService: OrganizationService,
|
||||
private tokenService: TokenService
|
||||
) {
|
||||
super(searchService);
|
||||
super(searchService, cipherService);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -223,6 +223,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
|
||||
}
|
||||
|
||||
async doSearch(indexedCiphers?: CipherView[]) {
|
||||
indexedCiphers = indexedCiphers ?? (await this.cipherService.getAllDecrypted());
|
||||
this.ciphers = await this.searchService.searchCiphers(
|
||||
this.searchText,
|
||||
[this.filter, this.deletedFilter],
|
||||
|
||||
@@ -110,7 +110,8 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
|
||||
(c) => c.organizationId === this.organization?.id
|
||||
);
|
||||
}
|
||||
await this.searchService.indexCiphers(this.organization?.id, this.allCiphers);
|
||||
|
||||
this.searchService.indexCiphers(this.allCiphers, this.organization?.id);
|
||||
}
|
||||
|
||||
async refreshCollections(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user