From 0b9083915a5624a15a055d9ecc0108e8959e28ea Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 19 Apr 2017 09:57:47 -0400 Subject: [PATCH] remove login from individual subvault --- .../organizationVaultController.js | 22 ++++++++++++++++ .../organization/views/organizationVault.html | 2 +- src/app/vault/vaultSubvaultsController.js | 25 +++++++++++++++++++ src/app/vault/views/vaultSubvaults.html | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/app/organization/organizationVaultController.js b/src/app/organization/organizationVaultController.js index 982c7f7686..57fd5fdead 100644 --- a/src/app/organization/organizationVaultController.js +++ b/src/app/organization/organizationVaultController.js @@ -94,4 +94,26 @@ } }); }; + + $scope.removeLogin = function (login, subvault) { + if (!confirm('Are you sure you want to remove this login (' + login.name + ') from the ' + + 'subvault (' + subvault.name + ') ?')) { + return; + } + + var request = { + subvaultIds: [] + }; + + for (var i = 0; i < login.subvaultIds.length; i++) { + if (login.subvaultIds[i] !== subvault.id) { + request.subvaultIds.push(login.subvaultIds[i]); + } + } + + apiService.ciphers.putSubvaults({ id: login.id }, request).$promise.then(function (response) { + $analytics.eventTrack('Removed From Subvault'); + login.subvaultIds = request.subvaultIds; + }); + }; }); diff --git a/src/app/organization/views/organizationVault.html b/src/app/organization/views/organizationVault.html index 43e500c9e6..3fd7cc021d 100644 --- a/src/app/organization/views/organizationVault.html +++ b/src/app/organization/views/organizationVault.html @@ -47,7 +47,7 @@
  • - Remove diff --git a/src/app/vault/vaultSubvaultsController.js b/src/app/vault/vaultSubvaultsController.js index 5ca5225419..25b6fb4fed 100644 --- a/src/app/vault/vaultSubvaultsController.js +++ b/src/app/vault/vaultSubvaultsController.js @@ -113,6 +113,31 @@ }); }; + $scope.removeLogin = function (login, subvault) { + if (!confirm('Are you sure you want to remove this login (' + login.name + ') from the ' + + 'subvault (' + subvault.name + ') ?')) { + return; + } + + var request = { + subvaultIds: [] + }; + + for (var i = 0; i < login.subvaultIds.length; i++) { + if (login.subvaultIds[i] !== subvault.id) { + request.subvaultIds.push(login.subvaultIds[i]); + } + } + + apiService.ciphers.putSubvaults({ id: login.id }, request).$promise.then(function (response) { + $analytics.eventTrack('Removed From Subvault'); + login.subvaultIds = request.subvaultIds; + if (!login.subvaultIds.length) { + removeRootLogin(findRootLogin(login)); + } + }); + }; + function findRootLogin(login) { if ($rootScope.vaultLogins) { var rootLogins = $filter('filter')($rootScope.vaultLogins, { id: login.id }); diff --git a/src/app/vault/views/vaultSubvaults.html b/src/app/vault/views/vaultSubvaults.html index f6221c14ca..b0b4cd230e 100644 --- a/src/app/vault/views/vaultSubvaults.html +++ b/src/app/vault/views/vaultSubvaults.html @@ -70,7 +70,7 @@
  • - + Remove