* refactor: 💡 remove route-action usage for groups ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12605
38 lines
856 B
JavaScript
38 lines
856 B
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { inject as service } from '@ember/service';
|
|
|
|
export default class ScopesScopeGroupsRoute 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 groups under current scope
|
|
* @return {Promise[GroupModel]}
|
|
*/
|
|
async model() {
|
|
const scope = this.modelFor('scopes.scope');
|
|
const { id: scope_id } = scope;
|
|
if (this.can.can('list model', scope, { collection: 'groups' })) {
|
|
return this.store.query('group', { scope_id });
|
|
}
|
|
}
|
|
}
|