mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +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) {
|
||||
|
||||
// Required services
|
||||
var $location = $injector.get('$location');
|
||||
var $routeParams = $injector.get('$routeParams');
|
||||
var userService = $injector.get('userService');
|
||||
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
|
||||
userService.getUser(identifier).success(function userReceived(user) {
|
||||
userService.getUser(username).success(function userReceived(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() {
|
||||
userEditModal.deactivate();
|
||||
};
|
||||
|
||||
/*
|
||||
* 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];
|
||||
$scope.cancel = function cancel() {
|
||||
$location.path('/manage/');
|
||||
};
|
||||
|
||||
/**
|
||||
* Save the user and close the modal.
|
||||
* Saves the user, updating the existing user only.
|
||||
*/
|
||||
$scope.save = function save() {
|
||||
$scope.saveUser = function saveUser() {
|
||||
|
||||
if($scope.passwordMatch !== $scope.user.password) {
|
||||
//TODO: Display an error
|
||||
// Verify passwords match
|
||||
if ($scope.passwordMatch !== $scope.user.password) {
|
||||
$scope.showStatus({
|
||||
'className' : 'error',
|
||||
'title' : 'manage.error.title',
|
||||
'text' : 'manage.edit.user.passwordMismatch',
|
||||
'actions' : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
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
|
||||
var connectionPermissionsToCreate = [],
|
||||
connectionPermissionsToDelete = [],
|
||||
connectionGroupPermissionsToCreate = [],
|
||||
connectionGroupPermissionsToDelete = [],
|
||||
systemPermissionsToCreate = [],
|
||||
systemPermissionsToDelete = [];
|
||||
// TODO: Save permissions
|
||||
})
|
||||
|
||||
for(var type in $scope.modifiedSystemPermissions) {
|
||||
// It was added
|
||||
if($scope.modifiedSystemPermissions[type] && !originalSystemPermissions[type]) {
|
||||
systemPermissionsToCreate.push(type);
|
||||
}
|
||||
// It was removed
|
||||
else if(!$scope.modifiedSystemPermissions[type] && originalSystemPermissions[type]) {
|
||||
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"
|
||||
// Notify of any errors
|
||||
.error(function userSaveFailed(error) {
|
||||
$scope.showStatus({
|
||||
'className' : 'error',
|
||||
'title' : 'manage.error.title',
|
||||
'text' : error.message,
|
||||
'actions' : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
}
|
||||
|
||||
// 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 = [];
|
||||
|
||||
// Maps of connection and connection group IDs to access permission booleans
|
||||
$scope.connectionPermissions = {};
|
||||
$scope.connectionGroupPermissions = {};
|
||||
$scope.systemPermissions = {};
|
||||
|
||||
// The original permissions to compare against
|
||||
var originalConnectionPermissions,
|
||||
originalConnectionGroupPermissions,
|
||||
originalSystemPermissions;
|
||||
|
||||
// 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;
|
||||
/**
|
||||
* An action to be provided along with the object sent to showStatus which
|
||||
* immediately deletes the current user.
|
||||
*/
|
||||
var DELETE_ACTION = {
|
||||
name : "manage.edit.user.delete",
|
||||
className : "danger",
|
||||
// Handle action
|
||||
callback : function deleteCallback() {
|
||||
deleteUserImmediately();
|
||||
$scope.showStatus(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
userService.deleteUser($scope.user).success(function successfullyDeletedUser() {
|
||||
var CANCEL_ACTION = {
|
||||
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
|
||||
userEditModal.deactivate();
|
||||
// Delete the user
|
||||
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>
|
||||
</div>
|
||||
|
||||
<!-- User edit modal -->
|
||||
<h2>{{user.username}}</h2>
|
||||
<!-- Main property editor -->
|
||||
<h2>{{'manage.edit.user.title' | translate}}</h2>
|
||||
<div class="properties">
|
||||
<table>
|
||||
<tr>
|
||||
<th>{{'manage.edit.user.username' | translate}}</th>
|
||||
|
||||
<td>{{user.username}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{{'manage.edit.user.password' | translate}}</th>
|
||||
|
||||
@@ -117,9 +122,9 @@ THE SOFTWARE.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Form controls -->
|
||||
<!-- Form action buttons -->
|
||||
<div class="action-buttons">
|
||||
<button ng-click="save()">{{'manage.edit.user.save' | translate}}</button>
|
||||
<button ng-click="close()">{{'manage.edit.user.cancel' | translate}}</button>
|
||||
<button ng-click="delete()" class="danger">{{'manage.edit.user.delete' | translate}}</button>
|
||||
<button ng-click="saveUser()">{{'manage.edit.user.save' | translate}}</button>
|
||||
<button ng-click="cancel()">{{'manage.edit.user.cancel' | translate}}</button>
|
||||
<button ng-click="deleteUser()" class="danger">{{'manage.edit.user.delete' | translate}}</button>
|
||||
</div>
|
@@ -83,13 +83,20 @@
|
||||
"name" : "Name:"
|
||||
},
|
||||
"user": {
|
||||
"title" : "Edit User",
|
||||
"cancel" : "Cancel",
|
||||
"save" : "Save",
|
||||
"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:",
|
||||
"password" : "Password:",
|
||||
"passwordMatch" : "Re-enter Password:",
|
||||
"passwordMismatch" : "The provided passwords do not match.",
|
||||
"permissions" : "Permissions:",
|
||||
"username" : "Username:",
|
||||
"administerSystem" : "Administer system:",
|
||||
"createUser" : "Create new users:",
|
||||
"createConnection" : "Create new connections:",
|
||||
|
Reference in New Issue
Block a user