Files
threshold-ui/ui/admin/app/routes/scopes/scope/index.js
T
Lisbet Alvarez 3ba93927fe Update copyright headers (#3146)
* empty commit

* Add missing copyright headers

* chore: 🤖 update copywrite config file with correct year

* Add missing copyright headers

* empty commit (gh action merge checks are stuck)
2026-01-28 17:09:06 -08:00

48 lines
1.3 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { 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')
.filter((scope) => scope.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 targets
if (model.isProject) {
return this.router.transitionTo('scopes.scope.targets');
}
// For all other scope types (global and org), show sub scopes
return this.router.transitionTo('scopes.scope.scopes');
}
}