Skip to content

fix(DHIS2-16608): enforce setting validators and reject invalid saves#1478

Open
Chisomchima wants to merge 2 commits intomasterfrom
DHIS2-16608-settings-field-validation
Open

fix(DHIS2-16608): enforce setting validators and reject invalid saves#1478
Chisomchima wants to merge 2 commits intomasterfrom
DHIS2-16608-settings-field-validation

Conversation

@Chisomchima
Copy link
Copy Markdown
Member

  • Add shared buildValidatorsForMapping with min/max range checks
  • Block saveKey when validation fails so bad values are not persisted
  • Forward TextField onChange to FormBuilder for correct blur validation
  • Add positive_number validator for credentialsExpiresReminderInDays

- Add shared buildValidatorsForMapping with min/max range checks
- Block saveKey when validation fails so bad values are not persisted
- Forward TextField onChange to FormBuilder for correct blur validation
- Add positive_number validator for credentialsExpiresReminderInDays

Made-with: Cursor
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 5, 2026

@dhis2-bot
Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-1478.settings.netlify.dhis2.org

@dhis2-bot dhis2-bot temporarily deployed to netlify April 5, 2026 14:14 Inactive
Copy link
Copy Markdown
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for looking into this!

I've left a couple of comments. Also, if we have a min/max restrictions for a given setting, I think we can probably drop the 'positive_number' validator (e.g. if min:1, max:24, the value -1 would already fail because it's out of this range)? I don't care strongly about this point, but it seems like it would be unneeded.

Comment thread src/settingValidators.js
mapping.validators.forEach((name) => {
if (wordToValidatorMap.has(name)) {
const validator = wordToValidatorMap.get(name)
console.log('validator', validator.message, mapping)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove?

Comment thread src/settingValidators.js
validators.push({
validator: (value) => {
if (value === '' || value === null || value === undefined) {
return true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

don't we want this to be false in this case? E.g. if there's a min value, shouldn't it fail validation if it's empty?

Comment thread src/settingsActions.js
// Can be undefined for some custom sections, i.e. 'keyStopMetadataSync'
const mapping = settingsKeyMapping[key]

if (mapping && !locale) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there a reason to check for !locale? I think locale is only defined for the appearance settings, which don't have validators, so it seems like this won't make a difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants