From 9c706f07f09de2257167b64827edd441ebfc50b0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 May 2017 16:01:36 -0400 Subject: [PATCH] groups list/add/edit --- src/app/global/mainController.js | 4 + .../organizationGroupsAddController.js | 24 ++++++ .../organizationGroupsController.js | 83 ++++++++++++++++++- .../organizationGroupsEditController.js | 31 +++++++ .../views/organizationGroups.html | 65 ++++++++++++++- .../views/organizationGroupsAdd.html | 30 +++++++ .../views/organizationGroupsEdit.html | 31 +++++++ src/app/services/apiService.js | 8 ++ src/app/views/organizationLayout.html | 7 ++ src/index.html | 2 + 10 files changed, 280 insertions(+), 5 deletions(-) create mode 100644 src/app/organization/organizationGroupsAddController.js create mode 100644 src/app/organization/organizationGroupsEditController.js create mode 100644 src/app/organization/views/organizationGroupsAdd.html create mode 100644 src/app/organization/views/organizationGroupsEdit.html diff --git a/src/app/global/mainController.js b/src/app/global/mainController.js index 76bae441c1..33cf89d6f0 100644 --- a/src/app/global/mainController.js +++ b/src/app/global/mainController.js @@ -60,6 +60,10 @@ angular $scope.$broadcast('organizationPeopleInvite'); }; + $scope.addOrganizationGroup = function () { + $scope.$broadcast('organizationGroupsAdd'); + }; + // Append dropdown menu somewhere else var bodyScrollbarWidth, appendedDropdownMenu, diff --git a/src/app/organization/organizationGroupsAddController.js b/src/app/organization/organizationGroupsAddController.js new file mode 100644 index 0000000000..f3af1cd1d0 --- /dev/null +++ b/src/app/organization/organizationGroupsAddController.js @@ -0,0 +1,24 @@ +angular + .module('bit.organization') + + .controller('organizationGroupsAddController', function ($scope, $state, $uibModalInstance, apiService, + $analytics) { + $analytics.eventTrack('organizationGroupsAddController', { category: 'Modal' }); + + $scope.submit = function (model) { + var group = { + name: model.name + }; + $scope.submitPromise = apiService.groups.post({ orgId: $state.params.orgId }, group, function (response) { + $analytics.eventTrack('Created Group'); + $uibModalInstance.close({ + id: response.Id, + name: response.Name + }); + }).$promise; + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/organizationGroupsController.js b/src/app/organization/organizationGroupsController.js index 7dd131566c..e6414f97f4 100644 --- a/src/app/organization/organizationGroupsController.js +++ b/src/app/organization/organizationGroupsController.js @@ -1,6 +1,85 @@ angular .module('bit.organization') - .controller('organizationGroupsController', function ($scope, $state) { - + .controller('organizationGroupsController', function ($scope, $state, apiService, $uibModal, $filter, + toastr, $analytics) { + $scope.groups = []; + $scope.loading = true; + $scope.$on('$viewContentLoaded', function () { + loadList(); + }); + + $scope.$on('organizationGroupsAdd', function (event, args) { + $scope.add(); + }); + + $scope.add = function () { + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationGroupsAdd.html', + controller: 'organizationGroupsAddController' + }); + + modal.result.then(function (group) { + $scope.groups.push(group); + }); + }; + + $scope.edit = function (group) { + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationGroupsEdit.html', + controller: 'organizationGroupsEditController', + resolve: { + id: function () { return group.id; } + } + }); + + modal.result.then(function (editedGroup) { + var existingGroups = $filter('filter')($scope.groups, { id: editedGroup.id }, true); + if (existingGroups && existingGroups.length > 0) { + existingGroups[0].name = editedGroup.name; + } + }); + }; + + $scope.users = function (group) { + + }; + + $scope.collections = function (collection) { + + }; + + $scope.delete = function (group) { + if (!confirm('Are you sure you want to delete this group (' + group.name + ')?')) { + return; + } + + apiService.groups.del({ orgId: $state.params.orgId, id: group.id }, function () { + var index = $scope.groups.indexOf(group); + if (index > -1) { + $scope.groups.splice(index, 1); + } + + $analytics.eventTrack('Deleted Group'); + toastr.success(group.name + ' has been deleted.', 'Group Deleted'); + }, function () { + toastr.error(group.name + ' was not able to be deleted.', 'Error'); + }); + }; + + function loadList() { + apiService.groups.listOrganization({ orgId: $state.params.orgId }, function (list) { + var groups = []; + for (var i = 0; i < list.Data.length; i++) { + groups.push({ + id: list.Data[i].Id, + name: list.Data[i].Name + }); + } + $scope.groups = groups; + $scope.loading = false; + }); + } }); diff --git a/src/app/organization/organizationGroupsEditController.js b/src/app/organization/organizationGroupsEditController.js new file mode 100644 index 0000000000..2366ac9394 --- /dev/null +++ b/src/app/organization/organizationGroupsEditController.js @@ -0,0 +1,31 @@ +angular + .module('bit.organization') + + .controller('organizationGroupsEditController', function ($scope, $state, $uibModalInstance, apiService, + $analytics, id) { + $analytics.eventTrack('organizationGroupsEditController', { category: 'Modal' }); + $scope.collection = {}; + + $uibModalInstance.opened.then(function () { + apiService.groups.get({ orgId: $state.params.orgId, id: id }, function (group) { + $scope.group = { + id: id, + name: group.Name + }; + }); + }); + + $scope.submit = function () { + $scope.submitPromise = apiService.groups.put({ orgId: $state.params.orgId }, $scope.group, function (response) { + $analytics.eventTrack('Edited Group'); + $uibModalInstance.close({ + id: response.Id, + name: response.Name + }); + }).$promise; + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/views/organizationGroups.html b/src/app/organization/views/organizationGroups.html index 99dd23a3db..d7396850d7 100644 --- a/src/app/organization/views/organizationGroups.html +++ b/src/app/organization/views/organizationGroups.html @@ -7,10 +7,69 @@
-

