PublicDashboards: Delete on folder deletion (#99040)
This commit is contained in:
@@ -682,48 +682,53 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestFindByFolder(t *testing.T) {
|
||||
t.Run("returns nil when dashboard is not a folder", func(t *testing.T) {
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
dashboard := &dashboards.Dashboard{OrgID: 1, UID: "dashboarduid", IsFolder: false}
|
||||
func TestDeleteByDashboardUIDs(t *testing.T) {
|
||||
var sqlStore db.DB
|
||||
var cfg *setting.Cfg
|
||||
var dashboardStore dashboards.Store
|
||||
var publicdashboardStore *PublicDashboardStoreImpl
|
||||
var savedDashboard *dashboards.Dashboard
|
||||
//var savedPublicDashboard *PublicDashboard
|
||||
var err error
|
||||
|
||||
setup := func() {
|
||||
sqlStore, cfg = db.InitTestDBWithCfg(t)
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore))
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
_ = insertPublicDashboard(t, publicdashboardStore, savedDashboard.UID, savedDashboard.OrgID, true, PublicShareType)
|
||||
}
|
||||
|
||||
t.Run("returns nil when dashboardUIDs is empty", func(t *testing.T) {
|
||||
setup()
|
||||
var dashboardUIDs []string
|
||||
store := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
pubdashes, err := store.FindByFolder(context.Background(), dashboard.OrgID, dashboard.UID)
|
||||
err := store.DeleteByDashboardUIDs(context.Background(), 1, dashboardUIDs)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, pubdashes)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("returns nil when parameters are empty", func(t *testing.T) {
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
store := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
pubdashes, err := store.FindByFolder(context.Background(), 0, "")
|
||||
t.Run("deletes public dashboards with provided dashboard uids", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
// confirm the pubdash exists
|
||||
pubdash, err := publicdashboardStore.FindByDashboardUid(context.Background(), savedDashboard.OrgID, savedDashboard.UID)
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, pubdashes)
|
||||
})
|
||||
assert.NotNil(t, pubdash)
|
||||
|
||||
t.Run("can get all pubdashes for dashboard folder and org", func(t *testing.T) {
|
||||
sqlStore, cfg := db.InitTestDBWithCfg(t)
|
||||
dashboardStore, err := dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore))
|
||||
dashboardUIDs := []string{savedDashboard.UID}
|
||||
|
||||
// delete the pubdash by dashboard uid
|
||||
err = publicdashboardStore.DeleteByDashboardUIDs(context.Background(), 1, dashboardUIDs)
|
||||
require.NoError(t, err)
|
||||
pubdashStore := ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
// insert folders
|
||||
folder := insertTestDashboard(t, dashboardStore, "This is a folder", 1, "", true, PublicShareType)
|
||||
folder2 := insertTestDashboard(t, dashboardStore, "This is another folder", 1, "", true, PublicShareType)
|
||||
// insert dashboard in a folder
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "Dashboard in a folder", 1, folder.UID, false, PublicShareType)
|
||||
// insert a dashboard in a different folder
|
||||
dashboard2 := insertTestDashboard(t, dashboardStore, "Another Dashboard in a different folder", 1, folder2.UID, false, PublicShareType)
|
||||
|
||||
// create 2 public dashboards
|
||||
pubdash := insertPublicDashboard(t, pubdashStore, dashboard.UID, dashboard.OrgID, true, PublicShareType)
|
||||
_ = insertPublicDashboard(t, pubdashStore, dashboard2.UID, dashboard2.OrgID, true, PublicShareType)
|
||||
|
||||
pubdashes, err := pubdashStore.FindByFolder(context.Background(), folder.OrgID, folder.UID)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// confirm the pubdash was deleted
|
||||
pubdash, err = publicdashboardStore.FindByDashboardUid(context.Background(), savedDashboard.OrgID, savedDashboard.UID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, pubdashes, 1)
|
||||
assert.Equal(t, pubdash, pubdashes[0])
|
||||
assert.Nil(t, pubdash)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user