GUAC-586: Simplify and fix connection permission checks in management UI.

This commit is contained in:
Michael Jumper
2015-09-03 15:44:03 -07:00
parent 7a47064cd1
commit df34b87460
2 changed files with 28 additions and 56 deletions

View File

@@ -86,7 +86,7 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
* All permissions associated with the current user, or null if the * All permissions associated with the current user, or null if the
* user's permissions have not yet been loaded. * user's permissions have not yet been loaded.
* *
* @type Object.<String, PermissionSet> * @type PermissionSet
*/ */
$scope.permissions = null; $scope.permissions = null;
@@ -106,11 +106,11 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
/** /**
* Returns whether the current user can create new connections * Returns whether the current user can create new connections
* within at least one data source. * within the current data source.
* *
* @return {Boolean} * @return {Boolean}
* true if the current user can create new connections within * true if the current user can create new connections within
* at least one data source, false otherwise. * the current data source, false otherwise.
*/ */
$scope.canCreateConnections = function canCreateConnections() { $scope.canCreateConnections = function canCreateConnections() {
@@ -118,18 +118,10 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
if (!$scope.permissions) if (!$scope.permissions)
return false; return false;
// For each data source // Can create connections if adminstrator or have explicit permission
for (var dataSource in $scope.permissions) { if (PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.ADMINISTER)
|| PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.CREATE_CONNECTION))
// Retrieve corresponding permission set return true;
var permissionSet = $scope.permissions[dataSource];
// Can create connections if adminstrator or have explicit permission
if (PermissionSet.hasSystemPermission(permissionSet, PermissionSet.SystemPermissionType.ADMINISTER)
|| PermissionSet.hasSystemPermission(permissionSet, PermissionSet.SystemPermissionType.CREATE_CONNECTION))
return true;
}
// No data sources allow connection creation // No data sources allow connection creation
return false; return false;
@@ -138,11 +130,11 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
/** /**
* Returns whether the current user can create new connection * Returns whether the current user can create new connection
* groups within at least one data source. * groups within the current data source.
* *
* @return {Boolean} * @return {Boolean}
* true if the current user can create new connection groups * true if the current user can create new connection groups
* within at least one data source, false otherwise. * within the current data source, false otherwise.
*/ */
$scope.canCreateConnectionGroups = function canCreateConnectionGroups() { $scope.canCreateConnectionGroups = function canCreateConnectionGroups() {
@@ -150,18 +142,10 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
if (!$scope.permissions) if (!$scope.permissions)
return false; return false;
// For each data source // Can create connections groups if adminstrator or have explicit permission
for (var dataSource in $scope.permissions) { if (PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.ADMINISTER)
|| PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.CREATE_CONNECTION_GROUP))
// Retrieve corresponding permission set return true;
var permissionSet = $scope.permissions[dataSource];
// Can create connections groups if adminstrator or have explicit permission
if (PermissionSet.hasSystemPermission(permissionSet, PermissionSet.SystemPermissionType.ADMINISTER)
|| PermissionSet.hasSystemPermission(permissionSet, PermissionSet.SystemPermissionType.CREATE_CONNECTION_GROUP))
return true;
}
// No data sources allow connection group creation // No data sources allow connection group creation
return false; return false;
@@ -171,14 +155,14 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
/** /**
* Returns whether the current user can create new connections or * Returns whether the current user can create new connections or
* connection groups or make changes to existing connections or * connection groups or make changes to existing connections or
* connection groups within at least one data source. The * connection groups within the current data source. The
* connection management interface as a whole is useless if this * connection management interface as a whole is useless if this
* function returns false. * function returns false.
* *
* @return {Boolean} * @return {Boolean}
* true if the current user can create new connections/groups * true if the current user can create new connections/groups
* or make changes to existing connections/groups within at * or make changes to existing connections/groups within the
* least one data source, false otherwise. * current data source, false otherwise.
*/ */
$scope.canManageConnections = function canManageConnections() { $scope.canManageConnections = function canManageConnections() {
@@ -190,23 +174,15 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
if ($scope.canCreateConnections() || $scope.canCreateConnectionGroups()) if ($scope.canCreateConnections() || $scope.canCreateConnectionGroups())
return true; return true;
// For each data source // Can manage connections if granted explicit update or delete
for (var dataSource in $scope.permissions) { if (PermissionSet.hasConnectionPermission($scope.permissions, PermissionSet.ObjectPermissionType.UPDATE)
|| PermissionSet.hasConnectionPermission($scope.permissions, PermissionSet.ObjectPermissionType.DELETE))
return true;
// Retrieve corresponding permission set // Can manage connections groups if granted explicit update or delete
var permissionSet = $scope.permissions[dataSource]; if (PermissionSet.hasConnectionGroupPermission($scope.permissions, PermissionSet.ObjectPermissionType.UPDATE)
|| PermissionSet.hasConnectionGroupPermission($scope.permissions, PermissionSet.ObjectPermissionType.DELETE))
// Can manage connections if granted explicit update or delete return true;
if (PermissionSet.hasConnectionPermission(permissionSet, PermissionSet.ObjectPermissionType.UPDATE)
|| PermissionSet.hasConnectionPermission(permissionSet, PermissionSet.ObjectPermissionType.DELETE))
return true;
// Can manage connections groups if granted explicit update or delete
if (PermissionSet.hasConnectionGroupPermission(permissionSet, PermissionSet.ObjectPermissionType.UPDATE)
|| PermissionSet.hasConnectionGroupPermission(permissionSet, PermissionSet.ObjectPermissionType.DELETE))
return true;
}
// No data sources allow management of connections or groups // No data sources allow management of connections or groups
return false; return false;
@@ -214,12 +190,8 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
}; };
// Retrieve current permissions // Retrieve current permissions
dataSourceService.apply( permissionService.getPermissions($scope.dataSource, currentUsername)
permissionService.getPermissions, .success(function permissionsRetrieved(permissions) {
[$scope.dataSource],
currentUsername
)
.then(function permissionsRetrieved(permissions) {
// Store retrieved permissions // Store retrieved permissions
$scope.permissions = permissions; $scope.permissions = permissions;

View File

@@ -28,11 +28,11 @@
<div class="action-buttons"> <div class="action-buttons">
<a class="add-connection button" <a class="add-connection button"
ng-show="canCreateConnections" ng-show="canCreateConnections()"
href="#/manage/{{dataSource}}/connections/">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION' | translate}}</a> href="#/manage/{{dataSource}}/connections/">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION' | translate}}</a>
<a class="add-connection-group button" <a class="add-connection-group button"
ng-show="canCreateConnectionGroups" ng-show="canCreateConnectionGroups()"
href="#/manage/{{dataSource}}/connectionGroups/">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION_GROUP' | translate}}</a> href="#/manage/{{dataSource}}/connectionGroups/">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION_GROUP' | translate}}</a>
</div> </div>