Files
threshold-ui/ui/admin/app/controllers/scopes/scope/policies/index.js
T
hashicorp-copywrite[bot] 3692922b3b [COMPLIANCE] Add Copyright and License Headers (#2296)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2024-05-13 12:59:37 -05:00

63 lines
1.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopePoliciesIndexController extends Controller {
// =services
@service can;
@service router;
// =actions
/**
* Rollback changes on a policy.
* @param {PolicyModel} policy
*/
@action
cancel(policy) {
const { isNew } = policy;
policy.rollbackAttributes();
if (isNew) this.router.transitionTo('scopes.scope.policies');
}
/**
* Save a policy in current scope.
* @param {PolicyModel} policy
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess('notifications.save-success')
async save(policy) {
await policy.save();
if (this.can.can('read model', policy)) {
await this.router.transitionTo('scopes.scope.policies.policy', policy);
} else {
await this.router.transitionTo('scopes.scope.policies');
}
await this.router.refresh();
}
/**
* Deletes the policy.
* @param {PolicyModel} policy
*/
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(policy) {
await policy.destroyRecord();
}
}