Skip to content

Commit

Permalink
When the user first hits the index page, redirect them to the instanc…
Browse files Browse the repository at this point in the history
…es page if they have no granted orgs (i.e. a personal account)
  • Loading branch information
Henry Mollman committed Mar 3, 2017
1 parent 6a200b6 commit aa8802c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions client/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ module.exports = [
controller: 'IndexController',
controllerAs: 'COS',
resolve: {
user: function ($state, fetchUser, keypather) {
return fetchUser()
.then(function (user) {
var prevLocation = keypather.get(user, 'attrs.userOptions.uiState.previousLocation.org');
var prevInstance = keypather.get(user, 'attrs.userOptions.uiState.previousLocation.instance');
user: function ($q, $state, fetchUser, fetchGrantedGithubOrgs, keypather) {
return $q.all({ user: fetchUser(), grantedOrgs: fetchGrantedGithubOrgs() })
.then(function (userAndFetchedOrgs) {
var prevLocation = keypather.get(userAndGrantedOrgs, 'user.attrs.userOptions.uiState.previousLocation.org');
var prevInstance = keypather.get(userAndGrantedOrgs, 'user.attrs.userOptions.uiState.previousLocation.instance');
if (prevLocation) {
if (prevInstance) {
$state.go('base.instances.instance', {
Expand All @@ -59,10 +59,14 @@ module.exports = [
userName: prevLocation
});
}
} else if (!keypather.get(userAndGrantedOrgs, 'grantedOrgs.models.length')) {
$state.go('base.instances', {
userName: keypather.get(userAndGrantedOrgs, 'user.attrs.accounts.github.username')
});
} else {
$state.go('orgSelect');
}
return user;
return userAndGrantedOrgs.user;
});
}
}
Expand Down

0 comments on commit aa8802c

Please sign in to comment.