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
This commit is contained in:
parent
aca098645a
commit
090ad790f5
|
@ -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<void>;
|
||||
indexCiphers: (indexedEntityGuid?: string, ciphersToIndex?: CipherView[]) => Promise<void>;
|
||||
searchCiphers: (query: string,
|
||||
filter?: ((cipher: CipherView) => boolean) | (((cipher: CipherView) => boolean)[]),
|
||||
ciphers?: CipherView[]) => Promise<CipherView[]>;
|
||||
|
|
|
@ -294,6 +294,11 @@ export class CipherService implements CipherServiceAbstraction {
|
|||
@sequentialize(() => 'getAllDecrypted')
|
||||
async getAllDecrypted(): Promise<CipherView[]> {
|
||||
if (this.decryptedCipherCache != null) {
|
||||
const userId = await this.userService.getUserId();
|
||||
if ((this.searchService().indexedEntityId ?? userId) !== userId)
|
||||
{
|
||||
await this.searchService().indexCiphers();
|
||||
}
|
||||
return this.decryptedCipherCache;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<void> {
|
||||
async indexCiphers(indexedEntityId?: string, ciphers?: CipherView[]): Promise<void> {
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue