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 (konveyor#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 <[email protected]>
  • Loading branch information
mansam committed Feb 28, 2024
1 parent 2552233 commit 5f8c106
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions assessment/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,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 @@ -78,19 +76,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 @@ -108,15 +93,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 5f8c106

Please sign in to comment.