From 090ad790f5ace3526ce8202d2ac74751e6618587 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Thu, 22 Apr 2021 14:53:45 -0500 Subject: [PATCH] Specify Organization indexed on search service (#356) * Specify Organization indexed on search service a null indexedEntityId specifies it is the users entire vault. otherwise, organizations specify their id to signify the index is a subset. user's vault will re-index if the indexed entity does not match the users id or null. at the moment, user's vault does not set userId because indexing occurs in the setter for decryptedCipherCache, which cannot be asynchronous * Linter fix --- src/abstractions/search.service.ts | 3 ++- src/services/cipher.service.ts | 5 +++++ src/services/search.service.ts | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/abstractions/search.service.ts b/src/abstractions/search.service.ts index fe60532963e..d95bea418ec 100644 --- a/src/abstractions/search.service.ts +++ b/src/abstractions/search.service.ts @@ -2,9 +2,10 @@ import { CipherView } from '../models/view/cipherView'; import { SendView } from '../models/view/sendView'; export abstract class SearchService { + indexedEntityId?: string = null; clearIndex: () => void; isSearchable: (query: string) => boolean; - indexCiphers: (ciphersToIndex?: CipherView[]) => Promise; + indexCiphers: (indexedEntityGuid?: string, ciphersToIndex?: CipherView[]) => Promise; searchCiphers: (query: string, filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]), ciphers?: CipherView[]) => Promise; diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 7ba468caca2..37b47d430b5 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -294,6 +294,11 @@ export class CipherService implements CipherServiceAbstraction { @sequentialize(() => 'getAllDecrypted') async getAllDecrypted(): Promise { if (this.decryptedCipherCache != null) { + const userId = await this.userService.getUserId(); + if ((this.searchService().indexedEntityId ?? userId) !== userId) + { + await this.searchService().indexCiphers(); + } return this.decryptedCipherCache; } diff --git a/src/services/search.service.ts b/src/services/search.service.ts index f593e08bbf4..58b4c96efda 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -13,6 +13,7 @@ import { UriMatchType } from '../enums/uriMatchType'; import { SendView } from '../models/view/sendView'; export class SearchService implements SearchServiceAbstraction { + indexedEntityId?: string = null; private indexing = false; private index: lunr.Index = null; private searchableMinLength = 2; @@ -34,7 +35,7 @@ export class SearchService implements SearchServiceAbstraction { return !notSearchable; } - async indexCiphers(ciphers?: CipherView[]): Promise { + async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise { if (this.indexing) { return; } @@ -69,6 +70,7 @@ export class SearchService implements SearchServiceAbstraction { ciphers = ciphers || await this.cipherService.getAllDecrypted(); ciphers.forEach(c => builder.add(c)); this.index = builder.build(); + this.indexedEntityId = indexedEntityId; this.indexing = false; this.logService.timeEnd('search indexing');