mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 11:37:04 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
93 lines
2.8 KiB
JavaScript
93 lines
2.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import AdapterError from '@ember-data/adapter/error';
|
|
import { inject as service } from '@ember/service';
|
|
import Component from '@ember/component';
|
|
import { computed } from '@ember/object';
|
|
import { task } from 'ember-concurrency';
|
|
import { waitFor } from '@ember/test-waiters';
|
|
|
|
/**
|
|
* @module GeneratedItem
|
|
* The `GeneratedItem` component is the form to configure generated items related to mounts (e.g. groups, roles, users)
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <GeneratedItem @model={{model}} @mode={{mode}} @itemType={{itemType/>
|
|
* ```
|
|
*
|
|
* @property model=null {DS.Model} - The corresponding item model that is being configured.
|
|
* @property mode {String} - which config mode to use. either `show`, `edit`, or `create`
|
|
* @property itemType {String} - the type of item displayed
|
|
*
|
|
*/
|
|
|
|
export default Component.extend({
|
|
model: null,
|
|
itemType: null,
|
|
flashMessages: service(),
|
|
router: service(),
|
|
modelValidations: null,
|
|
isFormInvalid: false,
|
|
props: computed('model', function () {
|
|
return this.model.serialize();
|
|
}),
|
|
saveModel: task(
|
|
waitFor(function* () {
|
|
try {
|
|
yield this.model.save();
|
|
} catch (err) {
|
|
// AdapterErrors are handled by the error-message component
|
|
// in the form
|
|
if (err instanceof AdapterError === false) {
|
|
throw err;
|
|
}
|
|
return;
|
|
}
|
|
this.router.transitionTo('vault.cluster.access.method.item.list').followRedirects();
|
|
this.flashMessages.success(`Successfully saved ${this.itemType} ${this.model.id}.`);
|
|
})
|
|
),
|
|
init() {
|
|
this._super(...arguments);
|
|
if (this.mode === 'edit') {
|
|
// For validation to work in edit mode,
|
|
// reconstruct the model values from field group
|
|
this.model.fieldGroups.forEach((element) => {
|
|
if (element.default) {
|
|
element.default.forEach((attr) => {
|
|
const fieldValue = attr.options && attr.options.fieldValue;
|
|
if (fieldValue) {
|
|
this.model[attr.name] = this.model[fieldValue];
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
},
|
|
actions: {
|
|
onKeyUp(name, value) {
|
|
this.model.set(name, value);
|
|
if (this.model.validate) {
|
|
// Set validation error message for updated attribute
|
|
const { isValid, state } = this.model.validate();
|
|
this.setProperties({
|
|
modelValidations: state,
|
|
isFormInvalid: !isValid,
|
|
});
|
|
} else {
|
|
this.set('isFormInvalid', false);
|
|
}
|
|
},
|
|
deleteItem() {
|
|
this.model.destroyRecord().then(() => {
|
|
this.router.transitionTo('vault.cluster.access.method.item.list').followRedirects();
|
|
this.flashMessages.success(`Successfully deleted ${this.itemType} ${this.model.id}.`);
|
|
});
|
|
},
|
|
},
|
|
});
|