org import and collection encrypt function

This commit is contained in:
Kyle Spearrin 2018-07-05 23:38:27 -04:00
parent ed93fa9ea3
commit a600c4a539
5 changed files with 23 additions and 6 deletions

View File

@ -97,7 +97,7 @@ export abstract class ApiService {
putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise<any>;
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
postImportCiphers: (request: ImportCiphersRequest) => Promise<any>;
postImportOrganizationCiphers: (request: ImportOrganizationCiphersRequest) => Promise<any>;
postImportOrganizationCiphers: (organizationId: string, request: ImportOrganizationCiphersRequest) => Promise<any>;
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
postCipherAttachmentAdmin: (id: string, data: FormData) => Promise<CipherResponse>;
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;

View File

@ -8,6 +8,7 @@ export abstract class CollectionService {
decryptedCollectionCache: CollectionView[];
clearCache: () => void;
encrypt: (model: CollectionView) => Promise<Collection>;
get: (id: string) => Promise<Collection>;
getAll: () => Promise<Collection[]>;
getAllDecrypted: () => Promise<CollectionView[]>;

View File

@ -3,7 +3,7 @@ import { CollectionRequest } from './collectionRequest';
import { KvpRequest } from './kvpRequest';
export class ImportOrganizationCiphersRequest {
ciphers: CipherRequest[];
collections: CollectionRequest[];
collectionRelationships: Array<KvpRequest<number, number>>;
ciphers: CipherRequest[] = [];
collections: CollectionRequest[] = [];
collectionRelationships: Array<KvpRequest<number, number>> = [];
}

View File

@ -318,8 +318,8 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('POST', '/ciphers/import', request, true, false);
}
postImportOrganizationCiphers(request: ImportOrganizationCiphersRequest): Promise<any> {
return this.send('POST', '/ciphers/import-organization', request, true, false);
postImportOrganizationCiphers(organizationId: string, request: ImportOrganizationCiphersRequest): Promise<any> {
return this.send('POST', '/ciphers/import-organization?organizationId=' + organizationId, request, true, false);
}
// Attachments APIs

View File

@ -25,6 +25,22 @@ export class CollectionService implements CollectionServiceAbstraction {
this.decryptedCollectionCache = null;
}
async encrypt(model: CollectionView): Promise<Collection> {
if (model.organizationId == null) {
throw new Error('Collection has no organization id.');
}
const key = await this.cryptoService.getOrgKey(model.organizationId);
if (key == null) {
throw new Error('No key for this collection\'s organization.');
}
const collection = new Collection();
collection.id = model.id;
collection.organizationId = model.organizationId;
collection.readOnly = model.readOnly;
collection.name = await this.cryptoService.encrypt(model.name, key);
return collection;
}
async get(id: string): Promise<Collection> {
const userId = await this.userService.getUserId();
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(