1
0

fix(view): correctly resolve bucket filter when paginating

(cherry picked from commit 45ff5907e69b24f00926841790d0f4f3d11e530a)
This commit is contained in:
kolaente 2024-09-13 19:45:48 +02:00
parent 6b850c56f7
commit 1049b27d37
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
2 changed files with 31 additions and 1 deletions

View File

@ -17,6 +17,8 @@
package models
import (
"regexp"
"strconv"
"strings"
"code.vikunja.io/api/pkg/user"
@ -174,6 +176,28 @@ func getRelevantProjectsFromCollection(s *xorm.Session, a web.Auth, tf *TaskColl
return []*Project{{ID: tf.ProjectID}}, nil
}
func getFilterValueForBucketFilter(filter string, view *ProjectView) (newFilter string, err error) {
re := regexp.MustCompile(`bucket_id\s*=\s*(\d+)`)
match := re.FindStringSubmatch(filter)
if len(match) < 2 {
return filter, nil
}
bucketID, err := strconv.Atoi(match[1])
if err != nil {
return "", err
}
for id, bucket := range view.BucketConfiguration {
if id == bucketID {
return re.ReplaceAllString(filter, `(`+bucket.Filter+`)`), nil
}
}
return filter, nil
}
// ReadAll gets all tasks for a collection
// @Summary Get tasks in a project
// @Description Returns all tasks for the current project.
@ -251,6 +275,13 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
tf.Filter = view.Filter
}
}
if view.BucketConfigurationMode == BucketConfigurationModeFilter && strings.Contains(tf.Filter, "bucket_id") {
tf.Filter, err = getFilterValueForBucketFilter(tf.Filter, view)
if err != nil {
return nil, 0, 0, err
}
}
}
opts, err := getTaskFilterOptsFromCollection(tf, view)

View File

@ -325,7 +325,6 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op
}
func getTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, opts *taskSearchOptions, view *ProjectView) (tasks []*Task, resultCount int, totalItems int64, err error) {
tasks, resultCount, totalItems, err = getRawTasksForProjects(s, projects, a, opts)
if err != nil {
return nil, 0, 0, err