Skip to content

Commit baa284a

Browse files
fix: delete provisioned dashboard in unified if forceDeleteRules is set
1 parent d1d8aa7 commit baa284a

File tree

9 files changed

+74
-64
lines changed

9 files changed

+74
-64
lines changed

pkg/api/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func (hs *HTTPServer) deleteDashboard(c *contextmodel.ReqContext) response.Respo
381381
"error", err)
382382
}
383383

384-
err = hs.DashboardService.DeleteDashboard(c.Req.Context(), dash.ID, dash.UID, c.GetOrgID())
384+
err = hs.DashboardService.DeleteDashboard(c.Req.Context(), dash.ID, dash.UID, c.GetOrgID(), true)
385385
if err != nil {
386386
return dashboardErrResponse(err, "Failed to delete dashboard")
387387
}

pkg/services/dashboards/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
//go:generate mockery --name DashboardService --structname FakeDashboardService --inpackage --filename dashboard_service_mock.go
2121
type DashboardService interface {
2222
BuildSaveDashboardCommand(ctx context.Context, dto *SaveDashboardDTO, validateProvisionedDashboard bool) (*SaveDashboardCommand, error)
23-
DeleteDashboard(ctx context.Context, dashboardId int64, dashboardUID string, orgId int64) error
23+
DeleteDashboard(ctx context.Context, dashboardId int64, dashboardUID string, orgId int64, validateProvisionedDashboard bool) error
2424
DeleteAllDashboards(ctx context.Context, orgID int64) error
2525
FindDashboards(ctx context.Context, query *FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error)
2626
// GetDashboard fetches a dashboard.

pkg/services/dashboards/dashboard_provisioning_mock.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/services/dashboards/dashboard_service_mock.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/services/dashboards/service/dashboard_service.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,10 @@ func (dr *DashboardServiceImpl) Run(ctx context.Context) error {
365365
return ctx.Err()
366366
}
367367

368-
var _ dashboards.PermissionsRegistrationService = (*DashboardServiceImpl)(nil)
369-
var _ registry.BackgroundService = (*DashboardServiceImpl)(nil)
368+
var (
369+
_ dashboards.PermissionsRegistrationService = (*DashboardServiceImpl)(nil)
370+
_ registry.BackgroundService = (*DashboardServiceImpl)(nil)
371+
)
370372

371373
// This is the uber service that implements a three smaller services
372374
func ProvideDashboardServiceImpl(
@@ -645,7 +647,8 @@ func (dr *DashboardServiceImpl) ValidateBasicDashboardProperties(title string, u
645647

646648
//nolint:gocyclo
647649
func (dr *DashboardServiceImpl) BuildSaveDashboardCommand(ctx context.Context, dto *dashboards.SaveDashboardDTO,
648-
validateProvisionedDashboard bool) (*dashboards.SaveDashboardCommand, error) {
650+
validateProvisionedDashboard bool,
651+
) (*dashboards.SaveDashboardCommand, error) {
649652
ctx, span := tracer.Start(ctx, "dashboards.service.BuildSaveDashboardcommand")
650653
defer span.End()
651654

@@ -976,7 +979,8 @@ func (dr *DashboardServiceImpl) ValidateDashboardRefreshInterval(minRefreshInter
976979
}
977980

978981
func (dr *DashboardServiceImpl) SaveProvisionedDashboard(ctx context.Context, dto *dashboards.SaveDashboardDTO,
979-
provisioning *dashboards.DashboardProvisioning) (*dashboards.Dashboard, error) {
982+
provisioning *dashboards.DashboardProvisioning,
983+
) (*dashboards.Dashboard, error) {
980984
ctx, span := tracer.Start(ctx, "dashboards.service.SaveProvisionedDashboard")
981985
defer span.End()
982986

@@ -1050,7 +1054,8 @@ func (dr *DashboardServiceImpl) UpdateFolderWithManagedByAnnotation(ctx context.
10501054
}
10511055

10521056
func (dr *DashboardServiceImpl) SaveDashboard(ctx context.Context, dto *dashboards.SaveDashboardDTO,
1053-
allowUiUpdate bool) (*dashboards.Dashboard, error) {
1057+
allowUiUpdate bool,
1058+
) (*dashboards.Dashboard, error) {
10541059
ctx, span := tracer.Start(ctx, "dashboards.service.SaveDashboard")
10551060
defer span.End()
10561061

@@ -1085,8 +1090,8 @@ func (dr *DashboardServiceImpl) saveDashboard(ctx context.Context, cmd *dashboar
10851090

10861091
// DeleteDashboard removes dashboard from the DB. Errors out if the dashboard was provisioned. Should be used for
10871092
// operations by the user where we want to make sure user does not delete provisioned dashboard.
1088-
func (dr *DashboardServiceImpl) DeleteDashboard(ctx context.Context, dashboardId int64, dashboardUID string, orgId int64) error {
1089-
return dr.deleteDashboard(ctx, dashboardId, dashboardUID, orgId, true)
1093+
func (dr *DashboardServiceImpl) DeleteDashboard(ctx context.Context, dashboardId int64, dashboardUID string, orgId int64, validateProvisionedDashboard bool) error {
1094+
return dr.deleteDashboard(ctx, dashboardId, dashboardUID, orgId, validateProvisionedDashboard)
10901095
}
10911096

10921097
// DeleteAllDashboards will delete all dashboards within a given org.
@@ -1114,7 +1119,8 @@ func (dr *DashboardServiceImpl) deleteDashboard(ctx context.Context, dashboardId
11141119
}
11151120

11161121
func (dr *DashboardServiceImpl) ImportDashboard(ctx context.Context, dto *dashboards.SaveDashboardDTO) (
1117-
*dashboards.Dashboard, error) {
1122+
*dashboards.Dashboard, error,
1123+
) {
11181124
ctx, span := tracer.Start(ctx, "dashboards.service.ImportDashboard")
11191125
defer span.End()
11201126

@@ -1638,7 +1644,8 @@ func (dr *DashboardServiceImpl) GetDashboardTags(ctx context.Context, query *das
16381644
Limit: 100000,
16391645
},
16401646
},
1641-
Limit: 100000})
1647+
Limit: 100000,
1648+
})
16421649
if err != nil {
16431650
return nil, err
16441651
}
@@ -1682,7 +1689,6 @@ func (dr *DashboardServiceImpl) DeleteInFolders(ctx context.Context, orgID int64
16821689
OrgId: orgID,
16831690
FolderUIDs: folderUIDs,
16841691
})
1685-
16861692
if err != nil {
16871693
return folder.ErrInternal.Errorf("failed to fetch dashboards: %w", err)
16881694
}
@@ -1698,7 +1704,7 @@ func (dr *DashboardServiceImpl) DeleteInFolders(ctx context.Context, orgID int64
16981704
}
16991705

17001706
for _, dash := range dashes {
1701-
errDel := dr.DeleteDashboard(ctx, dash.ID, dash.UID, orgID)
1707+
errDel := dr.DeleteDashboard(ctx, dash.ID, dash.UID, orgID, false)
17021708
if errDel != nil {
17031709
dr.log.Error("failed to delete dashboard inside folder", "dashboardUID", dash.UID, "folderUIDs", folderUIDs, "error", errDel)
17041710
}
@@ -1714,7 +1720,7 @@ func (dr *DashboardServiceImpl) CleanUpDashboard(ctx context.Context, dashboardU
17141720
defer span.End()
17151721

17161722
// cleanup things related to dashboards that are not stored in unistore yet
1717-
var err = dr.publicDashboardService.DeleteByDashboardUIDs(ctx, orgId, []string{dashboardUID})
1723+
err := dr.publicDashboardService.DeleteByDashboardUIDs(ctx, orgId, []string{dashboardUID})
17181724
if err != nil {
17191725
return err
17201726
}
@@ -1894,7 +1900,8 @@ func (dr *DashboardServiceImpl) searchDashboardsThroughK8sRaw(ctx context.Contex
18941900
Fields: []*resourcepb.Requirement{},
18951901
Labels: []*resourcepb.Requirement{},
18961902
},
1897-
Limit: 100000}
1903+
Limit: 100000,
1904+
}
18981905

18991906
if len(query.DashboardUIDs) > 0 {
19001907
request.Options.Fields = []*resourcepb.Requirement{{

pkg/services/dashboards/service/dashboard_service_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ func TestDeleteDashboard(t *testing.T) {
12361236
ctx, k8sCliMock := setupK8sDashboardTests(service)
12371237
k8sCliMock.On("Delete", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
12381238

1239-
err := service.DeleteDashboard(ctx, 1, "uid", 1)
1239+
err := service.DeleteDashboard(ctx, 1, "uid", 1, true)
12401240
require.NoError(t, err)
12411241
k8sCliMock.AssertExpectations(t)
12421242
})
@@ -1272,7 +1272,7 @@ func TestDeleteDashboard(t *testing.T) {
12721272
},
12731273
TotalHits: 1,
12741274
}, nil)
1275-
err := service.DeleteDashboard(ctx, 1, "", 1)
1275+
err := service.DeleteDashboard(ctx, 1, "", 1, true)
12761276
require.NoError(t, err)
12771277
k8sCliMock.AssertExpectations(t)
12781278
k8sCliMock.AssertExpectations(t)
@@ -1967,7 +1967,8 @@ func TestSearchDashboardsThroughK8sRaw(t *testing.T) {
19671967
Results: &resourcepb.ResourceTable{
19681968
Columns: []*resourcepb.ResourceTableColumnDefinition{},
19691969
Rows: []*resourcepb.ResourceTableRow{},
1970-
}}, nil)
1970+
},
1971+
}, nil)
19711972
_, err := service.searchDashboardsThroughK8s(ctx, query)
19721973
require.NoError(t, err)
19731974
})

