EntityStore: Use standard user identifier rather than custom version (#89080)

user uid string
This commit is contained in:
Ryan McKinley 2024-06-12 19:39:34 +03:00 committed by GitHub
parent 1abaa825c6
commit ed400f0bbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 34 deletions

View File

@ -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)
}

View File

@ -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.

View File

@ -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"