GUAC-586: Pull connection groups from multiple data sources when determining home page.

This commit is contained in:
Michael Jumper
2015-08-31 14:30:55 -07:00
parent e0a4fc3257
commit a68243765a

View File

@@ -69,39 +69,49 @@ 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) {
var homePage = null;
// Determine whether a connection or balancing group should serve as
// the home page
for (var dataSource in rootGroups) {
// Get corresponding root group
var rootGroup = rootGroups[dataSource];
// Get children // Get children
var connections = rootGroup.childConnections || []; var connections = rootGroup.childConnections || [];
var connectionGroups = rootGroup.childConnectionGroups || []; var connectionGroups = rootGroup.childConnectionGroups || [];
// Use main connection list screen as home if multiple connections // If exactly one connection or balancing group is available, use
// are available // that as the home page
if (connections.length + connectionGroups.length === 1) { if (homePage === null && connections.length + connectionGroups.length === 1) {
var connection = connections[0]; var connection = connections[0];
var connectionGroup = connectionGroups[0]; var connectionGroup = connectionGroups[0];
// Only one connection present, use as home page // Only one connection present, use as home page
if (connection) { if (connection) {
return new PageDefinition( homePage = new PageDefinition(
connection.name, connection.name,
'/client/c/' + encodeURIComponent(connection.identifier) '/client/c/' + encodeURIComponent(connection.identifier)
); );
} }
// Only one connection present, use as home page // Only one balancing group present, use as home page
if (connectionGroup if (connectionGroup
&& connectionGroup.type === ConnectionGroup.Type.BALANCING && connectionGroup.type === ConnectionGroup.Type.BALANCING
&& _.isEmpty(connectionGroup.childConnections) && _.isEmpty(connectionGroup.childConnections)
&& _.isEmpty(connectionGroup.childConnectionGroups)) { && _.isEmpty(connectionGroup.childConnectionGroups)) {
return new PageDefinition( homePage = new PageDefinition(
connectionGroup.name, connectionGroup.name,
'/client/g/' + encodeURIComponent(connectionGroup.identifier) '/client/g/' + encodeURIComponent(connectionGroup.identifier)
); );
@@ -109,8 +119,17 @@ angular.module('navigation').factory('userPageService', ['$injector',
} }
// Resolve promise with default home page // Otherwise, a connection or balancing group cannot serve as the
return SYSTEM_HOME_PAGE; // home page
else {
homePage = null;
break;
}
} // end for each data source
// Use default home page if no other is available
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();
}); });