Dashboards: Make path to default dashboard configurable (#25595)

Closes #25463

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
This commit is contained in:
Carl Bergquist
2020-06-22 18:00:39 +02:00
committed by GitHub
parent cc95754e0d
commit 703f728c0c
7 changed files with 77 additions and 6 deletions

View File

@@ -19,7 +19,6 @@ import (
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
@@ -315,15 +314,16 @@ func dashboardSaveErrorToApiResponse(err error) Response {
return Error(500, "Failed to save dashboard", err)
}
func GetHomeDashboard(c *models.ReqContext) Response {
// GetHomeDashboard returns the home dashboard.
func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) Response {
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
if err := bus.Dispatch(&prefsQuery); err != nil {
if err := hs.Bus.Dispatch(&prefsQuery); err != nil {
return Error(500, "Failed to get preferences", err)
}
if prefsQuery.Result.HomeDashboardId != 0 {
slugQuery := models.GetDashboardRefByIdQuery{Id: prefsQuery.Result.HomeDashboardId}
err := bus.Dispatch(&slugQuery)
err := hs.Bus.Dispatch(&slugQuery)
if err == nil {
url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug)
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
@@ -332,7 +332,11 @@ func GetHomeDashboard(c *models.ReqContext) Response {
log.Warn("Failed to get slug from database, %s", err.Error())
}
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
filePath := hs.Cfg.DefaultHomeDashboardPath
if filePath == "" {
filePath = path.Join(hs.Cfg.StaticRootPath, "dashboards/home.json")
}
file, err := os.Open(filePath)
if err != nil {
return Error(500, "Failed to load home dashboard", err)