From b5f8b1014e1e141a214572f6a2e4d6b6dea7ea6a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 27 Apr 2017 14:47:44 -0400 Subject: [PATCH] add/edit logins from org admin vault --- src/app/global/mainController.js | 8 +++ .../organizationVaultAddLoginController.js | 50 ++++++++++++++ .../organizationVaultController.js | 43 ++++++++++++ .../organizationVaultEditLoginController.js | 69 +++++++++++++++++++ .../organization/views/organizationVault.html | 11 ++- src/app/services/apiService.js | 3 + src/app/vault/vaultEditLoginController.js | 1 + src/app/vault/views/vaultAddLogin.html | 4 +- src/app/vault/views/vaultEditLogin.html | 4 +- src/app/views/organizationLayout.html | 15 ++++ src/app/views/userLayout.html | 2 +- src/index.html | 2 + 12 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 src/app/organization/organizationVaultAddLoginController.js create mode 100644 src/app/organization/organizationVaultEditLoginController.js diff --git a/src/app/global/mainController.js b/src/app/global/mainController.js index 67dd8bf6d4..fdf4928f9b 100644 --- a/src/app/global/mainController.js +++ b/src/app/global/mainController.js @@ -44,6 +44,10 @@ angular $state.go('backend.user.vault'); }; + $scope.searchOrganizationVault = function () { + $state.go('backend.org.vault', { orgId: $state.params.orgId }); + }; + $scope.addLogin = function () { $scope.$broadcast('vaultAddLogin'); }; @@ -52,6 +56,10 @@ angular $scope.$broadcast('vaultAddFolder'); }; + $scope.addOrganizationLogin = function () { + $scope.$broadcast('organizationVaultAddLogin'); + }; + // Append dropdown menu somewhere else var bodyScrollbarWidth, appendedDropdownMenu, diff --git a/src/app/organization/organizationVaultAddLoginController.js b/src/app/organization/organizationVaultAddLoginController.js new file mode 100644 index 0000000000..d529c80ce6 --- /dev/null +++ b/src/app/organization/organizationVaultAddLoginController.js @@ -0,0 +1,50 @@ +angular + .module('bit.vault') + + .controller('organizationVaultAddLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, + cipherService, passwordService, $analytics, orgId) { + $analytics.eventTrack('organizationVaultAddLoginController', { category: 'Modal' }); + $scope.login = {}; + $scope.hideFolders = $scope.hideFavorite = true; + + $scope.savePromise = null; + $scope.save = function (model) { + model.organizationId = orgId; + var login = cipherService.encryptLogin(model); + $scope.savePromise = apiService.logins.postAdmin(login, function (loginResponse) { + $analytics.eventTrack('Created Organization Login'); + var decLogin = cipherService.decryptLogin(loginResponse); + $uibModalInstance.close(decLogin); + }).$promise; + }; + + $scope.generatePassword = function () { + if (!$scope.login.password || confirm('Are you sure you want to overwrite the current password?')) { + $analytics.eventTrack('Generated Password From Add'); + $scope.login.password = passwordService.generatePassword({ length: 12, special: true }); + } + }; + + $scope.clipboardSuccess = function (e) { + e.clearSelection(); + selectPassword(e); + }; + + $scope.clipboardError = function (e, password) { + if (password) { + selectPassword(e); + } + alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); + }; + + function selectPassword(e) { + var target = $(e.trigger).parent().prev(); + if (target.attr('type') === 'text') { + target.select(); + } + } + + $scope.close = function () { + $uibModalInstance.dismiss('close'); + }; + }); diff --git a/src/app/organization/organizationVaultController.js b/src/app/organization/organizationVaultController.js index f72a4c9b8f..4d3517f2f5 100644 --- a/src/app/organization/organizationVaultController.js +++ b/src/app/organization/organizationVaultController.js @@ -77,6 +77,49 @@ } }; + $scope.editLogin = function (login) { + var editModel = $uibModal.open({ + animation: true, + templateUrl: 'app/vault/views/vaultEditLogin.html', + controller: 'organizationVaultEditLoginController', + resolve: { + loginId: function () { return login.id; } + } + }); + + editModel.result.then(function (returnVal) { + if (returnVal.action === 'edit') { + login.name = returnVal.data.name; + login.username = returnVal.data.username; + } + else if (returnVal.action === 'delete') { + var index = $scope.logins.indexOf(login); + if (index > -1) { + $scope.logins.splice(index, 1); + } + } + }); + }; + + $scope.$on('organizationVaultAddLogin', function (event, args) { + $scope.addLogin(); + }); + + $scope.addLogin = function () { + var addModel = $uibModal.open({ + animation: true, + templateUrl: 'app/vault/views/vaultAddLogin.html', + controller: 'organizationVaultAddLoginController', + resolve: { + orgId: function () { return $state.params.orgId; } + } + }); + + addModel.result.then(function (addedLogin) { + $scope.logins.push(addedLogin); + }); + }; + $scope.editCollections = function (cipher) { var modal = $uibModal.open({ animation: true, diff --git a/src/app/organization/organizationVaultEditLoginController.js b/src/app/organization/organizationVaultEditLoginController.js new file mode 100644 index 0000000000..84aea7f71e --- /dev/null +++ b/src/app/organization/organizationVaultEditLoginController.js @@ -0,0 +1,69 @@ +angular + .module('bit.vault') + + .controller('organizationVaultEditLoginController', function ($scope, apiService, $uibModalInstance, cryptoService, + cipherService, passwordService, loginId, $analytics) { + $analytics.eventTrack('organizationVaultEditLoginController', { category: 'Modal' }); + $scope.login = {}; + $scope.hideFolders = $scope.hideFavorite = true; + + apiService.logins.getAdmin({ id: loginId }, function (login) { + $scope.login = cipherService.decryptLogin(login); + }); + + $scope.save = function (model) { + var login = cipherService.encryptLogin(model); + $scope.savePromise = apiService.logins.putAdmin({ id: loginId }, login, function (loginResponse) { + $analytics.eventTrack('Edited Organization Login'); + var decLogin = cipherService.decryptLogin(loginResponse); + $uibModalInstance.close({ + action: 'edit', + data: decLogin + }); + }).$promise; + }; + + $scope.generatePassword = function () { + if (!$scope.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.clipboardSuccess = function (e) { + e.clearSelection(); + selectPassword(e); + }; + + $scope.clipboardError = function (e, password) { + if (password) { + selectPassword(e); + } + alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); + }; + + function selectPassword(e) { + var target = $(e.trigger).parent().prev(); + if (target.attr('type') === 'text') { + target.select(); + } + } + + $scope.delete = function () { + if (!confirm('Are you sure you want to delete this login (' + $scope.login.name + ')?')) { + return; + } + + apiService.ciphers.delAdmin({ id: $scope.login.id }, function () { + $analytics.eventTrack('Deleted Organization Login From Edit'); + $uibModalInstance.close({ + action: 'delete', + data: $scope.login.id + }); + }); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/views/organizationVault.html b/src/app/organization/views/organizationVault.html index 0f2df3d238..537dcbb568 100644 --- a/src/app/organization/views/organizationVault.html +++ b/src/app/organization/views/organizationVault.html @@ -13,7 +13,7 @@

