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

53 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';
import { hash } from 'rsvp';
export default class ScopesScopeAuthenticateRoute extends Route {
// =services
@service store;
@service session;
@service clusterUrl;
@service router;
// =methods
beforeModel() {
if (this.session.isAuthenticated)
this.router.replaceWith('scopes.scope.index');
}
/**
* Returns all auth methods for the current scope, along with the current
* scope and all scopes (for org navigation).
* @return {Promise} `{scope, scopes, authMethods}`
*/
model() {
const { id: scope_id } = this.modelFor('scopes.scope');
return hash({
scope: this.modelFor('scopes.scope'),
scopes: this.modelFor('scopes').filter((scope) => scope.isOrg),
authMethods: this.store.query('auth-method', { scope_id }),
});
}
redirect() {
if (!this.clusterUrl.rendererClusterUrl) this.router.replaceWith('index');
}
/**
* Adds the existing clusterUrl, if any, to the controller scope.
* @param {Controller} controller
*/
setupController(controller) {
super.setupController(...arguments);
const clusterUrl = this.clusterUrl.rendererClusterUrl;
controller.setProperties({ clusterUrl });
}
}