Files
threshold-ui/ui/admin/app/routes/scopes/scope/scopes.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

49 lines
1.1 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';
/**
* The scopes route lists subscopes under the currently active scope.
* For the global scope, the listed scopes are orgs.
* For org scopes, the listed scopes are projects.
*/
export default class ScopesScopeScopesRoute extends Route {
// =services
@service store;
@service session;
@service router;
// =methods
/**
* If arriving here unauthenticated, redirect to index for further processing.
*/
beforeModel() {
if (!this.session.isAuthenticated) this.router.transitionTo('index');
}
/**
* Loads sub scopes for the current scope.
* @return {Promise}
*/
async model() {
const currentScope = this.modelFor('scopes.scope');
const parentScope = !currentScope.isGlobal
? await this.store.findRecord('scope', currentScope.scopeID)
: null;
const subScopes = await this.store.query('scope', {
scope_id: currentScope.id,
});
return {
currentScope,
parentScope,
subScopes,
};
}
}