mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUAC-586: Add data source to user and permissions services.
This commit is contained in:
		| @@ -150,7 +150,7 @@ angular.module('index').config(['$routeProvider', '$locationProvider', | ||||
|         }) | ||||
|  | ||||
|         // User editor | ||||
|         .when('/manage/users/:id', { | ||||
|         .when('/manage/:dataSource/users/:id', { | ||||
|             title         : 'APP.NAME', | ||||
|             bodyClassName : 'manage', | ||||
|             templateUrl   : 'app/manage/templates/manageUser.html', | ||||
|   | ||||
| @@ -53,6 +53,14 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
|      * The unique identifier of the data source containing the user being | ||||
|      * edited. | ||||
|      * | ||||
|      * @type String | ||||
|      */ | ||||
|     var dataSource = $routeParams.dataSource; | ||||
|  | ||||
|     /** | ||||
|      * The username of the user being edited. | ||||
|      * | ||||
| @@ -137,12 +145,12 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | ||||
|     }); | ||||
|  | ||||
|     // Pull user data | ||||
|     userService.getUser(username).success(function userReceived(user) { | ||||
|     userService.getUser(dataSource, username).success(function userReceived(user) { | ||||
|         $scope.user = user; | ||||
|     }); | ||||
|  | ||||
|     // Pull user permissions | ||||
|     permissionService.getPermissions(username).success(function gotPermissions(permissions) { | ||||
|     permissionService.getPermissions(dataSource, username).success(function gotPermissions(permissions) { | ||||
|         $scope.permissionFlags = PermissionFlagSet.fromPermissionSet(permissions); | ||||
|     }); | ||||
|  | ||||
| @@ -152,8 +160,8 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | ||||
|         $scope.rootGroup = rootGroup; | ||||
|     }); | ||||
|      | ||||
|     // Query the user's permissions for the current connection | ||||
|     permissionService.getPermissions(authenticationService.getCurrentUsername()) | ||||
|     // Query the user's permissions for the current user | ||||
|     permissionService.getPermissions(dataSource, authenticationService.getCurrentUsername()) | ||||
|             .success(function permissionsReceived(permissions) { | ||||
|  | ||||
|         $scope.permissions = permissions; | ||||
| @@ -508,11 +516,11 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | ||||
|         } | ||||
|  | ||||
|         // Save the user | ||||
|         userService.saveUser($scope.user) | ||||
|         userService.saveUser(dataSource, $scope.user) | ||||
|         .success(function savedUser() { | ||||
|  | ||||
|             // Upon success, save any changed permissions | ||||
|             permissionService.patchPermissions($scope.user.username, permissionsAdded, permissionsRemoved) | ||||
|             permissionService.patchPermissions(dataSource, $scope.user.username, permissionsAdded, permissionsRemoved) | ||||
|             .success(function patchedUserPermissions() { | ||||
|                 $location.path('/settings/users'); | ||||
|             }) | ||||
| @@ -574,7 +582,7 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | ||||
|     var deleteUserImmediately = function deleteUserImmediately() { | ||||
|  | ||||
|         // Delete the user  | ||||
|         userService.deleteUser($scope.user) | ||||
|         userService.deleteUser(dataSource, $scope.user) | ||||
|         .success(function deletedUser() { | ||||
|             $location.path('/settings/users'); | ||||
|         }) | ||||
|   | ||||
| @@ -41,6 +41,11 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      * given user, returning a promise that provides an array of | ||||
|      * @link{Permission} objects if successful. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user whose | ||||
|      *     permissions should be retrieved. This identifier corresponds to an | ||||
|      *     AuthenticationProvider within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} userID | ||||
|      *     The ID of the user to retrieve the permissions for. | ||||
|      *                           | ||||
| @@ -48,7 +53,7 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      *     A promise which will resolve with a @link{PermissionSet} upon | ||||
|      *     success. | ||||
|      */ | ||||
|     service.getPermissions = function getPermissions(userID) { | ||||
|     service.getPermissions = function getPermissions(dataSource, userID) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -59,7 +64,7 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|         return $http({ | ||||
|             cache   : cacheService.users, | ||||
|             method  : 'GET', | ||||
|             url     : 'api/users/' + encodeURIComponent(userID) + '/permissions', | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(userID) + '/permissions', | ||||
|             params  : httpParameters | ||||
|         }); | ||||
|  | ||||
| @@ -70,6 +75,11 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      * returning a promise that can be used for processing the results of the | ||||
|      * call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user whose | ||||
|      *     permissions should be modified. This identifier corresponds to an | ||||
|      *     AuthenticationProvider within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} userID | ||||
|      *     The ID of the user to modify the permissions of. | ||||
|      *                           | ||||
| @@ -80,8 +90,8 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     add operation is successful. | ||||
|      */ | ||||
|     service.addPermissions = function addPermissions(userID, permissions) { | ||||
|         return service.patchPermissions(userID, permissions, null); | ||||
|     service.addPermissions = function addPermissions(dataSource, userID, permissions) { | ||||
|         return service.patchPermissions(dataSource, userID, permissions, null); | ||||
|     }; | ||||
|      | ||||
|     /** | ||||
| @@ -89,6 +99,11 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      * returning a promise that can be used for processing the results of the | ||||
|      * call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user whose | ||||
|      *     permissions should be modified. This identifier corresponds to an | ||||
|      *     AuthenticationProvider within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} userID | ||||
|      *     The ID of the user to modify the permissions of. | ||||
|      *                           | ||||
| @@ -99,8 +114,8 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     remove operation is successful. | ||||
|      */ | ||||
|     service.removePermissions = function removePermissions(userID, permissions) { | ||||
|         return service.patchPermissions(userID, null, permissions); | ||||
|     service.removePermissions = function removePermissions(dataSource, userID, permissions) { | ||||
|         return service.patchPermissions(dataSource, userID, null, permissions); | ||||
|     }; | ||||
|  | ||||
|     /** | ||||
| @@ -186,6 +201,11 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      * user, returning a promise that can be used for processing the results of | ||||
|      * the call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user whose | ||||
|      *     permissions should be modified. This identifier corresponds to an | ||||
|      *     AuthenticationProvider within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} userID | ||||
|      *     The ID of the user to modify the permissions of. | ||||
|      *                           | ||||
| @@ -199,7 +219,7 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|      *     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(dataSource, userID, permissionsToAdd, permissionsToRemove) { | ||||
|  | ||||
|         var permissionPatch = []; | ||||
|          | ||||
| @@ -217,7 +237,7 @@ angular.module('rest').factory('permissionService', ['$injector', | ||||
|         // Patch user permissions | ||||
|         return $http({ | ||||
|             method  : 'PATCH',  | ||||
|             url     : 'api/users/' + encodeURIComponent(userID) + '/permissions', | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(userID) + '/permissions', | ||||
|             params  : httpParameters, | ||||
|             data    : permissionPatch | ||||
|         }) | ||||
|   | ||||
| @@ -41,6 +41,11 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * returning a promise that provides an array of @link{User} objects if | ||||
|      * successful. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the users to be | ||||
|      *     retrieved. This identifier corresponds to an AuthenticationProvider | ||||
|      *     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.  | ||||
| @@ -51,7 +56,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      *     A promise which will resolve with an array of @link{User} objects | ||||
|      *     upon success. | ||||
|      */ | ||||
|     service.getUsers = function getUsers(permissionTypes) { | ||||
|     service.getUsers = function getUsers(dataSource, permissionTypes) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -66,7 +71,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         return $http({ | ||||
|             cache   : cacheService.users, | ||||
|             method  : 'GET', | ||||
|             url     : 'api/users', | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users', | ||||
|             params  : httpParameters | ||||
|         }); | ||||
|  | ||||
| @@ -76,14 +81,19 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * Makes a request to the REST API to get the user having the given | ||||
|      * username, returning a promise that provides the corresponding | ||||
|      * @link{User} if successful. | ||||
|      *  | ||||
|      * | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user to be | ||||
|      *     retrieved. This identifier corresponds to an AuthenticationProvider | ||||
|      *     within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} username | ||||
|      *     The username of the user to retrieve. | ||||
|      *  | ||||
|      * @returns {Promise.<User>} | ||||
|      *     A promise which will resolve with a @link{User} upon success. | ||||
|      */ | ||||
|     service.getUser = function getUser(username) { | ||||
|     service.getUser = function getUser(dataSource, username) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -94,7 +104,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         return $http({ | ||||
|             cache   : cacheService.users, | ||||
|             method  : 'GET', | ||||
|             url     : 'api/users/' + encodeURIComponent(username), | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(username), | ||||
|             params  : httpParameters | ||||
|         }); | ||||
|  | ||||
| @@ -104,6 +114,11 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * Makes a request to the REST API to delete a user, returning a promise | ||||
|      * that can be used for processing the results of the call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user to be | ||||
|      *     deleted. This identifier corresponds to an AuthenticationProvider | ||||
|      *     within the Guacamole web application. | ||||
|      * | ||||
|      * @param {User} user | ||||
|      *     The user to delete. | ||||
|      *                           | ||||
| @@ -111,7 +126,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     delete operation is successful. | ||||
|      */ | ||||
|     service.deleteUser = function deleteUser(user) { | ||||
|     service.deleteUser = function deleteUser(dataSource, user) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -121,7 +136,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         // Delete user | ||||
|         return $http({ | ||||
|             method  : 'DELETE', | ||||
|             url     : 'api/users/' + encodeURIComponent(user.username), | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(user.username), | ||||
|             params  : httpParameters | ||||
|         }) | ||||
|  | ||||
| @@ -137,6 +152,11 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * Makes a request to the REST API to create a user, returning a promise | ||||
|      * that can be used for processing the results of the call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source in which the user should be | ||||
|      *     created. This identifier corresponds to an AuthenticationProvider | ||||
|      *     within the Guacamole web application. | ||||
|      * | ||||
|      * @param {User} user | ||||
|      *     The user to create. | ||||
|      *                           | ||||
| @@ -144,7 +164,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     create operation is successful. | ||||
|      */ | ||||
|     service.createUser = function createUser(user) { | ||||
|     service.createUser = function createUser(dataSource, user) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -154,7 +174,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         // Create user | ||||
|         return $http({ | ||||
|             method  : 'POST', | ||||
|             url     : 'api/users', | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users', | ||||
|             params  : httpParameters, | ||||
|             data    : user | ||||
|         }) | ||||
| @@ -170,6 +190,11 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * Makes a request to the REST API to save a user, returning a promise that | ||||
|      * can be used for processing the results of the call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user to be | ||||
|      *     updated. This identifier corresponds to an AuthenticationProvider | ||||
|      *     within the Guacamole web application. | ||||
|      * | ||||
|      * @param {User} user | ||||
|      *     The user to update. | ||||
|      *                           | ||||
| @@ -177,7 +202,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     save operation is successful. | ||||
|      */ | ||||
|     service.saveUser = function saveUser(user) { | ||||
|     service.saveUser = function saveUser(dataSource, user) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
|         var httpParameters = { | ||||
| @@ -187,7 +212,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         // Update user | ||||
|         return $http({ | ||||
|             method  : 'PUT', | ||||
|             url     : 'api/users/' + encodeURIComponent(user.username), | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(user.username), | ||||
|             params  : httpParameters, | ||||
|             data    : user | ||||
|         }) | ||||
| @@ -203,6 +228,11 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      * Makes a request to the REST API to update the password for a user,  | ||||
|      * returning a promise that can be used for processing the results of the call. | ||||
|      *  | ||||
|      * @param {String} dataSource | ||||
|      *     The unique identifier of the data source containing the user to be | ||||
|      *     updated. This identifier corresponds to an AuthenticationProvider | ||||
|      *     within the Guacamole web application. | ||||
|      * | ||||
|      * @param {String} username | ||||
|      *     The username of the user to update. | ||||
|      *      | ||||
| @@ -216,7 +246,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|      *     A promise for the HTTP call which will succeed if and only if the | ||||
|      *     password update operation is successful. | ||||
|      */ | ||||
|     service.updateUserPassword = function updateUserPassword(username,  | ||||
|     service.updateUserPassword = function updateUserPassword(dataSource, username, | ||||
|             oldPassword, newPassword) { | ||||
|  | ||||
|         // Build HTTP parameters set | ||||
| @@ -227,7 +257,7 @@ angular.module('rest').factory('userService', ['$injector', | ||||
|         // Update user password | ||||
|         return $http({ | ||||
|             method  : 'PUT', | ||||
|             url     : 'api/users/' + encodeURIComponent(username) + '/password', | ||||
|             url     : 'api/data/' + encodeURIComponent(dataSource) + '/users/' + encodeURIComponent(username) + '/password', | ||||
|             params  : httpParameters, | ||||
|             data    : new UserPasswordUpdate({ | ||||
|                 oldPassword : oldPassword, | ||||
|   | ||||
| @@ -62,6 +62,15 @@ angular.module('settings').directive('guacSettingsUsers', [function guacSettings | ||||
|                 } | ||||
|             }; | ||||
|  | ||||
|             /** | ||||
|              * The data source from which the list of users should be pulled. | ||||
|              * For the time being, this is just the data source which | ||||
|              * authenticated the current user. | ||||
|              * | ||||
|              * @type String | ||||
|              */ | ||||
|             $scope.dataSource = authenticationService.getDataSource(); | ||||
|  | ||||
|             /** | ||||
|              * All visible users. | ||||
|              * | ||||
| @@ -118,7 +127,7 @@ angular.module('settings').directive('guacSettingsUsers', [function guacSettings | ||||
|             }; | ||||
|  | ||||
|             // Retrieve current permissions | ||||
|             permissionService.getPermissions(currentUsername) | ||||
|             permissionService.getPermissions($scope.dataSource, currentUsername) | ||||
|             .success(function permissionsRetrieved(permissions) { | ||||
|  | ||||
|                 $scope.permissions = permissions; | ||||
| @@ -141,8 +150,10 @@ angular.module('settings').directive('guacSettingsUsers', [function guacSettings | ||||
|             }); | ||||
|  | ||||
|             // Retrieve all users for whom we have UPDATE or DELETE permission | ||||
|             userService.getUsers([PermissionSet.ObjectPermissionType.UPDATE,  | ||||
|                 PermissionSet.ObjectPermissionType.DELETE]) | ||||
|             userService.getUsers($scope.dataSource, [ | ||||
|                 PermissionSet.ObjectPermissionType.UPDATE, | ||||
|                 PermissionSet.ObjectPermissionType.DELETE | ||||
|             ]) | ||||
|             .success(function usersReceived(users) { | ||||
|  | ||||
|                 // Display only other users, not self | ||||
| @@ -164,7 +175,7 @@ angular.module('settings').directive('guacSettingsUsers', [function guacSettings | ||||
|                 }); | ||||
|  | ||||
|                 // Create specified user | ||||
|                 userService.createUser(user) | ||||
|                 userService.createUser($scope.dataSource, user) | ||||
|  | ||||
|                 // Add user to visible list upon success | ||||
|                 .success(function userCreated() { | ||||
|   | ||||
| @@ -33,7 +33,7 @@ | ||||
|     <!-- List of users this user has access to --> | ||||
|     <div class="user-list"> | ||||
|         <div ng-repeat="user in userPage" class="user list-item"> | ||||
|             <a ng-href="#/manage/users/{{user.username}}"> | ||||
|             <a ng-href="#/manage/{{dataSource}}/users/{{user.username}}"> | ||||
|                 <div class="caption"> | ||||
|                     <div class="icon user"></div> | ||||
|                     <span class="name">{{user.username}}</span> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user