Coming soon...

+   + +
+ +
-
-

Groups are coming soon to bitwarden Enterprise organizations.

+
+
+ Loading... +
+
+ No groups to list. +
+
+

There are no groups yet for your organization.

+ +
+
+ + + + + + + +
+
+ + +
+
+ + {{group.name}} + +
+
diff --git a/src/app/organization/views/organizationGroupsAdd.html b/src/app/organization/views/organizationGroupsAdd.html new file mode 100644 index 0000000000..07100589c0 --- /dev/null +++ b/src/app/organization/views/organizationGroupsAdd.html @@ -0,0 +1,30 @@ + +
+ + +
diff --git a/src/app/organization/views/organizationGroupsEdit.html b/src/app/organization/views/organizationGroupsEdit.html new file mode 100644 index 0000000000..b0ee892a0b --- /dev/null +++ b/src/app/organization/views/organizationGroupsEdit.html @@ -0,0 +1,31 @@ + +
+ + +
diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 476cf43d1c..03a36e37f3 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -81,6 +81,14 @@ del: { url: _apiUri + '/organizations/:orgId/collectionUsers/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } } }); + _service.groups = $resource(_apiUri + '/organizations/:orgId/groups/:id', {}, { + get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } }, + listOrganization: { method: 'GET', params: { orgId: '@orgId' } }, + post: { method: 'POST', params: { orgId: '@orgId' } }, + put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } }, + del: { url: _apiUri + '/organizations/:orgId/groups/: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/app/views/organizationLayout.html b/src/app/views/organizationLayout.html index b43ba9fec4..0962bc52e3 100644 --- a/src/app/views/organizationLayout.html +++ b/src/app/views/organizationLayout.html @@ -84,6 +84,13 @@ Groups +
  • diff --git a/src/index.html b/src/index.html index ee0bf8b2c2..ca699c7970 100644 --- a/src/index.html +++ b/src/index.html @@ -149,6 +149,8 @@ + +