From 58497f29e6f60dbe2e791e3cc6334cd17fb75399 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 11 Oct 2023 18:43:16 +0200 Subject: [PATCH] fix(kanban): filter for tasks in buckets by assignee should not modify the filter directly Resolves https://github.com/go-vikunja/api/issues/84 --- pkg/models/task_search.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/pkg/models/task_search.go b/pkg/models/task_search.go index 3085319cafc..a5dbf1e2a22 100644 --- a/pkg/models/task_search.go +++ b/pkg/models/task_search.go @@ -92,8 +92,13 @@ func (d *dbTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCo // To still find tasks with nil values, we exclude 0s when comparing with >/< values. for _, f := range opts.filters { if f.field == "reminders" { - f.field = "reminder" // This is the name in the db - filter, err := getFilterCond(f, opts.filterIncludeNulls) + filter, err := getFilterCond(&taskFilter{ + // recreating the struct here to avoid modifying it when reusing the opts struct + field: "reminder", + value: f.value, + comparator: f.comparator, + isNumeric: f.isNumeric, + }, opts.filterIncludeNulls) if err != nil { return nil, totalCount, err } @@ -105,8 +110,13 @@ func (d *dbTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCo if f.comparator == taskFilterComparatorLike { return nil, totalCount, err } - f.field = "username" - filter, err := getFilterCond(f, opts.filterIncludeNulls) + filter, err := getFilterCond(&taskFilter{ + // recreating the struct here to avoid modifying it when reusing the opts struct + field: "username", + value: f.value, + comparator: f.comparator, + isNumeric: f.isNumeric, + }, opts.filterIncludeNulls) if err != nil { return nil, totalCount, err } @@ -115,8 +125,13 @@ func (d *dbTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCo } if f.field == "labels" || f.field == "label_id" { - f.field = "label_id" - filter, err := getFilterCond(f, opts.filterIncludeNulls) + filter, err := getFilterCond(&taskFilter{ + // recreating the struct here to avoid modifying it when reusing the opts struct + field: "label_id", + value: f.value, + comparator: f.comparator, + isNumeric: f.isNumeric, + }, opts.filterIncludeNulls) if err != nil { return nil, totalCount, err } @@ -125,8 +140,13 @@ func (d *dbTaskSearcher) Search(opts *taskSearchOptions) (tasks []*Task, totalCo } if f.field == "parent_project" || f.field == "parent_project_id" { - f.field = "parent_project_id" - filter, err := getFilterCond(f, opts.filterIncludeNulls) + filter, err := getFilterCond(&taskFilter{ + // recreating the struct here to avoid modifying it when reusing the opts struct + field: "parent_project_id", + value: f.value, + comparator: f.comparator, + isNumeric: f.isNumeric, + }, opts.filterIncludeNulls) if err != nil { return nil, totalCount, err }