GUAC-586: Invoke REST service functions across multiple data sources using dataSourceService.apply().
This commit is contained in:
1 parent
8f39671c6b
commit
7235ed980f
6 files changed
+138
-179
No files matched your search
@@ -78,65 +78,6 @@ angular.module('rest').factory('userService', ['$injector',
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a promise which resolves with all users accessible by the
|
||||
* current user, as a map of @link{User} arrays by the identifier of their
|
||||
* corresponding data source. All given data sources are queried. If an
|
||||
* error occurs while retrieving any user, the promise will be rejected.
|
||||
*
|
||||
* @param {String[]} dataSources
|
||||
* The unique identifier of the data sources containing the user to be
|
||||
* retrieved. These identifiers correspond to AuthenticationProviders
|
||||
* within the Guacamole web application.
|
||||
*
|
||||
* @param {String[]} [permissionTypes]
|
||||
* The set of permissions to filter with. A user must have one or more
|
||||
* of these permissions for a user to appear in the result.
|
||||
* If null, no filtering will be performed. Valid values are listed
|
||||
* within PermissionSet.ObjectType.
|
||||
*
|
||||
* @returns {Promise.<Object.<String, User[]>>}
|
||||
* A promise which resolves with all user objects available to the
|
||||
* current user, as a map of @link{User} arrays grouped by the
|
||||
* identifier of their corresponding data source.
|
||||
*/
|
||||
service.getAllUsers = function getAllUsers(dataSources, permissionTypes) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
var userRequests = [];
|
||||
var userArrays = {};
|
||||
|
||||
// Retrieve all users from all data sources
|
||||
angular.forEach(dataSources, function retrieveUsers(dataSource) {
|
||||
userRequests.push(
|
||||
service.getUsers(dataSource, permissionTypes)
|
||||
.success(function usersRetrieved(users) {
|
||||
userArrays[dataSource] = users;
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Resolve when all requests are completed
|
||||
$q.all(userRequests)
|
||||
.then(
|
||||
|
||||
// All requests completed successfully
|
||||
function allUsersRetrieved() {
|
||||
deferred.resolve(userArrays);
|
||||
},
|
||||
|
||||
// At least one request failed
|
||||
function userRetrievalFailed(e) {
|
||||
deferred.reject(e);
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
return deferred.promise;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the user having the given
|
||||
* username, returning a promise that provides the corresponding
|
||||
|
||||
Reference in new issue
Block a user