diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java index 6a09bb7cac..9c5399dc89 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/UIUtils.java @@ -31,7 +31,7 @@ public final class UIUtils { public static boolean selectContainsOption(Select select, String optionText) { for (WebElement option : select.getOptions()) { - if (option.getText().equals(optionText)) { + if (option.getText().trim().equals(optionText)) { return true; } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/clientscopes/ClientScopesSetupForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/clientscopes/ClientScopesSetupForm.java index b917d7605e..e52d4f7613 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/clientscopes/ClientScopesSetupForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/clients/clientscopes/ClientScopesSetupForm.java @@ -93,7 +93,7 @@ public class ClientScopesSetupForm extends Form { static Set getSelectValues(Select select) { Set roles = new HashSet<>(); for (WebElement option : select.getOptions()) { - roles.add(getTextFromElement(option)); + roles.add(getTextFromElement(option).trim()); } return roles; } diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js index e86371b1bf..cc0b8fcb25 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/clients.js @@ -676,7 +676,7 @@ module.controller('ClientOfflineSessionsCtrl', function($scope, realm, offlineSe module.controller('ClientRoleDetailCtrl', function($scope, realm, client, role, roles, clients, Role, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites, - $http, $location, Dialog, Notifications) { + $http, $location, Dialog, Notifications, ComponentUtils) { $scope.realm = realm; $scope.client = client; $scope.role = angular.copy(role); @@ -754,7 +754,7 @@ module.controller('ClientRoleDetailCtrl', function($scope, realm, client, role, roleControl($scope, realm, role, roles, clients, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites, - $http, $location, Notifications, Dialog); + $http, $location, Notifications, Dialog, ComponentUtils); }); @@ -1610,41 +1610,45 @@ module.controller('ClientScopeMappingCtrl', function($scope, $http, realm, clien }; $scope.addRealmRole = function() { - var roles = $scope.selectedRealmRoles; + $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']'); $scope.selectedRealmRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/realm', - roles).then(function() { + $scope.selectedRealmRolesToAdd).then(function() { updateRealmRoles(); + $scope.selectedRealmRolesToAdd = []; Notifications.success("Scope mappings updated."); }); }; $scope.deleteRealmRole = function() { - var roles = $scope.selectedRealmMappings; + $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']'); $scope.selectedRealmMappings = []; $http.delete(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/realm', - {data : roles, headers : {"content-type" : "application/json"}}).then(function () { + {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () { updateRealmRoles(); + $scope.selectedRealmMappingsToRemove = []; Notifications.success("Scope mappings updated."); }); }; $scope.addClientRole = function() { - var roles = $scope.selectedClientRoles; + $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']'); $scope.selectedClientRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/clients/' + $scope.targetClient.id, - roles).then(function () { + $scope.selectedClientRolesToAdd).then(function () { updateClientRoles(); + $scope.selectedClientRolesToAdd = []; Notifications.success("Scope mappings updated."); }); }; $scope.deleteClientRole = function() { - var roles = $scope.selectedClientMappings; + $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']'); $scope.selectedClientMappings = []; $http.delete(authUrl + '/admin/realms/' + realm.realm + '/clients/' + client.id + '/scope-mappings/clients/' + $scope.targetClient.id, - {data : roles, headers : {"content-type" : "application/json"}}).then(function () { + {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () { updateClientRoles(); + $scope.selectedClientMappingsToRemove = []; Notifications.success("Scope mappings updated."); }); }; @@ -2125,11 +2129,11 @@ module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, } $scope.addDefaultClientScope = function () { + $scope.selectedDefaultClientScopesToAdd = JSON.parse('[' + $scope.selectedDefaultClientScopes + ']'); + toAdd = $scope.selectedDefaultClientScopesToAdd.length; - toAdd = $scope.selectedDefaultClientScopes.length; - - for (var i = 0; i < $scope.selectedDefaultClientScopes.length; i++) { - var currentScope = $scope.selectedDefaultClientScopes[i]; + for (var i = 0; i < $scope.selectedDefaultClientScopesToAdd.length; i++) { + var currentScope = $scope.selectedDefaultClientScopesToAdd[i]; ClientDefaultClientScopes.update({ realm : realm.realm, @@ -2143,14 +2147,15 @@ module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefaultClientScopesToAdd = []; }; $scope.deleteDefaultClientScope = function () { + $scope.selectedDefDefaultClientScopesToRemove = JSON.parse('[' + $scope.selectedDefDefaultClientScopes + ']'); + toRemove = $scope.selectedDefDefaultClientScopesToRemove.length; - toRemove = $scope.selectedDefDefaultClientScopes.length; - - for (var i = 0; i < $scope.selectedDefDefaultClientScopes.length; i++) { - var currentScope = $scope.selectedDefDefaultClientScopes[i]; + for (var i = 0; i < $scope.selectedDefDefaultClientScopesToRemove.length; i++) { + var currentScope = $scope.selectedDefDefaultClientScopesToRemove[i]; ClientDefaultClientScopes.remove({ realm : realm.realm, @@ -2164,14 +2169,15 @@ module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefDefaultClientScopesToRemove = []; }; $scope.addOptionalClientScope = function () { + $scope.selectedOptionalClientScopesToAdd = JSON.parse('[' + $scope.selectedOptionalClientScopes + ']'); + toAdd = $scope.selectedOptionalClientScopesToAdd.length; - toAdd = $scope.selectedOptionalClientScopes.length; - - for (var i = 0; i < $scope.selectedOptionalClientScopes.length; i++) { - var currentScope = $scope.selectedOptionalClientScopes[i]; + for (var i = 0; i < $scope.selectedOptionalClientScopesToAdd.length; i++) { + var currentScope = $scope.selectedOptionalClientScopesToAdd[i]; ClientOptionalClientScopes.update({ realm : realm.realm, @@ -2188,11 +2194,11 @@ module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, }; $scope.deleteOptionalClientScope = function () { + $scope.selectedDefOptionalClientScopesToRemove = JSON.parse('[' + $scope.selectedDefOptionalClientScopes + ']'); + toRemove = $scope.selectedDefOptionalClientScopesToRemove.length; - toRemove = $scope.selectedDefOptionalClientScopes.length; - - for (var i = 0; i < $scope.selectedDefOptionalClientScopes.length; i++) { - var currentScope = $scope.selectedDefOptionalClientScopes[i]; + for (var i = 0; i < $scope.selectedDefOptionalClientScopesToRemove.length; i++) { + var currentScope = $scope.selectedDefOptionalClientScopesToRemove[i]; ClientOptionalClientScopes.remove({ realm : realm.realm, @@ -2206,13 +2212,14 @@ module.controller('ClientClientScopesSetupCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefOptionalClientScopesToRemove = []; }; }); module.controller('ClientClientScopesEvaluateCtrl', function($scope, Realm, User, ClientEvaluateProtocolMappers, ClientEvaluateGrantedRoles, ClientEvaluateNotGrantedRoles, ClientEvaluateGenerateExampleToken, realm, client, clients, clientScopes, serverInfo, - clientOptionalClientScopes, clientDefaultClientScopes, $route, $routeParams, $http, Notifications, $location) { + ComponentUtils, clientOptionalClientScopes, clientDefaultClientScopes, $route, $routeParams, $http, Notifications, $location) { console.log('ClientClientScopesEvaluateCtrl'); @@ -2279,37 +2286,38 @@ module.controller('ClientClientScopesEvaluateCtrl', function($scope, Realm, User $scope.addAppliedClientScope = function () { - - for (var i = 0; i < $scope.selectedClientScopes.length; i++) { - var currentScope = $scope.selectedClientScopes[i]; + $scope.selectedClientScopesToAdd = JSON.parse('[' + $scope.selectedClientScopes + ']'); + for (var i = 0; i < $scope.selectedClientScopesToAdd.length; i++) { + var currentScope = $scope.selectedClientScopesToAdd[i]; $scope.assignedClientScopes.push(currentScope); - var index = $scope.availableClientScopes.indexOf(currentScope); + var index = ComponentUtils.findIndexById($scope.availableClientScopes, currentScope.id); if (index > -1) { $scope.availableClientScopes.splice(index, 1); } } $scope.selectedClientScopes = []; - + $scope.selectedClientScopesToAdd = []; updateState(); }; - $scope.deleteAppliedClientScope = function () { - for (var i = 0; i < $scope.selectedDefClientScopes.length; i++) { - var currentScope = $scope.selectedDefClientScopes[i]; + $scope.selectedDefClientScopesToRemove = JSON.parse('[' + $scope.selectedDefClientScopes + ']'); + for (var i = 0; i < $scope.selectedDefClientScopesToRemove.length; i++) { + var currentScope = $scope.selectedDefClientScopesToRemove[i]; $scope.availableClientScopes.push(currentScope); - var index = $scope.assignedClientScopes.indexOf(currentScope); + var index = ComponentUtils.findIndexById($scope.assignedClientScopes, currentScope.id); if (index > -1) { $scope.assignedClientScopes.splice(index, 1); } } $scope.selectedDefClientScopes = []; + $scope.selectedDefClientScopesToRemove = []; updateState(); }; @@ -2538,11 +2546,11 @@ module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, } $scope.addDefaultClientScope = function () { + $scope.selectedDefaultClientScopesToAdd = JSON.parse('[' + $scope.selectedDefaultClientScopes + ']'); + toAdd = $scope.selectedDefaultClientScopesToAdd.length; - toAdd = $scope.selectedDefaultClientScopes.length; - - for (var i = 0; i < $scope.selectedDefaultClientScopes.length; i++) { - var currentScope = $scope.selectedDefaultClientScopes[i]; + for (var i = 0; i < $scope.selectedDefaultClientScopesToAdd.length; i++) { + var currentScope = $scope.selectedDefaultClientScopesToAdd[i]; RealmDefaultClientScopes.update({ realm : realm.realm, @@ -2556,14 +2564,15 @@ module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefaultClientScopesToAdd = []; }; $scope.deleteDefaultClientScope = function () { + $scope.selectedDefDefaultClientScopesToRemove = JSON.parse('[' + $scope.selectedDefDefaultClientScopes + ']'); + toRemove = $scope.selectedDefDefaultClientScopesToRemove.length; - toRemove = $scope.selectedDefDefaultClientScopes.length; - - for (var i = 0; i < $scope.selectedDefDefaultClientScopes.length; i++) { - var currentScope = $scope.selectedDefDefaultClientScopes[i]; + for (var i = 0; i < $scope.selectedDefDefaultClientScopesToRemove.length; i++) { + var currentScope = $scope.selectedDefDefaultClientScopesToRemove[i]; RealmDefaultClientScopes.remove({ realm : realm.realm, @@ -2576,14 +2585,15 @@ module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefDefaultClientScopesToRemove = []; }; $scope.addOptionalClientScope = function () { + $scope.selectedOptionalClientScopesToAdd = JSON.parse('[' + $scope.selectedOptionalClientScopes + ']'); + toAdd = $scope.selectedOptionalClientScopesToAdd.length; - toAdd = $scope.selectedOptionalClientScopes.length; - - for (var i = 0; i < $scope.selectedOptionalClientScopes.length; i++) { - var currentScope = $scope.selectedOptionalClientScopes[i]; + for (var i = 0; i < $scope.selectedOptionalClientScopesToAdd.length; i++) { + var currentScope = $scope.selectedOptionalClientScopesToAdd[i]; RealmOptionalClientScopes.update({ realm : realm.realm, @@ -2597,14 +2607,15 @@ module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, } }); } + $scope.selectedOptionalClientScopesToAdd = []; }; $scope.deleteOptionalClientScope = function () { + $scope.selectedDefOptionalClientScopesToRemove = JSON.parse('[' + $scope.selectedDefOptionalClientScopes + ']'); + toRemove = $scope.selectedDefOptionalClientScopesToRemove.length; - toRemove = $scope.selectedDefOptionalClientScopes.length; - - for (var i = 0; i < $scope.selectedDefOptionalClientScopes.length; i++) { - var currentScope = $scope.selectedDefOptionalClientScopes[i]; + for (var i = 0; i < $scope.selectedDefOptionalClientScopesToRemove.length; i++) { + var currentScope = $scope.selectedDefOptionalClientScopesToRemove[i]; RealmOptionalClientScopes.remove({ realm : realm.realm, @@ -2617,6 +2628,7 @@ module.controller('ClientScopesRealmDefaultCtrl', function($scope, realm, Realm, } }); } + $scope.selectedDefOptionalClientScopesToRemove = []; }; }); @@ -3015,41 +3027,45 @@ module.controller('ClientScopeScopeMappingCtrl', function($scope, $http, realm, }; $scope.addRealmRole = function() { - var roles = $scope.selectedRealmRoles; + $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']'); $scope.selectedRealmRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/realm', - roles).then(function() { + $scope.selectedRealmRolesToAdd).then(function() { updateScopeRealmRoles(); + $scope.selectedRealmRolesToAdd = []; Notifications.success("Scope mappings updated."); }); }; $scope.deleteRealmRole = function() { - var roles = $scope.selectedRealmMappings; + $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']'); $scope.selectedRealmMappings = []; $http.delete(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/realm', - {data : roles, headers : {"content-type" : "application/json"}}).then(function () { + {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () { updateScopeRealmRoles(); + $scope.selectedRealmMappingsToRemove = []; Notifications.success("Scope mappings updated."); }); }; $scope.addClientRole = function() { - var roles = $scope.selectedClientRoles; + $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']'); $scope.selectedClientRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/clients/' + $scope.targetClient.id, - roles).then(function () { + $scope.selectedClientRolesToAdd).then(function () { updateScopeClientRoles(); + $scope.selectedClientRolesToAdd = []; Notifications.success("Scope mappings updated."); }); }; $scope.deleteClientRole = function() { - var roles = $scope.selectedClientMappings; + $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']'); $scope.selectedClientMappings = []; $http.delete(authUrl + '/admin/realms/' + realm.realm + '/client-scopes/' + clientScope.id + '/scope-mappings/clients/' + $scope.targetClient.id, - {data : roles, headers : {"content-type" : "application/json"}}).then(function () { + {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function () { updateScopeClientRoles(); + $scope.selectedClientMappingsToRemove = []; Notifications.success("Scope mappings updated."); }); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js index 4114ae59cc..7547bbb765 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/groups.js @@ -313,10 +313,10 @@ module.controller('GroupRoleMappingCtrl', function($scope, $http, realm, group, $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.addRealmRole = function() { - var roles = $scope.selectedRealmRoles; + $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']'); $scope.selectedRealmRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm', - roles).then(function() { + $scope.selectedRealmRolesToAdd).then(function() { $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); @@ -330,14 +330,16 @@ module.controller('GroupRoleMappingCtrl', function($scope, $http, realm, group, $scope.selectedClientRoles = []; $scope.selectedClientMappings = []; } + $scope.selectedRealmRolesToAdd = []; Notifications.success("Role mappings updated."); }); }; $scope.deleteRealmRole = function() { + $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm', - {data : $scope.selectedRealmMappings, headers : {"content-type" : "application/json"}}).then(function() { + {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() { $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); @@ -351,13 +353,15 @@ module.controller('GroupRoleMappingCtrl', function($scope, $http, realm, group, $scope.selectedClientRoles = []; $scope.selectedClientMappings = []; } + $scope.selectedRealmMappingsToRemove = []; Notifications.success("Role mappings updated."); }); }; $scope.addClientRole = function() { + $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']'); $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.targetClient.id, - $scope.selectedClientRoles).then(function() { + $scope.selectedClientRolesToAdd).then(function() { $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); @@ -365,13 +369,15 @@ module.controller('GroupRoleMappingCtrl', function($scope, $http, realm, group, $scope.selectedClientMappings = []; $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); + $scope.selectedClientRolesToAdd = []; Notifications.success("Role mappings updated."); }); }; $scope.deleteClientRole = function() { + $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.targetClient.id, - {data : $scope.selectedClientMappings, headers : {"content-type" : "application/json"}}).then(function() { + {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() { $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.targetClient.id}); @@ -379,6 +385,7 @@ module.controller('GroupRoleMappingCtrl', function($scope, $http, realm, group, $scope.selectedClientMappings = []; $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id}); + $scope.selectedClientMappingsToRemove = []; Notifications.success("Role mappings updated."); }); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index 936a7c1be4..029d849158 100644 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -1461,7 +1461,7 @@ module.controller('RoleListCtrl', function($scope, $route, Dialog, Notifications module.controller('RoleDetailCtrl', function($scope, realm, role, roles, clients, Role, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites, - $http, $location, Dialog, Notifications, RealmRoleRemover) { + $http, $location, Dialog, Notifications, RealmRoleRemover, ComponentUtils) { $scope.realm = realm; $scope.role = angular.copy(role); $scope.create = !role.name; @@ -1530,7 +1530,7 @@ module.controller('RoleDetailCtrl', function($scope, realm, role, roles, clients roleControl($scope, realm, role, roles, clients, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites, - $http, $location, Notifications, Dialog); + $http, $location, Notifications, Dialog, ComponentUtils); }); module.controller('RealmSMTPSettingsCtrl', function($scope, Current, Realm, realm, $http, $location, Dialog, Notifications, RealmSMTPConnectionTester) { 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 dec8f34af8..ea95366b2d 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 @@ -20,10 +20,10 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl $scope.realmComposite = CompositeRealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.addRealmRole = function() { - var roles = $scope.selectedRealmRoles; + $scope.realmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']'); $scope.selectedRealmRoles = []; $http.post(authUrl + '/admin/realms/' + realm.realm + '/users/' + user.id + '/role-mappings/realm', - roles).then(function() { + $scope.realmRolesToAdd).then(function() { $scope.realmMappings = RealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.realmRoles = AvailableRealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.realmComposite = CompositeRealmRoleMapping.query({realm : realm.realm, userId : user.id}); @@ -43,8 +43,9 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl }; $scope.deleteRealmRole = function() { + $scope.realmRolesToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/users/' + user.id + '/role-mappings/realm', - {data : $scope.selectedRealmMappings, headers : {"content-type" : "application/json"}}).then(function() { + {data : $scope.realmRolesToRemove, headers : {"content-type" : "application/json"}}).then(function() { $scope.realmMappings = RealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.realmRoles = AvailableRealmRoleMapping.query({realm : realm.realm, userId : user.id}); $scope.realmComposite = CompositeRealmRoleMapping.query({realm : realm.realm, userId : user.id}); @@ -63,8 +64,9 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl }; $scope.addClientRole = function() { + $scope.clientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']'); $http.post(authUrl + '/admin/realms/' + realm.realm + '/users/' + user.id + '/role-mappings/clients/' + $scope.targetClient.id, - $scope.selectedClientRoles).then(function() { + $scope.clientRolesToAdd).then(function() { $scope.clientMappings = ClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); $scope.clientRoles = AvailableClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); $scope.clientComposite = CompositeClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); @@ -77,8 +79,9 @@ module.controller('UserRoleMappingCtrl', function($scope, $http, realm, user, cl }; $scope.deleteClientRole = function() { + $scope.clientRolesToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/users/' + user.id + '/role-mappings/clients/' + $scope.targetClient.id, - {data : $scope.selectedClientMappings, headers : {"content-type" : "application/json"}}).then(function() { + {data : $scope.clientRolesToRemove, headers : {"content-type" : "application/json"}}).then(function() { $scope.clientMappings = ClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); $scope.clientRoles = AvailableClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); $scope.clientComposite = CompositeClientRoleMapping.query({realm : realm.realm, userId : user.id, client : $scope.targetClient.id}); diff --git a/themes/src/main/resources/theme/base/admin/resources/js/services.js b/themes/src/main/resources/theme/base/admin/resources/js/services.js index 3598a2744a..a2751fe67f 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/services.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/services.js @@ -196,6 +196,13 @@ module.factory('ComponentUtils', function() { var utils = {}; + utils.findIndexById = function(array, id) { + for (var i = 0; i < array.length; i++) { + if (array[i].id === id) return i; + } + return -1; + } + utils.addLastEmptyValueToMultivaluedLists = function(properties, config) { if (!properties) { return; @@ -761,7 +768,7 @@ module.factory('RoleClientComposites', function($resource) { function roleControl($scope, realm, role, roles, clients, ClientRole, RoleById, RoleRealmComposites, RoleClientComposites, - $http, $location, Notifications, Dialog) { + $http, $location, Notifications, Dialog, ComponentUtils) { $scope.$watch(function () { return $location.path(); @@ -833,68 +840,76 @@ function roleControl($scope, realm, role, roles, clients, $scope.addRealmRole = function() { $scope.compositeSwitchDisabled=true; + $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']'); $http.post(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites', - $scope.selectedRealmRoles).then(function() { - for (var i = 0; i < $scope.selectedRealmRoles.length; i++) { - var role = $scope.selectedRealmRoles[i]; - var idx = $scope.realmRoles.indexOf($scope.selectedRealmRoles[i]); + $scope.selectedRealmRolesToAdd).then(function() { + for (var i = 0; i < $scope.selectedRealmRolesToAdd.length; i++) { + var role = $scope.selectedRealmRolesToAdd[i]; + var idx = ComponentUtils.findIndexById($scope.realmRoles, role.id); if (idx != -1) { $scope.realmRoles.splice(idx, 1); $scope.realmMappings.push(role); } } $scope.selectedRealmRoles = []; + $scope.selectedRealmRolesToAdd = []; Notifications.success("Role added to composite."); }); }; - + $scope.deleteRealmRole = function() { $scope.compositeSwitchDisabled=true; + $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites', - {data : $scope.selectedRealmMappings, headers : {"content-type" : "application/json"}}).then(function() { - for (var i = 0; i < $scope.selectedRealmMappings.length; i++) { - var role = $scope.selectedRealmMappings[i]; - var idx = $scope.realmMappings.indexOf($scope.selectedRealmMappings[i]); + {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() { + for (var i = 0; i < $scope.selectedRealmMappingsToRemove.length; i++) { + var role = $scope.selectedRealmMappingsToRemove[i]; + var idx = ComponentUtils.findIndexById($scope.realmMappings, role.id); if (idx != -1) { $scope.realmMappings.splice(idx, 1); $scope.realmRoles.push(role); } } $scope.selectedRealmMappings = []; + $scope.selectedRealmMappingsToRemove = []; Notifications.success("Role removed from composite."); }); }; $scope.addClientRole = function() { $scope.compositeSwitchDisabled=true; + $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']'); $http.post(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites', - $scope.selectedClientRoles).then(function() { - for (var i = 0; i < $scope.selectedClientRoles.length; i++) { - var role = $scope.selectedClientRoles[i]; - var idx = $scope.clientRoles.indexOf($scope.selectedClientRoles[i]); + $scope.selectedClientRolesToAdd).then(function() { + for (var i = 0; i < $scope.selectedClientRolesToAdd.length; i++) { + var role = $scope.selectedClientRolesToAdd[i]; + var idx = ComponentUtils.findIndexById($scope.clientRoles, role.id); if (idx != -1) { $scope.clientRoles.splice(idx, 1); $scope.clientMappings.push(role); } } $scope.selectedClientRoles = []; + $scope.selectedClientRolesToAdd = []; Notifications.success("Client role added."); }); }; $scope.deleteClientRole = function() { $scope.compositeSwitchDisabled=true; + $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']'); $http.delete(authUrl + '/admin/realms/' + realm.realm + '/roles-by-id/' + role.id + '/composites', - {data : $scope.selectedClientMappings, headers : {"content-type" : "application/json"}}).then(function() { - for (var i = 0; i < $scope.selectedClientMappings.length; i++) { - var role = $scope.selectedClientMappings[i]; - var idx = $scope.clientMappings.indexOf($scope.selectedClientMappings[i]); + {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() { + for (var i = 0; i < $scope.selectedClientMappingsToRemove.length; i++) { + var role = $scope.selectedClientMappingsToRemove[i]; + var idx = ComponentUtils.findIndexById($scope.clientMappings, role.id); if (idx != -1) { $scope.clientMappings.splice(idx, 1); $scope.clientRoles.push(role); } } $scope.selectedClientMappings = []; + $scope.selectedClientMappingsToRemove = []; Notifications.success("Client role removed."); }); }; diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/client-role-detail.html b/themes/src/main/resources/theme/base/admin/resources/partials/client-role-detail.html index f17872e3e9..9b6fd7d9ab 100755 --- a/themes/src/main/resources/theme/base/admin/resources/partials/client-role-detail.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/client-role-detail.html @@ -63,10 +63,12 @@
{{:: 'composite.available-realm-roles.tooltip' | translate}} -
@@ -78,10 +84,12 @@
{{:: 'assign.available-roles.tooltip' | translate}} -
diff --git a/themes/src/main/resources/theme/base/admin/resources/partials/client-scope-scope-mappings.html b/themes/src/main/resources/theme/base/admin/resources/partials/client-scope-scope-mappings.html index ba2ac7f310..2a52ac0d11 100755 --- a/themes/src/main/resources/theme/base/admin/resources/partials/client-scope-scope-mappings.html +++ b/themes/src/main/resources/theme/base/admin/resources/partials/client-scope-scope-mappings.html @@ -19,10 +19,12 @@ {{:: 'scope.available-roles.tooltip' | translate}} -