GUACAMOLE-723: Consider entire connection hierarchy when determining whether only one connection is available.

This commit is contained in:
Michael Jumper
2019-06-23 12:39:44 -07:00
parent b1d3070748
commit 40ee0d3775

View File

@@ -67,7 +67,6 @@ angular.module('navigation').factory('userPageService', ['$injector',
*/ */
var generateHomePage = function generateHomePage(rootGroups, permissions) { var generateHomePage = function generateHomePage(rootGroups, permissions) {
var homePage = null;
var settingsPages = generateSettingsPages(permissions); var settingsPages = generateSettingsPages(permissions);
// If user has access to settings pages, return home page and skip // If user has access to settings pages, return home page and skip
@@ -79,67 +78,87 @@ angular.module('navigation').factory('userPageService', ['$injector',
if (settingsPages.length > 2) if (settingsPages.length > 2)
return SYSTEM_HOME_PAGE; return SYSTEM_HOME_PAGE;
// If exactly one connection or balancing group is available, use
// that as the home page
var clientPages = service.getClientPages(rootGroups);
return (clientPages.length === 1) ? clientPages[0] : SYSTEM_HOME_PAGE;
};
/**
* Adds to the given array all pages that the current user may use to
* access connections or balancing groups that are descendants of the given
* connection group.
*
* @param {PageDefinition[]} clientPages
* The array that pages should be added to.
*
* @param {String} dataSource
* The data source containing the given connection group.
*
* @param {ConnectionGroup} connectionGroup
* The connection group ancestor of the connection or balancing group
* descendants whose pages should be added to the given array.
*/
var addClientPages = function addClientPages(clientPages, dataSource, connectionGroup) {
// Add pages for all child connections
angular.forEach(connectionGroup.childConnections, function addConnectionPage(connection) {
clientPages.push(new PageDefinition({
name : connection.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION,
id : connection.identifier
})
}));
});
// Add pages for all child balancing groups, as well as the connectable
// descendants of all balancing groups of any type
angular.forEach(connectionGroup.childConnectionGroups, function addConnectionGroupPage(connectionGroup) {
if (connectionGroup.type === ConnectionGroup.Type.BALANCING) {
clientPages.push(new PageDefinition({
name : connectionGroup.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION_GROUP,
id : connectionGroup.identifier
})
}));
}
addClientPages(clientPages, dataSource, connectionGroup);
});
};
/**
* Returns a full list of all pages that the current user may use to access
* a connection or balancing group, regardless of the depth of those
* connections/groups within the connection hierarchy.
*
* @param {Object.<String, ConnectionGroup>} rootGroups
* A map of all root connection groups visible to the current user,
* where each key is the identifier of the corresponding data source.
*
* @returns {PageDefinition[]}
* A list of all pages that the current user may use to access a
* connection or balancing group.
*/
service.getClientPages = function getClientPages(rootGroups) {
var clientPages = [];
// Determine whether a connection or balancing group should serve as // Determine whether a connection or balancing group should serve as
// the home page // the home page
for (var dataSource in rootGroups) { for (var dataSource in rootGroups) {
addClientPages(clientPages, dataSource, rootGroups[dataSource]);
}
// Get corresponding root group return clientPages;
var rootGroup = rootGroups[dataSource];
// Get children
var connections = rootGroup.childConnections || [];
var connectionGroups = rootGroup.childConnectionGroups || [];
// Calculate total number of root-level objects
var totalRootObjects = connections.length + connectionGroups.length;
// If exactly one connection or balancing group is available, use
// that as the home page
if (homePage === null && totalRootObjects === 1) {
var connection = connections[0];
var connectionGroup = connectionGroups[0];
// Only one connection present, use as home page
if (connection) {
homePage = new PageDefinition({
name : connection.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION,
id : connection.identifier
})
});
}
// Only one balancing group present, use as home page
if (connectionGroup
&& connectionGroup.type === ConnectionGroup.Type.BALANCING
&& _.isEmpty(connectionGroup.childConnections)
&& _.isEmpty(connectionGroup.childConnectionGroups)) {
homePage = new PageDefinition({
name : connectionGroup.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION_GROUP,
id : connectionGroup.identifier
})
});
}
}
// Otherwise, a connection or balancing group cannot serve as the
// home page
else if (totalRootObjects >= 1) {
homePage = null;
break;
}
} // end for each data source
// Use default home page if no other is available
return homePage || SYSTEM_HOME_PAGE;
}; };