Skip to content

Commit 988e673

Browse files
author
Henry Mollman
committed
When the user first hits the index page, redirect them to the instances page if they have no granted orgs (i.e. a personal account)
1 parent 6a200b6 commit 988e673

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

client/config/routes.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ module.exports = [
4343
controller: 'IndexController',
4444
controllerAs: 'COS',
4545
resolve: {
46-
user: function ($state, fetchUser, keypather) {
47-
return fetchUser()
48-
.then(function (user) {
49-
var prevLocation = keypather.get(user, 'attrs.userOptions.uiState.previousLocation.org');
50-
var prevInstance = keypather.get(user, 'attrs.userOptions.uiState.previousLocation.instance');
46+
user: function ($q, $state, fetchUser, fetchGrantedGithubOrgs, keypather) {
47+
return $q.all({ user: fetchUser(), grantedOrgs: fetchGrantedGithubOrgs() })
48+
.then(function (userAndGrantedOrgs) {
49+
var prevLocation = keypather.get(userAndGrantedOrgs, 'user.attrs.userOptions.uiState.previousLocation.org');
50+
var prevInstance = keypather.get(userAndGrantedOrgs, 'user.attrs.userOptions.uiState.previousLocation.instance');
5151
if (prevLocation) {
5252
if (prevInstance) {
5353
$state.go('base.instances.instance', {
@@ -59,10 +59,14 @@ module.exports = [
5959
userName: prevLocation
6060
});
6161
}
62+
} else if (!keypather.get(userAndGrantedOrgs, 'grantedOrgs.models.length')) {
63+
$state.go('base.instances', {
64+
userName: keypather.get(userAndGrantedOrgs, 'user.attrs.accounts.github.username')
65+
});
6266
} else {
6367
$state.go('orgSelect');
6468
}
65-
return user;
69+
return userAndGrantedOrgs.user;
6670
});
6771
}
6872
}

test/unit/services/serviceFetch.unit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('serviceFetch'.bold.underline.blue, function () {
8383
var fetchUserPromise = fetchUser();
8484
$rootScope.$digest();
8585
expect(fetchUserPromise, 'Returned err').to.eventually.rejectedWith(err);
86-
expect(windowMock.location).to.equal('https://runnable.com');
86+
expect(windowMock.location).to.equal('https://runnable.io');
8787
});
8888
});
8989

0 commit comments

Comments
 (0)