Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service * Rename package to contextmodel * Generate ngalert files * Remove unused imports
This commit is contained in:
+10
-9
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
dashboardsstore "github.com/grafana/grafana/pkg/services/dashboards/database"
|
||||
dashboardservice "github.com/grafana/grafana/pkg/services/dashboards/service"
|
||||
@@ -76,7 +77,7 @@ func loggedInUserScenarioWithRole(t *testing.T, desc string, method string, url
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.sqlStore = sqlStore
|
||||
sc.userService = usertest.NewUserServiceFake()
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
sc.defaultHandler = routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
sc.context = c
|
||||
sc.context.UserID = testUserID
|
||||
sc.context.OrgID = testOrgID
|
||||
@@ -102,7 +103,7 @@ func loggedInUserScenarioWithRole(t *testing.T, desc string, method string, url
|
||||
func anonymousUserScenario(t *testing.T, desc string, method string, url string, routePattern string, fn scenarioFunc) {
|
||||
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
sc.defaultHandler = routing.Wrap(func(c *contextmodel.ReqContext) response.Response {
|
||||
sc.context = c
|
||||
if sc.handlerFunc != nil {
|
||||
return sc.handlerFunc(sc.context)
|
||||
@@ -178,7 +179,7 @@ type scenarioContext struct {
|
||||
t *testing.T
|
||||
cfg *setting.Cfg
|
||||
m *web.Mux
|
||||
context *models.ReqContext
|
||||
context *contextmodel.ReqContext
|
||||
resp *httptest.ResponseRecorder
|
||||
handlerFunc handlerFunc
|
||||
defaultHandler web.Handler
|
||||
@@ -197,7 +198,7 @@ func (sc *scenarioContext) exec() {
|
||||
}
|
||||
|
||||
type scenarioFunc func(c *scenarioContext)
|
||||
type handlerFunc func(c *models.ReqContext) response.Response
|
||||
type handlerFunc func(c *contextmodel.ReqContext) response.Response
|
||||
|
||||
func getContextHandler(t *testing.T, cfg *setting.Cfg) *contexthandler.ContextHandler {
|
||||
t.Helper()
|
||||
@@ -266,7 +267,7 @@ type accessControlScenarioContext struct {
|
||||
|
||||
// initCtx is used in a middleware to set the initial context
|
||||
// of the request server side. Can be used to pretend sign in.
|
||||
initCtx *models.ReqContext
|
||||
initCtx *contextmodel.ReqContext
|
||||
|
||||
// hs is a minimal HTTPServer for the accesscontrol tests to pass.
|
||||
hs *HTTPServer
|
||||
@@ -302,17 +303,17 @@ func userWithPermissions(orgID int64, permissions []accesscontrol.Permission) *u
|
||||
}
|
||||
|
||||
// setInitCtxSignedInUser sets a copy of the user in initCtx
|
||||
func setInitCtxSignedInUser(initCtx *models.ReqContext, user user.SignedInUser) {
|
||||
func setInitCtxSignedInUser(initCtx *contextmodel.ReqContext, user user.SignedInUser) {
|
||||
initCtx.IsSignedIn = true
|
||||
initCtx.SignedInUser = &user
|
||||
}
|
||||
|
||||
func setInitCtxSignedInViewer(initCtx *models.ReqContext) {
|
||||
func setInitCtxSignedInViewer(initCtx *contextmodel.ReqContext) {
|
||||
initCtx.IsSignedIn = true
|
||||
initCtx.SignedInUser = &user.SignedInUser{UserID: testUserID, OrgID: 1, OrgRole: org.RoleViewer, Login: testUserLogin}
|
||||
}
|
||||
|
||||
func setInitCtxSignedInOrgAdmin(initCtx *models.ReqContext) {
|
||||
func setInitCtxSignedInOrgAdmin(initCtx *contextmodel.ReqContext) {
|
||||
initCtx.IsSignedIn = true
|
||||
initCtx.SignedInUser = &user.SignedInUser{UserID: testUserID, OrgID: 1, OrgRole: org.RoleAdmin, Login: testUserLogin}
|
||||
}
|
||||
@@ -434,7 +435,7 @@ func setupHTTPServerWithCfgDb(
|
||||
m := web.New()
|
||||
|
||||
// middleware to set the test initial context
|
||||
initCtx := &models.ReqContext{}
|
||||
initCtx := &contextmodel.ReqContext{}
|
||||
m.Use(func(c *web.Context) {
|
||||
initCtx.Context = c
|
||||
initCtx.Logger = log.New("api-test")
|
||||
|
||||
Reference in New Issue
Block a user