diff --git a/pkg/api/org_invite.go b/pkg/api/org_invite.go index 0ce96f453b1..b7ab25d1f65 100644 --- a/pkg/api/org_invite.go +++ b/pkg/api/org_invite.go @@ -129,7 +129,7 @@ func (hs *HTTPServer) AddOrgInvite(c *contextmodel.ReqContext) response.Response "OrgName": c.SignedInUser.GetOrgName(), "Email": c.SignedInUser.GetEmail(), "LinkUrl": setting.ToAbsUrl("invite/" + cmd.Code), - "InvitedBy": c.SignedInUser.GetDisplayName(), + "InvitedBy": c.SignedInUser.GetName(), }, } @@ -169,7 +169,7 @@ func (hs *HTTPServer) inviteExistingUserToOrg(c *contextmodel.ReqContext, user * Data: map[string]any{ "Name": user.NameOrFallback(), "OrgName": c.SignedInUser.GetOrgName(), - "InvitedBy": c.SignedInUser.GetDisplayName(), + "InvitedBy": c.SignedInUser.GetName(), }, } diff --git a/pkg/api/user.go b/pkg/api/user.go index 26096c78d38..292aa7fc3cd 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -36,7 +36,7 @@ func (hs *HTTPServer) GetSignedInUser(c *contextmodel.ReqContext) response.Respo IsGrafanaAdmin: c.SignedInUser.GetIsGrafanaAdmin(), OrgID: c.SignedInUser.GetOrgID(), UID: c.SignedInUser.GetID(), - Name: c.SignedInUser.NameOrFallback(), + Name: c.SignedInUser.GetName(), Email: c.SignedInUser.GetEmail(), Login: c.SignedInUser.GetLogin(), }) diff --git a/pkg/apimachinery/identity/requester.go b/pkg/apimachinery/identity/requester.go index c8795bfeae2..c8fbf6fd3e7 100644 --- a/pkg/apimachinery/identity/requester.go +++ b/pkg/apimachinery/identity/requester.go @@ -23,9 +23,6 @@ type Requester interface { // GetID returns namespaced internalID for the entity // Deprecated: use GetUID instead GetID() string - // GetDisplayName returns the display name of the active entity. - // The display name is the name if it is set, otherwise the login or email. - GetDisplayName() string // GetEmail returns the email of the active entity. // Can be empty. GetEmail() string @@ -62,6 +59,8 @@ type Requester interface { // IsNil returns true if the identity is nil // FIXME: remove this method once all services are using an interface IsNil() bool + // GetIDToken returns a signed token representing the identity that can be forwarded to plugins and external services. + GetIDToken() string // Legacy @@ -72,8 +71,6 @@ type Requester interface { GetCacheKey() string // HasUniqueId returns true if the entity has a unique id HasUniqueId() bool - // GetIDToken returns a signed token representing the identity that can be forwarded to plugins and external services. - GetIDToken() string } // IntIdentifier converts a typeID to an int64. diff --git a/pkg/apimachinery/identity/static.go b/pkg/apimachinery/identity/static.go index 7785207bb1d..e520e63348c 100644 --- a/pkg/apimachinery/identity/static.go +++ b/pkg/apimachinery/identity/static.go @@ -22,7 +22,6 @@ type StaticRequester struct { OrgRole RoleType Login string Name string - DisplayName string Email string EmailVerified bool AuthID string @@ -89,7 +88,13 @@ func (u *StaticRequester) GetGroups() []string { // GetName implements Requester. func (u *StaticRequester) GetName() string { - return u.DisplayName + if u.Name != "" { + return u.Name + } + if u.Login != "" { + return u.Login + } + return u.Email } func (u *StaticRequester) HasRole(role RoleType) bool { @@ -211,25 +216,6 @@ func (u *StaticRequester) GetCacheKey() string { return u.CacheKey } -// GetDisplayName returns the display name of the active entity -// The display name is the name if it is set, otherwise the login or email -func (u *StaticRequester) GetDisplayName() string { - if u.DisplayName != "" { - return u.DisplayName - } - if u.Name != "" { - return u.Name - } - if u.Login != "" { - return u.Login - } - return u.Email -} - func (u *StaticRequester) GetIDToken() string { return u.IDToken } - -func (u *StaticRequester) GetIDClaims() *authnlib.Claims[authnlib.IDTokenClaims] { - return u.IDTokenClaims -} diff --git a/pkg/apimachinery/identity/wrapper.go b/pkg/apimachinery/identity/wrapper.go index 02f8d591f58..09eab3eea41 100644 --- a/pkg/apimachinery/identity/wrapper.go +++ b/pkg/apimachinery/identity/wrapper.go @@ -25,7 +25,7 @@ func (i *IDClaimsWrapper) AuthenticatedBy() string { // GetDisplayName implements claims.IdentityClaims. func (i *IDClaimsWrapper) DisplayName() string { - return i.Source.GetDisplayName() + return i.Source.GetName() } // GetEmail implements claims.IdentityClaims. diff --git a/pkg/expr/testing.go b/pkg/expr/testing.go index d70dd097743..75c0e8c54ec 100644 --- a/pkg/expr/testing.go +++ b/pkg/expr/testing.go @@ -35,7 +35,7 @@ func (f *fakePluginContextProvider) Get(_ context.Context, pluginID string, user if user != nil { u = &backend.User{ Login: user.GetLogin(), - Name: user.GetDisplayName(), + Name: user.GetName(), Email: user.GetEmail(), } } diff --git a/pkg/services/auth/idimpl/service.go b/pkg/services/auth/idimpl/service.go index e407c9f6061..8c11374d910 100644 --- a/pkg/services/auth/idimpl/service.go +++ b/pkg/services/auth/idimpl/service.go @@ -105,7 +105,7 @@ func (s *Service) SignIdentity(ctx context.Context, id identity.Requester) (stri idClaims.Rest.EmailVerified = id.IsEmailVerified() idClaims.Rest.AuthenticatedBy = id.GetAuthenticatedBy() idClaims.Rest.Username = id.GetLogin() - idClaims.Rest.DisplayName = id.GetDisplayName() + idClaims.Rest.DisplayName = id.GetName() } token, err := s.signer.SignIDToken(ctx, idClaims) diff --git a/pkg/services/authn/identity.go b/pkg/services/authn/identity.go index 76438f8eb0c..382530c9ca8 100644 --- a/pkg/services/authn/identity.go +++ b/pkg/services/authn/identity.go @@ -80,7 +80,6 @@ type Identity struct { AccessTokenClaims *authn.Claims[authn.AccessTokenClaims] } -// Access implements claims.AuthInfo. func (i *Identity) GetAccess() claims.AccessClaims { if i.AccessTokenClaims != nil { return authn.NewAccessClaims(*i.AccessTokenClaims) @@ -88,7 +87,6 @@ func (i *Identity) GetAccess() claims.AccessClaims { return &identity.IDClaimsWrapper{Source: i} } -// Identity implements claims.AuthInfo. func (i *Identity) GetIdentity() claims.IdentityClaims { if i.IDTokenClaims != nil { return authn.NewIdentityClaims(*i.IDTokenClaims) @@ -96,27 +94,22 @@ func (i *Identity) GetIdentity() claims.IdentityClaims { return &identity.IDClaimsWrapper{Source: i} } -// GetRawIdentifier implements Requester. func (i *Identity) GetRawIdentifier() string { return i.UID } -// GetInternalID implements Requester. func (i *Identity) GetInternalID() (int64, error) { return identity.IntIdentifier(i.GetID()) } -// GetIdentityType implements Requester. func (i *Identity) GetIdentityType() claims.IdentityType { return i.Type } -// GetIdentityType implements Requester. func (i *Identity) IsIdentityType(expected ...claims.IdentityType) bool { return claims.IsIdentityType(i.GetIdentityType(), expected...) } -// GetExtra implements identity.Requester. func (i *Identity) GetExtra() map[string][]string { extra := map[string][]string{} if i.IDToken != "" { @@ -128,14 +121,18 @@ func (i *Identity) GetExtra() map[string][]string { return extra } -// GetGroups implements identity.Requester. func (i *Identity) GetGroups() []string { return []string{} // teams? } -// GetName implements identity.Requester. func (i *Identity) GetName() string { - return i.Name + if i.Name != "" { + return i.Name + } + if i.Login != "" { + return i.Login + } + return i.Email } func (i *Identity) GetID() string { @@ -165,10 +162,6 @@ func (i *Identity) GetCacheKey() string { return fmt.Sprintf("%d-%s-%s", i.GetOrgID(), i.Type, id) } -func (i *Identity) GetDisplayName() string { - return i.Name -} - func (i *Identity) GetEmail() string { return i.Email } diff --git a/pkg/services/live/features/dashboard.go b/pkg/services/live/features/dashboard.go index a0459f39664..d627c16a132 100644 --- a/pkg/services/live/features/dashboard.go +++ b/pkg/services/live/features/dashboard.go @@ -43,7 +43,7 @@ func newUserDisplayDTOFromRequester(requester identity.Requester) *userDisplayDT ID: userID, UID: requester.GetRawIdentifier(), Login: requester.GetLogin(), - Name: requester.GetDisplayName(), + Name: requester.GetName(), } } diff --git a/pkg/services/navtree/navtreeimpl/navtree.go b/pkg/services/navtree/navtreeimpl/navtree.go index ff679f41e56..9d4f7ac98f2 100644 --- a/pkg/services/navtree/navtreeimpl/navtree.go +++ b/pkg/services/navtree/navtreeimpl/navtree.go @@ -262,7 +262,7 @@ func (s *ServiceImpl) addHelpLinks(treeRoot *navtree.NavTreeRoot, c *contextmode func (s *ServiceImpl) getProfileNode(c *contextmodel.ReqContext) *navtree.NavLink { // Only set login if it's different from the name var login string - if c.SignedInUser.GetLogin() != c.SignedInUser.GetDisplayName() { + if c.SignedInUser.GetLogin() != c.SignedInUser.GetName() { login = c.SignedInUser.GetLogin() } gravatarURL := dtos.GetGravatarUrl(s.cfg, c.SignedInUser.GetEmail()) @@ -297,7 +297,7 @@ func (s *ServiceImpl) getProfileNode(c *contextmodel.ReqContext) *navtree.NavLin } return &navtree.NavLink{ - Text: c.SignedInUser.GetDisplayName(), + Text: c.SignedInUser.GetName(), SubTitle: login, Id: "profile", Img: gravatarURL, diff --git a/pkg/services/pluginsintegration/adapters/adapters.go b/pkg/services/pluginsintegration/adapters/adapters.go index d52c85a349a..9eff40eb3db 100644 --- a/pkg/services/pluginsintegration/adapters/adapters.go +++ b/pkg/services/pluginsintegration/adapters/adapters.go @@ -52,7 +52,7 @@ func BackendUserFromSignedInUser(requester identity.Requester) *backend.User { } return &backend.User{ Login: requester.GetLogin(), - Name: requester.GetDisplayName(), + Name: requester.GetName(), Email: requester.GetEmail(), Role: string(requester.GetOrgRole()), } diff --git a/pkg/services/user/identity.go b/pkg/services/user/identity.go index c82507baf0a..2ea72e1cb9a 100644 --- a/pkg/services/user/identity.go +++ b/pkg/services/user/identity.go @@ -102,7 +102,6 @@ func (u *SignedInUser) IsIdentityType(expected ...claims.IdentityType) bool { return claims.IsIdentityType(u.GetIdentityType(), expected...) } -// GetName implements identity.Requester. func (u *SignedInUser) GetName() string { // kubernetesAggregator feature flag which allows Cloud Apps to become available // in single tenant Grafana requires that GetName() returns something and not an empty string @@ -110,11 +109,9 @@ func (u *SignedInUser) GetName() string { if u.Name != "" { return u.Name } - if u.Login != "" { return u.Login } - return u.Email } @@ -143,16 +140,6 @@ func (u *SignedInUser) ShouldUpdateLastSeenAt() bool { return u.UserID > 0 && time.Since(u.LastSeenAt) > time.Minute*5 } -func (u *SignedInUser) NameOrFallback() string { - if u.Name != "" { - return u.Name - } - if u.Login != "" { - return u.Login - } - return u.Email -} - func (u *SignedInUser) HasRole(role identity.RoleType) bool { if u.IsGrafanaAdmin { return true @@ -324,12 +311,6 @@ func (u *SignedInUser) IsEmailVerified() bool { return u.EmailVerified } -// GetDisplayName returns the display name of the active entity -// The display name is the name if it is set, otherwise the login or email -func (u *SignedInUser) GetDisplayName() string { - return u.NameOrFallback() -} - func (u *SignedInUser) GetIDToken() string { return u.IDToken }