Files
threshold-ui/ui/admin/app/routes/scopes/scope/index.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

47 lines
1.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class ScopesScopeIndexRoute extends Route {
// =services
@service store;
@service session;
@service router;
// =methods
/**
* Redirects to scopes/scope/authenticate for further processing.
* If already authenticated, redirects to scopes/scope/scopes to display
* list of sub scopes.
*
* If authenticated but no orgs exist, redirect into onboarding.
*/
redirect(model) {
const hasOrgs = this.store.peekAll('scope').filterBy('type', 'org').length;
// Must authenticate before proceeding anywhere else
if (!this.session.isAuthenticated) {
return this.router.transitionTo('scopes.scope.authenticate');
}
// If authenticated but no orgs exist yet, redirect to onboarding
if (this.session.isAuthenticated && !hasOrgs) {
return this.router.transitionTo('onboarding');
}
// 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');
}
}