fix(labels): make sure labels of shared sub projects are usable

Resolves https://community.vikunja.io/t/cannot-filter-on-projets-labels/1736
This commit is contained in:
kolaente 2023-12-03 14:33:43 +01:00
parent d35c30dd0c
commit 8a3f16fcfb
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 1 deletions

View File

@ -176,11 +176,23 @@ func GetLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*Lab
cond = builder.And(builder.In("label_tasks.task_id", opts.TaskIDs), cond)
}
if opts.GetForUser != 0 {
projects, _, _, err := getRawProjectsForUser(s, &projectOptions{
user: &user.User{ID: opts.GetForUser},
})
if err != nil {
return nil, 0, 0, err
}
projectIDs := make([]int64, 0, len(projects))
for _, project := range projects {
projectIDs = append(projectIDs, project.ID)
}
cond = builder.And(builder.In("label_tasks.task_id",
builder.
Select("id").
From("tasks").
Where(builder.In("project_id", getUserProjectsStatement(nil, opts.GetForUser, "", false).Select("l.id"))),
Where(builder.In("project_id", projectIDs)),
), cond)
}
if opts.GetUnusedLabels {