* [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>
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { A } from '@ember/array';
|
|
import { inject as service } from '@ember/service';
|
|
|
|
export default class ScopesRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Attempt to load all scopes from the API. This is allowed
|
|
* to fail, since in some cases the user may not have permission to read a
|
|
* scope directly, but may have permission to read resources under it.
|
|
* If scopes fails to load, we still proceed using an empty array.
|
|
* @param {object} params
|
|
* @param {string} params.scope_id
|
|
* @return {Promise{[ScopeModel]}}
|
|
*/
|
|
async model() {
|
|
// Always preload the global scope, if possible, since the query below
|
|
// only fetches org scopes.
|
|
await this.store.findRecord('scope', 'global').catch(() => {
|
|
/* no op */
|
|
});
|
|
// NOTE: In the absence of a `scope_id` query parameter, this endpoint is
|
|
// expected to default to the global scope, thus returning org scopes.
|
|
return this.store.findAll('scope').catch(() => A([]));
|
|
}
|
|
}
|