Provisioning: Do not allow deletion of provisioned dashboards (#16211)
* Unprovision dashboard in case of DisableDeletion = true * Rename command struct * Handle removed provision files * Allow html in confirm-modal * Do not show confirm button without onConfirm * Show dialog on deleting provisioned dashboard * Changed DeleteDashboard to DeleteProvisionedDashboard * Remove unreachable return * Add provisioned checks to API * Remove filter func * Fix and add tests for deleting dashboards * Change delete confirm text * Added and used pkg/errors for error wrapping
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package dashboards
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
@@ -200,8 +199,61 @@ func TestDashboardService(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Given provisioned dashboard", func() {
|
||||
result := setupDeleteHandlers(true)
|
||||
|
||||
Convey("DeleteProvisionedDashboard should delete it", func() {
|
||||
err := service.DeleteProvisionedDashboard(1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
So(result.deleteWasCalled, ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("DeleteDashboard should fail to delete it", func() {
|
||||
err := service.DeleteDashboard(1, 1)
|
||||
So(err, ShouldEqual, models.ErrDashboardCannotDeleteProvisionedDashboard)
|
||||
So(result.deleteWasCalled, ShouldBeFalse)
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Given non provisioned dashboard", func() {
|
||||
result := setupDeleteHandlers(false)
|
||||
|
||||
Convey("DeleteProvisionedDashboard should delete it", func() {
|
||||
err := service.DeleteProvisionedDashboard(1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
So(result.deleteWasCalled, ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("DeleteDashboard should delete it", func() {
|
||||
err := service.DeleteDashboard(1, 1)
|
||||
So(err, ShouldBeNil)
|
||||
So(result.deleteWasCalled, ShouldBeTrue)
|
||||
})
|
||||
})
|
||||
|
||||
Reset(func() {
|
||||
guardian.New = origNewDashboardGuardian
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
deleteWasCalled bool
|
||||
}
|
||||
|
||||
func setupDeleteHandlers(provisioned bool) *Result {
|
||||
bus.AddHandler("test", func(cmd *models.IsDashboardProvisionedQuery) error {
|
||||
cmd.Result = provisioned
|
||||
return nil
|
||||
})
|
||||
|
||||
result := &Result{}
|
||||
bus.AddHandler("test", func(cmd *models.DeleteDashboardCommand) error {
|
||||
So(cmd.Id, ShouldEqual, 1)
|
||||
So(cmd.OrgId, ShouldEqual, 1)
|
||||
result.deleteWasCalled = true
|
||||
return nil
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user