1
0

feat: add proper checks and errors to see if an attachment belongs to the task it's being used as cover image in

This commit is contained in:
kolaente
2022-10-02 13:56:37 +02:00
parent e113fe34d0
commit 631a265d2d
3 changed files with 51 additions and 5 deletions

View File

@ -1042,7 +1042,7 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
"position",
"repeat_mode",
"kanban_position",
"cover_image_attachment_id", // TODO: check if the attachment belongs to the task
"cover_image_attachment_id",
}
// If the task is being moved between lists, make sure to move the bucket + index as well
@ -1057,6 +1057,23 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
colsToUpdate = append(colsToUpdate, "index")
}
// If a task attachment is being set as cover image, check if the attachment actually belongs to the task
if t.CoverImageAttachmentID != 0 {
is, err := s.Exist(&TaskAttachment{
TaskID: t.ID,
ID: t.CoverImageAttachmentID,
})
if err != nil {
return err
}
if !is {
return &ErrAttachmentDoesNotBelongToTask{
AttachmentID: t.CoverImageAttachmentID,
TaskID: t.ID,
}
}
}
wasFavorite, err := isFavorite(s, t.ID, a, FavoriteKindTask)
if err != nil {
return