Chore: Remove bus from admin (#44920)
* Chore: Remove bus from admin * fix test Co-authored-by: Ying WANG <ying.wang@grafana.com>
This commit is contained in:
+2
-3
@@ -5,7 +5,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -19,10 +18,10 @@ func (hs *HTTPServer) AdminGetSettings(c *models.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, settings)
|
||||
}
|
||||
|
||||
func AdminGetStats(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) AdminGetStats(c *models.ReqContext) response.Response {
|
||||
statsQuery := models.GetAdminStatsQuery{}
|
||||
|
||||
if err := bus.Dispatch(c.Req.Context(), &statsQuery); err != nil {
|
||||
if err := hs.SQLStore.GetAdminStats(c.Req.Context(), &statsQuery); err != nil {
|
||||
return response.Error(500, "Failed to get admin stats from database", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -147,6 +148,7 @@ func TestAdmin_AccessControl(t *testing.T) {
|
||||
sc, hs := setupAccessControlScenarioContext(t, cfg, test.url, test.permissions)
|
||||
sc.resp = httptest.NewRecorder()
|
||||
hs.SettingsProvider = &setting.OSSImpl{Cfg: cfg}
|
||||
hs.SQLStore = mockstore.NewSQLStoreMock()
|
||||
|
||||
var err error
|
||||
sc.req, err = http.NewRequest(test.method, test.url, nil)
|
||||
|
||||
+1
-1
@@ -463,7 +463,7 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
if hs.Features.IsEnabled(featuremgmt.FlagShowFeatureFlagsInUI) {
|
||||
adminRoute.Get("/settings/features", authorize(reqGrafanaAdmin, ac.EvalPermission(ac.ActionSettingsRead)), hs.Features.HandleGetSettings)
|
||||
}
|
||||
adminRoute.Get("/stats", authorize(reqGrafanaAdmin, ac.EvalPermission(ac.ActionServerStatsRead)), routing.Wrap(AdminGetStats))
|
||||
adminRoute.Get("/stats", authorize(reqGrafanaAdmin, ac.EvalPermission(ac.ActionServerStatsRead)), routing.Wrap(hs.AdminGetStats))
|
||||
adminRoute.Post("/pause-all-alerts", reqGrafanaAdmin, routing.Wrap(hs.PauseAllAlerts))
|
||||
|
||||
if hs.ThumbService != nil {
|
||||
|
||||
Reference in New Issue
Block a user