GUACAMOLE-220: Ignore missing user or group when retrieving permissions/memberships.

This commit is contained in:
Michael Jumper
2018-10-05 11:56:42 -07:00
parent 7fcb506711
commit adb9aaa5e2
3 changed files with 65 additions and 16 deletions

View File

@@ -248,18 +248,25 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto
var loadExistingUser = function loadExistingUser(dataSource, username) {
return $q.all({
users : dataSourceService.apply(userService.getUser, dataSources, username),
permissions : permissionService.getPermissions(dataSource, username),
parentGroups : membershipService.getUserGroups(dataSource, username)
// Use empty permission set if user cannot be found
permissions:
permissionService.getPermissions(dataSource, username)
['catch'](requestService.defaultValue(new PermissionSet())),
// Assume no parent groups if user cannot be found
parentGroups:
membershipService.getUserGroups(dataSource, username)
['catch'](requestService.defaultValue([]))
})
.then(function userDataRetrieved(values) {
$scope.users = values.users;
$scope.user = values.users[dataSource];
$scope.parentGroups = values.parentGroups;
// Create skeleton user if user does not exist
if (!$scope.user)
$scope.user = new User({
$scope.user = values.users[dataSource] || new User({
'username' : username
});

View File

@@ -303,22 +303,37 @@ angular.module('manage').controller('manageUserGroupController', ['$scope', '$in
var loadExistingUserGroup = function loadExistingGroup(dataSource, identifier) {
return $q.all({
userGroups : dataSourceService.apply(userGroupService.getUserGroup, dataSources, identifier),
permissions : permissionService.getPermissions(dataSource, identifier, true),
parentGroups : membershipService.getUserGroups(dataSource, identifier, true),
memberGroups : membershipService.getMemberUserGroups(dataSource, identifier),
memberUsers : membershipService.getMemberUsers(dataSource, identifier)
// Use empty permission set if group cannot be found
permissions:
permissionService.getPermissions(dataSource, identifier, true)
['catch'](requestService.defaultValue(new PermissionSet())),
// Assume no parent groups if group cannot be found
parentGroups:
membershipService.getUserGroups(dataSource, identifier, true)
['catch'](requestService.defaultValue([])),
// Assume no member groups if group cannot be found
memberGroups:
membershipService.getMemberUserGroups(dataSource, identifier)
['catch'](requestService.defaultValue([])),
// Assume no member users if group cannot be found
memberUsers:
membershipService.getMemberUsers(dataSource, identifier)
['catch'](requestService.defaultValue([]))
})
.then(function userGroupDataRetrieved(values) {
$scope.userGroups = values.userGroups;
$scope.userGroup = values.userGroups[dataSource];
$scope.parentGroups = values.parentGroups;
$scope.memberGroups = values.memberGroups;
$scope.memberUsers = values.memberUsers;
// Create skeleton user group if user group does not exist
if (!$scope.userGroup)
$scope.userGroup = new UserGroup({
$scope.userGroup = values.userGroups[dataSource] || new UserGroup({
'identifier' : identifier
});

View File

@@ -91,6 +91,33 @@ angular.module('rest').factory('requestService', ['$injector',
});
};
/**
* Creates a promise error callback which resolves the promise with the
* given default value only if the @link{Error} in the original rejection
* is a NOT_FOUND error. All other errors are passed through and must be
* handled as yet more rejections.
*
* @param {*} value
* The default value to use to resolve the promise if the promise is
* rejected with a NOT_FOUND error.
*
* @returns {Function}
* A function which can be provided as the error callback for a
* promise.
*/
service.defaultValue = function defaultValue(value) {
return service.createErrorCallback(function resolveIfNotFound(error) {
// Return default value only if not found
if (error.type === Error.Type.NOT_FOUND)
return value;
// Reject promise with original error otherwise
throw error;
});
};
/**
* Promise error callback which ignores all rejections due to REST errors,
* but logs all other rejections, such as those due to JavaScript errors.