1
0

fix(list): when list background is removed, delete file from file system and DB (#1372)

Co-authored-by: testinho.testador <testinho.testador@noreply.kolaente.de>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/1372
Reviewed-by: konrad <k@knt.li>
Co-authored-by: clos <clos@noreply.kolaente.de>
Co-committed-by: clos <clos@noreply.kolaente.de>
This commit is contained in:
clos
2023-02-01 11:38:23 +00:00
committed by konrad
parent 437960b146
commit afdceb0aff
6 changed files with 112 additions and 17 deletions

View File

@ -795,6 +795,11 @@ func (l *List) Create(s *xorm.Session, a web.Auth) (err error) {
// @Router /lists/{id} [delete]
func (l *List) Delete(s *xorm.Session, a web.Auth) (err error) {
fullList, err := GetListSimpleByID(s, l.ID)
if err != nil {
return
}
// Delete the list
_, err = s.ID(l.ID).Delete(&List{})
if err != nil {
@ -815,12 +820,28 @@ func (l *List) Delete(s *xorm.Session, a web.Auth) (err error) {
}
}
err = fullList.DeleteBackgroundFileIfExists()
if err != nil {
return
}
return events.Dispatch(&ListDeletedEvent{
List: l,
Doer: a,
})
}
// DeleteBackgroundFileIfExists deletes the list's background file from the db and the filesystem,
// if one exists
func (l *List) DeleteBackgroundFileIfExists() (err error) {
if l.BackgroundFileID == 0 {
return
}
file := files.File{ID: l.BackgroundFileID}
return file.Delete()
}
// SetListBackground sets a background file as list background in the db
func SetListBackground(s *xorm.Session, listID int64, background *files.File, blurHash string) (err error) {
l := &List{