Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Treat tags that are inherited from archetype assessments as assessment tags rather than archetype tags #603

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading