2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-24 19:12:20 -04:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
|
|
|
|
|
export default class ScopesIndexRoute extends Route {
|
|
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service session;
|
2022-01-03 12:35:48 -05:00
|
|
|
@service router;
|
2020-07-24 19:12:20 -04:00
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If authenticated, redirects to the scope route of the authenticted scope.
|
|
|
|
|
* If unauthenticated, redirects to the first scope that was loaded (if any).
|
|
|
|
|
* @param {[ScopeModel]} model
|
|
|
|
|
* @param {?ScopeModel} model.firstObject
|
|
|
|
|
*/
|
2020-08-17 14:43:12 -04:00
|
|
|
redirect() {
|
2020-07-29 15:47:23 -04:00
|
|
|
const authenticatedScopeID = get(
|
|
|
|
|
this.session,
|
|
|
|
|
'data.authenticated.scope.id'
|
|
|
|
|
);
|
2020-07-24 19:12:20 -04:00
|
|
|
if (authenticatedScopeID) {
|
2022-01-03 12:35:48 -05:00
|
|
|
this.router.transitionTo('scopes.scope', authenticatedScopeID);
|
2020-08-17 14:43:12 -04:00
|
|
|
} else {
|
2022-01-03 12:35:48 -05:00
|
|
|
this.router.transitionTo('scopes.scope', 'global');
|
2020-07-24 19:12:20 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|