2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-22 17:16:20 -04:00
|
|
|
import Route from '@ember/routing/route';
|
2020-07-24 17:05:55 -04:00
|
|
|
import { A } from '@ember/array';
|
2022-11-07 15:17:23 -08:00
|
|
|
import { inject as service } from '@ember/service';
|
2024-01-12 15:01:16 -08:00
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
import { loading } from 'ember-loading';
|
|
|
|
|
import { confirm } from 'core/decorators/confirm';
|
|
|
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
2020-07-22 17:16:20 -04:00
|
|
|
|
|
|
|
|
export default class ScopesRoute extends Route {
|
2022-11-07 15:17:23 -08:00
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service store;
|
|
|
|
|
|
2020-07-24 17:05:55 -04:00
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-30 17:03:59 -04:00
|
|
|
* Attempt to load all scopes from the API. This is allowed
|
2020-07-24 17:05:55 -04:00
|
|
|
* 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.
|
2020-07-30 17:03:59 -04:00
|
|
|
* If scopes fails to load, we still proceed using an empty array.
|
2020-07-24 17:05:55 -04:00
|
|
|
* @param {object} params
|
|
|
|
|
* @param {string} params.scope_id
|
2020-07-30 17:03:59 -04:00
|
|
|
* @return {Promise{[ScopeModel]}}
|
2020-07-24 17:05:55 -04:00
|
|
|
*/
|
2022-07-18 16:36:43 -07:00
|
|
|
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 */
|
|
|
|
|
});
|
2020-07-24 17:05:55 -04:00
|
|
|
// NOTE: In the absence of a `scope_id` query parameter, this endpoint is
|
|
|
|
|
// expected to default to the global scope, thus returning org scopes.
|
2023-11-21 10:36:59 -08:00
|
|
|
return this.store.query('scope', {}).catch(() => A([]));
|
2020-07-24 17:05:55 -04:00
|
|
|
}
|
2024-01-12 15:01:16 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deletes the scope and redirects to index.
|
|
|
|
|
* @param {Model} scope
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
@loading
|
|
|
|
|
@confirm('resources.policy.questions.detach')
|
|
|
|
|
@notifyError(({ message }) => message)
|
|
|
|
|
@notifySuccess('resources.policy.messages.detach')
|
|
|
|
|
async detachStoragePolicy(scope) {
|
|
|
|
|
const { storage_policy_id } = scope;
|
|
|
|
|
scope.storage_policy_id = '';
|
2024-01-19 14:06:51 -08:00
|
|
|
await scope.detachStoragePolicy(storage_policy_id);
|
2024-01-12 15:01:16 -08:00
|
|
|
}
|
2020-07-29 15:47:23 -04:00
|
|
|
}
|