fix(views): move bucket update to extra endpoint
BREAKING CHANGE: The bucket id of the task model is now only used internally and will not trigger a change in buckets when updating the task. This resolves a problem where the task update routine needs to know the view context it is in. Because that's not really what it should be used for, the extra endpoint takes all required parameters and handles the complexity of actually updating the bucket. This fixes a bug where it was impossible to move a task around between buckets of a saved filter view. In that case, the view of the bucket and the project the task was in would be different, hence the update failed.
This commit is contained in:
@ -189,6 +189,7 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
}
|
||||
|
||||
// Create all views, create default views if we don't have any
|
||||
var kanbanView *models.ProjectView
|
||||
viewsByOldIDs := make(map[int64]*models.ProjectView, len(oldViews))
|
||||
if len(oldViews) > 0 {
|
||||
for _, view := range oldViews {
|
||||
@ -216,12 +217,16 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
return
|
||||
}
|
||||
viewsByOldIDs[oldID] = view
|
||||
if view.ViewKind == models.ProjectViewKindKanban {
|
||||
kanbanView = view
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Only using the default views
|
||||
// Add all buckets to the default kanban view
|
||||
for _, view := range project.Views {
|
||||
if view.ViewKind == models.ProjectViewKindKanban {
|
||||
kanbanView = view
|
||||
for _, b := range bucketsByOldID {
|
||||
b.ProjectViewID = view.ID
|
||||
err = b.Update(s, user)
|
||||
@ -236,25 +241,36 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
|
||||
log.Debugf("[creating structure] Creating %d tasks", len(tasks))
|
||||
|
||||
setBucketOrDefault := func(task *models.Task) {
|
||||
bucket, exists := bucketsByOldID[task.BucketID]
|
||||
setBucketOrDefault := func(task *models.Task) (err error) {
|
||||
var bucketID = task.BucketID
|
||||
bucket, exists := bucketsByOldID[bucketID]
|
||||
if exists {
|
||||
task.BucketID = bucket.ID
|
||||
} else if task.BucketID > 0 {
|
||||
bucketID = bucket.ID
|
||||
tb := &models.TaskBucket{
|
||||
TaskID: task.ID,
|
||||
BucketID: bucketID,
|
||||
ProjectID: task.ProjectID,
|
||||
ProjectViewID: kanbanView.ID,
|
||||
}
|
||||
err = tb.Update(s, user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else if bucketID > 0 {
|
||||
log.Debugf("[creating structure] No bucket created for original bucket id %d", task.BucketID)
|
||||
task.BucketID = 0
|
||||
bucketID = 0
|
||||
}
|
||||
if !exists || task.BucketID == 0 {
|
||||
if !exists || bucketID == 0 {
|
||||
needsDefaultBucket = true
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
tasksByOldID := make(map[int64]*models.TaskWithComments, len(tasks))
|
||||
newTaskIDs := []int64{}
|
||||
// Create all tasks
|
||||
for i, t := range tasks {
|
||||
setBucketOrDefault(&tasks[i].Task)
|
||||
|
||||
oldid := t.ID
|
||||
t.ProjectID = project.ID
|
||||
err = t.Create(s, user)
|
||||
@ -262,6 +278,11 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
continue
|
||||
}
|
||||
|
||||
err = setBucketOrDefault(&tasks[i].Task)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
newTaskIDs = append(newTaskIDs, t.ID)
|
||||
|
||||
if err != nil {
|
||||
@ -285,7 +306,10 @@ func createProjectWithEverything(s *xorm.Session, project *models.ProjectWithTas
|
||||
// First create the related tasks if they do not exist
|
||||
if _, exists := tasksByOldID[rt.ID]; !exists || rt.ID == 0 {
|
||||
oldid := rt.ID
|
||||
setBucketOrDefault(rt)
|
||||
err = setBucketOrDefault(rt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rt.ProjectID = t.ProjectID
|
||||
err = rt.Create(s, user)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user