Chore: Add NewAnonymousSignedInUser to user service (#57537)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/localcache"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models/roletype"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
@@ -254,6 +255,31 @@ func (s *Service) GetSignedInUser(ctx context.Context, query *user.GetSignedInUs
|
||||
return signedInUser, err
|
||||
}
|
||||
|
||||
func (s *Service) NewAnonymousSignedInUser(ctx context.Context) (*user.SignedInUser, error) {
|
||||
if !s.cfg.AnonymousEnabled {
|
||||
return nil, fmt.Errorf("anonymous access is disabled")
|
||||
}
|
||||
|
||||
usr := &user.SignedInUser{
|
||||
IsAnonymous: true,
|
||||
OrgRole: roletype.RoleType(s.cfg.AnonymousOrgRole),
|
||||
}
|
||||
|
||||
if s.cfg.AnonymousOrgName == "" {
|
||||
return usr, nil
|
||||
}
|
||||
|
||||
getOrg := org.GetOrgByNameQuery{Name: s.cfg.AnonymousOrgName}
|
||||
anonymousOrg, err := s.orgService.GetByName(ctx, &getOrg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
usr.OrgID = anonymousOrg.ID
|
||||
usr.OrgName = anonymousOrg.Name
|
||||
return usr, nil
|
||||
}
|
||||
|
||||
func (s *Service) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
|
||||
return s.store.Search(ctx, query)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user