diff --git a/src/app/global/mainController.js b/src/app/global/mainController.js index 76bae441..33cf89d6 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 00000000..f3af1cd1 --- /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 7dd13156..e6414f97 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 00000000..2366ac93 --- /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 99dd23a3..d7396850 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 00000000..07100589 --- /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 00000000..b0ee892a --- /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 476cf43d..03a36e37 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 b43ba9fe..0962bc52 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 ee0bf8b2..ca699c79 100644 --- a/src/index.html +++ b/src/index.html @@ -149,6 +149,8 @@ + +