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:
idafurjes
2023-01-27 08:50:36 +01:00
committed by GitHub
parent 8379a29b53
commit 6c5a573772
180 changed files with 1208 additions and 1182 deletions
+2 -2
View File
@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
grpccontext "github.com/grafana/grafana/pkg/services/grpcserver/context"
"github.com/grafana/grafana/pkg/services/user"
)
@@ -33,7 +33,7 @@ func User(ctx context.Context) (*user.SignedInUser, error) {
}
// Set by incoming HTTP request
c, ok := ctxkey.Get(ctx).(*models.ReqContext)
c, ok := ctxkey.Get(ctx).(*contextmodel.ReqContext)
if ok && c.SignedInUser != nil {
return c.SignedInUser, nil
}
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
grpccontext "github.com/grafana/grafana/pkg/services/grpcserver/context"
"github.com/grafana/grafana/pkg/services/user"
"github.com/stretchr/testify/require"
@@ -47,7 +47,7 @@ func TestUserFromContext(t *testing.T) {
t.Run("should return user set by HTTP ReqContext", func(t *testing.T) {
expected := testUser()
ctx := ctxkey.Set(context.Background(), &models.ReqContext{
ctx := ctxkey.Set(context.Background(), &contextmodel.ReqContext{
SignedInUser: expected,
})
actual, err := appcontext.User(ctx)
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/accesscontrol"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
)
const rootUrl = "/api/admin"
@@ -20,7 +20,7 @@ func (uss *UsageStats) registerAPIEndpoints() {
})
}
func (uss *UsageStats) getUsageReportPreview(ctx *models.ReqContext) response.Response {
func (uss *UsageStats) getUsageReportPreview(ctx *contextmodel.ReqContext) response.Response {
usageReport, err := uss.GetUsageReport(ctx.Req.Context())
if err != nil {
return response.Error(http.StatusInternalServerError, "failed to get usage report", err)
+2 -2
View File
@@ -11,8 +11,8 @@ import (
"github.com/grafana/grafana/pkg/infra/db/dbtest"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/stats"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
@@ -93,7 +93,7 @@ type testContext struct {
func contextProvider(tc *testContext) web.Handler {
return func(c *web.Context) {
signedIn := tc.user != nil
reqCtx := &models.ReqContext{
reqCtx := &contextmodel.ReqContext{
Context: c,
SignedInUser: tc.user,
IsSignedIn: signedIn,