From e02d2f323bbe75c527f7c8d70a621a2f70f40aec Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Mon, 18 Dec 2023 16:19:52 -0500 Subject: [PATCH] Questionnaires require at least one section/q/a Fixes https://issues.redhat.com/browse/MTA-1907 --- api/questionnaire.go | 2 +- assessment/assessment.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/questionnaire.go b/api/questionnaire.go index ff25a92c1..c7f69935c 100644 --- a/api/questionnaire.go +++ b/api/questionnaire.go @@ -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"` diff --git a/assessment/assessment.go b/assessment/assessment.go index a9e0f30e2..43fdef1d6 100644 --- a/assessment/assessment.go +++ b/assessment/assessment.go @@ -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"` } @@ -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"` } //