mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
org import and collection encrypt function
This commit is contained in:
parent
ed93fa9ea3
commit
a600c4a539
@ -97,7 +97,7 @@ export abstract class ApiService {
|
|||||||
putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise<any>;
|
putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise<any>;
|
||||||
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
|
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
|
||||||
postImportCiphers: (request: ImportCiphersRequest) => 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>;
|
postCipherAttachment: (id: string, data: FormData) => Promise<CipherResponse>;
|
||||||
postCipherAttachmentAdmin: (id: string, data: FormData) => Promise<CipherResponse>;
|
postCipherAttachmentAdmin: (id: string, data: FormData) => Promise<CipherResponse>;
|
||||||
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
|
deleteCipherAttachment: (id: string, attachmentId: string) => Promise<any>;
|
||||||
|
@ -8,6 +8,7 @@ export abstract class CollectionService {
|
|||||||
decryptedCollectionCache: CollectionView[];
|
decryptedCollectionCache: CollectionView[];
|
||||||
|
|
||||||
clearCache: () => void;
|
clearCache: () => void;
|
||||||
|
encrypt: (model: CollectionView) => Promise<Collection>;
|
||||||
get: (id: string) => Promise<Collection>;
|
get: (id: string) => Promise<Collection>;
|
||||||
getAll: () => Promise<Collection[]>;
|
getAll: () => Promise<Collection[]>;
|
||||||
getAllDecrypted: () => Promise<CollectionView[]>;
|
getAllDecrypted: () => Promise<CollectionView[]>;
|
||||||
|
@ -3,7 +3,7 @@ import { CollectionRequest } from './collectionRequest';
|
|||||||
import { KvpRequest } from './kvpRequest';
|
import { KvpRequest } from './kvpRequest';
|
||||||
|
|
||||||
export class ImportOrganizationCiphersRequest {
|
export class ImportOrganizationCiphersRequest {
|
||||||
ciphers: CipherRequest[];
|
ciphers: CipherRequest[] = [];
|
||||||
collections: CollectionRequest[];
|
collections: CollectionRequest[] = [];
|
||||||
collectionRelationships: Array<KvpRequest<number, number>>;
|
collectionRelationships: Array<KvpRequest<number, number>> = [];
|
||||||
}
|
}
|
||||||
|
@ -318,8 +318,8 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
return this.send('POST', '/ciphers/import', request, true, false);
|
return this.send('POST', '/ciphers/import', request, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
postImportOrganizationCiphers(request: ImportOrganizationCiphersRequest): Promise<any> {
|
postImportOrganizationCiphers(organizationId: string, request: ImportOrganizationCiphersRequest): Promise<any> {
|
||||||
return this.send('POST', '/ciphers/import-organization', request, true, false);
|
return this.send('POST', '/ciphers/import-organization?organizationId=' + organizationId, request, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attachments APIs
|
// Attachments APIs
|
||||||
|
@ -25,6 +25,22 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
this.decryptedCollectionCache = null;
|
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> {
|
async get(id: string): Promise<Collection> {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||||
|
Loading…
Reference in New Issue
Block a user