open-vault/ui/app/components/config-pki.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

70 lines
1.4 KiB
JavaScript

import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { get } from '@ember/object';
export default Component.extend({
classNames: 'config-pki',
flashMessages: service(),
errors: null,
/*
*
* @param String
* @public
* String corresponding to the route parameter for the current section
*
*/
section: null,
/*
* @param DS.Model
* @public
*
* a `pki-config` model - passed in in the component useage
*
*/
config: null,
/*
* @param Function
* @public
*
* function that gets called to refresh the config model
*
*/
onRefresh() {},
loading: false,
actions: {
save(section) {
this.set('loading', true);
const config = this.config;
config
.save({
adapterOptions: {
method: section,
fields: get(config, `${section}Attrs`).map((attr) => attr.name),
},
})
.then(() => {
this.flashMessages.success(`The ${section} config for this backend has been updated.`);
// attrs aren't persistent for Tidy
if (section === 'tidy') {
config.rollbackAttributes();
}
this.send('refresh');
})
.catch((e) => {
this.set('errors', e.errors);
})
.finally(() => {
this.set('loading', false);
});
},
refresh() {
this.onRefresh();
},
},
});