Files
threshold-ui/ui/admin/app/routes/scopes/scope/index.js
T

46 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* 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';
2020-07-24 19:12:20 -04:00
export default class ScopesScopeIndexRoute extends Route {
// =services
@service store;
@service session;
@service router;
2020-07-24 19:12:20 -04:00
// =methods
/**
* Redirects to scopes/scope/authenticate for further processing.
2020-10-27 16:50:10 -04:00
* If already authenticated, redirects to scopes/scope/scopes to display
* list of sub scopes.
2022-06-14 14:21:48 -07:00
*
* If authenticated but no orgs exist, redirect into onboarding.
2020-07-24 19:12:20 -04:00
*/
redirect(model) {
2022-06-14 14:21:48 -07:00
const hasOrgs = this.store.peekAll('scope').filterBy('type', 'org').length;
// Must authenticate before proceeding anywhere else
if (!this.session.isAuthenticated) {
2022-06-14 14:21:48 -07:00
return this.router.transitionTo('scopes.scope.authenticate');
}
// If authenticated but no orgs exist yet, redirect to onboarding
if (this.session.isAuthenticated && !hasOrgs) {
2023-01-31 12:05:52 -08:00
return this.router.transitionTo('onboarding');
}
2022-06-14 14:21:48 -07:00
// If this a project scope, there are no further sub scopes, so show edit
if (model.isProject) {
return this.router.transitionTo('scopes.scope.edit');
}
// For all other scope types (global and org), show sub scopes
return this.router.transitionTo('scopes.scope.scopes');
2020-07-24 19:12:20 -04:00
}
}