diff --git a/api/application.go b/api/application.go index 5de64271c..669f63d35 100644 --- a/api/application.go +++ b/api/application.go @@ -959,7 +959,7 @@ func (h ApplicationHandler) StakeholdersUpdate(ctx *gin.Context) { func (h ApplicationHandler) AssessmentList(ctx *gin.Context) { m := &model.Application{} id := h.pk(ctx) - db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups") + db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire") db = db.Omit("Analyses") result := db.First(m, id) if result.Error != nil { @@ -994,6 +994,12 @@ func (h ApplicationHandler) AssessmentList(ctx *gin.Context) { for i := range assessments { r := Assessment{} r.With(&assessments[i]) + if assessments[i].Questionnaire.ID != 0 { + r.QuestionnaireRequired = assessments[i].Questionnaire.Required + } else { + r.QuestionnaireRequired = false + } + resources = append(resources, r) } diff --git a/api/archetype.go b/api/archetype.go index c1c6dea91..e21337cec 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -254,7 +254,7 @@ func (h ArchetypeHandler) Update(ctx *gin.Context) { func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) { m := &model.Archetype{} id := h.pk(ctx) - db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups") + db := h.preLoad(h.DB(ctx), clause.Associations, "Assessments.Stakeholders", "Assessments.StakeholderGroups", "Assessments.Questionnaire") result := db.First(m, id) if result.Error != nil { _ = ctx.Error(result.Error) @@ -264,6 +264,12 @@ func (h ArchetypeHandler) AssessmentList(ctx *gin.Context) { resources := []Assessment{} for i := range m.Assessments { r := Assessment{} + if m.Assessments[i].Questionnaire.ID != 0 { + r.QuestionnaireRequired = m.Assessments[i].Questionnaire.Required + } else { + r.QuestionnaireRequired = false + } + r.With(&m.Assessments[i]) resources = append(resources, r) } diff --git a/api/assessment.go b/api/assessment.go index 4f34de7d9..441ff0675 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -52,7 +52,11 @@ func (h AssessmentHandler) Get(ctx *gin.Context) { _ = ctx.Error(result.Error) return } + r := Assessment{} + + r.QuestionnaireRequired = m.Questionnaire.Required + r.With(m) h.Respond(ctx, http.StatusOK, r) @@ -159,11 +163,12 @@ type Assessment struct { Stakeholders []Ref `json:"stakeholders"` StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"` // read only - Risk string `json:"risk"` - Confidence int `json:"confidence"` - Status string `json:"status"` - Thresholds assessment.Thresholds `json:"thresholds"` - RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"` + Risk string `json:"risk"` + Confidence int `json:"confidence"` + Status string `json:"status"` + Thresholds assessment.Thresholds `json:"thresholds"` + RiskMessages assessment.RiskMessages `json:"riskMessages" yaml:"riskMessages"` + QuestionnaireRequired bool `json:"questionnaireRequired"` } //