open-vault/ui/app/models/policy.js
Peter Schultz a786ef8a4a Fix capability test for policies in UI (#4566)
Fix incorrect path for capability check in the policies UI.

Fixes #4564.
2018-05-14 17:20:07 -05:00

47 lines
1.1 KiB
JavaScript

import DS from 'ember-data';
import Ember from 'ember';
import { queryRecord } from 'ember-computed-query';
let { attr } = DS;
let { computed } = Ember;
export default DS.Model.extend({
name: attr('string'),
policy: attr('string'),
policyType: computed(function() {
return this.constructor.modelName.split('/')[1];
}),
updatePath: queryRecord(
'capabilities',
context => {
const { policyType, id } = context.getProperties('policyType', 'id');
if (!policyType && id) {
return;
}
return {
id: `sys/policies/${policyType}/${id}`,
};
},
'id',
'policyType'
),
canDelete: computed.alias('updatePath.canDelete'),
canEdit: computed.alias('updatePath.canUpdate'),
canRead: computed.alias('updatePath.canRead'),
format: computed('policy', function() {
let policy = this.get('policy');
let isJSON;
try {
let parsed = JSON.parse(policy);
if (parsed) {
isJSON = true;
}
} catch (e) {
// can't parse JSON
isJSON = false;
}
return isJSON ? 'json' : 'hcl';
}),
});