mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-975: Do not use index controller as permissions cache.
This commit is contained in:
@@ -28,20 +28,47 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
|
||||
|
||||
// Get required types
|
||||
var ConnectionGroup = $injector.get("ConnectionGroup");
|
||||
var PermissionSet = $injector.get("PermissionSet");
|
||||
|
||||
// Get required services
|
||||
var connectionGroupService = $injector.get("connectionGroupService");
|
||||
var authenticationService = $injector.get("authenticationService");
|
||||
var connectionGroupService = $injector.get("connectionGroupService");
|
||||
var permissionService = $injector.get("permissionService");
|
||||
|
||||
// Set status to loading until we have all the connections and groups loaded
|
||||
$scope.loading = true;
|
||||
/**
|
||||
* The root connection group, or null if the connection group hierarchy has
|
||||
* not yet been loaded.
|
||||
*
|
||||
* @type ConnectionGroup
|
||||
*/
|
||||
$scope.rootConnectionGroup = null;
|
||||
|
||||
/**
|
||||
* Whether the current user has sufficient permissions to use the
|
||||
* management interface. If permissions have not yet been loaded, this will
|
||||
* be null.
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
$scope.canManageGuacamole = null;
|
||||
|
||||
// Retrieve root group and all descendants
|
||||
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
||||
.success(function rootGroupRetrieved(rootConnectionGroup) {
|
||||
|
||||
$scope.rootConnectionGroup = rootConnectionGroup;
|
||||
$scope.loading = false;
|
||||
});
|
||||
|
||||
// Retrieve current permissions
|
||||
permissionService.getPermissions(authenticationService.getCurrentUserID())
|
||||
.success(function permissionsRetrieved(permissions) {
|
||||
|
||||
// Determine whether the current user can access the management UI
|
||||
$scope.canManageGuacamole =
|
||||
PermissionSet.hasSystemPermission(permissions, PermissionSet.SystemPermissionType.ADMINISTER)
|
||||
|| PermissionSet.hasConnectionPermission(permissions, PermissionSet.ObjectPermissionType.UPDATE)
|
||||
|| PermissionSet.hasConnectionGroupPermission(permissions, PermissionSet.ObjectPermissionType.UPDATE)
|
||||
|| PermissionSet.hasUserPermission(permissions, PermissionSet.ObjectPermissionType.UPDATE);
|
||||
|
||||
});
|
||||
|
||||
}]);
|
||||
|
@@ -23,19 +23,19 @@
|
||||
<div class="connection-list-ui">
|
||||
|
||||
<div class="logout-panel">
|
||||
<a class="manage button" ng-show="currentUserHasUpdate" href="#/manage">{{'HOME.ACTION_MANAGE' | translate}}</a>
|
||||
<a class="manage button" ng-show="canManageGuacamole" href="#/manage">{{'HOME.ACTION_MANAGE' | translate}}</a>
|
||||
<a class="logout button" ng-click="logout()">{{'HOME.ACTION_LOGOUT' | translate}}</a>
|
||||
</div>
|
||||
|
||||
<!-- The recent connections for this user -->
|
||||
<h2>{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}</h2>
|
||||
<div class="recent-connections" ng-class="{loading: loading}">
|
||||
<div class="recent-connections" ng-class="{loading: !rootConnectionGroup}">
|
||||
<guac-recent-connections root-group="rootConnectionGroup"/>
|
||||
</div>
|
||||
|
||||
<!-- All connections for this user -->
|
||||
<h2>{{'HOME.SECTION_HEADER_ALL_CONNECTIONS' | translate}}</h2>
|
||||
<div class="all-connections" ng-class="{loading: loading}">
|
||||
<div class="all-connections" ng-class="{loading: !rootConnectionGroup}">
|
||||
<guac-group-list
|
||||
connection-group="rootConnectionGroup"
|
||||
connection-template="'app/home/templates/connection.html'"
|
||||
|
@@ -26,16 +26,11 @@
|
||||
angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
function indexController($scope, $injector) {
|
||||
|
||||
// Required types
|
||||
var PermissionSet = $injector.get("PermissionSet");
|
||||
|
||||
// Required services
|
||||
var $document = $injector.get("$document");
|
||||
var $location = $injector.get("$location");
|
||||
var $q = $injector.get("$q");
|
||||
var $window = $injector.get("$window");
|
||||
var authenticationService = $injector.get("authenticationService");
|
||||
var permissionService = $injector.get("permissionService");
|
||||
var $document = $injector.get("$document");
|
||||
var $location = $injector.get("$location");
|
||||
var $window = $injector.get("$window");
|
||||
var authenticationService = $injector.get("authenticationService");
|
||||
|
||||
/**
|
||||
* The current status notification, or false if no status is currently
|
||||
@@ -52,27 +47,35 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
*/
|
||||
$scope.notifications = [];
|
||||
|
||||
// Put some useful variables in the top level scope
|
||||
/**
|
||||
* Basic page-level information.
|
||||
*/
|
||||
$scope.page = {
|
||||
|
||||
/**
|
||||
* The title of the page.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
title: '',
|
||||
|
||||
/**
|
||||
* The name of the CSS class to apply to the page body, if any.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
bodyClassName: ''
|
||||
|
||||
};
|
||||
$scope.currentUserID = null;
|
||||
$scope.currentUserIsAdmin = false;
|
||||
$scope.currentUserHasUpdate = false;
|
||||
$scope.currentUserPermissions = null;
|
||||
|
||||
/**
|
||||
* The ID of the most recently shown notification, or 0 if no notifications
|
||||
* have yet been shown.
|
||||
*
|
||||
* @type Number
|
||||
*/
|
||||
var notificationUniqueID = 0;
|
||||
|
||||
// A promise to be fulfilled when all basic user permissions are loaded.
|
||||
var permissionsLoaded= $q.defer();
|
||||
$scope.basicPermissionsLoaded = permissionsLoaded.promise;
|
||||
|
||||
$scope.currentUserID = authenticationService.getCurrentUserID();
|
||||
|
||||
// If the user is unknown, force a login
|
||||
if(!$scope.currentUserID)
|
||||
$location.path('/login');
|
||||
|
||||
/**
|
||||
* Shows or hides the given notification as a modal status. If a status
|
||||
* notification is currently shown, no further statuses will be shown
|
||||
@@ -150,25 +153,6 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
}
|
||||
};
|
||||
|
||||
// Allow the permissions to be reloaded elsewhere if needed
|
||||
$scope.loadBasicPermissions = function loadBasicPermissions() {
|
||||
|
||||
permissionService.getPermissions($scope.currentUserID).success(function fetchCurrentUserPermissions(permissions) {
|
||||
$scope.currentUserPermissions = permissions;
|
||||
|
||||
// Whether the user has system-wide admin permission
|
||||
$scope.currentUserIsAdmin = PermissionSet.hasSystemPermission($scope.currentUserPermissions, PermissionSet.SystemPermissionType.ADMINISTER);
|
||||
|
||||
// Whether the user can update at least one object
|
||||
$scope.currentUserHasUpdate = $scope.currentUserIsAdmin
|
||||
|| PermissionSet.hasConnectionPermission($scope.currentUserPermissions, "UPDATE")
|
||||
|| PermissionSet.hasConnectionGroupPermission($scope.currentUserPermissions, "UPDATE")
|
||||
|| PermissionSet.hasUserPermission($scope.currentUserPermissions, "UPDATE");
|
||||
|
||||
permissionsLoaded.resolve();
|
||||
});
|
||||
};
|
||||
|
||||
// Provide simple mechanism for logging out the current user
|
||||
$scope.logout = function logout() {
|
||||
authenticationService.logout()['finally'](function logoutComplete() {
|
||||
@@ -176,9 +160,6 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
});
|
||||
};
|
||||
|
||||
// Try to load them now
|
||||
$scope.loadBasicPermissions();
|
||||
|
||||
// Create event listeners at the global level
|
||||
var keyboard = new Guacamole.Keyboard($document[0]);
|
||||
|
||||
|
@@ -52,8 +52,6 @@ angular.module('login').controller('loginController', ['$scope', '$injector',
|
||||
|
||||
// Redirect to main view upon success
|
||||
.success(function success(data, status, headers, config) {
|
||||
// Set up the basic permissions for the user
|
||||
$scope.loadBasicPermissions();
|
||||
$location.path('/');
|
||||
})
|
||||
|
||||
|
@@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||
</div>
|
||||
|
||||
<h2>{{'MANAGE.SECTION_HEADER_ADMINISTRATION' | translate}}</h2>
|
||||
<div ng-show="currentUserHasUpdate" class="settings section">
|
||||
<div class="settings section">
|
||||
|
||||
<h3 class="require-manage-users">{{'MANAGE.SECTION_HEADER_USERS' | translate}}</h3>
|
||||
<div class="require-manage-users users">
|
||||
|
Reference in New Issue
Block a user