getAll ciphers FromApiForOrganization

This commit is contained in:
Kyle Spearrin 2018-12-14 13:55:44 -05:00
parent e55926336c
commit e10523cc61
2 changed files with 19 additions and 0 deletions

View File

@ -22,6 +22,7 @@ export abstract class CipherService {
getAllDecrypted: () => Promise<CipherView[]>; getAllDecrypted: () => Promise<CipherView[]>;
getAllDecryptedForGrouping: (groupingId: string, folder?: boolean) => Promise<CipherView[]>; getAllDecryptedForGrouping: (groupingId: string, folder?: boolean) => Promise<CipherView[]>;
getAllDecryptedForUrl: (url: string, includeOtherTypes?: CipherType[]) => Promise<CipherView[]>; getAllDecryptedForUrl: (url: string, includeOtherTypes?: CipherType[]) => Promise<CipherView[]>;
getAllFromApiForOrganization: (organizationId: string) => Promise<CipherView[]>;
getLastUsedForUrl: (url: string) => Promise<CipherView>; getLastUsedForUrl: (url: string) => Promise<CipherView>;
updateLastUsedDate: (id: string) => Promise<void>; updateLastUsedDate: (id: string) => Promise<void>;
saveNeverDomain: (domain: string) => Promise<void>; saveNeverDomain: (domain: string) => Promise<void>;

View File

@ -405,6 +405,24 @@ export class CipherService implements CipherServiceAbstraction {
}); });
} }
async getAllFromApiForOrganization(organizationId: string): Promise<CipherView[]> {
const ciphers = await this.apiService.getCiphersOrganization(organizationId);
if (ciphers != null && ciphers.data != null && ciphers.data.length) {
const decCiphers: CipherView[] = [];
const promises: any[] = [];
ciphers.data.forEach((r) => {
const data = new CipherData(r);
const cipher = new Cipher(data);
promises.push(cipher.decrypt().then((c) => decCiphers.push(c)));
});
await Promise.all(promises);
decCiphers.sort(this.getLocaleSortingFunction());
return decCiphers;
} else {
return [];
}
}
async getLastUsedForUrl(url: string): Promise<CipherView> { async getLastUsedForUrl(url: string): Promise<CipherView> {
const ciphers = await this.getAllDecryptedForUrl(url); const ciphers = await this.getAllDecryptedForUrl(url);
if (ciphers.length === 0) { if (ciphers.length === 0) {