mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 17:06:57 -06:00
Cloud Aggregation: make it work for users with no name (#96509)
This commit is contained in:
parent
29cdfdff87
commit
9223cd8f59
@ -104,7 +104,18 @@ func (u *SignedInUser) IsIdentityType(expected ...claims.IdentityType) bool {
|
||||
|
||||
// GetName implements identity.Requester.
|
||||
func (u *SignedInUser) GetName() string {
|
||||
return u.Name
|
||||
// kubernetesAggregator feature flag which allows Cloud Apps to become available
|
||||
// in single tenant Grafana requires that GetName() returns something and not an empty string
|
||||
// the logic below ensures that something is returned
|
||||
if u.Name != "" {
|
||||
return u.Name
|
||||
}
|
||||
|
||||
if u.Login != "" {
|
||||
return u.Login
|
||||
}
|
||||
|
||||
return u.Email
|
||||
}
|
||||
|
||||
// GetExtra implements Requester.
|
||||
|
36
pkg/services/user/identity_test.go
Normal file
36
pkg/services/user/identity_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIdentityGetName(t *testing.T) {
|
||||
tt := []struct {
|
||||
name string
|
||||
user *SignedInUser
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "GetName on a user with empty name returns Login, if set",
|
||||
user: &SignedInUser{
|
||||
Login: "userLogin",
|
||||
Email: "user@grafana.com",
|
||||
},
|
||||
expected: "userLogin",
|
||||
},
|
||||
{
|
||||
name: "GetName on a user with empty name returns Email, if no Login is set",
|
||||
user: &SignedInUser{
|
||||
Email: "user@grafana.com",
|
||||
},
|
||||
expected: "user@grafana.com",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
user := tc.user
|
||||
require.Equal(t, user.GetName(), tc.expected, tc.name)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user