From 6ea0ce5287b8bf9a120e807e5d44ff8cb060d8ff Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Fri, 10 Apr 2020 16:42:34 -0400 Subject: [PATCH] [Sot Delete] update to view and i18n for delete --- src/angular/components/add-edit.component.ts | 4 +- src/angular/components/view.component.ts | 55 ++++++++++++++++++-- src/services/cipher.service.ts | 6 +++ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/angular/components/add-edit.component.ts b/src/angular/components/add-edit.component.ts index 40d3261d63..389f6d4908 100644 --- a/src/angular/components/add-edit.component.ts +++ b/src/angular/components/add-edit.component.ts @@ -328,8 +328,8 @@ export class AddEditComponent implements OnInit { async delete(): Promise { const confirmed = await this.platformUtilsService.showDialog( - this.i18nService.t('deleteItemConfirmation'), this.i18nService.t('deleteItem'), - this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); + this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeleteItemConfirmation' : 'deleteItemConfirmation'), + this.i18nService.t('deleteItem'), this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); if (!confirmed) { return false; } diff --git a/src/angular/components/view.component.ts b/src/angular/components/view.component.ts index d325a5f895..7e9d97894e 100644 --- a/src/angular/components/view.component.ts +++ b/src/angular/components/view.component.ts @@ -27,6 +27,7 @@ import { CipherView } from '../../models/view/cipherView'; import { FieldView } from '../../models/view/fieldView'; import { LoginUriView } from '../../models/view/loginUriView'; import { BroadcasterService } from '../services/broadcaster.service'; +import { Cipher } from '../../models/domain'; const BroadcasterSubscriptionId = 'ViewComponent'; @@ -34,7 +35,8 @@ export class ViewComponent implements OnDestroy, OnInit { @Input() cipherId: string; @Output() onEditCipher = new EventEmitter(); @Output() onCloneCipher = new EventEmitter(); - @Output() onRestoreCipher = new EventEmitter(); + @Output() onRestoredCipher = new EventEmitter(); + @Output() onDeletedCipher = new EventEmitter(); cipher: CipherView; showPassword: boolean; @@ -111,11 +113,45 @@ export class ViewComponent implements OnDestroy, OnInit { this.onCloneCipher.emit(this.cipher); } - restore() { - if (!this.cipher.isDeleted) { - return; + async delete(): Promise { + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeleteItemConfirmation' : 'deleteItemConfirmation'), + this.i18nService.t('deleteItem'), this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); + if (!confirmed) { + return false; } - this.onRestoreCipher.emit(this.cipher); + + try { + await this.deleteCipher(); + this.platformUtilsService.eventTrack((this.cipher.isDeleted ? 'Permanently ' : '') + 'Deleted Cipher'); + this.platformUtilsService.showToast('success', null, + this.i18nService.t(this.cipher.isDeleted ? 'permanentlyDeletedItem' : 'deletedItem')); + this.onDeletedCipher.emit(this.cipher); + } catch { } + + return true; + } + + async restore(): Promise { + if (!this.cipher.isDeleted) { + return false; + } + + const confirmed = await this.platformUtilsService.showDialog( + this.i18nService.t('restoreItemConfirmation'), this.i18nService.t('restoreItem'), + this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); + if (!confirmed) { + return false; + } + + try { + await this.restoreCipher(); + this.platformUtilsService.eventTrack('Restored Cipher'); + this.platformUtilsService.showToast('success', null, this.i18nService.t('restoredItem')); + this.onRestoredCipher.emit(this.cipher); + } catch { } + + return true; } togglePassword() { @@ -225,6 +261,15 @@ export class ViewComponent implements OnDestroy, OnInit { a.downloading = false; } + protected deleteCipher() { + return this.cipher.isDeleted ? this.cipherService.deleteWithServer(this.cipher.id) + : this.cipherService.softDeleteWithServer(this.cipher.id); + } + + protected restoreCipher() { + return this.cipherService.restoreWithServer(this.cipher.id); + } + private cleanUp() { this.totpCode = null; this.cipher = null; diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index d2856d7449..7b519a1a4f 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -310,6 +310,9 @@ export class CipherService implements CipherServiceAbstraction { const ciphers = await this.getAllDecrypted(); return ciphers.filter((cipher) => { + if (cipher.isDeleted) { + return false; + } if (folder && cipher.folderId === groupingId) { return true; } else if (!folder && cipher.collectionIds != null && cipher.collectionIds.indexOf(groupingId) > -1) { @@ -352,6 +355,9 @@ export class CipherService implements CipherServiceAbstraction { } return ciphers.filter((cipher) => { + if (cipher.deletedDate != null) { + return false; + } if (includeOtherTypes != null && includeOtherTypes.indexOf(cipher.type) > -1) { return true; }