Skip to content

Commit

Permalink
🐛 Treat tags that are inherited from archetype assessments as assessm…
Browse files Browse the repository at this point in the history
…ent tags rather than archetype tags (#603)

Prior to this commit, tags that applications inherited due to their
archetypes' assessments were categorized as archetype tags rather than
assessment tags. This corrects the categorization, and in addition fixes
some bugs where tags could be inherited from archived assessments.

Fixes https://issues.redhat.com/browse/MTA-1972

Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam committed Feb 21, 2024
1 parent e1fa5f6 commit 2388891
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions assessment/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func (r *ApplicationResolver) Archetypes() (archetypes []Archetype, err error) {
return
}

// ArchetypeTags returns the list of tags that the application should inherit from the archetypes it is a member of,
// including any tags that would be inherited due to answers given to the archetypes' assessments.
// ArchetypeTags returns the list of tags that the application should inherit from the archetypes it is a member of.
func (r *ApplicationResolver) ArchetypeTags() (tags []model.Tag, err error) {
archetypes, err := r.Archetypes()
if err != nil {
Expand All @@ -72,19 +71,6 @@ func (r *ApplicationResolver) ArchetypeTags() (tags []model.Tag, err error) {
tags = append(tags, t)
}
}
// if an application has any of its own assessments then it should not
// inherit assessment tags from any of its archetypes.
if len(r.application.Assessments) == 0 {
for _, assessment := range a.Assessments {
aTags := r.tagResolver.Assessment(assessment)
for _, t := range aTags {
if _, found := seenTags[t.ID]; !found {
seenTags[t.ID] = true
tags = append(tags, t)
}
}
}
}
}
return
}
Expand All @@ -100,15 +86,37 @@ func (r *ApplicationResolver) RequiredAssessments() (required []Assessment) {
}

// AssessmentTags returns the list of tags that the application should inherit from the answers given
// to its assessments.
// to its assessments or those of its archetypes. Archetype assessments are only inherited if the application
// does not have any answers to required questionnaires.
func (r *ApplicationResolver) AssessmentTags() (tags []model.Tag) {
seenTags := make(map[uint]bool)
for _, assessment := range r.RequiredAssessments() {
aTags := r.tagResolver.Assessment(assessment)
for _, t := range aTags {
if _, found := seenTags[t.ID]; !found {
seenTags[t.ID] = true
tags = append(tags, t)
if len(r.RequiredAssessments()) > 0 {
for _, assessment := range r.RequiredAssessments() {
aTags := r.tagResolver.Assessment(assessment)
for _, t := range aTags {
if _, found := seenTags[t.ID]; !found {
seenTags[t.ID] = true
tags = append(tags, t)
}
}
}
return
}

archetypes, err := r.Archetypes()
if err != nil {
return
}
for _, a := range archetypes {
for _, assessment := range a.Assessments {
if r.questionnaireResolver.Required(assessment.QuestionnaireID) {
aTags := r.tagResolver.Assessment(assessment)
for _, t := range aTags {
if _, found := seenTags[t.ID]; !found {
seenTags[t.ID] = true
tags = append(tags, t)
}
}
}
}
}
Expand Down

0 comments on commit 2388891

Please sign in to comment.