mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Sqlstore: guard against getting a dashboard without specifying identi… (#22246)
* Sqlstore: guard against getting a dashboard without specifying identifier * Sqlstore: linting
This commit is contained in:
parent
0c4dae321c
commit
10fbabfb2e
@ -32,6 +32,7 @@ var (
|
||||
ErrDashboardUidToLong = errors.New("uid to long. max 40 characters")
|
||||
ErrDashboardCannotSaveProvisionedDashboard = errors.New("Cannot save provisioned dashboard")
|
||||
ErrDashboardCannotDeleteProvisionedDashboard = errors.New("provisioned dashboard cannot be deleted")
|
||||
ErrDashboardIdentifierNotSet = errors.New("Unique identfier needed to be able to get a dashboard")
|
||||
RootFolderName = "General"
|
||||
)
|
||||
|
||||
|
@ -169,6 +169,10 @@ func generateNewDashboardUid(sess *DBSession, orgId int64) (string, error) {
|
||||
}
|
||||
|
||||
func GetDashboard(query *models.GetDashboardQuery) error {
|
||||
if query.Id == 0 && len(query.Slug) == 0 && len(query.Uid) == 0 {
|
||||
return models.ErrDashboardIdentifierNotSet
|
||||
}
|
||||
|
||||
dashboard := models.Dashboard{Slug: query.Slug, OrgId: query.OrgId, Id: query.Id, Uid: query.Uid}
|
||||
has, err := x.Get(&dashboard)
|
||||
|
||||
|
@ -88,6 +88,15 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
So(query.Result.IsFolder, ShouldBeFalse)
|
||||
})
|
||||
|
||||
Convey("Shouldn't be able to get a dashboard with just an OrgID", func() {
|
||||
query := m.GetDashboardQuery{
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := GetDashboard(&query)
|
||||
So(err, ShouldEqual, m.ErrDashboardIdentifierNotSet)
|
||||
})
|
||||
|
||||
Convey("Should be able to delete dashboard", func() {
|
||||
dash := insertTestDashboard("delete me", 1, 0, false, "delete this")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user