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:
co-authored by
Karl Persson
parent
d1df896962
commit
e3501dfa4d
@@ -61,6 +61,16 @@ type GetOrgIDForNewUserCommand struct {
|
||||
SkipOrgSetup bool
|
||||
}
|
||||
|
||||
type GetUserOrgListQuery struct {
|
||||
UserID int64
|
||||
}
|
||||
|
||||
type UserOrgDTO struct {
|
||||
OrgID int64 `json:"orgId"`
|
||||
Name string `json:"name"`
|
||||
Role RoleType `json:"role"`
|
||||
}
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ type Service interface {
|
||||
GetIDForNewUser(context.Context, GetOrgIDForNewUserCommand) (int64, error)
|
||||
InsertOrgUser(context.Context, *OrgUser) (int64, error)
|
||||
DeleteUserFromAll(context.Context, int64) error
|
||||
GetUserOrgList(context.Context, *GetUserOrgListQuery) ([]*UserOrgDTO, error)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -16,6 +18,8 @@ type Service struct {
|
||||
store store
|
||||
cfg *setting.Cfg
|
||||
log log.Logger
|
||||
// TODO remove sqlstore
|
||||
sqlStore *sqlstore.SQLStore
|
||||
}
|
||||
|
||||
func ProvideService(db db.DB, cfg *setting.Cfg) org.Service {
|
||||
@@ -80,3 +84,23 @@ func (s *Service) InsertOrgUser(ctx context.Context, orguser *org.OrgUser) (int6
|
||||
func (s *Service) DeleteUserFromAll(ctx context.Context, userID int64) error {
|
||||
return s.store.DeleteUserFromAll(ctx, userID)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQuery) ([]*org.UserOrgDTO, error) {
|
||||
q := &models.GetUserOrgListQuery{
|
||||
UserId: query.UserID,
|
||||
}
|
||||
err := s.sqlStore.GetUserOrgList(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result []*org.UserOrgDTO
|
||||
for _, orga := range q.Result {
|
||||
result = append(result, &org.UserOrgDTO{
|
||||
OrgID: orga.OrgId,
|
||||
Name: orga.Name,
|
||||
Role: orga.Role,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type FakeOrgService struct {
|
||||
ExpectedOrgUserID int64
|
||||
ExpectedError error
|
||||
ExpectedOrgUserID int64
|
||||
ExpectedError error
|
||||
ExpectedUserOrgDTO []*org.UserOrgDTO
|
||||
}
|
||||
|
||||
func NewOrgServiceFake() *FakeOrgService {
|
||||
@@ -30,3 +31,7 @@ func (f *FakeOrgService) InsertOrgUser(ctx context.Context, cmd *org.OrgUser) (i
|
||||
func (f *FakeOrgService) DeleteUserFromAll(ctx context.Context, userID int64) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQuery) ([]*org.UserOrgDTO, error) {
|
||||
return f.ExpectedUserOrgDTO, f.ExpectedError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user