From 3072c252602437329d99b0600b13d0cc636074cf Mon Sep 17 00:00:00 2001 From: Samuel Lucidi Date: Tue, 14 Nov 2023 15:55:31 -0500 Subject: [PATCH] :bug: Fix loop variable pointer bug in assessment logic (#555) This bug was causing the slice of application/archetype assessments to be populated with copies of the last assessment, breaking the assessment status check and likely other things as well. 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)