mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
Update userpass validations to handle password_hash (#26577)
* Update userpass validations to handle password_hash * Add changelog
This commit is contained in:
3
changelog/26577.txt
Normal file
3
changelog/26577.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
ui: Update userpass user form to allow setting `password_hash` field.
|
||||||
|
```
|
||||||
@@ -35,8 +35,27 @@ export default Component.extend({
|
|||||||
props: computed('model', function () {
|
props: computed('model', function () {
|
||||||
return this.model.serialize();
|
return this.model.serialize();
|
||||||
}),
|
}),
|
||||||
|
validateForm() {
|
||||||
|
// Only validate on new models because blank passwords will not be updated
|
||||||
|
// in practice this only happens for userpass users
|
||||||
|
if (this.model.validate && this.model.isNew) {
|
||||||
|
const { isValid, state } = this.model.validate();
|
||||||
|
this.setProperties({
|
||||||
|
modelValidations: state,
|
||||||
|
isFormInvalid: !isValid,
|
||||||
|
});
|
||||||
|
return isValid;
|
||||||
|
} else {
|
||||||
|
this.set('isFormInvalid', false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
saveModel: task(
|
saveModel: task(
|
||||||
waitFor(function* () {
|
waitFor(function* () {
|
||||||
|
const isValid = this.validateForm();
|
||||||
|
if (!isValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
yield this.model.save();
|
yield this.model.save();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -71,16 +90,6 @@ export default Component.extend({
|
|||||||
actions: {
|
actions: {
|
||||||
onKeyUp(name, value) {
|
onKeyUp(name, value) {
|
||||||
this.model.set(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() {
|
deleteItem() {
|
||||||
this.model.destroyRecord().then(() => {
|
this.model.destroyRecord().then(() => {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
pathToHelpUrlSegment,
|
pathToHelpUrlSegment,
|
||||||
reducePathsByPathName,
|
reducePathsByPathName,
|
||||||
} from 'vault/utils/openapi-helpers';
|
} from 'vault/utils/openapi-helpers';
|
||||||
|
import { isPresent } from '@ember/utils';
|
||||||
|
|
||||||
export default class PathHelpService extends Service {
|
export default class PathHelpService extends Service {
|
||||||
@service store;
|
@service store;
|
||||||
@@ -272,16 +273,19 @@ export default class PathHelpService extends Service {
|
|||||||
// Build and add validations on model
|
// Build and add validations on model
|
||||||
// NOTE: For initial phase, initialize validations only for user pass auth
|
// NOTE: For initial phase, initialize validations only for user pass auth
|
||||||
if (backend === 'userpass') {
|
if (backend === 'userpass') {
|
||||||
const validations = fieldGroups.reduce((obj, element) => {
|
const validations = {
|
||||||
if (element.default) {
|
password: [
|
||||||
element.default.forEach((v) => {
|
{
|
||||||
const key = v.options.fieldValue || v.name;
|
validator(model) {
|
||||||
obj[key] = [{ type: 'presence', message: `${v.name} can't be blank` }];
|
return (
|
||||||
});
|
!(isPresent(model.password) && isPresent(model.passwordHash)) &&
|
||||||
}
|
(isPresent(model.password) || isPresent(model.passwordHash))
|
||||||
return obj;
|
);
|
||||||
}, {});
|
},
|
||||||
|
message: 'You must provide either password or password hash, but not both.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
newModel = withModelValidations(validations)(class GeneratedItemModel extends newModel {});
|
newModel = withModelValidations(validations)(class GeneratedItemModel extends newModel {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,12 +59,7 @@
|
|||||||
<div class="box is-sideless is-fullwidth is-marginless">
|
<div class="box is-sideless is-fullwidth is-marginless">
|
||||||
<NamespaceReminder @mode="save" @noun={{this.itemType}} />
|
<NamespaceReminder @mode="save" @noun={{this.itemType}} />
|
||||||
<MessageError @model={{this.model}} />
|
<MessageError @model={{this.model}} />
|
||||||
<FormFieldGroups
|
<FormFieldGroups @model={{this.model}} @mode={{this.mode}} @modelValidations={{this.modelValidations}} />
|
||||||
@model={{this.model}}
|
|
||||||
@mode={{this.mode}}
|
|
||||||
@onKeyUp={{action "onKeyUp"}}
|
|
||||||
@modelValidations={{this.modelValidations}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="field is-grouped-split box is-fullwidth is-bottomless">
|
<div class="field is-grouped-split box is-fullwidth is-bottomless">
|
||||||
<Hds::ButtonSet>
|
<Hds::ButtonSet>
|
||||||
|
|||||||
Reference in New Issue
Block a user