admin cipher apis

This commit is contained in:
Kyle Spearrin 2018-07-05 09:42:13 -04:00
parent 278b4402da
commit 9b008ff382
3 changed files with 62 additions and 3 deletions

View File

@ -80,20 +80,28 @@ export abstract class ApiService {
postFolder: (request: FolderRequest) => Promise<FolderResponse>;
putFolder: (id: string, request: FolderRequest) => Promise<FolderResponse>;
deleteFolder: (id: string) => Promise<any>;
getCipher: (id: string) => Promise<CipherResponse>;
getCipherAdmin: (id: string) => Promise<CipherResponse>;
getCiphersOrganization: (organizationId: string) => Promise<ListResponse<CipherResponse>>;
postCipher: (request: CipherRequest) => Promise<CipherResponse>;
postCipherAdmin: (request: CipherRequest) => Promise<CipherResponse>;
putCipher: (id: string, request: CipherRequest) => Promise<CipherResponse>;
putCipherAdmin: (id: string, request: CipherRequest) => Promise<CipherResponse>;
deleteCipher: (id: string) => Promise<any>;
deleteCipherAdmin: (id: string) => Promise<any>;
deleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise<any>;
putMoveCiphers: (request: CipherBulkMoveRequest) => Promise<any>;
putShareCipher: (id: string, request: CipherShareRequest) => Promise<any>;
putShareCiphers: (request: CipherBulkShareRequest) => Promise<any>;
putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise<any>;
putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise<any>;
postPurgeCiphers: (request: PasswordVerificationRequest) => Promise<any>;
postImportCiphers: (request: ImportCiphersRequest) => Promise<any>;
postImportOrganizationCiphers: (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>;
deleteCipherAttachmentAdmin: (id: string, attachmentId: string) => Promise<any>;
postShareCipherAttachment: (id: string, attachmentId: string, data: FormData,
organizationId: string) => Promise<any>;
getCollections: (organizationId: string) => Promise<ListResponse<CollectionResponse>>;

View File

@ -19,6 +19,8 @@ import { I18nService } from '../../abstractions/i18n.service';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
import { StateService } from '../../abstractions/state.service';
import { Cipher } from '../../models/domain/cipher';
import { CardView } from '../../models/view/cardView';
import { CipherView } from '../../models/view/cipherView';
import { FieldView } from '../../models/view/fieldView';
@ -130,7 +132,7 @@ export class AddEditComponent {
await this.stateService.remove('addEditCipher');
if (this.cipher == null) {
if (this.editMode) {
const cipher = await this.cipherService.get(this.cipherId);
const cipher = await this.loadCipher();
this.cipher = await cipher.decrypt();
} else {
this.cipher = new CipherView();
@ -163,7 +165,7 @@ export class AddEditComponent {
const cipher = await this.cipherService.encrypt(this.cipher);
try {
this.formPromise = this.cipherService.saveWithServer(cipher);
this.formPromise = this.saveCipher(cipher);
await this.formPromise;
this.cipher.id = cipher.id;
this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Cipher' : 'Added Cipher' });
@ -233,7 +235,7 @@ export class AddEditComponent {
}
try {
this.deletePromise = this.cipherService.deleteWithServer(this.cipher.id);
this.deletePromise = this.deleteCipher();
await this.deletePromise;
this.analytics.eventTrack.next({ action: 'Deleted Cipher' });
this.toasterService.popAsync('success', null, this.i18nService.t('deletedItem'));
@ -304,4 +306,16 @@ export class AddEditComponent {
this.toasterService.popAsync('success', null, this.i18nService.t('passwordSafe'));
}
}
protected loadCipher() {
return this.cipherService.get(this.cipherId);
}
protected saveCipher(cipher: Cipher) {
return this.cipherService.saveWithServer(cipher);
}
protected deleteCipher() {
return this.cipherService.deleteWithServer(this.cipher.id);
}
}

View File

@ -242,6 +242,16 @@ export class ApiService implements ApiServiceAbstraction {
// Cipher APIs
async getCipher(id: string): Promise<CipherResponse> {
const r = await this.send('GET', '/ciphers/' + id, null, true, true);
return new CipherResponse(r);
}
async getCipherAdmin(id: string): Promise<CipherResponse> {
const r = await this.send('GET', '/ciphers/' + id + '/admin', null, true, true);
return new CipherResponse(r);
}
async getCiphersOrganization(organizationId: string): Promise<ListResponse<CipherResponse>> {
const r = await this.send('GET', '/ciphers/organization-details?organizationId=' + organizationId,
null, true, true);
@ -253,15 +263,29 @@ export class ApiService implements ApiServiceAbstraction {
return new CipherResponse(r);
}
async postCipherAdmin(request: CipherRequest): Promise<CipherResponse> {
const r = await this.send('POST', '/ciphers/admin', request, true, true);
return new CipherResponse(r);
}
async putCipher(id: string, request: CipherRequest): Promise<CipherResponse> {
const r = await this.send('PUT', '/ciphers/' + id, request, true, true);
return new CipherResponse(r);
}
async putCipherAdmin(id: string, request: CipherRequest): Promise<CipherResponse> {
const r = await this.send('PUT', '/ciphers/' + id + '/admin', request, true, true);
return new CipherResponse(r);
}
deleteCipher(id: string): Promise<any> {
return this.send('DELETE', '/ciphers/' + id, null, true, false);
}
deleteCipherAdmin(id: string): Promise<any> {
return this.send('DELETE', '/ciphers/' + id + '/admin', null, true, false);
}
deleteManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
return this.send('DELETE', '/ciphers', request, true, false);
}
@ -282,6 +306,10 @@ export class ApiService implements ApiServiceAbstraction {
return this.send('PUT', '/ciphers/' + id + '/collections', request, true, false);
}
putCipherCollectionsAdmin(id: string, request: CipherCollectionsRequest): Promise<any> {
return this.send('PUT', '/ciphers/' + id + '/collections-admin', request, true, false);
}
postPurgeCiphers(request: PasswordVerificationRequest): Promise<any> {
return this.send('POST', '/ciphers/purge', request, true, false);
}
@ -301,10 +329,19 @@ export class ApiService implements ApiServiceAbstraction {
return new CipherResponse(r);
}
async postCipherAttachmentAdmin(id: string, data: FormData): Promise<CipherResponse> {
const r = await this.send('POST', '/ciphers/' + id + '/attachment-admin', data, true, true);
return new CipherResponse(r);
}
deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId, null, true, false);
}
deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise<any> {
return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId + '/admin', null, true, false);
}
postShareCipherAttachment(id: string, attachmentId: string, data: FormData,
organizationId: string): Promise<any> {
return this.send('POST', '/ciphers/' + id + '/attachment/' +