29 lines
526 B
Go
29 lines
526 B
Go
package models
|
|
|
|
func (l *List) Delete(id int64, doer *User) (err error) {
|
|
// Check if the list exists
|
|
list, err := GetListByID(id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// Check rights
|
|
user, _, err := GetUserByID(doer.ID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if !list.IsAdmin(&user) {
|
|
return ErrNeedToBeListAdmin{ListID:id, UserID:user.ID}
|
|
}
|
|
|
|
// Delete the list
|
|
_, err = x.ID(id).Delete(&List{})
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// Delete all todoitems on that list
|
|
_, err = x.Where("list_id = ?", id).Delete(&ListItem{})
|
|
return
|
|
}
|