From 9b008ff382d1dd6682185cf092afbf02a83ce951 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 5 Jul 2018 09:42:13 -0400 Subject: [PATCH] admin cipher apis --- src/abstractions/api.service.ts | 8 +++++ src/angular/components/add-edit.component.ts | 20 +++++++++-- src/services/api.service.ts | 37 ++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index c8bac36130..b466f04f45 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -80,20 +80,28 @@ export abstract class ApiService { postFolder: (request: FolderRequest) => Promise; putFolder: (id: string, request: FolderRequest) => Promise; deleteFolder: (id: string) => Promise; + getCipher: (id: string) => Promise; + getCipherAdmin: (id: string) => Promise; getCiphersOrganization: (organizationId: string) => Promise>; postCipher: (request: CipherRequest) => Promise; + postCipherAdmin: (request: CipherRequest) => Promise; putCipher: (id: string, request: CipherRequest) => Promise; + putCipherAdmin: (id: string, request: CipherRequest) => Promise; deleteCipher: (id: string) => Promise; + deleteCipherAdmin: (id: string) => Promise; deleteManyCiphers: (request: CipherBulkDeleteRequest) => Promise; putMoveCiphers: (request: CipherBulkMoveRequest) => Promise; putShareCipher: (id: string, request: CipherShareRequest) => Promise; putShareCiphers: (request: CipherBulkShareRequest) => Promise; putCipherCollections: (id: string, request: CipherCollectionsRequest) => Promise; + putCipherCollectionsAdmin: (id: string, request: CipherCollectionsRequest) => Promise; postPurgeCiphers: (request: PasswordVerificationRequest) => Promise; postImportCiphers: (request: ImportCiphersRequest) => Promise; postImportOrganizationCiphers: (request: ImportOrganizationCiphersRequest) => Promise; postCipherAttachment: (id: string, data: FormData) => Promise; + postCipherAttachmentAdmin: (id: string, data: FormData) => Promise; deleteCipherAttachment: (id: string, attachmentId: string) => Promise; + deleteCipherAttachmentAdmin: (id: string, attachmentId: string) => Promise; postShareCipherAttachment: (id: string, attachmentId: string, data: FormData, organizationId: string) => Promise; getCollections: (organizationId: string) => Promise>; diff --git a/src/angular/components/add-edit.component.ts b/src/angular/components/add-edit.component.ts index 3034c377f2..654353c28a 100644 --- a/src/angular/components/add-edit.component.ts +++ b/src/angular/components/add-edit.component.ts @@ -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); + } } diff --git a/src/services/api.service.ts b/src/services/api.service.ts index a81cf77c34..a8aee56913 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -242,6 +242,16 @@ export class ApiService implements ApiServiceAbstraction { // Cipher APIs + async getCipher(id: string): Promise { + const r = await this.send('GET', '/ciphers/' + id, null, true, true); + return new CipherResponse(r); + } + + async getCipherAdmin(id: string): Promise { + const r = await this.send('GET', '/ciphers/' + id + '/admin', null, true, true); + return new CipherResponse(r); + } + async getCiphersOrganization(organizationId: string): Promise> { 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 { + const r = await this.send('POST', '/ciphers/admin', request, true, true); + return new CipherResponse(r); + } + async putCipher(id: string, request: CipherRequest): Promise { const r = await this.send('PUT', '/ciphers/' + id, request, true, true); return new CipherResponse(r); } + async putCipherAdmin(id: string, request: CipherRequest): Promise { + const r = await this.send('PUT', '/ciphers/' + id + '/admin', request, true, true); + return new CipherResponse(r); + } + deleteCipher(id: string): Promise { return this.send('DELETE', '/ciphers/' + id, null, true, false); } + deleteCipherAdmin(id: string): Promise { + return this.send('DELETE', '/ciphers/' + id + '/admin', null, true, false); + } + deleteManyCiphers(request: CipherBulkDeleteRequest): Promise { 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 { + return this.send('PUT', '/ciphers/' + id + '/collections-admin', request, true, false); + } + postPurgeCiphers(request: PasswordVerificationRequest): Promise { 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 { + const r = await this.send('POST', '/ciphers/' + id + '/attachment-admin', data, true, true); + return new CipherResponse(r); + } + deleteCipherAttachment(id: string, attachmentId: string): Promise { return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId, null, true, false); } + deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise { + return this.send('DELETE', '/ciphers/' + id + '/attachment/' + attachmentId + '/admin', null, true, false); + } + postShareCipherAttachment(id: string, attachmentId: string, data: FormData, organizationId: string): Promise { return this.send('POST', '/ciphers/' + id + '/attachment/' +