Unverified Commit 5f8f6b87 authored by Angel Garbarino's avatar Angel Garbarino Committed by GitHub
Browse files

Remove Key validation on KV2 (#12045)

* remove check on key

* clean up

* amend test

* remove leftover
parent 8fc553c1
Showing with 11 additions and 20 deletions
+11 -20
...@@ -87,7 +87,6 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { ...@@ -87,7 +87,6 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
} }
this.set('validationMessages', { this.set('validationMessages', {
path: '', path: '',
key: '',
maxVersions: '', maxVersions: '',
}); });
// for validation, return array of path names already assigned // for validation, return array of path names already assigned
...@@ -195,20 +194,18 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { ...@@ -195,20 +194,18 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
}, },
checkValidation(name, value) { checkValidation(name, value) {
// because path and key are not on the model performing custom validations instead of cp-validations if (name === 'path') {
if (name === 'path' || name === 'key') {
// no value indicates missing presence
!value !value
? set(this.validationMessages, name, `${name} can't be blank.`) ? set(this.validationMessages, name, `${name} can't be blank.`)
: set(this.validationMessages, name, ''); : set(this.validationMessages, name, '');
// only check duplicate on path not on the key
if (name === 'path') {
this.secretPaths?.includes(value)
? set(this.validationMessages, name, `A secret with this ${name} already exists.`)
: set(this.validationMessages, name, '');
}
} }
// check duplicate on path
if (name === 'path' && value) {
this.secretPaths?.includes(value)
? set(this.validationMessages, name, `A secret with this ${name} already exists.`)
: set(this.validationMessages, name, '');
}
// check maxVersions is a number
if (name === 'maxVersions') { if (name === 'maxVersions') {
// checking for value because value which is blank on first load. No keyup event has occurred and default is 10. // checking for value because value which is blank on first load. No keyup event has occurred and default is 10.
if (value) { if (value) {
...@@ -362,15 +359,10 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, { ...@@ -362,15 +359,10 @@ export default Component.extend(FocusOnInsertMixin, WithNavToNearestAncestor, {
createOrUpdateKey(type, event) { createOrUpdateKey(type, event) {
event.preventDefault(); event.preventDefault();
let model = this.modelForData; let model = this.modelForData;
let arraySecretKeys = Object.keys(model.secretData);
if (type === 'create' && isBlank(model.path || model.id)) { if (type === 'create' && isBlank(model.path || model.id)) {
this.checkValidation('path', ''); this.checkValidation('path', '');
return; return;
} }
if (arraySecretKeys.includes('')) {
this.checkValidation('key', '');
return;
}
this.persistKey(() => { this.persistKey(() => {
this.transitionToRoute(SHOW_ROUTE, this.model.path || this.model.id); this.transitionToRoute(SHOW_ROUTE, this.model.path || this.model.id);
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
@value={{secret.name}} @value={{secret.name}}
placeholder="key" placeholder="key"
@change={{action @editActions.handleChange}} @change={{action @editActions.handleChange}}
class="input {{if @validationMessages.key "has-error-border"}}" class="input"
@autocomplete="off" @autocomplete="off"
@spellcheck="false" @spellcheck="false"
{{on "keyup" (fn @onKeyUp "key" secret.name)}} {{on "keyup" (fn @onKeyUp "key" secret.name)}}
......
...@@ -73,13 +73,12 @@ module('Acceptance | secrets/secret/create', function(hooks) { ...@@ -73,13 +73,12 @@ module('Acceptance | secrets/secret/create', function(hooks) {
await click('[data-test-secret-create="true"]'); await click('[data-test-secret-create="true"]');
await fillIn('[data-test-secret-path="true"]', secretPath); await fillIn('[data-test-secret-path="true"]', secretPath);
await fillIn('[data-test-input="maxVersions"]', maxVersions); await fillIn('[data-test-input="maxVersions"]', maxVersions);
await fillIn('[data-test-secret-key]', 'key');
await click('[data-test-secret-save]'); await click('[data-test-secret-save]');
await settled(); await settled();
await click('[data-test-secret-edit="true"]'); await click('[data-test-secret-edit="true"]');
await settled(); await settled();
// convert to number for IE11 browserstack test
let savedMaxVersions = document.querySelector('[data-test-input="maxVersions"]').value; let savedMaxVersions = Number(document.querySelector('[data-test-input="maxVersions"]').value);
assert.equal( assert.equal(
maxVersions, maxVersions,
savedMaxVersions, savedMaxVersions,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment