From 1db99dba472974e58a20c0db427880f76d24de9e Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 9 Jan 2025 16:21:28 +0100 Subject: [PATCH] fix(kanban): correctly check bucket limit for saved filters or view filters Resolves https://github.com/go-vikunja/vikunja/issues/355 --- pkg/models/kanban_task_bucket.go | 2 +- pkg/models/tasks.go | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pkg/models/kanban_task_bucket.go b/pkg/models/kanban_task_bucket.go index 868d22441..1777be217 100644 --- a/pkg/models/kanban_task_bucket.go +++ b/pkg/models/kanban_task_bucket.go @@ -123,7 +123,7 @@ func (b *TaskBucket) Update(s *xorm.Session, a web.Auth) (err error) { // Check the bucket limit // Only check the bucket limit if the task is being moved between buckets, allow reordering the task within a bucket if b.BucketID != 0 && b.BucketID != oldTaskBucket.BucketID { - err = checkBucketLimit(s, &task, bucket) + err = checkBucketLimit(s, a, &task, bucket) if err != nil { return err } diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 80e575478..3d13252ee 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -656,19 +656,39 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth, vi } // Checks if adding a new task would exceed the bucket limit -func checkBucketLimit(s *xorm.Session, t *Task, bucket *Bucket) (err error) { +func checkBucketLimit(s *xorm.Session, a web.Auth, t *Task, bucket *Bucket) (err error) { if bucket.Limit > 0 { - taskCount, err := s. - Where("bucket_id = ?", bucket.ID). - GroupBy("task_id"). - Count(&TaskBucket{}) + var taskCount int64 + view, err := GetProjectViewByID(s, bucket.ProjectViewID) if err != nil { return err } + + if view.ProjectID < 0 || (view.Filter != nil && view.Filter.Filter != "") { + tc := &TaskCollection{ + ProjectID: view.ProjectID, + ProjectViewID: bucket.ProjectViewID, + } + + _, _, taskCount, err = tc.ReadAll(s, a, "", 1, 1) + if err != nil { + return err + } + } else { + taskCount, err = s. + Where("bucket_id = ?", bucket.ID). + GroupBy("task_id"). + Count(&TaskBucket{}) + if err != nil { + return err + } + } + if taskCount >= bucket.Limit { return ErrBucketLimitExceeded{TaskID: t.ID, BucketID: bucket.ID, Limit: bucket.Limit} } } + return nil }