open-vault/ui/app/models/policy.js
claire bontempo fbce5986c1
UI/Wrong sentinel error message for auth methods (#14551)
* priortize adapter error over model error

* glimmerize message-error component

* message error tweaks

* fix glimmerize

* fix some tests

* change error handling for mount backend form

* throw API error for secret engine not mounting

* fix tests"

* fix tests

* cleanup error handling for secret engine mounts

* fix test selector

* add changelog

* STOP BEING FLAKY
2022-03-18 16:47:42 -07:00

32 lines
974 B
JavaScript

import Model, { attr } from '@ember-data/model';
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
export default Model.extend({
errors: attr('array'),
name: attr('string'),
policy: attr('string'),
policyType: computed('constructor.modelName', function () {
return this.constructor.modelName.split('/')[1];
}),
updatePath: lazyCapabilities(apiPath`sys/policies/${'policyType'}/${'id'}`, 'id', 'policyType'),
canDelete: alias('updatePath.canDelete'),
canEdit: alias('updatePath.canUpdate'),
canRead: alias('updatePath.canRead'),
format: computed('policy', function () {
let policy = this.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';
}),
});