mirror of
https://github.com/hashicorp/vault.git
synced 2026-06-27 10:00:32 -04:00
* updates oidc assignmenmts list view to use api service * updates oidc assignments details view to use api service * updates oidc assignment create and edit views to use api service and form class * updates oidc assignment-form tests * updates oidc-key-template component to use form class * updates oidc-assignment-template component to use form class * updates teardown in oidc-config clients tests to use api service Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { service } from '@ember/service';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { task } from 'ember-concurrency';
|
|
import { waitFor } from '@ember/test-waiters';
|
|
|
|
/**
|
|
* @module Oidc::AssignmentForm
|
|
* Oidc::AssignmentForm components are used to display the create view for OIDC providers assignments.
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <Oidc::AssignmentForm @form={this.form}
|
|
* @onCancel={transition-to "vault.cluster.access.oidc.assignment"} @param1={{param1}}
|
|
* @onSave={transition-to "vault.cluster.access.oidc.assignments.assignment.details" this.model.name}
|
|
* />
|
|
* ```
|
|
|
|
* @param {object} form - Form class
|
|
* @callback onCancel - callback triggered when cancel button is clicked
|
|
* @callback onSave - callback triggered when save button is clicked*
|
|
*/
|
|
|
|
export default class OidcAssignmentFormComponent extends Component {
|
|
@service api;
|
|
@service flashMessages;
|
|
|
|
@tracked modelValidations;
|
|
@tracked invalidFormMessage;
|
|
@tracked errorBanner;
|
|
|
|
save = task(
|
|
waitFor(async (event) => {
|
|
event.preventDefault();
|
|
try {
|
|
const { isValid, state, invalidFormMessage, data } = this.args.form.toJSON();
|
|
this.modelValidations = isValid ? null : state;
|
|
this.invalidFormMessage = invalidFormMessage;
|
|
|
|
if (isValid) {
|
|
const { name, ...payload } = data;
|
|
await this.api.identity.oidcWriteAssignment(name, payload);
|
|
this.flashMessages.success(
|
|
`Successfully ${this.args.form.isNew ? 'created' : 'updated'} the assignment ${name}.`
|
|
);
|
|
// this form is sometimes used in modal, passing the model notifies
|
|
// the parent if the save was successful
|
|
this.args.onSave(this.args.form);
|
|
}
|
|
} catch (error) {
|
|
const { message } = await this.api.parseError(error);
|
|
this.errorBanner = message;
|
|
}
|
|
})
|
|
);
|
|
}
|