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
This commit is contained in:
bergquist 2018-01-15 12:21:14 +01:00
parent 3951df136c
commit 1a6c2ea8d8
2 changed files with 7 additions and 3 deletions

View File

@ -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
}
}

View File

@ -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)