mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-13 16:37:42 +00:00
GUAC-919: Copy Angular changes from old GUAC-546 branch.
This commit is contained in:
committed by
Michael Jumper
parent
ac2617b92a
commit
5c43ae4ff9
26
guacamole/src/main/webapp/app/permission/permissionModule.js
Normal file
26
guacamole/src/main/webapp/app/permission/permissionModule.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A module for code relating to permissions.
|
||||
*/
|
||||
angular.module('permission', []);
|
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A service for checking if a specific permission exists
|
||||
* in a given list of permissions.
|
||||
*/
|
||||
angular.module('permission').factory('permissionCheckService', [
|
||||
function permissionCheckService() {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* A service for checking if the given permission list contains the given
|
||||
* permission, defined by the objectType, objectID, and permissionType.
|
||||
* If the objectType or objectID are not passed, they will not be checked.
|
||||
*
|
||||
* For example, checkPermission(list, "CONNECTION", undefined, "READ") would
|
||||
* check if the permission list contains permission to read any connection.
|
||||
*
|
||||
* @param {array} permissions The array of permissions to check.
|
||||
* @param {string} objectType The object type for the permission.
|
||||
* If not passed, this will not be checked.
|
||||
* @param {string} objectID The ID of the object the permission is for.
|
||||
* If not passed, this will not be checked.
|
||||
* @param {string} permissionType The actual permission type to check for.
|
||||
* @returns {boolean} True if the given permissions contain the requested permission, false otherwise.
|
||||
*/
|
||||
service.checkPermission = function checkPermission(permissions, objectType, objectID, permissionType) {
|
||||
|
||||
// Loop through all the permissions and check if any of them match the given parameters
|
||||
for(var i = 0; i < permissions.length; i++) {
|
||||
var permission = permissions[i];
|
||||
|
||||
if(objectType === "SYSTEM") {
|
||||
// System permissions have no object ID, we only need to check the type.
|
||||
if(permission.permissionType === permissionType)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// Object permissions need to match the object ID and type if given.
|
||||
if(permission.permissionType === permissionType &&
|
||||
(!objectType || permission.objectType === objectType) &&
|
||||
(!objectID || permission.objectID === objectID))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Didn't find any that matched
|
||||
return false;
|
||||
}
|
||||
|
||||
return service;
|
||||
}]);
|
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The DAO for permission operations agains the REST API.
|
||||
*/
|
||||
angular.module('permission').factory('permissionDAO', ['$http', 'localStorageUtility',
|
||||
function permissionDAO($http, localStorageUtility) {
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to get the list of permissions for a given user,
|
||||
* returning a promise that can be used for processing the results of the call.
|
||||
*
|
||||
* @param {string} userID The ID of the user to retrieve the permissions for.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.getPermissions = function getPermissions(userID) {
|
||||
return $http.get("api/permission/" + userID + "/?token=" + localStorageUtility.get('authToken'));
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to add a permission for a given user,
|
||||
* 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 {object} permission The permission to add.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.addPermission = function addPermission(userID, permission) {
|
||||
return $http.post("api/permission/" + userID + "/?token=" + localStorageUtility.get('authToken'), permission);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to remove a permission for a given 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 {object} permission The permission to remove.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.removePermission = function removePermission(userID, permission) {
|
||||
return $http.post("api/permission/remove/" + userID + "/?token=" + localStorageUtility.get('authToken'), permission);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the REST API to modify the permissions for a given 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 {array} permissionsToAdd The permissions to add.
|
||||
* @param {array} permissionsToRemove The permissions to remove.
|
||||
*
|
||||
* @returns {promise} A promise for the HTTP call.
|
||||
*/
|
||||
service.patchPermissions = function patchPermissions(userID, permissionsToAdd, permissionsToRemove) {
|
||||
var permissionPatch = [];
|
||||
|
||||
// Add all the add operations to the patch
|
||||
for(var i = 0; i < permissionsToAdd.length; i++ ) {
|
||||
permissionPatch.push({
|
||||
op : "add",
|
||||
path : userID,
|
||||
value : permissionsToAdd[i]
|
||||
});
|
||||
}
|
||||
|
||||
// Add all the remove operations to the patch
|
||||
for(var i = 0; i < permissionsToRemove.length; i++ ) {
|
||||
permissionPatch.push({
|
||||
op : "remove",
|
||||
path : userID,
|
||||
value : permissionsToRemove[i]
|
||||
});
|
||||
}
|
||||
|
||||
// Make the HTTP call
|
||||
return $http({
|
||||
method : 'PATCH',
|
||||
url : "api/permission/?token=" + localStorageUtility.get('authToken'),
|
||||
data : permissionPatch
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return service;
|
||||
}]);
|
Reference in New Issue
Block a user