From b9eb6aa582dffd8560119be3b1466771f8591871 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Thu, 5 Oct 2023 16:13:41 -0400 Subject: [PATCH] Only marshal assessment sections if not empty Signed-off-by: Sam Lucidi --- api/application.go | 4 ++-- api/archetype.go | 4 ++-- api/assessment.go | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/application.go b/api/application.go index 2e048bfa4..c0e982347 100644 --- a/api/application.go +++ b/api/application.go @@ -1072,9 +1072,9 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { m.Thresholds = q.Thresholds m.RiskMessages = q.RiskMessages m.CreateUser = h.CurrentUser(ctx) - // if sections aren't nil that indicates that this assessment is being + // if sections aren't empty that indicates that this assessment is being // created "as-is" and should not have its sections populated or autofilled. - if m.Sections == nil { + if len(m.Sections) == 0 { m.Sections = q.Sections resolver, rErr := assessment.NewTagResolver(h.DB(ctx)) if rErr != nil { diff --git a/api/archetype.go b/api/archetype.go index 2388e0572..bb605a545 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -315,9 +315,9 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { m.Thresholds = q.Thresholds m.RiskMessages = q.RiskMessages m.CreateUser = h.CurrentUser(ctx) - // if sections aren't nil that indicates that this assessment is being + // if sections aren't empty that indicates that this assessment is being // created "as-is" and should not have its sections populated or autofilled. - if m.Sections == nil { + if len(m.Sections) == 0 { m.Sections = q.Sections resolver, rErr := assessment.NewTagResolver(h.DB(ctx)) if rErr != nil { diff --git a/api/assessment.go b/api/assessment.go index 5eb56f92f..b6bbc326a 100644 --- a/api/assessment.go +++ b/api/assessment.go @@ -220,7 +220,9 @@ func (r *Assessment) With(m *model.Assessment) { func (r *Assessment) Model() (m *model.Assessment) { m = &model.Assessment{} m.ID = r.ID - m.Sections, _ = json.Marshal(r.Sections) + if r.Sections != nil { + m.Sections, _ = json.Marshal(r.Sections) + } m.QuestionnaireID = r.Questionnaire.ID if r.Archetype != nil { m.ArchetypeID = &r.Archetype.ID