Skip to content
Snippets Groups Projects
Commit f5de5d5e authored by Christian Pointner's avatar Christian Pointner
Browse files

fix check playlist existence before deleting it

parent fb95ea46
No related branches found
No related tags found
No related merge requests found
...@@ -100,6 +100,7 @@ func (st *Store) GetFileUsage(group string, id uint64) (playlists Playlists, err ...@@ -100,6 +100,7 @@ func (st *Store) GetFileUsage(group string, id uint64) (playlists Playlists, err
func (st *Store) DeleteFile(group string, id uint64) error { func (st *Store) DeleteFile(group string, id uint64) error {
tx := st.db.Begin() tx := st.db.Begin()
// make sure the file exists and actually belongs to <group>
if err := tx.Where("group_name = ?", group).First(&File{}, id).Error; err != nil { if err := tx.Where("group_name = ?", group).First(&File{}, id).Error; err != nil {
tx.Rollback() tx.Rollback()
return err return err
......
...@@ -109,7 +109,8 @@ func (st *Store) UpdatePlaylist(group string, id uint64, playlist Playlist) (*Pl ...@@ -109,7 +109,8 @@ func (st *Store) UpdatePlaylist(group string, id uint64, playlist Playlist) (*Pl
func (st *Store) DeletePlaylist(group string, id uint64) (err error) { func (st *Store) DeletePlaylist(group string, id uint64) (err error) {
tx := st.db.Begin() tx := st.db.Begin()
if err = tx.First(&Playlist{}, id).Error; err != nil { // make sure the playlist exists and actually belongs to <group>
if err = tx.Where("group_name = ?", group).First(&Playlist{}, id).Error; err != nil {
tx.Rollback() tx.Rollback()
return return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment