Skip to content

Commit

Permalink
🐛 [MTA-1907] Questionnaires require at least one section/question/ans…
Browse files Browse the repository at this point in the history
…wer (#582)

Adds validation to ensure that Questionnaires have at least one section,
each section has at least one question, and each question has at least
one answer. Fixes a problem where submitting a questionnaire with a
question with no answers would break the UI.

Fixes https://issues.redhat.com/browse/MTA-1907

Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam authored Dec 19, 2023
1 parent 8fa486a commit 9fc9bdb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ type Questionnaire struct {
Name string `json:"name" yaml:"name" binding:"required"`
Description string `json:"description" yaml:"description"`
Required bool `json:"required" yaml:"required"`
Sections []assessment.Section `json:"sections" yaml:"sections" binding:"required,dive"`
Sections []assessment.Section `json:"sections" yaml:"sections" binding:"required,min=1,dive"`
Thresholds assessment.Thresholds `json:"thresholds" yaml:"thresholds" binding:"required"`
RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages" binding:"required"`
Builtin bool `json:"builtin,omitempty" yaml:"builtin,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions assessment/assessment.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (r *Assessment) Confidence() (score int) {
type Section struct {
Order *uint `json:"order" yaml:"order" binding:"required"`
Name string `json:"name" yaml:"name"`
Questions []Question `json:"questions" yaml:"questions" binding:"dive"`
Questions []Question `json:"questions" yaml:"questions" binding:"min=1,dive"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
}

Expand Down Expand Up @@ -184,7 +184,7 @@ type Question struct {
Explanation string `json:"explanation" yaml:"explanation"`
IncludeFor []CategorizedTag `json:"includeFor,omitempty" yaml:"includeFor,omitempty"`
ExcludeFor []CategorizedTag `json:"excludeFor,omitempty" yaml:"excludeFor,omitempty"`
Answers []Answer `json:"answers" yaml:"answers" binding:"dive"`
Answers []Answer `json:"answers" yaml:"answers" binding:"min=1,dive"`
}

//
Expand Down

0 comments on commit 9fc9bdb

Please sign in to comment.