[KEYCLOAK-4549] - Scope Permission Form is not showing saved resource

This commit is contained in:
Pedro Igor 2017-03-10 17:32:55 -03:00
parent e7cd8d41c6
commit 45caea4dbd
2 changed files with 57 additions and 42 deletions

View file

@ -1042,6 +1042,7 @@ module.controller('ResourceServerPolicyScopeDetailCtrl', function($scope, $route
}; };
$scope.selectResource = function() { $scope.selectResource = function() {
$scope.policy.config.scopes = null;
if ($scope.policy.config.resources) { if ($scope.policy.config.resources) {
ResourceServerResource.scopes({ ResourceServerResource.scopes({
realm: $route.current.params.realm, realm: $route.current.params.realm,
@ -1055,28 +1056,48 @@ module.controller('ResourceServerPolicyScopeDetailCtrl', function($scope, $route
}, },
onInitUpdate : function(policy) { onInitUpdate : function(policy) {
policy.config.resources = eval(policy.config.resources); ResourceServerPolicy.resources({
realm : $route.current.params.realm,
if (policy.config.resources == null) { client : client.id,
policy.config.resources = []; id : policy.id
} }, function(resources) {
if (resources.length > 0) {
if (policy.config.resources.length > 0) { for (i = 0; i < resources.length; i++) {
ResourceServerResource.query({ ResourceServerResource.get({
realm: $route.current.params.realm, realm: $route.current.params.realm,
client: client.id, client: client.id,
_id: policy.config.resources[0], rsrid: resources[0]._id,
deep: false }, function (resource) {
}, function (data) { ResourceServerResource.query({
data[0].text = data[0].name; realm: $route.current.params.realm,
$scope.policy.config.resources = data[0]; client: client.id,
ResourceServerResource.scopes({ _id: resource._id,
realm: $route.current.params.realm, deep: false
client: client.id, }, function (resource) {
rsrid: policy.config.resources[0] resource[0].text = resource[0].name;
}, function (data) { $scope.policy.config.resources = resource[0];
$scope.policy.config.resources.scopes = data; ResourceServerResource.scopes({
}); realm: $route.current.params.realm,
client: client.id,
rsrid: resource[0]._id
}, function (scopes) {
$scope.policy.config.resources.scopes = scopes;
});
ResourceServerPolicy.scopes({
realm: $route.current.params.realm,
client: client.id,
id: policy.id
}, function (scopes) {
$scope.policy.config.scopes = [];
for (i = 0; i < scopes.length; i++) {
$scope.policy.config.scopes.push(scopes[i].id);
}
});
});
});
}
} else {
$scope.policy.config.resources = null;
ResourceServerPolicy.scopes({ ResourceServerPolicy.scopes({
realm : $route.current.params.realm, realm : $route.current.params.realm,
client : client.id, client : client.id,
@ -1084,24 +1105,12 @@ module.controller('ResourceServerPolicyScopeDetailCtrl', function($scope, $route
}, function(scopes) { }, function(scopes) {
$scope.policy.config.scopes = []; $scope.policy.config.scopes = [];
for (i = 0; i < scopes.length; i++) { for (i = 0; i < scopes.length; i++) {
$scope.policy.config.scopes.push(scopes[i].id); scopes[i].text = scopes[i].name;
$scope.policy.config.scopes.push(scopes[i]);
} }
}); });
}); }
} else { });
policy.config.resources = null;
ResourceServerPolicy.scopes({
realm : $route.current.params.realm,
client : client.id,
id : policy.id
}, function(scopes) {
$scope.policy.config.scopes = [];
for (i = 0; i < scopes.length; i++) {
scopes[i].text = scopes[i].name;
$scope.policy.config.scopes.push(scopes[i]);
}
});
}
policy.config.applyPolicies = []; policy.config.applyPolicies = [];
ResourceServerPolicy.associatedPolicies({ ResourceServerPolicy.associatedPolicies({
@ -1119,12 +1128,14 @@ module.controller('ResourceServerPolicyScopeDetailCtrl', function($scope, $route
onUpdate : function() { onUpdate : function() {
if ($scope.policy.config.resources != null) { if ($scope.policy.config.resources != null) {
$scope.policy.config.resources = JSON.stringify([$scope.policy.config.resources._id]); $scope.policy.config.resources = JSON.stringify([$scope.policy.config.resources._id]);
} else {
$scope.policy.config.resources = JSON.stringify([""]);
} }
var scopes = []; var scopes = [];
for (i = 0; i < $scope.policy.config.scopes.length; i++) { for (i = 0; i < $scope.policy.config.scopes.length; i++) {
if ($scope.policy.config.resources == null) { if ($scope.policy.config.scopes[i].id) {
scopes.push($scope.policy.config.scopes[i].id); scopes.push($scope.policy.config.scopes[i].id);
} else { } else {
scopes.push($scope.policy.config.scopes[i]); scopes.push($scope.policy.config.scopes[i]);
@ -1237,8 +1248,12 @@ module.controller('ResourceServerPolicyUserDetailCtrl', function($scope, $route,
$scope.selectedUsers.push(user); $scope.selectedUsers.push(user);
} }
$scope.removeFromList = function(list, index) { $scope.removeFromList = function(list, user) {
list.splice(index, 1); for (i = 0; i < angular.copy(list).length; i++) {
if (user == list[i]) {
list.splice(i, 1);
}
}
} }
}, },

View file

@ -53,7 +53,7 @@
<tr ng-repeat="user in selectedUsers | orderBy:'username'"> <tr ng-repeat="user in selectedUsers | orderBy:'username'">
<td>{{user.username}}</td> <td>{{user.username}}</td>
<td class="kc-action-cell"> <td class="kc-action-cell">
<button class="btn btn-default btn-block btn-sm" ng-click="removeFromList(selectedUsers, $index);">{{:: 'remove' | translate}}</button> <button class="btn btn-default btn-block btn-sm" ng-click="removeFromList(selectedUsers, user);">{{:: 'remove' | translate}}</button>
</td> </td>
</tr> </tr>
<tr data-ng-show="!selectedUsers.length"> <tr data-ng-show="!selectedUsers.length">