mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
EntityStore: Use standard user identifier rather than custom version (#89080)
user uid string
This commit is contained in:
parent
1abaa825c6
commit
ed400f0bbf
@ -1,30 +0,0 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
// Really just spitballing here :) this should hook into a system that can give better display info
|
||||
func GetUserIDString(user *user.SignedInUser) string {
|
||||
// TODO: should we check IsDisabled?
|
||||
// TODO: could we use the NamespacedID.ID() as prefix instead of manually
|
||||
// setting "anon", "key", etc.?
|
||||
// TODO: the default unauthenticated user is not anonymous and would be
|
||||
// returned as `sys:0:` here. We may want to do something special in that
|
||||
// case
|
||||
if user == nil {
|
||||
return ""
|
||||
}
|
||||
if user.IsAnonymous {
|
||||
return "anon"
|
||||
}
|
||||
if user.ApiKeyID > 0 {
|
||||
return fmt.Sprintf("key:%d", user.UserID)
|
||||
}
|
||||
if user.IsRealUser() {
|
||||
return fmt.Sprintf("user:%d:%s", user.UserID, user.Login)
|
||||
}
|
||||
return fmt.Sprintf("sys:%d:%s", user.UserID, user.Login)
|
||||
}
|
@ -9,7 +9,6 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity/db"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity/sqlstash/sqltemplate"
|
||||
)
|
||||
@ -33,7 +32,7 @@ func getCurrentUser(ctx context.Context) (string, error) {
|
||||
return "", fmt.Errorf("%w: %w", ErrUserNotFoundInContext, err)
|
||||
}
|
||||
|
||||
return store.GetUserIDString(user), nil
|
||||
return user.GetUID().String(), nil
|
||||
}
|
||||
|
||||
// ptrOr returns the first non-nil pointer in the list or a new non-nil pointer.
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity"
|
||||
)
|
||||
|
||||
@ -122,7 +121,7 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
testCtx := createTestContext(t)
|
||||
ctx := appcontext.WithUser(testCtx.ctx, testCtx.user)
|
||||
|
||||
fakeUser := store.GetUserIDString(testCtx.user)
|
||||
fakeUser := testCtx.user.GetUID().String()
|
||||
firstVersion := int64(0)
|
||||
group := "test.grafana.app"
|
||||
resource := "jsonobjs"
|
||||
|
Loading…
Reference in New Issue
Block a user