diff options
author | beccabroek <beccabroek@gmail.com> | 2018-11-07 12:22:31 -0600 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2019-09-26 20:04:56 +0000 |
commit | 5e258e43070b46b9d1ec5ec01e02b9f707cbf7b8 (patch) | |
tree | dcce595926ecd55bdb86f93800dcb95886cd06e5 /app/common/directives/ldap-user-roles.js | |
parent | 5dac9e155e46cd8615a057ff6fe1577a9f21a0a7 (diff) | |
download | phosphor-webui-5e258e43070b46b9d1ec5ec01e02b9f707cbf7b8.tar.gz phosphor-webui-5e258e43070b46b9d1ec5ec01e02b9f707cbf7b8.zip |
LDAP configuration and user groups
Adds LDAP page and ability to add and change configuration settings.
Adds ability to add, remove and edit user groups for LDAP.
Resolves openbmc/phosphor-webui#38
Resolves openbmc/phosphor-webui#39
Tested: Loaded on to a witherspoon and able to add initial LDAP config
as well us update the configuration and role groups. Appropriate messages displayed
to user when required fields are missing or in the incorrect format.
Change-Id: If8a21f3f9d9334415ead73472e90b2a0823bf9ea
Signed-off-by: beccabroek <beccabroek@gmail.com>
Signed-off-by: Dixsie Wolmers <dixsiew@gmail.com>
Signed-off-by: Derick Montague <derick.montague@ibm.com>
Diffstat (limited to 'app/common/directives/ldap-user-roles.js')
-rw-r--r-- | app/common/directives/ldap-user-roles.js | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/app/common/directives/ldap-user-roles.js b/app/common/directives/ldap-user-roles.js new file mode 100644 index 0000000..4e83606 --- /dev/null +++ b/app/common/directives/ldap-user-roles.js @@ -0,0 +1,231 @@ +window.angular && (function(angular) { + 'use strict'; + + angular.module('app.common.directives').directive('ldapUserRoles', [ + 'APIUtils', + function(APIUtils) { + return { + restrict: 'E', + template: require('./ldap-user-roles.html'), + scope: {roleGroups: '=', enabled: '=', roleGroupType: '='}, + controller: [ + '$scope', 'APIUtils', 'toastService', '$q', + function($scope, APIUtils, toastService, $q) { + $scope.privileges = []; + $scope.loading = true; + $scope.newGroup = {}; + $scope.selectedGroupIndex = ''; + $scope.editGroup = false; + $scope.removeGroup = false; + $scope.removeMultipleGroups = false; + $scope.all = false; + $scope.sortPropertyName = 'id'; + $scope.reverse = false; + $scope.addGroup = false; + $scope.hasSelectedGroup = false; + + APIUtils.getAccountServiceRoles() + .then( + (data) => { + $scope.privileges = data; + }, + (error) => { + console.log(JSON.stringify(error)); + }) + .finally(() => { + $scope.loading = false; + }); + + $scope.addGroupFn = () => { + $scope.addGroup = true; + }; + + $scope.addRoleGroup = () => { + const newGroup = {}; + newGroup.RemoteGroup = $scope.newGroup.RemoteGroup; + newGroup.LocalRole = $scope.newGroup.LocalRole; + + $scope.loading = true; + const data = {}; + + if ($scope.roleGroupType == 'ldap') { + data.LDAP = {}; + data.LDAP.RemoteRoleMapping = $scope.roleGroups; + data.LDAP.RemoteRoleMapping.push(newGroup); + } else { + data.ActiveDirectory = {}; + data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups; + data.ActiveDirectory.RemoteRoleMapping.push(newGroup); + } + + APIUtils.saveLdapProperties(data) + .then( + (response) => { + toastService.success( + 'Group has been created successfully.'); + }, + (error) => { + toastService.error('Failed to create new group.'); + }) + .finally(() => { + $scope.loading = false; + }); + }; + + $scope.editGroupFn = (group, role, index) => { + $scope.editGroup = true; + $scope.selectedGroupIndex = index; + $scope.newGroup.RemoteGroup = group; + $scope.newGroup.LocalRole = role; + }; + + $scope.editRoleGroup = () => { + $scope.loading = true; + const data = {}; + + if ($scope.roleGroupType == 'ldap') { + data.LDAP = {}; + data.LDAP.RemoteRoleMapping = $scope.roleGroups; + data.LDAP.RemoteRoleMapping[$scope.selectedGroupIndex] + .LocalRole = $scope.newGroup.LocalRole; + } else { + data.ActiveDirectory = {}; + data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups; + data.ActiveDirectory + .RemoteRoleMapping[$scope.selectedGroupIndex] + .LocalRole = $scope.newGroup.LocalRole; + } + + APIUtils.saveLdapProperties(data) + .then( + (response) => { + toastService.success( + 'Group has been edited successfully.'); + }, + (error) => { + toastService.error('Failed to edit group.'); + }) + .finally(() => { + $scope.loading = false; + }); + $scope.editGroup = false; + }; + + $scope.removeGroupFn = (index) => { + $scope.removeGroup = true; + $scope.selectedGroupIndex = index; + }; + + $scope.removeRoleGroup = () => { + $scope.loading = true; + const data = {}; + + if ($scope.roleGroupType == 'ldap') { + data.LDAP = {}; + data.LDAP.RemoteRoleMapping = $scope.roleGroups; + data.LDAP.RemoteRoleMapping[$scope.selectedGroupIndex] = + $scope.newGroup; + } else { + data.ActiveDirectory = {}; + data.ActiveDirectory.RemoteRoleMapping = $scope.roleGroups; + data.ActiveDirectory + .RemoteRoleMapping[$scope.selectedGroupIndex] = + $scope.newGroup; + } + + $scope.roleGroups[$scope.selectedGroupIndex] = null; + + APIUtils.saveLdapProperties(data) + .then( + (response) => { + toastService.success( + 'Group has been removed successfully.'); + }, + (error) => { + toastService.error('Failed to remove group.'); + }) + .finally(() => { + $scope.loading = false; + $scope.$parent.loadLdap(); + }); + $scope.removeGroup = false; + }; + + $scope.removeMultipleRoleGroupsFn = () => { + $scope.removeMultipleGroups = true; + }; + + $scope.roleGroupIsSelectedChanged = () => { + let groupSelected = false; + $scope.roleGroups.forEach(group => { + if (group['isSelected']) { + groupSelected = true; + } + }); + $scope.hasSelectedGroup = groupSelected; + }; + + $scope.removeMultipleRoleGroups = () => { + $scope.loading = true; + const data = {}; + + if ($scope.roleGroupType == 'ldap') { + data.LDAP = {}; + data.LDAP.RemoteRoleMapping = $scope.roleGroups.map((group) => { + if (group['isSelected']) { + return null; + } else { + return group; + } + }); + } else { + data.ActiveDirectory = {}; + data.ActiveDirectory.RemoteRoleMapping = + $scope.roleGroups.map((group) => { + if (group['isSelected']) { + return null; + } else { + return group; + } + }); + } + + APIUtils.saveLdapProperties(data) + .then( + (response) => { + toastService.success( + 'Groups has been removed successfully.'); + }, + (error) => { + toastService.error('Failed to remove groups.'); + }) + .finally(() => { + $scope.loading = false; + $scope.$parent.loadLdap(); + }); + $scope.removeMultipleGroups = false; + }; + + $scope.toggleAll = () => { + let toggleStatus = !$scope.all; + $scope.roleGroups.forEach((group) => { + group.isSelected = toggleStatus; + }); + }; + + $scope.optionToggled = () => { + $scope.all = $scope.roleGroups.every((group) => { + return group.isSelected; + }); + }; + + $scope.sortBy = (propertyName, isReverse) => { + $scope.reverse = isReverse; + $scope.sortPropertyName = propertyName; + }; + } + ] + }; + } + ]); +})(window.angular); |