dashboards as cfg: logs error when trying to import dashboard with id

dashboard json cannot contain fixed id when importing from
disk. We used to override this but it didnt caught all problems
so now we block dashboards from beeing imported instead.

closes #10504
pull/10519/merge
bergquist 7 years ago
parent 3951df136c
commit 1a6c2ea8d8
  1. 9
      pkg/services/provisioning/dashboards/file_reader.go
  2. 1
      pkg/services/provisioning/dashboards/types.go

@ -156,13 +156,15 @@ func createWalkFn(fr *fileReader, folderId int64) filepath.WalkFunc {
return nil
}
// id = 0 indicates ID validation should be avoided before writing to the db.
dash.Dashboard.Id = 0
if dash.Dashboard.Id != 0 {
fr.log.Error("Cannot provision dashboard. Please remove the id property from the json file")
return nil
}
cmd := &models.GetDashboardQuery{Slug: dash.Dashboard.Slug}
err = bus.Dispatch(cmd)
// if we dont have the dashboard in the db, save it!
// if we don't have the dashboard in the db, save it!
if err == models.ErrDashboardNotFound {
fr.log.Debug("saving new dashboard", "file", path)
_, err = fr.dashboardRepo.SaveDashboard(dash)
@ -181,6 +183,7 @@ func createWalkFn(fr *fileReader, folderId int64) filepath.WalkFunc {
fr.log.Debug("loading dashboard from disk into database.", "file", path)
_, err = fr.dashboardRepo.SaveDashboard(dash)
return err
}
}

@ -24,6 +24,7 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das
dash.UpdatedAt = lastModified
dash.Overwrite = true
dash.OrgId = cfg.OrgId
dash.Dashboard.OrgId = cfg.OrgId
dash.Dashboard.FolderId = folderId
if !cfg.Editable {
dash.Dashboard.Data.Set("editable", cfg.Editable)

Loading…
Cancel
Save