From c4d2045884607849d261a58da131aa53ecb6ed98 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 6 Oct 2017 21:24:04 -0400 Subject: [PATCH] convert edit to generic ciphers --- src/app/constants.js | 11 + src/app/vault/vaultController.js | 24 +- ...roller.js => vaultEditCipherController.js} | 61 ++--- src/app/vault/views/vaultEditCipher.html | 254 ++++++++++++++++++ src/app/vault/views/vaultEditLogin.html | 192 ------------- src/index.html | 2 +- 6 files changed, 309 insertions(+), 235 deletions(-) rename src/app/vault/{vaultEditLoginController.js => vaultEditCipherController.js} (59%) create mode 100644 src/app/vault/views/vaultEditCipher.html delete mode 100644 src/app/vault/views/vaultEditLogin.html diff --git a/src/app/constants.js b/src/app/constants.js index 0b729f5de6..b88f1e8f3f 100644 --- a/src/app/constants.js +++ b/src/app/constants.js @@ -28,6 +28,17 @@ angular.module('bit') email: 1, remember: 5 }, + cipherType: { + login: 1, + secureNote: 2, + card: 3, + identity: 4 + }, + fieldType: { + text: 0, + hidden: 1, + boolean: 2 + }, twoFactorProviderInfo: [ { type: 0, diff --git a/src/app/vault/vaultController.js b/src/app/vault/vaultController.js index 2505c6452d..d406f2fc23 100644 --- a/src/app/vault/vaultController.js +++ b/src/app/vault/vaultController.js @@ -137,32 +137,32 @@ } }; - $scope.editLogin = function (login) { + $scope.editLogin = function (cipher) { var editModel = $uibModal.open({ animation: true, - templateUrl: 'app/vault/views/vaultEditLogin.html', - controller: 'vaultEditLoginController', + templateUrl: 'app/vault/views/vaultEditCipher.html', + controller: 'vaultEditCipherController', resolve: { - loginId: function () { return login.id; } + cipherId: function () { return cipher.id; } } }); editModel.result.then(function (returnVal) { if (returnVal.action === 'edit') { - login.folderId = returnVal.data.folderId; - login.name = returnVal.data.name; - login.username = returnVal.data.username; - login.password = returnVal.data.password; - login.favorite = returnVal.data.favorite; + cipher.folderId = returnVal.data.folderId; + cipher.name = returnVal.data.name; + cipher.username = returnVal.data.login.username; + cipher.password = returnVal.data.login.password; + cipher.favorite = returnVal.data.favorite; sortScopedLoginData(); } else if (returnVal.action === 'partialEdit') { - login.folderId = returnVal.data.folderId; - login.favorite = returnVal.data.favorite; + cipher.folderId = returnVal.data.folderId; + cipher.favorite = returnVal.data.favorite; } else if (returnVal.action === 'delete') { - removeLoginFromScopes(login); + removeLoginFromScopes(cipher); } }); }; diff --git a/src/app/vault/vaultEditLoginController.js b/src/app/vault/vaultEditCipherController.js similarity index 59% rename from src/app/vault/vaultEditLoginController.js rename to src/app/vault/vaultEditCipherController.js index 2906ecc3b8..9c5ebb55f3 100644 --- a/src/app/vault/vaultEditLoginController.js +++ b/src/app/vault/vaultEditCipherController.js @@ -1,33 +1,34 @@ angular .module('bit.vault') - .controller('vaultEditLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, - passwordService, loginId, $analytics, $rootScope, authService, $uibModal) { - $analytics.eventTrack('vaultEditLoginController', { category: 'Modal' }); + .controller('vaultEditCipherController', function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, + passwordService, cipherId, $analytics, $rootScope, authService, $uibModal, constants) { + $analytics.eventTrack('vaultEditCipherController', { category: 'Modal' }); $scope.folders = $rootScope.vaultFolders; - $scope.login = {}; + $scope.cipher = {}; $scope.readOnly = false; + $scope.constants = constants; authService.getUserProfile().then(function (profile) { $scope.useTotp = profile.premium; - return apiService.ciphers.get({ id: loginId }).$promise; - }).then(function (login) { - $scope.login = cipherService.decryptLogin(login); - $scope.readOnly = !$scope.login.edit; - $scope.useTotp = $scope.useTotp || $scope.login.organizationUseTotp; + return apiService.ciphers.get({ id: cipherId }).$promise; + }).then(function (cipher) { + $scope.cipher = cipherService.decryptCipher(cipher); + $scope.readOnly = !$scope.cipher.edit; + $scope.useTotp = $scope.useTotp || $scope.cipher.organizationUseTotp; }); $scope.save = function (model) { if ($scope.readOnly) { - $scope.savePromise = apiService.ciphers.putPartial({ id: loginId }, { + $scope.savePromise = apiService.ciphers.putPartial({ id: cipherId }, { folderId: model.folderId, favorite: model.favorite }, function (response) { - $analytics.eventTrack('Partially Edited Login'); + $analytics.eventTrack('Partially Edited Cipher'); $uibModalInstance.close({ action: 'partialEdit', data: { - id: loginId, + id: cipherId, favorite: model.favorite, folderId: model.folderId && model.folderId !== '' ? model.folderId : null } @@ -35,46 +36,46 @@ }).$promise; } else { - var login = cipherService.encryptLogin(model); - $scope.savePromise = apiService.ciphers.put({ id: loginId }, login, function (loginResponse) { - $analytics.eventTrack('Edited Login'); - var decLogin = cipherService.decryptLogin(loginResponse); + var cipher = cipherService.encryptCipher(model, $scope.cipher.type); + $scope.savePromise = apiService.ciphers.put({ id: cipherId }, cipher, function (cipherResponse) { + $analytics.eventTrack('Edited Cipher'); + var decCipher = cipherService.decryptCipher(cipherResponse); $uibModalInstance.close({ action: 'edit', - data: decLogin + data: decCipher }); }).$promise; } }; $scope.generatePassword = function () { - if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) { + if (!$scope.cipher.login.password || confirm('Are you sure you want to overwrite the current password?')) { $analytics.eventTrack('Generated Password From Edit'); - $scope.login.password = passwordService.generatePassword({ length: 12, special: true }); + $scope.cipher.login.password = passwordService.generatePassword({ length: 12, special: true }); } }; $scope.addField = function () { - if (!$scope.login.fields) { - $scope.login.fields = []; + if (!$scope.cipher.fields) { + $scope.cipher.fields = []; } - $scope.login.fields.push({ - type: '0', + $scope.cipher.fields.push({ + type: constants.fieldType.text, name: null, value: null }); }; $scope.removeField = function (field) { - var index = $scope.login.fields.indexOf(field); + var index = $scope.cipher.fields.indexOf(field); if (index > -1) { - $scope.login.fields.splice(index, 1); + $scope.cipher.fields.splice(index, 1); } }; $scope.toggleFavorite = function () { - $scope.login.favorite = !$scope.login.favorite; + $scope.cipher.favorite = !$scope.cipher.favorite; }; $scope.clipboardSuccess = function (e) { @@ -105,15 +106,15 @@ } $scope.delete = function () { - if (!confirm('Are you sure you want to delete this login (' + $scope.login.name + ')?')) { + if (!confirm('Are you sure you want to delete this item (' + $scope.cipher.name + ')?')) { return; } - apiService.ciphers.del({ id: $scope.login.id }, function () { - $analytics.eventTrack('Deleted Login From Edit'); + apiService.ciphers.del({ id: $scope.cipher.id }, function () { + $analytics.eventTrack('Deleted Cipher From Edit'); $uibModalInstance.close({ action: 'delete', - data: $scope.login.id + data: $scope.cipher.id }); }); }; diff --git a/src/app/vault/views/vaultEditCipher.html b/src/app/vault/views/vaultEditCipher.html new file mode 100644 index 0000000000..76d51bba94 --- /dev/null +++ b/src/app/vault/views/vaultEditCipher.html @@ -0,0 +1,254 @@ + +
+ + +
diff --git a/src/app/vault/views/vaultEditLogin.html b/src/app/vault/views/vaultEditLogin.html deleted file mode 100644 index 35c9ec0e15..0000000000 --- a/src/app/vault/views/vaultEditLogin.html +++ /dev/null @@ -1,192 +0,0 @@ - -
- - -
diff --git a/src/index.html b/src/index.html index 09336e40a1..db2ff45947 100644 --- a/src/index.html +++ b/src/index.html @@ -210,7 +210,7 @@ - +