Chore: use org service methods (#55768)
* Chore: use org service methods * fix tests * fix errors * adjust func signatures for getbyname * 💩 * Use the same fake service to get the user in AC and in HS * Fix middleware test * Fix more middleware test * Fix api tests Co-authored-by: gamab <gabi.mabs@gmail.com> Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
This commit is contained in:
co-authored by
gamab
Ida Furjesova
parent
169f1ab974
commit
7715672fb3
@@ -213,7 +213,7 @@ func getContextHandler(t *testing.T, cfg *setting.Cfg) *contexthandler.ContextHa
|
||||
authProxy := authproxy.ProvideAuthProxy(cfg, remoteCacheSvc, loginservice.LoginServiceMock{}, &usertest.FakeUserService{}, sqlStore)
|
||||
loginService := &logintest.LoginServiceFake{}
|
||||
authenticator := &logintest.AuthenticatorFake{}
|
||||
ctxHdlr := contexthandler.ProvideService(cfg, userAuthTokenSvc, authJWTSvc, remoteCacheSvc, renderSvc, sqlStore, tracer, authProxy, loginService, nil, authenticator, usertest.NewUserServiceFake())
|
||||
ctxHdlr := contexthandler.ProvideService(cfg, userAuthTokenSvc, authJWTSvc, remoteCacheSvc, renderSvc, sqlStore, tracer, authProxy, loginService, nil, authenticator, usertest.NewUserServiceFake(), orgtest.NewOrgServiceFake())
|
||||
|
||||
return ctxHdlr
|
||||
}
|
||||
@@ -379,6 +379,10 @@ func setupHTTPServerWithCfgDb(
|
||||
var acService accesscontrol.Service
|
||||
|
||||
var userSvc user.Service
|
||||
userMock := usertest.NewUserServiceFake()
|
||||
userMock.ExpectedUser = &user.User{ID: 1}
|
||||
orgMock := orgtest.NewOrgServiceFake()
|
||||
orgMock.ExpectedOrg = &org.Org{}
|
||||
|
||||
// Defining the accesscontrol service has to be done before registering routes
|
||||
if useFakeAccessControl {
|
||||
@@ -388,7 +392,7 @@ func setupHTTPServerWithCfgDb(
|
||||
}
|
||||
ac = acmock
|
||||
acService = acmock
|
||||
userSvc = &usertest.FakeUserService{}
|
||||
userSvc = userMock
|
||||
} else {
|
||||
var err error
|
||||
acService, err = acimpl.ProvideService(cfg, db, routeRegister, localcache.ProvideService())
|
||||
@@ -418,7 +422,7 @@ func setupHTTPServerWithCfgDb(
|
||||
),
|
||||
preferenceService: preftest.NewPreferenceServiceFake(),
|
||||
userService: userSvc,
|
||||
orgService: orgtest.NewOrgServiceFake(),
|
||||
orgService: orgMock,
|
||||
teamService: teamService,
|
||||
annotationsRepo: annotationstest.NewFakeAnnotationsRepo(),
|
||||
}
|
||||
|
||||
+21
-20
@@ -62,7 +62,7 @@ func (hs *HTTPServer) GetOrgByID(c *models.ReqContext) response.Response {
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
|
||||
org, err := hs.SQLStore.GetOrgByName(web.Params(c.Req)[":name"])
|
||||
orga, err := hs.orgService.GetByName(c.Req.Context(), &org.GetOrgByNameQuery{Name: web.Params(c.Req)[":name"]})
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Organization not found", err)
|
||||
@@ -71,15 +71,15 @@ func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get organization", err)
|
||||
}
|
||||
result := models.OrgDetailsDTO{
|
||||
Id: org.Id,
|
||||
Name: org.Name,
|
||||
Id: orga.ID,
|
||||
Name: orga.Name,
|
||||
Address: models.Address{
|
||||
Address1: org.Address1,
|
||||
Address2: org.Address2,
|
||||
City: org.City,
|
||||
ZipCode: org.ZipCode,
|
||||
State: org.State,
|
||||
Country: org.Country,
|
||||
Address1: orga.Address1,
|
||||
Address2: orga.Address2,
|
||||
City: orga.City,
|
||||
ZipCode: orga.ZipCode,
|
||||
State: orga.State,
|
||||
Country: orga.Country,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -87,26 +87,27 @@ func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getOrgHelper(ctx context.Context, orgID int64) response.Response {
|
||||
query := models.GetOrgByIdQuery{Id: orgID}
|
||||
query := org.GetOrgByIdQuery{ID: orgID}
|
||||
|
||||
if err := hs.SQLStore.GetOrgById(ctx, &query); err != nil {
|
||||
res, err := hs.orgService.GetByID(ctx, &query)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Organization not found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get organization", err)
|
||||
}
|
||||
|
||||
org := query.Result
|
||||
orga := res
|
||||
result := models.OrgDetailsDTO{
|
||||
Id: org.Id,
|
||||
Name: org.Name,
|
||||
Id: orga.ID,
|
||||
Name: orga.Name,
|
||||
Address: models.Address{
|
||||
Address1: org.Address1,
|
||||
Address2: org.Address2,
|
||||
City: org.City,
|
||||
ZipCode: org.ZipCode,
|
||||
State: org.State,
|
||||
Country: org.Country,
|
||||
Address1: orga.Address1,
|
||||
Address2: orga.Address2,
|
||||
City: orga.City,
|
||||
ZipCode: orga.ZipCode,
|
||||
State: orga.State,
|
||||
Country: orga.Country,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user