Files
threshold-ui/ui/admin/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

69 lines
1.8 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 session;
@service router;
@service resourceFilterStore;
// =methods
beforeModel() {
if (this.session.isAuthenticated)
this.router.transitionTo('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}`
*/
async model() {
const { id: scope_id } = this.modelFor('scopes.scope');
// Fetch auth methods for the current scope
const authMethods = await this.resourceFilterStore.queryBy(
'auth-method',
{
authorized_actions: [{ contains: 'authenticate' }],
},
{
scope_id,
}
);
// Preload all authenticatable auth methods into the store
const authMethodsForAllScopes = await this.resourceFilterStore.queryBy(
'auth-method',
{
authorized_actions: [{ contains: 'authenticate' }],
},
{
scope_id: 'global',
recursive: true,
}
);
// Fetch org scopes
// and filter out any that have no auth methods
const scopes = this.modelFor('scopes').filter(
({ id: scope_id, isOrg }) =>
isOrg && authMethodsForAllScopes.filterBy('scopeID', scope_id).length
);
return hash({
scope: this.modelFor('scopes.scope'),
scopes,
authMethods,
// for integration testing:
// authMethods: A([{
// id: 'am_1234567890',
// type: 'password'
// }])
});
}
}