Remove org methods from sqlstore interface (#56358)

* Remove org methods from sqlstore interface

* Remove some mocks

* Fix some tests
This commit is contained in:
idafurjes
2022-10-05 15:47:56 +02:00
committed by GitHub
parent ad2a1dd680
commit bc7a383252
11 changed files with 50 additions and 76 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
@@ -286,26 +287,28 @@ func (hs *HTTPServer) GetUserOrgList(c *models.ReqContext) response.Response {
}
func (hs *HTTPServer) getUserOrgList(ctx context.Context, userID int64) response.Response {
query := models.GetUserOrgListQuery{UserId: userID}
query := org.GetUserOrgListQuery{UserID: userID}
if err := hs.SQLStore.GetUserOrgList(ctx, &query); err != nil {
result, err := hs.orgService.GetUserOrgList(ctx, &query)
if err != nil {
return response.Error(500, "Failed to get user organizations", err)
}
return response.JSON(http.StatusOK, query.Result)
return response.JSON(http.StatusOK, result)
}
func (hs *HTTPServer) validateUsingOrg(ctx context.Context, userID int64, orgID int64) bool {
query := models.GetUserOrgListQuery{UserId: userID}
query := org.GetUserOrgListQuery{UserID: userID}
if err := hs.SQLStore.GetUserOrgList(ctx, &query); err != nil {
result, err := hs.orgService.GetUserOrgList(ctx, &query)
if err != nil {
return false
}
// validate that the org id in the list
valid := false
for _, other := range query.Result {
if other.OrgId == orgID {
for _, other := range result {
if other.OrgID == orgID {
valid = true
}
}