GUAC-975: Do not use index controller as permissions cache.

This commit is contained in:
Michael Jumper
2015-01-04 16:12:55 -08:00
parent a484d77d25
commit 5a6a23cdd7
5 changed files with 63 additions and 57 deletions

View File

@@ -28,20 +28,47 @@ angular.module('home').controller('homeController', ['$scope', '$injector',
// Get required types // Get required types
var ConnectionGroup = $injector.get("ConnectionGroup"); var ConnectionGroup = $injector.get("ConnectionGroup");
var PermissionSet = $injector.get("PermissionSet");
// Get required services // 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 // Retrieve root group and all descendants
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER) connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
.success(function rootGroupRetrieved(rootConnectionGroup) { .success(function rootGroupRetrieved(rootConnectionGroup) {
$scope.rootConnectionGroup = 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);
}); });
}]); }]);

View File

@@ -23,19 +23,19 @@
<div class="connection-list-ui"> <div class="connection-list-ui">
<div class="logout-panel"> <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> <a class="logout button" ng-click="logout()">{{'HOME.ACTION_LOGOUT' | translate}}</a>
</div> </div>
<!-- The recent connections for this user --> <!-- The recent connections for this user -->
<h2>{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}</h2> <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"/> <guac-recent-connections root-group="rootConnectionGroup"/>
</div> </div>
<!-- All connections for this user --> <!-- All connections for this user -->
<h2>{{'HOME.SECTION_HEADER_ALL_CONNECTIONS' | translate}}</h2> <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 <guac-group-list
connection-group="rootConnectionGroup" connection-group="rootConnectionGroup"
connection-template="'app/home/templates/connection.html'" connection-template="'app/home/templates/connection.html'"

View File

@@ -26,16 +26,11 @@
angular.module('index').controller('indexController', ['$scope', '$injector', angular.module('index').controller('indexController', ['$scope', '$injector',
function indexController($scope, $injector) { function indexController($scope, $injector) {
// Required types
var PermissionSet = $injector.get("PermissionSet");
// Required services // Required services
var $document = $injector.get("$document"); var $document = $injector.get("$document");
var $location = $injector.get("$location"); var $location = $injector.get("$location");
var $q = $injector.get("$q"); var $window = $injector.get("$window");
var $window = $injector.get("$window"); var authenticationService = $injector.get("authenticationService");
var authenticationService = $injector.get("authenticationService");
var permissionService = $injector.get("permissionService");
/** /**
* The current status notification, or false if no status is currently * The current status notification, or false if no status is currently
@@ -52,27 +47,35 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
*/ */
$scope.notifications = []; $scope.notifications = [];
// Put some useful variables in the top level scope /**
* Basic page-level information.
*/
$scope.page = { $scope.page = {
/**
* The title of the page.
*
* @type String
*/
title: '', title: '',
/**
* The name of the CSS class to apply to the page body, if any.
*
* @type String
*/
bodyClassName: '' bodyClassName: ''
}; };
$scope.currentUserID = null;
$scope.currentUserIsAdmin = false; /**
$scope.currentUserHasUpdate = false; * The ID of the most recently shown notification, or 0 if no notifications
$scope.currentUserPermissions = null; * have yet been shown.
*
* @type Number
*/
var notificationUniqueID = 0; 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 * Shows or hides the given notification as a modal status. If a status
* notification is currently shown, no further statuses will be shown * 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 // Provide simple mechanism for logging out the current user
$scope.logout = function logout() { $scope.logout = function logout() {
authenticationService.logout()['finally'](function logoutComplete() { 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 // Create event listeners at the global level
var keyboard = new Guacamole.Keyboard($document[0]); var keyboard = new Guacamole.Keyboard($document[0]);

View File

@@ -52,8 +52,6 @@ angular.module('login').controller('loginController', ['$scope', '$injector',
// Redirect to main view upon success // Redirect to main view upon success
.success(function success(data, status, headers, config) { .success(function success(data, status, headers, config) {
// Set up the basic permissions for the user
$scope.loadBasicPermissions();
$location.path('/'); $location.path('/');
}) })

View File

@@ -26,7 +26,7 @@ THE SOFTWARE.
</div> </div>
<h2>{{'MANAGE.SECTION_HEADER_ADMINISTRATION' | translate}}</h2> <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> <h3 class="require-manage-users">{{'MANAGE.SECTION_HEADER_USERS' | translate}}</h3>
<div class="require-manage-users users"> <div class="require-manage-users users">