Chore: Require OrgId to be specified in delete playlist command (#29117)

This commit is contained in:
Emil Hessman
2020-11-14 09:49:07 +01:00
committed by GitHub
parent fbf0d2c086
commit bdc6e2fe0a
2 changed files with 31 additions and 3 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ func GetPlaylist(query *models.GetPlaylistByIdQuery) error {
}
func DeletePlaylist(cmd *models.DeletePlaylistCommand) error {
if cmd.Id == 0 {
if cmd.Id == 0 || cmd.OrgId == 0 {
return models.ErrCommandValidationFailed
}
+30 -2
View File
@@ -3,6 +3,7 @@
package sqlstore
import (
"fmt"
"testing"
"github.com/grafana/grafana/pkg/models"
@@ -32,9 +33,36 @@ func TestPlaylistDataAccess(t *testing.T) {
})
t.Run("Can remove playlist", func(t *testing.T) {
query := models.DeletePlaylistCommand{Id: 1}
err = DeletePlaylist(&query)
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
err = DeletePlaylist(&deleteQuery)
require.NoError(t, err)
getQuery := models.GetPlaylistByIdQuery{Id: 1}
err = GetPlaylist(&getQuery)
require.NoError(t, err)
require.Equal(t, int64(0), getQuery.Result.Id, "playlist should've been removed")
})
})
t.Run("Delete playlist that doesn't exist", func(t *testing.T) {
deleteQuery := models.DeletePlaylistCommand{Id: 1, OrgId: 1}
err := DeletePlaylist(&deleteQuery)
require.NoError(t, err)
})
t.Run("Delete playlist with invalid command yields error", func(t *testing.T) {
testCases := []struct {
desc string
cmd models.DeletePlaylistCommand
}{
{desc: "none", cmd: models.DeletePlaylistCommand{}},
{desc: "no OrgId", cmd: models.DeletePlaylistCommand{Id: 1}},
{desc: "no Id", cmd: models.DeletePlaylistCommand{OrgId: 1}},
}
for _, tc := range testCases {
err := DeletePlaylist(&tc.cmd)
require.EqualError(t, err, models.ErrCommandValidationFailed.Error(), fmt.Sprintf("expected command validation error for %q", tc.desc))
}
})
}