Files
threshold-ui/ui/admin/app/routes/scopes/scope/aliases.js
T
Dharini Jeeva db75b2e292 chore: 🤖 aliases list view (#2197)
* chore: 🤖 aliases list view
2024-03-25 16:54:15 -07:00

57 lines
1.4 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 { all, hash } from 'rsvp';
export default class ScopesScopeAliasesRoute extends Route {
// =services
@service store;
@service session;
@service can;
@service router;
// =methods
/**
* If arriving here unauthenticated, redirect to index for further processing.
*/
beforeModel() {
if (!this.session.isAuthenticated) this.router.transitionTo('index');
}
/**
* Load all aliases in current scope
* @return {Promise<[AliasModel]>}
*/
async model() {
const scope = this.modelFor('scopes.scope');
const { id: scope_id } = scope;
if (
this.can.can('list model', scope, {
collection: 'aliases',
})
) {
const aliases = await this.store.query('alias', { scope_id });
// since we don't receive target info from aliases list API,
// we query the store to fetch target information based on the destination id
const aliasesWithResourceNames = await all(
aliases.map((alias) =>
hash({
alias,
target: alias.destination_id
? this.store.findRecord('target', alias.destination_id)
: null,
}),
),
);
return aliasesWithResourceNames;
}
}
}