mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-30 00:23:21 +00:00 
			
		
		
		
	GUAC-932: Partially-working user editor (no permissions).
This commit is contained in:
		| @@ -27,231 +27,146 @@ angular.module('manage').controller('manageUserController', ['$scope', '$injecto | |||||||
|         function manageUserController($scope, $injector) { |         function manageUserController($scope, $injector) { | ||||||
|              |              | ||||||
|     // Required services |     // Required services | ||||||
|  |     var $location         = $injector.get('$location'); | ||||||
|     var $routeParams      = $injector.get('$routeParams'); |     var $routeParams      = $injector.get('$routeParams'); | ||||||
|     var userService       = $injector.get('userService'); |     var userService       = $injector.get('userService'); | ||||||
|     var permissionService = $injector.get('permissionService'); |     var permissionService = $injector.get('permissionService'); | ||||||
|  |  | ||||||
|     var identifier = $routeParams.id; |     /** | ||||||
|  |      * An action to be provided along with the object sent to showStatus which | ||||||
|  |      * closes the currently-shown status dialog. | ||||||
|  |      */ | ||||||
|  |     var ACKNOWLEDGE_ACTION = { | ||||||
|  |         name        : "manage.error.action.acknowledge", | ||||||
|  |         // Handle action | ||||||
|  |         callback    : function acknowledgeCallback() { | ||||||
|  |             $scope.showStatus(false); | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * The username of the user being edited. | ||||||
|  |      * | ||||||
|  |      * @type String | ||||||
|  |      */ | ||||||
|  |     var username = $routeParams.id; | ||||||
|  |  | ||||||
|     // Pull user data |     // Pull user data | ||||||
|     userService.getUser(identifier).success(function userReceived(user) { |     userService.getUser(username).success(function userReceived(user) { | ||||||
|         $scope.user = user; |         $scope.user = user; | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     // Pull user permissions | ||||||
|  |     permissionService.getPermissions(username).success(function gotPermissions(permissions) { | ||||||
|  |         $scope.permissions = permissions; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|      /** |      /** | ||||||
|      * Close the modal. |      * Cancels all pending edits, returning to the management page. | ||||||
|      */ |      */ | ||||||
|     $scope.close = function close() { |     $scope.cancel = function cancel() { | ||||||
|         userEditModal.deactivate(); |         $location.path('/manage/'); | ||||||
|     }; |  | ||||||
|      |  | ||||||
|     /* |  | ||||||
|      * All the permissions that have been modified since this modal was opened. |  | ||||||
|      * Maps of type or id to value. |  | ||||||
|      */  |  | ||||||
|     $scope.modifiedSystemPermissions = {}; |  | ||||||
|     $scope.modifiedConnectionPermissions = {}; |  | ||||||
|     $scope.modifiedConnectionGroupPermissions = {}; |  | ||||||
|      |  | ||||||
|     $scope.markSystemPermissionModified = function markSystemPermissionModified(type) { |  | ||||||
|         $scope.modifiedSystemPermissions[type] = $scope.systemPermissions[type]; |  | ||||||
|     }; |  | ||||||
|      |  | ||||||
|     $scope.markConnectionPermissionModified = function markConnectionPermissionModified(id) { |  | ||||||
|         $scope.modifiedConnectionPermissions[id] = $scope.connectionPermissions[id]; |  | ||||||
|     }; |  | ||||||
|      |  | ||||||
|     $scope.markConnectionGroupPermissionModified = function markConnectionGroupPermissionModified(id) { |  | ||||||
|         $scope.modifiedConnectionGroupPermissions[id] = $scope.connectionGroupPermissions[id]; |  | ||||||
|     }; |     }; | ||||||
|              |              | ||||||
|     /** |     /** | ||||||
|      * Save the user and close the modal. |      * Saves the user, updating the existing user only. | ||||||
|      */ |      */ | ||||||
|     $scope.save = function save() { |     $scope.saveUser = function saveUser() { | ||||||
|  |  | ||||||
|  |         // Verify passwords match | ||||||
|         if ($scope.passwordMatch !== $scope.user.password) { |         if ($scope.passwordMatch !== $scope.user.password) { | ||||||
|             //TODO: Display an error |             $scope.showStatus({ | ||||||
|  |                 'className'  : 'error', | ||||||
|  |                 'title'      : 'manage.error.title', | ||||||
|  |                 'text'       : 'manage.edit.user.passwordMismatch', | ||||||
|  |                 'actions'    : [ ACKNOWLEDGE_ACTION ] | ||||||
|  |             }); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         userService.saveUser($scope.user).success(function successfullyUpdatedUser() { |         // Save the user | ||||||
|  |         userService.saveUser($scope.user) | ||||||
|  |         .success(function savedUser() { | ||||||
|  |             $location.path('/manage/'); | ||||||
|  |  | ||||||
|             //Figure out what permissions have changed |             // TODO: Save permissions | ||||||
|             var connectionPermissionsToCreate = [], |         }) | ||||||
|                 connectionPermissionsToDelete = [], |  | ||||||
|                 connectionGroupPermissionsToCreate = [], |  | ||||||
|                 connectionGroupPermissionsToDelete = [], |  | ||||||
|                 systemPermissionsToCreate = [], |  | ||||||
|                 systemPermissionsToDelete = []; |  | ||||||
|  |  | ||||||
|             for(var type in $scope.modifiedSystemPermissions) { |         // Notify of any errors | ||||||
|                 // It was added |         .error(function userSaveFailed(error) { | ||||||
|                 if($scope.modifiedSystemPermissions[type] && !originalSystemPermissions[type]) { |             $scope.showStatus({ | ||||||
|                     systemPermissionsToCreate.push(type); |                 'className'  : 'error', | ||||||
|                 } |                 'title'      : 'manage.error.title', | ||||||
|                 // It was removed |                 'text'       : error.message, | ||||||
|                 else if(!$scope.modifiedSystemPermissions[type] && originalSystemPermissions[type]) { |                 'actions'    : [ ACKNOWLEDGE_ACTION ] | ||||||
|                     systemPermissionsToDelete.push(type); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             for(var id in $scope.modifiedConnectionPermissions) { |  | ||||||
|                 // It was added |  | ||||||
|                 if($scope.modifiedConnectionPermissions[id] && !originalConnectionPermissions[id]) { |  | ||||||
|                     connectionPermissionsToCreate.push(id); |  | ||||||
|                 } |  | ||||||
|                 // It was removed |  | ||||||
|                 else if(!$scope.modifiedConnectionPermissions[id] && originalConnectionPermissions[id]) { |  | ||||||
|                     connectionPermissionsToDelete.push(id); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             for(var id in $scope.modifiedConnectionGroupPermissions) { |  | ||||||
|                 // It was added |  | ||||||
|                 if($scope.modifiedConnectionGroupPermissions[id] && !originalConnectionGroupPermissions[id]) { |  | ||||||
|                     connectionGroupPermissionsToCreate.push(id); |  | ||||||
|                 } |  | ||||||
|                 // It was removed |  | ||||||
|                 else if(!$scope.modifiedConnectionGroupPermissions[id] && originalConnectionGroupPermissions[id]) { |  | ||||||
|                     connectionGroupPermissionsToDelete.push(id); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             var permissionsToAdd = []; |  | ||||||
|             var permissionsToRemove = []; |  | ||||||
|              |  | ||||||
|             // Create new connection permissions |  | ||||||
|             for(var i = 0; i < connectionPermissionsToCreate.length; i++) { |  | ||||||
|                 permissionsToAdd.push({ |  | ||||||
|                     objectType :        "CONNECTION", |  | ||||||
|                     objectIdentifier :  connectionPermissionsToCreate[i], |  | ||||||
|                     permissionType :    "READ" |  | ||||||
|             }); |             }); | ||||||
|             } |  | ||||||
|              |  | ||||||
|             // Delete old connection permissions |  | ||||||
|             for(var i = 0; i < connectionPermissionsToDelete.length; i++) { |  | ||||||
|                 permissionsToRemove.push({ |  | ||||||
|                     objectType :        "CONNECTION", |  | ||||||
|                     objectIdentifier :  connectionPermissionsToDelete[i], |  | ||||||
|                     permissionType :    "READ" |  | ||||||
|         }); |         }); | ||||||
|             } |  | ||||||
|  |  | ||||||
|             // Create new connection group permissions |  | ||||||
|             for(var i = 0; i < connectionGroupPermissionsToCreate.length; i++) { |  | ||||||
|                 permissionsToAdd.push({ |  | ||||||
|                     objectType :        "CONNECTION_GROUP", |  | ||||||
|                     objectIdentifier :  connectionGroupPermissionsToCreate[i], |  | ||||||
|                     permissionType :    "READ" |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             // Delete old connection group permissions |  | ||||||
|             for(var i = 0; i < connectionGroupPermissionsToDelete.length; i++) { |  | ||||||
|                 permissionsToRemove.push({ |  | ||||||
|                     objectType :        "CONNECTION_GROUP", |  | ||||||
|                     objectIdentifier :  connectionGroupPermissionsToDelete[i], |  | ||||||
|                     permissionType :    "READ" |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             // Create new system permissions |  | ||||||
|             for(var i = 0; i < systemPermissionsToCreate.length; i++) { |  | ||||||
|                 permissionsToAdd.push({ |  | ||||||
|                     objectType :        "SYSTEM", |  | ||||||
|                     permissionType :    systemPermissionsToCreate[i] |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             // Delete old system permissions |  | ||||||
|             for(var i = 0; i < systemPermissionsToDelete.length; i++) { |  | ||||||
|                 permissionsToRemove.push({ |  | ||||||
|                     objectType :        "SYSTEM", |  | ||||||
|                     permissionType :    systemPermissionsToDelete[i] |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|          |  | ||||||
|             function completeSaveProcess() { |  | ||||||
|                 // Close the modal |  | ||||||
|                 userEditModal.deactivate(); |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             function handleFailure() { |  | ||||||
|                 //TODO: Handle the permission API call failure |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|             if(permissionsToAdd.length || permissionsToRemove.length) { |  | ||||||
|                 // Make the call to update the permissions |  | ||||||
|                 permissionService.patchPermissions( |  | ||||||
|                         $scope.user.username, permissionsToAdd, permissionsToRemove) |  | ||||||
|                         .success(completeSaveProcess).error(handleFailure); |  | ||||||
|             } else { |  | ||||||
|                 completeSaveProcess(); |  | ||||||
|             } |  | ||||||
|              |  | ||||||
|         }); |  | ||||||
|     }; |     }; | ||||||
|      |      | ||||||
|     $scope.permissions = []; |     /** | ||||||
|  |      * An action to be provided along with the object sent to showStatus which | ||||||
|     // Maps of connection and connection group IDs to access permission booleans |      * immediately deletes the current user. | ||||||
|     $scope.connectionPermissions = {}; |      */ | ||||||
|     $scope.connectionGroupPermissions = {}; |     var DELETE_ACTION = { | ||||||
|     $scope.systemPermissions = {}; |         name        : "manage.edit.user.delete", | ||||||
|      |         className   : "danger", | ||||||
|     // The original permissions to compare against  |         // Handle action | ||||||
|     var originalConnectionPermissions, |         callback    : function deleteCallback() { | ||||||
|         originalConnectionGroupPermissions, |             deleteUserImmediately(); | ||||||
|         originalSystemPermissions; |             $scope.showStatus(false); | ||||||
|      |  | ||||||
|     // Get the permissions for the user we are editing |  | ||||||
|     permissionService.getPermissions(identifier).success(function gotPermissions(permissions) { |  | ||||||
|         $scope.permissions = permissions; |  | ||||||
|          |  | ||||||
|         // Figure out if the user has any system level permissions |  | ||||||
|         for(var i = 0; i < $scope.permissions.length; i++) { |  | ||||||
|             var permission = $scope.permissions[i]; |  | ||||||
|             if(permission.objectType === "SYSTEM") { |  | ||||||
|                  |  | ||||||
|                 $scope.systemPermissions[permission.permissionType] = true; |  | ||||||
|                  |  | ||||||
|             // Only READ permission is editable via this UI |  | ||||||
|             } else if (permission.permissionType === "READ") { |  | ||||||
|                 switch(permission.objectType) { |  | ||||||
|                     case "CONNECTION": |  | ||||||
|                         $scope.connectionPermissions[permission.objectIdentifier] = true; |  | ||||||
|                         break; |  | ||||||
|                     case "CONNECTION_GROUP": |  | ||||||
|                         $scope.connectionGroupPermissions[permission.objectIdentifier] = true; |  | ||||||
|                         break; |  | ||||||
|         } |         } | ||||||
|             } |     }; | ||||||
|         } |  | ||||||
|          |  | ||||||
|         // Copy the original permissions so we can compare later |  | ||||||
|         originalConnectionPermissions = angular.copy($scope.connectionPermissions); |  | ||||||
|         originalConnectionGroupPermissions = angular.copy($scope.connectionGroupPermissions); |  | ||||||
|         originalSystemPermissions = angular.copy($scope.systemPermissions); |  | ||||||
|          |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Delete the user and close the modal. |      * An action to be provided along with the object sent to showStatus which | ||||||
|  |      * closes the currently-shown status dialog. | ||||||
|      */ |      */ | ||||||
|     $scope['delete'] = function deleteUser() { |     var CANCEL_ACTION = { | ||||||
|         userService.deleteUser($scope.user).success(function successfullyDeletedUser() { |         name        : "manage.edit.user.cancel", | ||||||
|  |         // Handle action | ||||||
|  |         callback    : function cancelCallback() { | ||||||
|  |             $scope.showStatus(false); | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|             // Remove the user from the list |     /** | ||||||
|             $scope.removeUser($scope.user); |      * Immediately deletes the current user, without prompting the user for | ||||||
|  |      * confirmation. | ||||||
|  |      */ | ||||||
|  |     var deleteUserImmediately = function deleteUserImmediately() { | ||||||
|  |  | ||||||
|             // Close the modal |         // Delete the user  | ||||||
|             userEditModal.deactivate(); |         userService.deleteUser($scope.user) | ||||||
|  |         .success(function deletedUser() { | ||||||
|  |             $location.path('/manage/'); | ||||||
|  |         }) | ||||||
|  |  | ||||||
|  |         // Notify of any errors | ||||||
|  |         .error(function userDeletionFailed(error) { | ||||||
|  |             $scope.showStatus({ | ||||||
|  |                 'className'  : 'error', | ||||||
|  |                 'title'      : 'manage.error.title', | ||||||
|  |                 'text'       : error.message, | ||||||
|  |                 'actions'    : [ ACKNOWLEDGE_ACTION ] | ||||||
|             }); |             }); | ||||||
|  |         }); | ||||||
|  |  | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Deletes the user, prompting the user first to confirm that deletion is | ||||||
|  |      * desired. | ||||||
|  |      */ | ||||||
|  |     $scope.deleteUser = function deleteUser() { | ||||||
|  |  | ||||||
|  |         // Confirm deletion request | ||||||
|  |         $scope.showStatus({ | ||||||
|  |             'title'      : 'manage.edit.user.confirmDelete.title', | ||||||
|  |             'text'       : 'manage.edit.user.confirmDelete.text', | ||||||
|  |             'actions'    : [ DELETE_ACTION, CANCEL_ACTION] | ||||||
|  |         }); | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| }]); | }]); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -60,10 +60,15 @@ THE SOFTWARE. | |||||||
|     <a class="logout button" ng-click="logout()">{{'home.logout' | translate}}</a> |     <a class="logout button" ng-click="logout()">{{'home.logout' | translate}}</a> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <!-- User edit modal --> | <!-- Main property editor --> | ||||||
| <h2>{{user.username}}</h2> | <h2>{{'manage.edit.user.title' | translate}}</h2> | ||||||
| <div class="properties"> | <div class="properties"> | ||||||
|     <table> |     <table> | ||||||
|  |         <tr> | ||||||
|  |             <th>{{'manage.edit.user.username' | translate}}</th> | ||||||
|  |                        | ||||||
|  |             <td>{{user.username}}</td> | ||||||
|  |         </tr> | ||||||
|         <tr> |         <tr> | ||||||
|             <th>{{'manage.edit.user.password' | translate}}</th> |             <th>{{'manage.edit.user.password' | translate}}</th> | ||||||
|                          |                          | ||||||
| @@ -117,9 +122,9 @@ THE SOFTWARE. | |||||||
|     </div> |     </div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <!-- Form controls --> | <!-- Form action buttons --> | ||||||
| <div class="action-buttons"> | <div class="action-buttons"> | ||||||
|     <button ng-click="save()">{{'manage.edit.user.save' | translate}}</button> |     <button ng-click="saveUser()">{{'manage.edit.user.save' | translate}}</button> | ||||||
|     <button ng-click="close()">{{'manage.edit.user.cancel' | translate}}</button> |     <button ng-click="cancel()">{{'manage.edit.user.cancel' | translate}}</button> | ||||||
|     <button ng-click="delete()" class="danger">{{'manage.edit.user.delete' | translate}}</button> |     <button ng-click="deleteUser()" class="danger">{{'manage.edit.user.delete' | translate}}</button> | ||||||
| </div> | </div> | ||||||
| @@ -83,13 +83,20 @@ | |||||||
|                 "name"              : "Name:" |                 "name"              : "Name:" | ||||||
|             }, |             }, | ||||||
|             "user": { |             "user": { | ||||||
|  |                 "title"                     : "Edit User", | ||||||
|                 "cancel"                    : "Cancel", |                 "cancel"                    : "Cancel", | ||||||
|                 "save"                      : "Save", |                 "save"                      : "Save", | ||||||
|                 "delete"                    : "Delete", |                 "delete"                    : "Delete", | ||||||
|  |                 "confirmDelete"     : { | ||||||
|  |                     "title"             : "Delete User", | ||||||
|  |                     "text"              : "Users cannot be restored after they have been deleted. Are you sure you want to delete this user?" | ||||||
|  |                 }, | ||||||
|                 "properties"                : "Properties:", |                 "properties"                : "Properties:", | ||||||
|                 "password"                  : "Password:", |                 "password"                  : "Password:", | ||||||
|                 "passwordMatch"             : "Re-enter Password:", |                 "passwordMatch"             : "Re-enter Password:", | ||||||
|  |                 "passwordMismatch"          : "The provided passwords do not match.", | ||||||
|                 "permissions"               : "Permissions:", |                 "permissions"               : "Permissions:", | ||||||
|  |                 "username"                  : "Username:", | ||||||
|                 "administerSystem"          : "Administer system:", |                 "administerSystem"          : "Administer system:", | ||||||
|                 "createUser"                : "Create new users:", |                 "createUser"                : "Create new users:", | ||||||
|                 "createConnection"          : "Create new connections:", |                 "createConnection"          : "Create new connections:", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user