mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add user service method GetByEmail (#53298)
This commit is contained in:
parent
1ecbe22751
commit
af83a09a92
@ -244,12 +244,13 @@ func (s *AuthInfoStore) GetUserByLogin(ctx context.Context, login string) (*user
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthInfoStore) GetUserByEmail(ctx context.Context, email string) (*user.User, error) {
|
func (s *AuthInfoStore) GetUserByEmail(ctx context.Context, email string) (*user.User, error) {
|
||||||
query := models.GetUserByEmailQuery{Email: email}
|
query := user.GetUserByEmailQuery{Email: email}
|
||||||
if err := s.sqlStore.GetUserByEmail(ctx, &query); err != nil {
|
usr, err := s.userService.GetByEmail(ctx, &query)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.Result, nil
|
return usr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeAndDecrypt will decode the string with the standard base64 decoder and then decrypt it
|
// decodeAndDecrypt will decode the string with the standard base64 decoder and then decrypt it
|
||||||
|
@ -137,10 +137,6 @@ func (m *SQLStoreMock) CreateUser(ctx context.Context, cmd user.CreateUserComman
|
|||||||
return nil, m.ExpectedError
|
return nil, m.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SQLStoreMock) GetUserByEmail(ctx context.Context, query *models.GetUserByEmailQuery) error {
|
|
||||||
return m.ExpectedError
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *SQLStoreMock) UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error {
|
func (m *SQLStoreMock) UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error {
|
||||||
return m.ExpectedError
|
return m.ExpectedError
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ type Store interface {
|
|||||||
GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error
|
GetUserLoginAttemptCount(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error
|
||||||
DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error
|
DeleteOldLoginAttempts(ctx context.Context, cmd *models.DeleteOldLoginAttemptsCommand) error
|
||||||
CreateUser(ctx context.Context, cmd user.CreateUserCommand) (*user.User, error)
|
CreateUser(ctx context.Context, cmd user.CreateUserCommand) (*user.User, error)
|
||||||
GetUserByEmail(ctx context.Context, query *models.GetUserByEmailQuery) error
|
|
||||||
UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error
|
UpdateUser(ctx context.Context, cmd *models.UpdateUserCommand) error
|
||||||
ChangeUserPassword(ctx context.Context, cmd *models.ChangeUserPasswordCommand) error
|
ChangeUserPassword(ctx context.Context, cmd *models.ChangeUserPasswordCommand) error
|
||||||
UpdateUserLastSeenAt(ctx context.Context, cmd *models.UpdateUserLastSeenAtCommand) error
|
UpdateUserLastSeenAt(ctx context.Context, cmd *models.UpdateUserLastSeenAtCommand) error
|
||||||
|
@ -62,6 +62,10 @@ type GetUserByLoginQuery struct {
|
|||||||
LoginOrEmail string
|
LoginOrEmail string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetUserByEmailQuery struct {
|
||||||
|
Email string
|
||||||
|
}
|
||||||
|
|
||||||
func (u *User) NameOrFallback() string {
|
func (u *User) NameOrFallback() string {
|
||||||
if u.Name != "" {
|
if u.Name != "" {
|
||||||
return u.Name
|
return u.Name
|
||||||
|
@ -9,4 +9,5 @@ type Service interface {
|
|||||||
Delete(context.Context, *DeleteUserCommand) error
|
Delete(context.Context, *DeleteUserCommand) error
|
||||||
GetByID(context.Context, *GetUserByIDQuery) (*User, error)
|
GetByID(context.Context, *GetUserByIDQuery) (*User, error)
|
||||||
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
|
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
|
||||||
|
GetByEmail(context.Context, *GetUserByEmailQuery) (*User, error)
|
||||||
}
|
}
|
||||||
|
@ -257,3 +257,13 @@ func (s *Service) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuer
|
|||||||
}
|
}
|
||||||
return q.Result, nil
|
return q.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove wrapper around sqlstore
|
||||||
|
func (s *Service) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
||||||
|
q := models.GetUserByEmailQuery{Email: query.Email}
|
||||||
|
err := s.sqlStore.GetUserByEmail(ctx, &q)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return q.Result, nil
|
||||||
|
}
|
||||||
|
@ -30,3 +30,7 @@ func (f *FakeUserService) GetByID(ctx context.Context, query *user.GetUserByIDQu
|
|||||||
func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuery) (*user.User, error) {
|
func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuery) (*user.User, error) {
|
||||||
return f.ExpectedUser, f.ExpectedError
|
return f.ExpectedUser, f.ExpectedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
||||||
|
return f.ExpectedUser, f.ExpectedError
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user