Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #97 from bitwarden/soft-delete
Browse files Browse the repository at this point in the history
[Soft Delete] - view component to handle soft delete and restore
  • Loading branch information
cscharf committed Apr 13, 2020
2 parents 8d796dc + 2227929 commit e9db844
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/angular/components/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ export class AddEditComponent implements OnInit {

async delete(): Promise<boolean> {
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;
}
Expand Down
52 changes: 48 additions & 4 deletions src/angular/components/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class ViewComponent implements OnDestroy, OnInit {
@Input() cipherId: string;
@Output() onEditCipher = new EventEmitter<CipherView>();
@Output() onCloneCipher = new EventEmitter<CipherView>();
@Output() onRestoreCipher = new EventEmitter<CipherView>();
@Output() onDeletedCipher = new EventEmitter<CipherView>();
@Output() onRestoredCipher = new EventEmitter<CipherView>();

cipher: CipherView;
showPassword: boolean;
Expand Down Expand Up @@ -111,11 +112,45 @@ export class ViewComponent implements OnDestroy, OnInit {
this.onCloneCipher.emit(this.cipher);
}

restore() {
async delete(): Promise<boolean> {
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;
}

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<boolean> {
if (!this.cipher.isDeleted) {
return;
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;
}
this.onRestoreCipher.emit(this.cipher);

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() {
Expand Down Expand Up @@ -225,6 +260,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;
Expand Down
6 changes: 6 additions & 0 deletions src/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e9db844

Please sign in to comment.