Commit 8c2b6b53 by bergquist

fix(preferences): fixes broken default home dashboard

closes #5167
parent 71d62012
...@@ -209,7 +209,7 @@ func Register(r *macaron.Macaron) { ...@@ -209,7 +209,7 @@ func Register(r *macaron.Macaron) {
r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard) r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard) r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
r.Get("/file/:file", GetDashboardFromJsonFile) r.Get("/file/:file", GetDashboardFromJsonFile)
r.Get("/home", GetHomeDashboard) r.Get("/home", wrap(GetHomeDashboard))
r.Get("/tags", GetDashboardTags) r.Get("/tags", GetDashboardTags)
r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard)) r.Post("/import", bind(dtos.ImportDashboardCommand{}), wrap(ImportDashboard))
}) })
......
...@@ -159,10 +159,10 @@ func canEditDashboard(role m.RoleType) bool { ...@@ -159,10 +159,10 @@ func canEditDashboard(role m.RoleType) bool {
return role == m.ROLE_ADMIN || role == m.ROLE_EDITOR || role == m.ROLE_READ_ONLY_EDITOR return role == m.ROLE_ADMIN || role == m.ROLE_EDITOR || role == m.ROLE_READ_ONLY_EDITOR
} }
func GetHomeDashboard(c *middleware.Context) { func GetHomeDashboard(c *middleware.Context) Response {
prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId} prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId}
if err := bus.Dispatch(&prefsQuery); err != nil { if err := bus.Dispatch(&prefsQuery); err != nil {
c.JsonApiErr(500, "Failed to get preferences", err) return ApiError(500, "Failed to get preferences", err)
} }
if prefsQuery.Result.HomeDashboardId != 0 { if prefsQuery.Result.HomeDashboardId != 0 {
...@@ -170,7 +170,7 @@ func GetHomeDashboard(c *middleware.Context) { ...@@ -170,7 +170,7 @@ func GetHomeDashboard(c *middleware.Context) {
err := bus.Dispatch(&slugQuery) err := bus.Dispatch(&slugQuery)
if err == nil { if err == nil {
dashRedirect := dtos.DashboardRedirect{RedirectUri: "db/" + slugQuery.Result} dashRedirect := dtos.DashboardRedirect{RedirectUri: "db/" + slugQuery.Result}
c.JSON(200, &dashRedirect) return Json(200, &dashRedirect)
} else { } else {
log.Warn("Failed to get slug from database, %s", err.Error()) log.Warn("Failed to get slug from database, %s", err.Error())
} }
...@@ -179,8 +179,7 @@ func GetHomeDashboard(c *middleware.Context) { ...@@ -179,8 +179,7 @@ func GetHomeDashboard(c *middleware.Context) {
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json") filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
file, err := os.Open(filePath) file, err := os.Open(filePath)
if err != nil { if err != nil {
c.JsonApiErr(500, "Failed to load home dashboard", err) return ApiError(500, "Failed to load home dashboard", err)
return
} }
dash := dtos.DashboardFullWithMeta{} dash := dtos.DashboardFullWithMeta{}
...@@ -188,11 +187,10 @@ func GetHomeDashboard(c *middleware.Context) { ...@@ -188,11 +187,10 @@ func GetHomeDashboard(c *middleware.Context) {
dash.Meta.CanEdit = canEditDashboard(c.OrgRole) dash.Meta.CanEdit = canEditDashboard(c.OrgRole)
jsonParser := json.NewDecoder(file) jsonParser := json.NewDecoder(file)
if err := jsonParser.Decode(&dash.Dashboard); err != nil { if err := jsonParser.Decode(&dash.Dashboard); err != nil {
c.JsonApiErr(500, "Failed to load home dashboard", err) return ApiError(500, "Failed to load home dashboard", err)
return
} }
c.JSON(200, &dash) return Json(200, &dash)
} }
func GetDashboardFromJsonFile(c *middleware.Context) { func GetDashboardFromJsonFile(c *middleware.Context) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment