mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 21:51:23 +00:00
GUAC-932: Update permission service to use Permission class.
This commit is contained in:
@@ -29,61 +29,74 @@ angular.module('rest').factory('permissionService', ['$http', 'authenticationSer
|
|||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a request to the REST API to get the list of permissions for a given user,
|
* Makes a request to the REST API to get the list of permissions for a
|
||||||
* returning a promise that can be used for processing the results of the call.
|
* given user, returning a promise that provides an array of
|
||||||
|
* @link{Permission} objects if successful.
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param {string} userID The ID of the user to retrieve the permissions for.
|
* @param {String} userID
|
||||||
|
* The ID of the user to retrieve the permissions for.
|
||||||
*
|
*
|
||||||
* @returns {promise} A promise for the HTTP call.
|
* @returns {Promise.<Permission[]>}
|
||||||
|
* A promise which will resolve with an array of @link{Permission}
|
||||||
|
* objects upon success.
|
||||||
*/
|
*/
|
||||||
service.getPermissions = function getPermissions(userID) {
|
service.getPermissions = function getPermissions(userID) {
|
||||||
return $http.get("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
return $http.get("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a request to the REST API to add a permission for a given user,
|
* 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 call.
|
* returning a promise that can be used for processing the results of the
|
||||||
|
* call.
|
||||||
*
|
*
|
||||||
* @param {string} userID The ID of the user to add the permission for.
|
* @param {String} userID The ID of the user to add the permission for.
|
||||||
* @param {object} permission The permission to add.
|
* @param {Permission[]} permissions The permissions to add.
|
||||||
*
|
*
|
||||||
* @returns {promise} A promise for the HTTP call.
|
* @returns {Promise}
|
||||||
|
* A promise for the HTTP call which will succeed if and only if the
|
||||||
|
* add operation is successful.
|
||||||
*/
|
*/
|
||||||
service.addPermission = function addPermission(userID, permission) {
|
service.addPermissions = function addPermissions(userID, permissions) {
|
||||||
return $http.post("api/permission/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
|
return service.patchPermissions(userID, permissions, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a request to the REST API to remove a permission for a given user,
|
* Makes a request to the REST API to remove permissions for a given user,
|
||||||
* returning a promise that can be used for processing the results of the call.
|
* returning a promise that can be used for processing the results of the
|
||||||
|
* call.
|
||||||
*
|
*
|
||||||
* @param {string} userID The ID of the user to remove the permission for.
|
* @param {String} userID The ID of the user to remove the permission for.
|
||||||
* @param {object} permission The permission to remove.
|
* @param {Permission[]} permissions The permissions to remove.
|
||||||
*
|
*
|
||||||
* @returns {promise} A promise for the HTTP call.
|
* @returns {Promise}
|
||||||
|
* A promise for the HTTP call which will succeed if and only if the
|
||||||
|
* remove operation is successful.
|
||||||
*/
|
*/
|
||||||
service.removePermission = function removePermission(userID, permission) {
|
service.removePermissions = function removePermissions(userID, permissions) {
|
||||||
return $http.post("api/permission/remove/" + userID + "/?token=" + authenticationService.getCurrentToken(), permission);
|
return service.patchPermissions(userID, [], permissions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a request to the REST API to modify the permissions for a given user,
|
* Makes a request to the REST API to modify the permissions for a given
|
||||||
* returning a promise that can be used for processing the results of the call.
|
* user, returning a promise that can be used for processing the results of
|
||||||
|
* the call.
|
||||||
*
|
*
|
||||||
* @param {string} userID The ID of the user to remove the permission for.
|
* @param {String} userID The ID of the user to remove the permission for.
|
||||||
* @param {array} permissionsToAdd The permissions to add.
|
* @param {Permission[]} permissionsToAdd The permissions to add.
|
||||||
* @param {array} permissionsToRemove The permissions to remove.
|
* @param {Permission[]} permissionsToRemove The permissions to remove.
|
||||||
*
|
*
|
||||||
* @returns {promise} A promise for the HTTP call.
|
* @returns {Promise}
|
||||||
|
* A promise for the HTTP call which will succeed if and only if the
|
||||||
|
* patch operation is successful.
|
||||||
*/
|
*/
|
||||||
service.patchPermissions = function patchPermissions(userID, permissionsToAdd, permissionsToRemove) {
|
service.patchPermissions = function patchPermissions(userID, permissionsToAdd, permissionsToRemove) {
|
||||||
|
|
||||||
|
var i;
|
||||||
var permissionPatch = [];
|
var permissionPatch = [];
|
||||||
|
|
||||||
// Add all the add operations to the patch
|
// Add all the add operations to the patch
|
||||||
for(var i = 0; i < permissionsToAdd.length; i++ ) {
|
for (i = 0; i < permissionsToAdd.length; i++ ) {
|
||||||
permissionPatch.push({
|
permissionPatch.push({
|
||||||
op : "add",
|
op : "add",
|
||||||
path : userID,
|
path : userID,
|
||||||
@@ -92,7 +105,7 @@ angular.module('rest').factory('permissionService', ['$http', 'authenticationSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add all the remove operations to the patch
|
// Add all the remove operations to the patch
|
||||||
for(var i = 0; i < permissionsToRemove.length; i++ ) {
|
for (i = 0; i < permissionsToRemove.length; i++ ) {
|
||||||
permissionPatch.push({
|
permissionPatch.push({
|
||||||
op : "remove",
|
op : "remove",
|
||||||
path : userID,
|
path : userID,
|
||||||
@@ -106,10 +119,9 @@ angular.module('rest').factory('permissionService', ['$http', 'authenticationSer
|
|||||||
url : "api/permission/?token=" + authenticationService.getCurrentToken(),
|
url : "api/permission/?token=" + authenticationService.getCurrentToken(),
|
||||||
data : permissionPatch
|
data : permissionPatch
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
Reference in New Issue
Block a user