fix(projects): don't return child projects twice

This commit is contained in:
kolaente 2023-03-27 12:02:35 +02:00
parent 0110f93313
commit aafcb0bac4
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 4 additions and 1 deletions

View File

@ -220,6 +220,7 @@ func (p *Project) ReadAll(s *xorm.Session, a web.Auth, search string, page int,
//////////////////////////
// Putting it all together
projectsResult := []*Project{}
for _, p := range allProjects {
if p.ParentProjectID != 0 {
if allProjects[p.ParentProjectID].ChildProjects == nil {
@ -229,11 +230,13 @@ func (p *Project) ReadAll(s *xorm.Session, a web.Auth, search string, page int,
continue
}
projectsResult = append(projectsResult, p)
// The projects variable will contain all projects which have no parents
// And because we're using the same pointers for everything, those will contain child projects
}
return prs, resultCount, totalItems, err
return projectsResult, resultCount, totalItems, err
}
// ReadOne gets one project by its ID