mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-08-31 12:45:51 -05:00
address pr-swarm finding: grouping the conflicts by view left them in map order, and the order is observable - resolving a lower group moves its tasks toward the next one, so which runs first decides whether the view gets a local respace or a full recalculation. Same data, different result per run. Also restores the count == 0 early return dropped when that guard was split, and lets the placement helper own the batch state so a caller cannot hand it tasks the state was not built from. Claude-Session: https://claude.ai/code/session_01GR9u1EFvq994jqGoeJqYSX
73 lines
2.4 KiB
Go
73 lines
2.4 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package models
|
|
|
|
import (
|
|
"code.vikunja.io/api/pkg/web"
|
|
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
// BulkTaskCreate represents a bulk task creation payload.
|
|
type BulkTaskCreate struct {
|
|
Tasks []*Task `json:"tasks" minItems:"1" maxItems:"200" doc:"The tasks to create, each with the project to create it in. Slice order is the order the tasks end up in: they are placed above everything the views already contain, keeping the order they were passed in."`
|
|
|
|
web.CRUDable `xorm:"-" json:"-"`
|
|
web.Permissions `xorm:"-" json:"-"`
|
|
}
|
|
|
|
// CanCreate checks if the user can create tasks in all involved projects.
|
|
func (bt *BulkTaskCreate) CanCreate(s *xorm.Session, a web.Auth) (bool, error) {
|
|
if len(bt.Tasks) == 0 {
|
|
return false, ErrBulkTasksNeedAtLeastOne{}
|
|
}
|
|
|
|
checked := map[int64]struct{}{}
|
|
for _, t := range bt.Tasks {
|
|
if _, has := checked[t.ProjectID]; has {
|
|
continue
|
|
}
|
|
checked[t.ProjectID] = struct{}{}
|
|
|
|
p := &Project{ID: t.ProjectID}
|
|
can, err := p.CanWrite(s, a)
|
|
if err != nil || !can {
|
|
return false, err
|
|
}
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
// Create creates multiple tasks at once.
|
|
func (bt *BulkTaskCreate) Create(s *xorm.Session, a web.Auth) (err error) {
|
|
if len(bt.Tasks) == 0 {
|
|
return ErrBulkTasksNeedAtLeastOne{}
|
|
}
|
|
|
|
return createTasksAtTopOfViews(s, a, bt.Tasks, func(tasks []*Task, state *taskCreateState) error {
|
|
return createTasks(s, tasks, a, createTaskOpts{
|
|
updateAssignees: true,
|
|
setBucket: true,
|
|
// Positions are set for the whole batch at once - one at a time would place
|
|
// every task at the same spot and leave the order to conflict repair.
|
|
skipPositions: true,
|
|
state: state,
|
|
})
|
|
})
|
|
}
|