mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add user methods to service (#53595)
This commit is contained in:
parent
7944f3a692
commit
0a2a8bc919
@ -15,4 +15,10 @@ type Service interface {
|
||||
UpdateLastSeenAt(context.Context, *UpdateUserLastSeenAtCommand) error
|
||||
SetUsingOrg(context.Context, *SetUsingOrgCommand) error
|
||||
GetSignedInUserWithCacheCtx(context.Context, *GetSignedInUserQuery) (*SignedInUser, error)
|
||||
GetSignedInUser(context.Context, *GetSignedInUserQuery) (*SignedInUser, error)
|
||||
Search(context.Context, *SearchUsersQuery) (*SearchUserQueryResult, error)
|
||||
Disable(context.Context, *DisableUserCommand) error
|
||||
BatchDisableUsers(context.Context, *BatchDisableUsersCommand) error
|
||||
UpdatePermissions(int64, bool) error
|
||||
SetUserHelpFlag(context.Context, *SetUserHelpFlagCommand) error
|
||||
}
|
||||
|
@ -321,3 +321,92 @@ func (s *Service) GetSignedInUserWithCacheCtx(ctx context.Context, query *user.G
|
||||
}
|
||||
return q.Result, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||
q := &models.GetSignedInUserQuery{
|
||||
UserId: query.UserID,
|
||||
Login: query.Login,
|
||||
Email: query.Email,
|
||||
OrgId: query.OrgID,
|
||||
}
|
||||
err := s.sqlStore.GetSignedInUser(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return q.Result, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
|
||||
var usrSeschHitDTOs []*user.UserSearchHitDTO
|
||||
q := &models.SearchUsersQuery{
|
||||
SignedInUser: query.SignedInUser,
|
||||
Query: query.Query,
|
||||
OrgId: query.OrgID,
|
||||
Page: query.Page,
|
||||
Limit: query.Limit,
|
||||
AuthModule: query.AuthModule,
|
||||
Filters: query.Filters,
|
||||
IsDisabled: query.IsDisabled,
|
||||
}
|
||||
err := s.sqlStore.SearchUsers(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, usrSearch := range q.Result.Users {
|
||||
usrSeschHitDTOs = append(usrSeschHitDTOs, &user.UserSearchHitDTO{
|
||||
ID: usrSearch.Id,
|
||||
Login: usrSearch.Login,
|
||||
Email: usrSearch.Email,
|
||||
Name: usrSearch.Name,
|
||||
AvatarUrl: usrSearch.AvatarUrl,
|
||||
IsDisabled: usrSearch.IsDisabled,
|
||||
IsAdmin: usrSearch.IsAdmin,
|
||||
LastSeenAt: usrSearch.LastSeenAt,
|
||||
LastSeenAtAge: usrSearch.LastSeenAtAge,
|
||||
AuthLabels: usrSearch.AuthLabels,
|
||||
AuthModule: user.AuthModuleConversion(usrSearch.AuthModule),
|
||||
})
|
||||
}
|
||||
|
||||
res := &user.SearchUserQueryResult{
|
||||
Users: usrSeschHitDTOs,
|
||||
TotalCount: q.Result.TotalCount,
|
||||
Page: q.Result.Page,
|
||||
PerPage: q.Result.PerPage,
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) Disable(ctx context.Context, cmd *user.DisableUserCommand) error {
|
||||
q := &models.DisableUserCommand{
|
||||
UserId: cmd.UserID,
|
||||
IsDisabled: cmd.IsDisabled,
|
||||
}
|
||||
return s.sqlStore.DisableUser(ctx, q)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) BatchDisableUsers(ctx context.Context, cmd *user.BatchDisableUsersCommand) error {
|
||||
c := &models.BatchDisableUsersCommand{
|
||||
UserIds: cmd.UserIDs,
|
||||
IsDisabled: cmd.IsDisabled,
|
||||
}
|
||||
return s.sqlStore.BatchDisableUsers(ctx, c)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) UpdatePermissions(userID int64, isAdmin bool) error {
|
||||
return s.sqlStore.UpdateUserPermissions(userID, isAdmin)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlagCommand) error {
|
||||
c := &models.SetUserHelpFlagCommand{
|
||||
UserId: cmd.UserID,
|
||||
HelpFlags1: cmd.HelpFlags1,
|
||||
}
|
||||
return s.sqlStore.SetUserHelpFlag(ctx, c)
|
||||
}
|
||||
|
@ -56,3 +56,27 @@ func (f *FakeUserService) SetUsingOrg(ctx context.Context, cmd *user.SetUsingOrg
|
||||
func (f *FakeUserService) GetSignedInUserWithCacheCtx(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||
return f.ExpectedSignedInUser, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
||||
return f.ExpectedSignedInUser, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
|
||||
return &user.SearchUserQueryResult{}, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) Disable(ctx context.Context, cmd *user.DisableUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) BatchDisableUsers(ctx context.Context, cmd *user.BatchDisableUsersCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) UpdatePermissions(userID int64, isAdmin bool) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlagCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user