mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
Chore: Add methods from sqlstore to org service interface (#55635)
* Chore: Copy methods from sqlstore to org store * Rename method, add test * Add comments of tests * Chore: Add methods from sqlstore to org service interface * Avoiding import cycle * Add and remove some methods
This commit is contained in:
parent
c9b5acfefc
commit
e8a60c1988
@ -115,6 +115,47 @@ type DeleteOrgCommand struct {
|
||||
ID int64 `xorm:"id"`
|
||||
}
|
||||
|
||||
type AddOrgUserCommand struct {
|
||||
LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
|
||||
OrgID int64 `json:"-"`
|
||||
UserID int64 `json:"-"`
|
||||
|
||||
// internal use: avoid adding service accounts to orgs via user routes
|
||||
AllowAddingServiceAccount bool `json:"-"`
|
||||
}
|
||||
|
||||
type UpdateOrgUserCommand struct {
|
||||
Role RoleType `json:"role" binding:"Required"`
|
||||
|
||||
OrgID int64 `json:"-"`
|
||||
UserID int64 `json:"-"`
|
||||
}
|
||||
|
||||
type OrgUserDTO struct {
|
||||
OrgID int64 `json:"orgId"`
|
||||
UserID int64 `json:"userId"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
AvatarURL string `json:"avatarUrl"`
|
||||
Login string `json:"login"`
|
||||
Role string `json:"role"`
|
||||
LastSeenAt time.Time `json:"lastSeenAt"`
|
||||
Updated time.Time `json:"-"`
|
||||
Created time.Time `json:"-"`
|
||||
LastSeenAtAge string `json:"lastSeenAtAge"`
|
||||
AccessControl map[string]bool `json:"accessControl,omitempty"`
|
||||
IsDisabled bool `json:"isDisabled"`
|
||||
}
|
||||
|
||||
type RemoveOrgUserCommand struct {
|
||||
UserID int64
|
||||
OrgID int64
|
||||
ShouldDeleteOrphanedUser bool
|
||||
UserWasDeleted bool
|
||||
}
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
|
||||
}
|
||||
|
@ -18,4 +18,7 @@ type Service interface {
|
||||
UpdateAddress(context.Context, *UpdateOrgAddressCommand) error
|
||||
Delete(context.Context, *DeleteOrgCommand) error
|
||||
GetOrCreate(context.Context, string) (int64, error)
|
||||
AddOrgUser(context.Context, *AddOrgUserCommand) error
|
||||
UpdateOrgUser(context.Context, *UpdateOrgUserCommand) error
|
||||
RemoveOrgUser(context.Context, *RemoveOrgUserCommand) error
|
||||
}
|
||||
|
@ -211,3 +211,36 @@ func (s *Service) GetOrCreate(ctx context.Context, orgName string) (int64, error
|
||||
}
|
||||
return orga.ID, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) AddOrgUser(ctx context.Context, cmd *org.AddOrgUserCommand) error {
|
||||
c := &models.AddOrgUserCommand{
|
||||
LoginOrEmail: cmd.LoginOrEmail,
|
||||
OrgId: cmd.OrgID,
|
||||
UserId: cmd.UserID,
|
||||
Role: cmd.Role,
|
||||
AllowAddingServiceAccount: cmd.AllowAddingServiceAccount,
|
||||
}
|
||||
return s.sqlStore.AddOrgUser(ctx, c)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) UpdateOrgUser(ctx context.Context, cmd *org.UpdateOrgUserCommand) error {
|
||||
c := &models.UpdateOrgUserCommand{
|
||||
UserId: cmd.UserID,
|
||||
OrgId: cmd.OrgID,
|
||||
Role: cmd.Role,
|
||||
}
|
||||
return s.sqlStore.UpdateOrgUser(ctx, c)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) RemoveOrgUser(ctx context.Context, cmd *org.RemoveOrgUserCommand) error {
|
||||
c := &models.RemoveOrgUserCommand{
|
||||
UserId: cmd.UserID,
|
||||
OrgId: cmd.OrgID,
|
||||
ShouldDeleteOrphanedUser: cmd.ShouldDeleteOrphanedUser,
|
||||
UserWasDeleted: cmd.UserWasDeleted,
|
||||
}
|
||||
return s.sqlStore.RemoveOrgUser(ctx, c)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package orgtest
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
)
|
||||
|
||||
@ -12,6 +13,7 @@ type FakeOrgService struct {
|
||||
ExpectedUserOrgDTO []*org.UserOrgDTO
|
||||
ExpectedOrgs []*org.OrgDTO
|
||||
ExpectedOrg *org.Org
|
||||
ExpectedOrgUsers []*org.OrgUserDTO
|
||||
}
|
||||
|
||||
func NewOrgServiceFake() *FakeOrgService {
|
||||
@ -73,3 +75,19 @@ func (f *FakeOrgService) Delete(ctx context.Context, cmd *org.DeleteOrgCommand)
|
||||
func (f *FakeOrgService) GetOrCreate(ctx context.Context, orgName string) (int64, error) {
|
||||
return 0, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) AddOrgUser(ctx context.Context, cmd *org.AddOrgUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) UpdateOrgUser(ctx context.Context, cmd *org.UpdateOrgUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) GetOrgUsers(ctx context.Context, query *models.GetOrgUsersQuery) ([]*org.OrgUserDTO, error) {
|
||||
return f.ExpectedOrgUsers, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) RemoveOrgUser(ctx context.Context, cmd *org.RemoveOrgUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user