Loading...

+ ng-show="collections.length && (!main.searchVaultText || collectionLogins.length)">

@@ -34,13 +34,18 @@ + filter: (main.searchVaultText || '') | orderBy: ['name', 'username']) track by login.id"> diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 6743071eeb..23539a3b72 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -7,9 +7,12 @@ _service.logins = $resource(_apiUri + '/logins/:id', {}, { get: { method: 'GET', params: { id: '@id' } }, + getAdmin: { url: _apiUri + '/logins/:id/admin', method: 'GET', params: { id: '@id' } }, list: { method: 'GET', params: {} }, post: { method: 'POST', params: {} }, + postAdmin: { url: _apiUri + '/logins/admin', method: 'POST', params: {} }, put: { method: 'POST', params: { id: '@id' } }, + putAdmin: { url: _apiUri + '/logins/:id/admin', method: 'POST', params: { id: '@id' } }, del: { url: _apiUri + '/logins/:id/delete', method: 'POST', params: { id: '@id' } } }); diff --git a/src/app/vault/vaultEditLoginController.js b/src/app/vault/vaultEditLoginController.js index f3554c681c..b3432942f5 100644 --- a/src/app/vault/vaultEditLoginController.js +++ b/src/app/vault/vaultEditLoginController.js @@ -79,6 +79,7 @@ } apiService.logins.del({ id: $scope.login.id }, function () { + $analytics.eventTrack('Deleted Login From Edit'); $uibModalInstance.close({ action: 'delete', data: $scope.login.id diff --git a/src/app/vault/views/vaultAddLogin.html b/src/app/vault/views/vaultAddLogin.html index eb29f64146..dbb433ef2b 100644 --- a/src/app/vault/views/vaultAddLogin.html +++ b/src/app/vault/views/vaultAddLogin.html @@ -17,7 +17,7 @@ -
+
-
+
-
+
-
+
+ + +
+ + +
+
- {{login.name}} + {{login.name}}
{{login.username}}