GUACAMOLE-5: Use contextual actions to add connections and connection groups.

This commit is contained in:
Michael Jumper
2016-08-07 23:41:09 -07:00
parent 4c7af7e692
commit 5779274e25
7 changed files with 174 additions and 16 deletions

View File

@@ -291,7 +291,10 @@ angular.module('manage').controller('manageConnectionController', ['$scope', '$i
// If we are creating a new connection, populate skeleton connection data
else {
$scope.connection = new Connection({ protocol: 'vnc' });
$scope.connection = new Connection({
protocol : 'vnc',
parentIdentifier : $location.search().parent
});
$scope.historyEntryWrappers = [];
$scope.parameters = {};
}

View File

@@ -175,7 +175,9 @@ angular.module('manage').controller('manageConnectionGroupController', ['$scope'
// If we are creating a new connection group, populate skeleton connection group data
else
$scope.connectionGroup = new ConnectionGroup();
$scope.connectionGroup = new ConnectionGroup({
parentIdentifier : $location.search().parent
});
/**
* Available connection group types, as translation string / internal value

View File

@@ -35,6 +35,7 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
// Required types
var ConnectionGroup = $injector.get('ConnectionGroup');
var GroupListItem = $injector.get('GroupListItem');
var PermissionSet = $injector.get('PermissionSet');
// Required services
@@ -205,6 +206,112 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
};
/**
* Returns whether the current user can update the connection group
* having the given identifier within the current data source.
*
* @param {String} identifier
* The identifier of the connection group to check.
*
* @return {Boolean}
* true if the current user can update the connection group
* having the given identifier within the current data source,
* false otherwise.
*/
$scope.canUpdateConnectionGroup = function canUpdateConnectionGroup(identifier) {
// Abort if permissions have not yet loaded
if (!$scope.permissions)
return false;
// Can update the connection if adminstrator or have explicit permission
if (PermissionSet.hasSystemPermission($scope.permissions, PermissionSet.SystemPermissionType.ADMINISTER)
|| PermissionSet.hasConnectionGroupPermission($scope.permissions, PermissionSet.ObjectPermissionType.UPDATE, identifier))
return true;
// Current data sources does not allow the connection group to be updated
return false;
};
/**
* Adds connection-group-specific contextual actions to the given
* array of GroupListItems. Each contextual action will be
* represented by a new GroupListItem.
*
* @param {GroupListItem[]} items
* The array of GroupListItems to which new GroupListItems
* representing connection-group-specific contextual actions
* should be added.
*
* @param {GroupListItem} [parent]
* The GroupListItem representing the connection group which
* contains the given array of GroupListItems, if known.
*/
var addConnectionGroupActions = function addConnectionGroupActions(items, parent) {
// Do nothing if we lack permission to modify the parent at all
if (parent && !$scope.canUpdateConnectionGroup(parent.identifier))
return;
// Add action for creating a child connection, if the user has
// permission to do so
if ($scope.canCreateConnections())
items.push(new GroupListItem({
type : 'new-connection',
dataSource : $scope.dataSource,
weight : 1,
wrappedItem : parent
}));
// Add action for creating a child connection group, if the user
// has permission to do so
if ($scope.canCreateConnectionGroups())
items.push(new GroupListItem({
type : 'new-connection-group',
dataSource : $scope.dataSource,
weight : 1,
wrappedItem : parent
}));
};
/**
* Decorates the given GroupListItem, including all descendants,
* adding contextual actions.
*
* @param {GroupListItem} item
* The GroupListItem which should be decorated with additional
* GroupListItems representing contextual actions.
*/
var decorateItem = function decorateItem(item) {
// If the item is a connection group, add actions specific to
// connection groups
if (item.type === GroupListItem.Type.CONNECTION_GROUP)
addConnectionGroupActions(item.children, item);
// Decorate all children
angular.forEach(item.children, decorateItem);
};
/**
* Callback which decorates all items within the given array of
* GroupListItems, including their descendants, adding contextual
* actions.
*
* @param {GroupListItem[]} items
* The array of GroupListItems which should be decorated with
* additional GroupListItems representing contextual actions.
*/
$scope.rootItemDecorator = function rootItemDecorator(items) {
// Decorate each root-level item
angular.forEach(items, decorateItem);
};
// Retrieve current permissions
permissionService.getPermissions($scope.dataSource, currentUsername)
.success(function permissionsRetrieved(permissions) {
@@ -219,19 +326,19 @@ angular.module('settings').directive('guacSettingsConnections', [function guacSe
if (!$scope.canManageConnections())
$location.path('/');
});
// Retrieve all connections for which we have UPDATE or DELETE permission
dataSourceService.apply(
connectionGroupService.getConnectionGroupTree,
[$scope.dataSource],
ConnectionGroup.ROOT_IDENTIFIER,
[PermissionSet.ObjectPermissionType.UPDATE, PermissionSet.ObjectPermissionType.DELETE]
)
.then(function connectionGroupsReceived(rootGroups) {
$scope.rootGroups = rootGroups;
});
// Retrieve all connections for which we have UPDATE or DELETE permission
dataSourceService.apply(
connectionGroupService.getConnectionGroupTree,
[$scope.dataSource],
ConnectionGroup.ROOT_IDENTIFIER,
[PermissionSet.ObjectPermissionType.UPDATE, PermissionSet.ObjectPermissionType.DELETE]
)
.then(function connectionGroupsReceived(rootGroups) {
$scope.rootGroups = rootGroups;
});
}); // end retrieve permissions
}]
};

View File

@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
.settings.connections .connection-list .new-connection,
.settings.connections .connection-list .new-connection-group {
opacity: 0.5;
font-style: italic;
}
.settings.connections .connection-list .new-connection a,
.settings.connections .connection-list .new-connection a:hover,
.settings.connections .connection-list .new-connection a:visited,
.settings.connections .connection-list .new-connection-group a,
.settings.connections .connection-list .new-connection-group a:hover,
.settings.connections .connection-list .new-connection-group a:visited {
text-decoration:none;
color: black;
}

View File

@@ -0,0 +1,3 @@
<a ng-href="#/manage/{{item.dataSource}}/connections/?parent={{item.wrappedItem.identifier}}">
<span class="name">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION' | translate}}</span>
</a>

View File

@@ -0,0 +1,3 @@
<a ng-href="#/manage/{{item.dataSource}}/connectionGroups/?parent={{item.wrappedItem.identifier}}">
<span class="name">{{'SETTINGS_CONNECTIONS.ACTION_NEW_CONNECTION_GROUP' | translate}}</span>
</a>

View File

@@ -33,9 +33,15 @@
<guac-group-list
page-size="25"
connection-groups="filteredRootGroups"
decorator="rootItemDecorator"
templates="{
'connection' : 'app/settings/templates/connection.html',
'connection-group' : 'app/settings/templates/connectionGroup.html'
'connection-group' : 'app/settings/templates/connectionGroup.html',
'new-connection' : 'app/settings/templates/newConnection.html',
'new-connection-group' : 'app/settings/templates/newConnectionGroup.html'
}"/>
</div>
</div>