vikunja-api/models/list_delete.go

30 lines
526 B
Go
Raw Normal View History

2018-06-12 18:17:21 +02:00
package models
2018-07-10 13:27:25 +02:00
func (l *List) Delete(id int64, doer *User) (err error) {
2018-06-12 18:17:21 +02:00
// Check if the list exists
2018-07-10 13:27:25 +02:00
list, err := GetListByID(id)
if err != nil {
return
}
// Check rights
user, _, err := GetUserByID(doer.ID)
2018-06-12 18:17:21 +02:00
if err != nil {
return
}
2018-07-10 13:27:25 +02:00
if !list.IsAdmin(&user) {
return ErrNeedToBeListAdmin{ListID:id, UserID:user.ID}
}
2018-06-12 18:17:21 +02:00
// Delete the list
2018-07-10 13:27:25 +02:00
_, err = x.ID(id).Delete(&List{})
2018-06-12 18:17:21 +02:00
if err != nil {
return
}
// Delete all todoitems on that list
2018-07-10 13:27:25 +02:00
_, err = x.Where("list_id = ?", id).Delete(&ListItem{})
2018-06-12 18:17:21 +02:00
return
}