mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-586: Pull connection groups from multiple data sources when determining home page.
This commit is contained in:
@@ -69,48 +69,67 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
/**
|
/**
|
||||||
* Returns an appropriate home page for the current user.
|
* Returns an appropriate home page for the current user.
|
||||||
*
|
*
|
||||||
* @param {ConnectionGroup} rootGroup
|
* @param {Object.<String, ConnectionGroup>} rootGroups
|
||||||
* The root of the connection group tree for the current user.
|
* 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}
|
* @returns {PageDefinition}
|
||||||
* The user's home page.
|
* The user's home page.
|
||||||
*/
|
*/
|
||||||
var generateHomePage = function generateHomePage(rootGroup) {
|
var generateHomePage = function generateHomePage(rootGroups) {
|
||||||
|
|
||||||
// Get children
|
var homePage = null;
|
||||||
var connections = rootGroup.childConnections || [];
|
|
||||||
var connectionGroups = rootGroup.childConnectionGroups || [];
|
|
||||||
|
|
||||||
// Use main connection list screen as home if multiple connections
|
// Determine whether a connection or balancing group should serve as
|
||||||
// are available
|
// the home page
|
||||||
if (connections.length + connectionGroups.length === 1) {
|
for (var dataSource in rootGroups) {
|
||||||
|
|
||||||
var connection = connections[0];
|
// Get corresponding root group
|
||||||
var connectionGroup = connectionGroups[0];
|
var rootGroup = rootGroups[dataSource];
|
||||||
|
|
||||||
|
// Get children
|
||||||
|
var connections = rootGroup.childConnections || [];
|
||||||
|
var connectionGroups = rootGroup.childConnectionGroups || [];
|
||||||
|
|
||||||
|
// If exactly one connection or balancing group is available, use
|
||||||
|
// that as the home page
|
||||||
|
if (homePage === null && connections.length + connectionGroups.length === 1) {
|
||||||
|
|
||||||
|
var connection = connections[0];
|
||||||
|
var connectionGroup = connectionGroups[0];
|
||||||
|
|
||||||
|
// Only one connection present, use as home page
|
||||||
|
if (connection) {
|
||||||
|
homePage = new PageDefinition(
|
||||||
|
connection.name,
|
||||||
|
'/client/c/' + encodeURIComponent(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(
|
||||||
|
connectionGroup.name,
|
||||||
|
'/client/g/' + encodeURIComponent(connectionGroup.identifier)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Only one connection present, use as home page
|
|
||||||
if (connection) {
|
|
||||||
return new PageDefinition(
|
|
||||||
connection.name,
|
|
||||||
'/client/c/' + encodeURIComponent(connection.identifier)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only one connection present, use as home page
|
// Otherwise, a connection or balancing group cannot serve as the
|
||||||
if (connectionGroup
|
// home page
|
||||||
&& connectionGroup.type === ConnectionGroup.Type.BALANCING
|
else {
|
||||||
&& _.isEmpty(connectionGroup.childConnections)
|
homePage = null;
|
||||||
&& _.isEmpty(connectionGroup.childConnectionGroups)) {
|
break;
|
||||||
return new PageDefinition(
|
|
||||||
connectionGroup.name,
|
|
||||||
'/client/g/' + encodeURIComponent(connectionGroup.identifier)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // end for each data source
|
||||||
|
|
||||||
// Resolve promise with default home page
|
// Use default home page if no other is available
|
||||||
return SYSTEM_HOME_PAGE;
|
return homePage || SYSTEM_HOME_PAGE;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -125,10 +144,14 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
// Resolve promise using home page derived from root connection group
|
// Resolve promise using home page derived from root connection groups
|
||||||
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
dataSourceService.apply(
|
||||||
.success(function rootConnectionGroupRetrieved(rootGroup) {
|
connectionGroupService.getConnectionGroupTree,
|
||||||
deferred.resolve(generateHomePage(rootGroup));
|
authenticationService.getAvailableDataSources(),
|
||||||
|
ConnectionGroup.ROOT_IDENTIFIER
|
||||||
|
)
|
||||||
|
.then(function rootConnectionGroupsRetrieved(rootGroups) {
|
||||||
|
deferred.resolve(generateHomePage(rootGroups));
|
||||||
});
|
});
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
@@ -280,8 +303,9 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
* include the home page, manage pages, etc. In the case that there are no
|
* include the home page, manage pages, etc. In the case that there are no
|
||||||
* applicable pages of this sort, it may return a client page.
|
* applicable pages of this sort, it may return a client page.
|
||||||
*
|
*
|
||||||
* @param {ConnectionGroup} rootGroup
|
* @param {Object.<String, ConnectionGroup>} rootGroups
|
||||||
* The root of the connection group tree for the current user.
|
* A map of all root connection groups visible to the current user,
|
||||||
|
* where each key is the identifier of the corresponding data source.
|
||||||
*
|
*
|
||||||
* @param {Object.<String, PermissionSet>} permissions
|
* @param {Object.<String, PermissionSet>} permissions
|
||||||
* A map of all permissions granted to the current user, where each
|
* A map of all permissions granted to the current user, where each
|
||||||
@@ -290,12 +314,12 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
* @returns {Page[]}
|
* @returns {Page[]}
|
||||||
* An array of all main pages that the current user can visit.
|
* An array of all main pages that the current user can visit.
|
||||||
*/
|
*/
|
||||||
var generateMainPages = function generateMainPages(rootGroup, permissions) {
|
var generateMainPages = function generateMainPages(rootGroups, permissions) {
|
||||||
|
|
||||||
var pages = [];
|
var pages = [];
|
||||||
|
|
||||||
// Get home page and settings pages
|
// Get home page and settings pages
|
||||||
var homePage = generateHomePage(rootGroup);
|
var homePage = generateHomePage(rootGroups);
|
||||||
var settingsPages = generateSettingsPages(permissions);
|
var settingsPages = generateSettingsPages(permissions);
|
||||||
|
|
||||||
// Only include the home page in the list of main pages if the user
|
// Only include the home page in the list of main pages if the user
|
||||||
@@ -328,7 +352,7 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
var rootGroup = null;
|
var rootGroups = null;
|
||||||
var permissions = null;
|
var permissions = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -336,14 +360,18 @@ angular.module('navigation').factory('userPageService', ['$injector',
|
|||||||
* insufficient data is available, this function does nothing.
|
* insufficient data is available, this function does nothing.
|
||||||
*/
|
*/
|
||||||
var resolveMainPages = function resolveMainPages() {
|
var resolveMainPages = function resolveMainPages() {
|
||||||
if (rootGroup && permissions)
|
if (rootGroups && permissions)
|
||||||
deferred.resolve(generateMainPages(rootGroup, permissions));
|
deferred.resolve(generateMainPages(rootGroups, permissions));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Retrieve root group, resolving main pages if possible
|
// Retrieve root group, resolving main pages if possible
|
||||||
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER)
|
dataSourceService.apply(
|
||||||
.success(function rootConnectionGroupRetrieved(retrievedRootGroup) {
|
connectionGroupService.getConnectionGroupTree,
|
||||||
rootGroup = retrievedRootGroup;
|
authenticationService.getAvailableDataSources(),
|
||||||
|
ConnectionGroup.ROOT_IDENTIFIER
|
||||||
|
)
|
||||||
|
.then(function rootConnectionGroupsRetrieved(retrievedRootGroups) {
|
||||||
|
rootGroups = retrievedRootGroups;
|
||||||
resolveMainPages();
|
resolveMainPages();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user