mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-05-05 19:18:16 -05:00
fix: use local variable for position to avoid cross-view contamination
When creating a task, calculateNewPositionForTask is called in a loop for each view. Previously it wrote the calculated position back to the shared *Task struct (t.Position), causing subsequent views to skip their own position calculation and reuse the first view's value. This resulted in new tasks appearing in the middle of other views instead of at the top. Use a local variable instead of mutating t.Position so each view calculates its position independently. Ref: https://github.com/go-vikunja/vikunja/issues/2329 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -303,7 +303,8 @@ func recalculateTaskPositionsForRepair(s *xorm.Session, view *ProjectView) error
|
||||
}
|
||||
|
||||
func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *ProjectView) (*TaskPosition, error) {
|
||||
if t.Position == 0 {
|
||||
position := t.Position
|
||||
if position == 0 {
|
||||
lowestPosition := &TaskPosition{}
|
||||
exists, err := s.Where("project_view_id = ?", view.ID).
|
||||
OrderBy("position asc").
|
||||
@@ -327,14 +328,14 @@ func calculateNewPositionForTask(s *xorm.Session, a web.Auth, t *Task, view *Pro
|
||||
}
|
||||
}
|
||||
|
||||
t.Position = lowestPosition.Position / 2
|
||||
position = lowestPosition.Position / 2
|
||||
}
|
||||
}
|
||||
|
||||
return &TaskPosition{
|
||||
TaskID: t.ID,
|
||||
ProjectViewID: view.ID,
|
||||
Position: calculateDefaultPosition(t.Index, t.Position),
|
||||
Position: calculateDefaultPosition(t.Index, position),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user