Ensure we delete playlists when deleting an org, fixes #98736 (#98771)

pull/99020/head
beejeebus 6 months ago committed by GitHub
parent e3e580edfa
commit a290db6a7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      pkg/services/org/orgimpl/store.go
  2. 25
      pkg/services/org/orgimpl/store_test.go

@ -221,6 +221,8 @@ func (ss *sqlStore) Delete(ctx context.Context, cmd *org.DeleteOrgCommand) error
deletes := []string{
"DELETE FROM star WHERE org_id = ?",
"DELETE FROM playlist_item WHERE playlist_id IN (SELECT id FROM playlist WHERE org_id = ?)",
"DELETE FROM playlist WHERE org_id = ?",
"DELETE FROM dashboard_tag WHERE org_id = ?",
"DELETE FROM api_key WHERE org_id = ?",
"DELETE FROM data_source WHERE org_id = ?",

@ -15,6 +15,8 @@ import (
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/playlist"
"github.com/grafana/grafana/pkg/services/playlist/playlistimpl"
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
"github.com/grafana/grafana/pkg/services/searchusers/sortopts"
"github.com/grafana/grafana/pkg/services/sqlstore"
@ -115,11 +117,32 @@ func TestIntegrationOrgDataAccess(t *testing.T) {
t.Run("Removing org", func(t *testing.T) {
// make sure ac2 has no org
ac2 := &org.Org{ID: 22, Name: "ac2", Version: 1, Created: time.Now(), Updated: time.Now()}
_, err := orgStore.Insert(context.Background(), ac2)
orgId, err := orgStore.Insert(context.Background(), ac2)
require.NoError(t, err)
// Create some org-scoped items like playlists, so we can assert that they
// are cleaned up on delete.
plItems := []playlist.PlaylistItem{
{
Type: "foo",
},
}
plStore := playlistimpl.ProvideService(ss, tracing.InitializeTracerForTest())
plCreateCommand := playlist.CreatePlaylistCommand{
OrgId: orgId,
Name: "test",
Items: plItems,
}
pl, err := plStore.Create(context.Background(), &plCreateCommand)
require.NoError(t, err)
err = orgStore.Delete(context.Background(), &org.DeleteOrgCommand{ID: ac2.ID})
require.NoError(t, err)
plDTO, err := plStore.Get(context.Background(), &playlist.GetPlaylistByUidQuery{OrgId: pl.OrgId, UID: pl.UID})
require.Error(t, err)
require.Nil(t, plDTO)
// TODO: this part of the test will be added when we move RemoveOrgUser to org store
// "Removing user from org should delete user completely if in no other org"
// // remove ac2 user from ac1 org

Loading…
Cancel
Save