Chore: get user from appcontext rather than store utility (#59926)

user from appcontext
This commit is contained in:
Ryan McKinley
2022-12-07 07:38:23 -08:00
committed by GitHub
parent e8ed79873a
commit d036225f7b
9 changed files with 31 additions and 51 deletions
@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/slugify"
@@ -109,7 +110,10 @@ func (s *sqlEntityServer) validateGRN(ctx context.Context, grn *entity.GRN) (*en
if grn == nil {
return nil, fmt.Errorf("missing GRN")
}
user := store.UserFromContext(ctx)
user, err := appcontext.User(ctx)
if err != nil {
return nil, err
}
if grn.TenantId == 0 {
grn.TenantId = user.OrgID
} else if grn.TenantId != user.OrgID {
@@ -281,7 +285,10 @@ func (s *sqlEntityServer) AdminWrite(ctx context.Context, r *entity.AdminWriteEn
updatedAt := r.UpdatedAt
updatedBy := r.UpdatedBy
if updatedBy == "" {
modifier := store.UserFromContext(ctx)
modifier, err := appcontext.User(ctx)
if err != nil {
return nil, err
}
if modifier == nil {
return nil, fmt.Errorf("can not find user in context")
}
@@ -618,7 +625,10 @@ func (s *sqlEntityServer) History(ctx context.Context, r *entity.EntityHistoryRe
}
func (s *sqlEntityServer) Search(ctx context.Context, r *entity.EntitySearchRequest) (*entity.EntitySearchResponse, error) {
user := store.UserFromContext(ctx)
user, err := appcontext.User(ctx)
if err != nil {
return nil, err
}
if user == nil {
return nil, fmt.Errorf("missing user in context")
}
+2 -2
View File
@@ -5,12 +5,12 @@ import (
"testing"
apikeygenprefix "github.com/grafana/grafana/pkg/components/apikeygenprefixed"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/org"
saAPI "github.com/grafana/grafana/pkg/services/serviceaccounts/api"
saTests "github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
"github.com/grafana/grafana/pkg/services/store"
"github.com/grafana/grafana/pkg/services/store/entity"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/tests/testinfra"
@@ -86,6 +86,6 @@ func createTestContext(t *testing.T) testContext {
authToken: authToken,
client: client,
user: serviceAccountUser,
ctx: store.ContextWithUser(context.Background(), serviceAccountUser),
ctx: appcontext.WithUser(context.Background(), serviceAccountUser),
}
}