GUAC-586: Invoke REST service functions across multiple data sources using dataSourceService.apply().

This commit is contained in:
Michael Jumper
2015-08-31 14:08:11 -07:00
parent 8f39671c6b
commit 7235ed980f
6 changed files with 138 additions and 179 deletions

View File

@@ -71,63 +71,6 @@ angular.module('rest').factory('permissionService', ['$injector',
};
/**
* Returns a promise which resolves with all permissions available to the
* given user, as a map of all PermissionSet objects by the identifier of
* their corresponding data source. All given data sources are queried. If
* an error occurs while retrieving any PermissionSet, the promise will be
* rejected.
*
* @param {String[]} dataSources
* The unique identifier of the data sources containing the user whose
* permissions should be retrieved. These identifiers corresponds to
* AuthenticationProviders within the Guacamole web application.
*
* @param {String} username
* The username of the user to retrieve the permissions for.
*
* @returns {Promise.<Object.<String, PermissionSet>>}
* A promise which resolves with all permissions available to the
* current user, as a map of app PermissionSet objects by the
* identifier of their corresponding data source.
*/
service.getAllPermissions = function getAllPermissions(dataSources, username) {
var deferred = $q.defer();
var permissionSetRequests = [];
var permissionSets = {};
// Retrieve all permissions from all data sources
angular.forEach(dataSources, function retrievePermissions(dataSource) {
permissionSetRequests.push(
service.getPermissions(dataSource, username)
.success(function permissionsRetrieved(permissions) {
permissionSets[dataSource] = permissions;
})
);
});
// Resolve when all requests are completed
$q.all(permissionSetRequests)
.then(
// All requests completed successfully
function allPermissionsRetrieved() {
deferred.resolve(permissionSets);
},
// At least one request failed
function permissionRetrievalFailed(e) {
deferred.reject(e);
}
);
return deferred.promise;
};
/**
* Makes a request to the REST API to add permissions for a given user,
* returning a promise that can be used for processing the results of the