1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +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:
Justin Baur
2023-04-07 11:11:20 -04:00
committed by GitHub
parent 36de1c8e32
commit 7263579eaf
20 changed files with 52 additions and 90 deletions

View File

@@ -5,7 +5,6 @@ import { LogService } from "../abstractions/log.service";
import { SearchService as SearchServiceAbstraction } from "../abstractions/search.service";
import { FieldType, UriMatchType } from "../enums";
import { SendView } from "../tools/send/models/view/send.view";
import { CipherService } from "../vault/abstractions/cipher.service";
import { CipherType } from "../vault/enums/cipher-type";
import { CipherView } from "../vault/models/view/cipher.view";
@@ -19,11 +18,7 @@ export class SearchService implements SearchServiceAbstraction {
private readonly defaultSearchableMinLength: number = 2;
private searchableMinLength: number = this.defaultSearchableMinLength;
constructor(
private cipherService: CipherService,
private logService: LogService,
private i18nService: I18nService
) {
constructor(private logService: LogService, private i18nService: I18nService) {
this.i18nService.locale$.subscribe((locale) => {
if (this.immediateSearchLocales.indexOf(locale) !== -1) {
this.searchableMinLength = 1;
@@ -55,7 +50,7 @@ export class SearchService implements SearchServiceAbstraction {
return !notSearchable;
}
async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise<void> {
indexCiphers(ciphers: CipherView[], indexedEntityId?: string): void {
if (this.indexing) {
return;
}
@@ -94,7 +89,7 @@ export class SearchService implements SearchServiceAbstraction {
extractor: (c: CipherView) => this.attachmentExtractor(c, true),
});
builder.field("organizationid", { extractor: (c: CipherView) => c.organizationId });
ciphers = ciphers || (await this.cipherService.getAllDecrypted());
ciphers = ciphers || [];
ciphers.forEach((c) => builder.add(c));
this.index = builder.build();
@@ -106,7 +101,7 @@ export class SearchService implements SearchServiceAbstraction {
async searchCiphers(
query: string,
filter: ((cipher: CipherView) => boolean) | ((cipher: CipherView) => boolean)[] = null,
ciphers: CipherView[] = null
ciphers: CipherView[]
): Promise<CipherView[]> {
const results: CipherView[] = [];
if (query != null) {
@@ -117,7 +112,7 @@ export class SearchService implements SearchServiceAbstraction {
}
if (ciphers == null) {
ciphers = await this.cipherService.getAllDecrypted();
ciphers = [];
}
if (filter != null && Array.isArray(filter) && filter.length > 0) {