fix(task): cleanup old task positions and task buckets when adding an updated or created task to filter
(cherry picked from commit 2123da49a38e8683a2a0272b89617634d45f7f45)
This commit is contained in:
parent
a21036340e
commit
d27b62db6e
@ -32,6 +32,7 @@ import (
|
|||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
|
||||||
"github.com/ThreeDotsLabs/watermill/message"
|
"github.com/ThreeDotsLabs/watermill/message"
|
||||||
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -725,6 +726,8 @@ func (l *UpdateTaskInSavedFilterViews) Handle(msg *message.Message) (err error)
|
|||||||
taskBuckets := []*TaskBucket{}
|
taskBuckets := []*TaskBucket{}
|
||||||
taskPositions := []*TaskPosition{}
|
taskPositions := []*TaskPosition{}
|
||||||
|
|
||||||
|
viewIDToCleanUp := []int64{}
|
||||||
|
|
||||||
for _, view := range kanbanFilterViews {
|
for _, view := range kanbanFilterViews {
|
||||||
filter, exists := filters[getSavedFilterIDFromProjectID(view.ProjectID)]
|
filter, exists := filters[getSavedFilterIDFromProjectID(view.ProjectID)]
|
||||||
if !exists {
|
if !exists {
|
||||||
@ -740,10 +743,27 @@ func (l *UpdateTaskInSavedFilterViews) Handle(msg *message.Message) (err error)
|
|||||||
if taskBucket != nil && taskPosition != nil {
|
if taskBucket != nil && taskPosition != nil {
|
||||||
taskBuckets = append(taskBuckets, taskBucket)
|
taskBuckets = append(taskBuckets, taskBucket)
|
||||||
taskPositions = append(taskPositions, taskPosition)
|
taskPositions = append(taskPositions, taskPosition)
|
||||||
|
viewIDToCleanUp = append(viewIDToCleanUp, view.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(taskBuckets) > 0 || len(taskPositions) > 0 {
|
if len(taskBuckets) > 0 || len(taskPositions) > 0 {
|
||||||
|
_, err = s.And(
|
||||||
|
builder.Eq{"task_id": event.Task.ID},
|
||||||
|
builder.In("project_view_id", viewIDToCleanUp),
|
||||||
|
).
|
||||||
|
Delete(&TaskBucket{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = s.And(
|
||||||
|
builder.Eq{"task_id": event.Task.ID},
|
||||||
|
builder.In("project_view_id", viewIDToCleanUp),
|
||||||
|
).
|
||||||
|
Delete(&TaskPosition{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = s.Insert(taskBuckets)
|
_, err = s.Insert(taskBuckets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -202,7 +202,12 @@ func (sf *SavedFilter) Update(s *xorm.Session, _ web.Auth) error {
|
|||||||
|
|
||||||
// Add all tasks which are not already in a bucket to the default bucket
|
// Add all tasks which are not already in a bucket to the default bucket
|
||||||
kanbanFilterViews := []*ProjectView{}
|
kanbanFilterViews := []*ProjectView{}
|
||||||
err = s.Where("project_id = ? and view_kind = ? and bucket_configuration_mode = ?", getProjectIDFromSavedFilterID(sf.ID), ProjectViewKindKanban, BucketConfigurationModeManual).
|
err = s.Where(
|
||||||
|
"project_id = ? and view_kind = ? and bucket_configuration_mode = ?",
|
||||||
|
getProjectIDFromSavedFilterID(sf.ID),
|
||||||
|
ProjectViewKindKanban,
|
||||||
|
BucketConfigurationModeManual,
|
||||||
|
).
|
||||||
Find(&kanbanFilterViews)
|
Find(&kanbanFilterViews)
|
||||||
if err != nil || len(kanbanFilterViews) == 0 {
|
if err != nil || len(kanbanFilterViews) == 0 {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user