mirror of
https://github.com/grafana/grafana.git
synced 2026-08-12 06:05:02 -05:00
Chore: Use context.Context for the get home dashboard API endpoint (#36735)
Use context.Context for the get home dashboard API endpoint. Ref #36734
This commit is contained in:
@@ -423,7 +423,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
|
||||
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
|
||||
homePage := hs.Cfg.HomePage
|
||||
|
||||
if err := hs.Bus.Dispatch(&prefsQuery); err != nil {
|
||||
if err := hs.Bus.DispatchCtx(c.Req.Context(), &prefsQuery); err != nil {
|
||||
return response.Error(500, "Failed to get preferences", err)
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
if prefsQuery.Result.HomeDashboardId != 0 {
|
||||
slugQuery := models.GetDashboardRefByIdQuery{Id: prefsQuery.Result.HomeDashboardId}
|
||||
err := hs.Bus.Dispatch(&slugQuery)
|
||||
err := hs.Bus.DispatchCtx(c.Req.Context(), &slugQuery)
|
||||
if err == nil {
|
||||
url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug)
|
||||
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -25,10 +26,13 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
func TestGetHomeDashboard(t *testing.T) {
|
||||
req := &models.ReqContext{SignedInUser: &models.SignedInUser{}}
|
||||
httpReq, err := http.NewRequest(http.MethodGet, "", nil)
|
||||
require.NoError(t, err)
|
||||
req := &models.ReqContext{SignedInUser: &models.SignedInUser{}, Context: &macaron.Context{Req: macaron.Request{Request: httpReq}}}
|
||||
cfg := setting.NewCfg()
|
||||
cfg.StaticRootPath = "../../public/"
|
||||
|
||||
@@ -36,7 +40,7 @@ func TestGetHomeDashboard(t *testing.T) {
|
||||
Cfg: cfg, Bus: bus.New(),
|
||||
PluginManager: &fakePluginManager{},
|
||||
}
|
||||
hs.Bus.AddHandler(func(query *models.GetPreferencesWithDefaultsQuery) error {
|
||||
hs.Bus.AddHandlerCtx(func(_ context.Context, query *models.GetPreferencesWithDefaultsQuery) error {
|
||||
query.Result = &models.Preferences{
|
||||
HomeDashboardId: 0,
|
||||
}
|
||||
|
||||
+1
-1
@@ -400,7 +400,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
|
||||
settings["dateFormats"] = hs.Cfg.DateFormats
|
||||
|
||||
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
|
||||
if err := bus.Dispatch(&prefsQuery); err != nil {
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &prefsQuery); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prefs := prefsQuery.Result
|
||||
|
||||
Reference in New Issue
Block a user