Add check for bucket limit when updating a task

This commit is contained in:
kolaente 2020-09-04 13:46:05 +02:00
parent 072ce4963d
commit 90153fae67
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 14 additions and 4 deletions

View File

@ -762,15 +762,19 @@ func (t *Task) Update() (err error) {
"repeat_from_current_date",
}
// If the task is being moved between lists, make sure to move the bucket + index as well
if t.ListID != 0 && ot.ListID != t.ListID {
b, err := getDefaultBucket(s, t.ListID)
// Make sure we have a bucket
var bucket *Bucket
if t.BucketID == 0 || (t.ListID != 0 && ot.ListID != t.ListID) {
bucket, err = getDefaultBucket(s, t.ListID)
if err != nil {
_ = s.Rollback()
return err
}
t.BucketID = b.ID
t.BucketID = bucket.ID
}
// If the task is being moved between lists, make sure to move the bucket + index as well
if t.ListID != 0 && ot.ListID != t.ListID {
latestTask := &Task{}
_, err = s.Where("list_id = ?", t.ListID).OrderBy("id desc").Get(latestTask)
if err != nil {
@ -782,6 +786,12 @@ func (t *Task) Update() (err error) {
colsToUpdate = append(colsToUpdate, "index")
}
// Check the bucket limit
if err := checkBucketLimit(s, t, bucket); err != nil {
_ = s.Rollback()
return err
}
// Update the labels
//
// Maybe FIXME: