From 79475258db9678736ab63afd7f2f22edce2a2559 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Mon, 13 Nov 2023 14:53:14 -0500 Subject: [PATCH] Fix loopvar ptr bug in assessment logic Signed-off-by: Sam Lucidi --- assessment/application.go | 5 +++-- assessment/archetype.go | 5 +++-- assessment/questionnaire.go | 8 ++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/assessment/application.go b/assessment/application.go index 1b7e7fd9a..57446c1a0 100644 --- a/assessment/application.go +++ b/assessment/application.go @@ -15,9 +15,10 @@ type Application struct { // With updates the Application with the db model and deserializes its assessments. func (r *Application) With(m *model.Application) { r.Application = m - for _, a := range m.Assessments { + for i := range m.Assessments { + a := &m.Assessments[i] assessment := Assessment{} - assessment.With(&a) + assessment.With(a) r.Assessments = append(r.Assessments, assessment) } } diff --git a/assessment/archetype.go b/assessment/archetype.go index ffe3cf647..2450c1c56 100644 --- a/assessment/archetype.go +++ b/assessment/archetype.go @@ -13,9 +13,10 @@ type Archetype struct { // With updates the Archetype with the db model and deserializes its assessments. func (r *Archetype) With(m *model.Archetype) { r.Archetype = m - for _, a := range m.Assessments { + for i := range m.Assessments { + a := &m.Assessments[i] assessment := Assessment{} - assessment.With(&a) + assessment.With(a) r.Assessments = append(r.Assessments, assessment) } } diff --git a/assessment/questionnaire.go b/assessment/questionnaire.go index 5d119206b..0e21bacd2 100644 --- a/assessment/questionnaire.go +++ b/assessment/questionnaire.go @@ -46,15 +46,11 @@ func (r *QuestionnaireResolver) cacheQuestionnaires() (err error) { // questionnaires. func (r *QuestionnaireResolver) Assessed(assessments []Assessment) (assessed bool) { answered := NewSet() -loop: for _, a := range assessments { if r.requiredQuestionnaires.Contains(a.QuestionnaireID) { - for _, s := range a.Sections { - if !s.Complete() { - continue loop - } + if a.Complete() { + answered.Add(a.QuestionnaireID) } - answered.Add(a.QuestionnaireID) } } assessed = answered.Superset(r.requiredQuestionnaires, false)