Chore: Add Get User Profile to user and Get User Org List to org service (#53788)

* Remove delete suer from store interface

* Remove get signed in user with cache ctx from store interface

* Support options when setting up access control tests

* Fix broken tests

* Fix lint

* Add user fake to middleware

* Fix middleware tests, remove usertest being initialised twice

* Chore: Add Get User Profile to user and Get User Org List to org service

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
This commit is contained in:
idafurjes
2022-08-16 17:50:45 +02:00
committed by GitHub
co-authored by Karl Persson
parent d1df896962
commit e3501dfa4d
8 changed files with 97 additions and 2 deletions
+21
View File
@@ -135,6 +135,27 @@ type UserSearchHitDTO struct {
AuthModule AuthModuleConversion `json:"-"`
}
type GetUserProfileQuery struct {
UserID int64
}
type UserProfileDTO struct {
ID int64 `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
Login string `json:"login"`
Theme string `json:"theme"`
OrgID int64 `json:"orgId,omitempty"`
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
IsDisabled bool `json:"isDisabled"`
IsExternal bool `json:"isExternal"`
AuthLabels []string `json:"authLabels"`
UpdatedAt time.Time `json:"updatedAt"`
CreatedAt time.Time `json:"createdAt"`
AvatarUrl string `json:"avatarUrl"`
AccessControl map[string]bool `json:"accessControl,omitempty"`
}
// implement Conversion interface to define custom field mapping (xorm feature)
type AuthModuleConversion []string
+1
View File
@@ -21,4 +21,5 @@ type Service interface {
BatchDisableUsers(context.Context, *BatchDisableUsersCommand) error
UpdatePermissions(int64, bool) error
SetUserHelpFlag(context.Context, *SetUserHelpFlagCommand) error
GetUserProfile(context.Context, *GetUserProfileQuery) (UserProfileDTO, error)
}
+28
View File
@@ -410,3 +410,31 @@ func (s *Service) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlag
}
return s.sqlStore.SetUserHelpFlag(ctx, c)
}
// TODO: remove wrapper around sqlstore
func (s *Service) GetUserProfile(ctx context.Context, query *user.GetUserProfileQuery) (user.UserProfileDTO, error) {
q := &models.GetUserProfileQuery{
UserId: query.UserID,
}
err := s.sqlStore.GetUserProfile(ctx, q)
if err != nil {
return user.UserProfileDTO{}, err
}
result := user.UserProfileDTO{
ID: q.Result.Id,
Email: q.Result.Email,
Name: q.Result.Name,
Login: q.Result.Login,
Theme: q.Result.Theme,
OrgID: q.Result.OrgId,
IsGrafanaAdmin: q.Result.IsGrafanaAdmin,
IsDisabled: q.Result.IsDisabled,
IsExternal: q.Result.IsExternal,
AuthLabels: q.Result.AuthLabels,
UpdatedAt: q.Result.UpdatedAt,
CreatedAt: q.Result.CreatedAt,
AvatarUrl: q.Result.AvatarUrl,
AccessControl: q.Result.AccessControl,
}
return result, nil
}
+5
View File
@@ -12,6 +12,7 @@ type FakeUserService struct {
ExpectedError error
ExpectedSetUsingOrgError error
ExpectedSearchUsers user.SearchUserQueryResult
ExpectedUSerProfileDTO user.UserProfileDTO
}
func NewUserServiceFake() *FakeUserService {
@@ -84,3 +85,7 @@ func (f *FakeUserService) UpdatePermissions(userID int64, isAdmin bool) error {
func (f *FakeUserService) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlagCommand) error {
return f.ExpectedError
}
func (f *FakeUserService) GetUserProfile(ctx context.Context, query *user.GetUserProfileQuery) (user.UserProfileDTO, error) {
return f.ExpectedUSerProfileDTO, f.ExpectedError
}