1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-02 08:40:08 +01:00

[jslib] Updated shared components for cipher cloning (#60)

This commit is contained in:
Vincent Salucci 2020-01-28 16:19:50 -06:00 committed by GitHub
parent e1d42f95d9
commit 337a7ba59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -42,6 +42,7 @@ import { SecureNoteView } from '../../models/view/secureNoteView';
import { Utils } from '../../misc/utils';
export class AddEditComponent implements OnInit {
@Input() cloneMode: boolean = false;
@Input() folderId: string = null;
@Input() cipherId: string;
@Input() type: CipherType;
@ -160,7 +161,12 @@ export class AddEditComponent implements OnInit {
this.editMode = this.cipherId != null;
if (this.editMode) {
this.editMode = true;
this.title = this.i18nService.t('editItem');
if (this.cloneMode) {
this.cloneMode = true;
this.title = this.i18nService.t('addItem');
} else{
this.title = this.i18nService.t('editItem');
}
} else {
this.title = this.i18nService.t('addItem');
}
@ -176,6 +182,11 @@ export class AddEditComponent implements OnInit {
if (this.editMode) {
const cipher = await this.loadCipher();
this.cipher = await cipher.decrypt();
// Adjust Cipher Name if Cloning
if (this.cloneMode) {
this.cipher.name += " - " + this.i18nService.t('clone');
}
} else {
this.cipher = new CipherView();
this.cipher.organizationId = this.organizationId == null ? null : this.organizationId;
@ -227,16 +238,21 @@ export class AddEditComponent implements OnInit {
this.collections.filter((c) => (c as any).checked).map((c) => c.id);
}
// Clear current Cipher Id to trigger "Add" cipher flow
if (this.cloneMode) {
this.cipher.id = null;
}
const cipher = await this.encryptCipher();
try {
this.formPromise = this.saveCipher(cipher);
await this.formPromise;
this.cipher.id = cipher.id;
this.platformUtilsService.eventTrack(this.editMode ? 'Edited Cipher' : 'Added Cipher');
this.platformUtilsService.eventTrack(this.editMode && !this.cloneMode ? 'Edited Cipher' : 'Added Cipher');
this.platformUtilsService.showToast('success', null,
this.i18nService.t(this.editMode ? 'editedItem' : 'addedItem'));
this.i18nService.t(this.editMode && !this.cloneMode ? 'editedItem' : 'addedItem'));
this.onSavedCipher.emit(this.cipher);
this.messagingService.send(this.editMode ? 'editedCipher' : 'addedCipher');
this.messagingService.send(this.editMode && !this.cloneMode ? 'editedCipher' : 'addedCipher');
return true;
} catch { }

View File

@ -33,6 +33,7 @@ const BroadcasterSubscriptionId = 'ViewComponent';
export class ViewComponent implements OnDestroy, OnInit {
@Input() cipherId: string;
@Output() onEditCipher = new EventEmitter<CipherView>();
@Output() onCloneCipher = new EventEmitter<CipherView>();
cipher: CipherView;
showPassword: boolean;
@ -105,6 +106,10 @@ export class ViewComponent implements OnDestroy, OnInit {
this.onEditCipher.emit(this.cipher);
}
clone() {
this.onCloneCipher.emit(this.cipher);
}
togglePassword() {
this.platformUtilsService.eventTrack('Toggled Password');
this.showPassword = !this.showPassword;