open-consul/ui-v2/app/components/policy-form.js
John Cowen 0c12a0fef1
ui: Remove the Policy/Service Identity selector from nspaces (#7124)
When editing Nspaces, although you can assign policies to a nspace using
PolicyDefaults you cannot assign a Service Identity to a policy like you
can when adding a policy to a token.

This commit adds an extra attribute to our policy-form/policy-selector
component so you can disable this setting. At a later date we may change
this to have a conficgurable `<Slot />` instead.

Simple acceptance tests is included here
2020-01-28 09:39:09 +00:00

55 lines
1.5 KiB
JavaScript

import FormComponent from './form-component';
import { inject as service } from '@ember/service';
import { get, set } from '@ember/object';
export default FormComponent.extend({
repo: service('repository/policy/component'),
datacenterRepo: service('repository/dc/component'),
type: 'policy',
name: 'policy',
allowServiceIdentity: true,
classNames: ['policy-form'],
isScoped: false,
init: function() {
this._super(...arguments);
set(this, 'isScoped', get(this, 'item.Datacenters.length') > 0);
set(this, 'datacenters', this.datacenterRepo.findAll());
this.templates = [
{
name: 'Policy',
template: '',
},
{
name: 'Service Identity',
template: 'service-identity',
},
];
},
actions: {
change: function(e) {
try {
this._super(...arguments);
} catch (err) {
const scoped = this.isScoped;
const name = err.target.name;
switch (name) {
case 'policy[isScoped]':
if (scoped) {
set(this, 'previousDatacenters', get(this.item, 'Datacenters'));
set(this.item, 'Datacenters', null);
} else {
set(this.item, 'Datacenters', this.previousDatacenters);
set(this, 'previousDatacenters', null);
}
set(this, 'isScoped', !scoped);
break;
default:
this.onerror(err);
}
this.onchange({ target: this.form });
}
},
},
});