Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ember-cp-validations on KV secret engine #11785

Merged
merged 16 commits into from
Jun 15, 2021

Conversation

Monkeychip
Copy link
Contributor

@Monkeychip Monkeychip commented Jun 7, 2021

One PR of many to come where we'll be adding form validations to various forms in the application. This first PR tackles the KV secret engine.

In an earlier demo, I used the ember-changeset-validations library. In this, I'm using the ember-cp-validations library and I much prefer the latter. It does not modify the whole model object but instead adds to it using a mixin. It's much easier to use, and more importantly, it should be usable in new glimmer components.

Notes:

  • the kv secret engine model is unique in that it gets path and secret-key from a mixin, therefore the validation is custom for these two and does not use the new cp-validations library. There was some previous custom validation that I modified to make more consistent with this new pattern/design.
  • I noticed the max_versions is not saving on create. This will be addressed in another ticket.

Path
path

Create and Edit Secret
validation

@Monkeychip Monkeychip added the ui label Jun 7, 2021
@Monkeychip Monkeychip added this to the 1.8 milestone Jun 7, 2021
@message="Your policies prevent you from reading the current secret data. Saving using this form will overwrite the existing values."
@class="is-marginless"
data-test-v1-write-without-read
{{#if (and (or @model.isNew @canEditV2Secret) @isV2 (not @model.failedServerRead))}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing spacing here, hence the big diff.

@vercel vercel bot temporarily deployed to Preview – vault June 11, 2021 15:48 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook June 11, 2021 15:52 Inactive
ui/app/components/secret-edit.js Outdated Show resolved Hide resolved
return;
}
const maxVersions = secret.get('maxVersions');
if (MAXIMUM_VERSIONS < maxVersions) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to future onlookers: this check was moved to secret-v2 model

ui/app/models/secret-engine.js Show resolved Hide resolved
ui/app/styles/components/form-field.scss Outdated Show resolved Hide resolved
ui/app/components/secret-edit.js Outdated Show resolved Hide resolved
ui/lib/core/addon/components/alert-inline.js Outdated Show resolved Hide resolved
* @param attr=null {Object} - This is usually derived from ember model `attributes` lookup, and all members of `attr.options` are optional.
* @param model=null {DS.Model} - The Ember Data model that `attr` is defined on
* @param [disabled=false] {Boolean} - whether the field is disabled
* @param [showHelpText=true] {Boolean} - whether to show the tooltip with help text from OpenAPI
* @param [subText] {String} - Text to be displayed below the label
* @param [validationMessage] {String} - AlertInline error message to be displayed if cp-validation error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

ui/lib/core/addon/templates/components/form-field.hbs Outdated Show resolved Hide resolved
@@ -56,6 +64,22 @@ module('Acceptance | secrets/secret/create', function(hooks) {
assert.ok(showPage.editIsPresent, 'shows the edit button');
});

test('it disables save when validation errors occur', async function(assert) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Contributor

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@Monkeychip Monkeychip merged commit a036b3a into master Jun 15, 2021
@Monkeychip Monkeychip deleted the ui/cp-validations-kv branch June 15, 2021 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants