From d35ccd9a5e8c058e69b1b9f358f8f828031c163b Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Thu, 31 Mar 2016 14:33:41 -0400 Subject: [PATCH] KEYCLOAK-2621 --- .../admin/resources/js/controllers/users.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js index 33a5d2b097..f09eb63096 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js @@ -1154,6 +1154,19 @@ module.controller('UserFederationMapperCreateCtrl', function($scope, realm, prov }); +function removeGroupMember(groups, member) { + for (var j = 0; j < groups.length; j++) { + //console.log('checking: ' + groups[j].path); + if (member.path == groups[j].path) { + groups.splice(j, 1); + break; + } + if (groups[j].subGroups && groups[j].subGroups.length > 0) { + //console.log('going into subgroups'); + removeGroupMember(groups[j].subGroups, member); + } + } +} module.controller('UserGroupMembershipCtrl', function($scope, $route, realm, groups, user, UserGroupMembership, UserGroupMapping, Notifications, $location, Dialog) { $scope.realm = realm; $scope.user = user; @@ -1163,9 +1176,15 @@ module.controller('UserGroupMembershipCtrl', function($scope, $route, realm, gro UserGroupMembership.query({realm: realm.realm, userId: user.id}, function(data) { $scope.groupMemberships = data; + for (var i = 0; i < data.length; i++) { + var member = data[i]; + removeGroupMember(groups, member); + } }); + + $scope.joinGroup = function() { if (!$scope.tree.currentNode) { Notifications.error('Please select a group to add'); @@ -1179,6 +1198,10 @@ module.controller('UserGroupMembershipCtrl', function($scope, $route, realm, gro }; $scope.leaveGroup = function() { + if (!$scope.selectedGroup) { + return; + + } UserGroupMapping.remove({realm: realm.realm, userId: user.id, groupId: $scope.selectedGroup.id}, function() { Notifications.success('Removed group membership'); $route.reload();