From a81572914a029c88f3cbf3c1415e6d41d64eb8ce Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 3 Apr 2017 12:26:43 -0400 Subject: [PATCH] Manage subvault users --- .../organizationSubvaultsController.js | 20 +++++-- .../organizationSubvaultsUsersController.js | 56 +++++++++++++++++++ .../views/organizationSubvaultsUsers.html | 51 +++++++++++++++++ src/app/services/apiService.js | 5 ++ src/index.html | 1 + 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 src/app/organization/organizationSubvaultsUsersController.js create mode 100644 src/app/organization/views/organizationSubvaultsUsers.html diff --git a/src/app/organization/organizationSubvaultsController.js b/src/app/organization/organizationSubvaultsController.js index a3206edfa9..0eeb8a40c4 100644 --- a/src/app/organization/organizationSubvaultsController.js +++ b/src/app/organization/organizationSubvaultsController.js @@ -39,6 +39,22 @@ }); }; + $scope.users = function (subvault) { + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationSubvaultsUsers.html', + controller: 'organizationSubvaultsUsersController', + size: 'lg', + resolve: { + subvault: function () { return subvault; } + } + }); + + modal.result.then(function () { + // nothing to do + }); + }; + $scope.delete = function (subvault) { if (!confirm('Are you sure you want to delete this subvault (' + subvault.name + ')?')) { return; @@ -56,10 +72,6 @@ }); }; - $scope.users = function (subvault) { - - }; - function loadList() { apiService.subvaults.listOrganization({ orgId: $state.params.orgId }, function (list) { $scope.subvaults = cipherService.decryptSubvaults(list.Data, $state.params.orgId, true); diff --git a/src/app/organization/organizationSubvaultsUsersController.js b/src/app/organization/organizationSubvaultsUsersController.js new file mode 100644 index 0000000000..959e2ed180 --- /dev/null +++ b/src/app/organization/organizationSubvaultsUsersController.js @@ -0,0 +1,56 @@ +angular + .module('bit.organization') + + .controller('organizationSubvaultsUsersController', function ($scope, $state, $uibModalInstance, apiService, cipherService, + $analytics, subvault, toastr) { + $scope.loading = true; + $scope.subvault = subvault; + $scope.users = []; + + $uibModalInstance.opened.then(function () { + $scope.loading = false; + apiService.subvaultUsers.listSubvault( + { + orgId: $state.params.orgId, + subvaultId: subvault.id + }, + function (userList) { + if (userList && userList.Data.length) { + var users = []; + for (var i = 0; i < userList.Data.length; i++) { + users.push({ + id: userList.Data[i].Id, + userId: userList.Data[i].UserId, + name: userList.Data[i].Name, + email: userList.Data[i].Email, + type: userList.Data[i].Type, + status: userList.Data[i].Status, + readOnly: userList.Data[i].ReadOnly + }); + } + $scope.users = users; + } + }); + }); + + $scope.remove = function (user) { + if (!confirm('Are you sure you want to remove this user (' + user.email + ') from this ' + + 'subvault (' + subvault.name + ')?')) { + return; + } + + apiService.subvaultUsers.del({ orgId: $state.params.orgId, id: user.id }, null, function () { + toastr.success(user.email + ' has been removed.', 'User Removed'); + var index = $scope.users.indexOf(user); + if (index > -1) { + $scope.users.splice(index, 1); + } + }, function () { + toastr.error('Unable to remove user.', 'Error'); + }); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/views/organizationSubvaultsUsers.html b/src/app/organization/views/organizationSubvaultsUsers.html new file mode 100644 index 0000000000..1846488e1c --- /dev/null +++ b/src/app/organization/views/organizationSubvaultsUsers.html @@ -0,0 +1,51 @@ + + + diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 6326c6e953..66b5315568 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -61,6 +61,11 @@ del: { url: _apiUri + '/organizations/:orgId/subvaults/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } } }); + _service.subvaultUsers = $resource(_apiUri + '/organizations/:orgId/subvaultUsers/:id', {}, { + listSubvault: { url: _apiUri + '/organizations/:orgId/subvaultUsers/:subvaultId', method: 'GET', params: { subvaultId: '@subvaultId', orgId: '@orgId' } }, + del: { url: _apiUri + '/organizations/:orgId/subvaultUsers/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } } + }); + _service.accounts = $resource(_apiUri + '/accounts', {}, { register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} }, emailToken: { url: _apiUri + '/accounts/email-token', method: 'POST', params: {} }, diff --git a/src/index.html b/src/index.html index 8eb114824a..e3da7efa10 100644 --- a/src/index.html +++ b/src/index.html @@ -131,6 +131,7 @@ +