pkg/services/dashboards/store_mock.go

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/services/plugindashboards/service/dashboard_updater.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818

1919
func ProvideDashboardUpdater(bus bus.Bus, pluginStore pluginstore.Store, pluginDashboardService plugindashboards.Service,
2020
dashboardImportService dashboardimport.Service, pluginSettingsService pluginsettings.Service,
21-
dashboardPluginService dashboards.PluginService, dashboardService dashboards.DashboardService) *DashboardUpdater {
21+
dashboardPluginService dashboards.PluginService, dashboardService dashboards.DashboardService,
22+
) *DashboardUpdater {
2223
du := newDashboardUpdater(bus, pluginStore, pluginDashboardService, dashboardImportService,
2324
pluginSettingsService, dashboardPluginService, dashboardService)
2425
return du
@@ -27,7 +28,8 @@ func ProvideDashboardUpdater(bus bus.Bus, pluginStore pluginstore.Store, pluginD
2728
func newDashboardUpdater(bus bus.Bus, pluginStore pluginstore.Store,
2829
pluginDashboardService plugindashboards.Service, dashboardImportService dashboardimport.Service,
2930
pluginSettingsService pluginsettings.Service, dashboardPluginService dashboards.PluginService,
30-
dashboardService dashboards.DashboardService) *DashboardUpdater {
31+
dashboardService dashboards.DashboardService,
32+
) *DashboardUpdater {
3133
s := &DashboardUpdater{
3234
pluginStore: pluginStore,
3335
pluginDashboardService: pluginDashboardService,
@@ -101,7 +103,7 @@ func (du *DashboardUpdater) syncPluginDashboards(ctx context.Context, plugin plu
101103
if dash.Removed {
102104
du.logger.Info("Deleting plugin dashboard", "pluginId", plugin.ID, "dashboard", dash.Slug)
103105

104-
if err := du.dashboardService.DeleteDashboard(ctx, dash.DashboardId, dash.UID, orgID); err != nil {
106+
if err := du.dashboardService.DeleteDashboard(ctx, dash.DashboardId, dash.UID, orgID, true); err != nil {
105107
du.logger.Error("Failed to auto update app dashboard", "pluginId", plugin.ID, "error", err)
106108
return
107109
}
@@ -157,7 +159,7 @@ func (du *DashboardUpdater) handlePluginStateChanged(ctx context.Context, event
157159

158160
for _, dash := range queryResult {
159161
du.logger.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug)
160-
if err := du.dashboardService.DeleteDashboard(ctx, dash.ID, dash.UID, dash.OrgID); err != nil {
162+
if err := du.dashboardService.DeleteDashboard(ctx, dash.ID, dash.UID, dash.OrgID, true); err != nil {
161163
return err
162164
}
163165
}

pkg/services/plugindashboards/service/dashboard_updater_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ type dashboardServiceMock struct {
449449
}
450450
}
451451

452-
func (s *dashboardServiceMock) DeleteDashboard(_ context.Context, dashboardId int64, dashboardUID string, orgId int64) error {
452+
func (s *dashboardServiceMock) DeleteDashboard(_ context.Context, dashboardId int64, dashboardUID string, orgId int64, _ bool) error {
453453
s.deleteDashboardArgs = append(s.deleteDashboardArgs, struct {
454454
orgId int64
455455
dashboardId int64

0 commit comments

Comments
 (0)