From 5a6a23cdd7e09bc24cefa46abb9eb72fce8e03cd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 4 Jan 2015 16:12:55 -0800 Subject: [PATCH] GUAC-975: Do not use index controller as permissions cache. --- .../app/home/controllers/homeController.js | 37 ++++++++-- .../main/webapp/app/home/templates/home.html | 6 +- .../app/index/controllers/indexController.js | 73 +++++++------------ .../app/login/controllers/loginController.js | 2 - .../webapp/app/manage/templates/manage.html | 2 +- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/guacamole/src/main/webapp/app/home/controllers/homeController.js b/guacamole/src/main/webapp/app/home/controllers/homeController.js index a8d3caccb..b48bf186f 100644 --- a/guacamole/src/main/webapp/app/home/controllers/homeController.js +++ b/guacamole/src/main/webapp/app/home/controllers/homeController.js @@ -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); + }); }]); diff --git a/guacamole/src/main/webapp/app/home/templates/home.html b/guacamole/src/main/webapp/app/home/templates/home.html index 9e8bf7eb8..dda302bf5 100644 --- a/guacamole/src/main/webapp/app/home/templates/home.html +++ b/guacamole/src/main/webapp/app/home/templates/home.html @@ -23,19 +23,19 @@

{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}

-
+

{{'HOME.SECTION_HEADER_ALL_CONNECTIONS' | translate}}

-
+

{{'MANAGE.SECTION_HEADER_ADMINISTRATION' | translate}}

-
+

{{'MANAGE.SECTION_HEADER_USERS' | translate}}