04396e5f9c
* wip tests * fix links * Revert "wip tests" This reverts commit aed9bb9b8fffb1b4d52d9c27644033ff3d983fff. * wip tests * add policy generator * add workflow tests for key * change apostrophe -___- * fix workflow tests * add update to key form tests * fix capability check for read * finish tests * fix flash messages; * rename policy generator file, update tests
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { inject as service } from '@ember/service';
|
|
import { task } from 'ember-concurrency';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import errorMessage from 'vault/utils/error-message';
|
|
import { waitFor } from '@ember/test-waiters';
|
|
|
|
/**
|
|
* @module PkiKeyForm
|
|
* PkiKeyForm components are used to create and update PKI keys.
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <PkiKeyForm @model={{this.model}}/>
|
|
* ```
|
|
*
|
|
* @param {Object} model - pki/key model.
|
|
* @callback onCancel - Callback triggered when cancel button is clicked.
|
|
* @callback onSave - Callback triggered on save success.
|
|
*/
|
|
|
|
export default class PkiKeyForm extends Component {
|
|
@service flashMessages;
|
|
|
|
@tracked errorBanner;
|
|
@tracked invalidFormAlert;
|
|
@tracked modelValidations;
|
|
|
|
@task
|
|
@waitFor
|
|
*save(event) {
|
|
event.preventDefault();
|
|
try {
|
|
const { isNew, keyName } = this.args.model;
|
|
const { isValid, state, invalidFormMessage } = this.args.model.validate();
|
|
if (isNew) {
|
|
this.modelValidations = isValid ? null : state;
|
|
this.invalidFormAlert = invalidFormMessage;
|
|
}
|
|
if (!isValid && isNew) return;
|
|
yield this.args.model.save({ adapterOptions: { import: false } });
|
|
this.flashMessages.success(
|
|
`Successfully ${isNew ? 'generated' : 'updated'} key${keyName ? ` ${keyName}.` : '.'}`
|
|
);
|
|
this.args.onSave();
|
|
} catch (error) {
|
|
this.errorBanner = errorMessage(error);
|
|
this.invalidFormAlert = 'There was an error submitting this form.';
|
|
}
|
|
}
|
|
|
|
@action
|
|
cancel() {
|
|
const method = this.args.model.isNew ? 'unloadRecord' : 'rollbackAttributes';
|
|
this.args.model[method]();
|
|
this.args.onCancel();
|
|
}
|
|
}
|