mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Move SearchOrgs to org service (#55416)
* Chore: Move SearchOrgs to org service * Fix lint * Fix lint 2
This commit is contained in:
parent
e25612092b
commit
7ce7c9b64c
@ -42,6 +42,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/login/loginservice"
|
||||
"github.com/grafana/grafana/pkg/services/login/logintest"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
"github.com/grafana/grafana/pkg/services/preference/preftest"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
@ -410,6 +411,7 @@ func setupHTTPServerWithCfgDb(
|
||||
),
|
||||
preferenceService: preftest.NewPreferenceServiceFake(),
|
||||
userService: userMock,
|
||||
orgService: orgtest.NewOrgServiceFake(),
|
||||
annotationsRepo: annotationstest.NewFakeAnnotationsRepo(),
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ func newTestLive(t *testing.T, store *sqlstore.SQLStore) *live.GrafanaLive {
|
||||
nil,
|
||||
&usagestats.UsageStatsMock{T: t},
|
||||
nil,
|
||||
features, accesscontrolmock.New(), &dashboards.FakeDashboardService{}, annotationstest.NewFakeAnnotationsRepo())
|
||||
features, accesscontrolmock.New(), &dashboards.FakeDashboardService{}, annotationstest.NewFakeAnnotationsRepo(), nil)
|
||||
require.NoError(t, err)
|
||||
return gLive
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/multildap"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@ -67,23 +66,24 @@ type LDAPServerDTO struct {
|
||||
}
|
||||
|
||||
// FetchOrgs fetches the organization(s) information by executing a single query to the database. Then, populating the DTO with the information retrieved.
|
||||
func (user *LDAPUserDTO) FetchOrgs(ctx context.Context, sqlstore sqlstore.Store) error {
|
||||
func (user *LDAPUserDTO) FetchOrgs(ctx context.Context, orga org.Service) error {
|
||||
orgIds := []int64{}
|
||||
|
||||
for _, or := range user.OrgRoles {
|
||||
orgIds = append(orgIds, or.OrgId)
|
||||
}
|
||||
|
||||
q := &models.SearchOrgsQuery{}
|
||||
q.Ids = orgIds
|
||||
q := &org.SearchOrgsQuery{}
|
||||
q.IDs = orgIds
|
||||
|
||||
if err := sqlstore.SearchOrgs(ctx, q); err != nil {
|
||||
result, err := orga.Search(ctx, q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
orgNamesById := map[int64]string{}
|
||||
for _, org := range q.Result {
|
||||
orgNamesById[org.Id] = org.Name
|
||||
for _, org := range result {
|
||||
orgNamesById[org.ID] = org.Name
|
||||
}
|
||||
|
||||
for i, orgDTO := range user.OrgRoles {
|
||||
@ -355,7 +355,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
ldapLogger.Debug("mapping org roles", "orgsRoles", u.OrgRoles)
|
||||
if err := u.FetchOrgs(c.Req.Context(), hs.SQLStore); err != nil {
|
||||
if err := u.FetchOrgs(c.Req.Context(), hs.orgService); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "An organization was not found - Please verify your LDAP configuration", err)
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/login/logintest"
|
||||
"github.com/grafana/grafana/pkg/services/multildap"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgtest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/usertest"
|
||||
@ -58,7 +59,7 @@ func (m *LDAPMock) User(login string) (*models.ExternalUserInfo, ldap.ServerConf
|
||||
// GetUserFromLDAP tests
|
||||
// ***
|
||||
|
||||
func getUserFromLDAPContext(t *testing.T, requestURL string, searchOrgRst []*models.OrgDTO) *scenarioContext {
|
||||
func getUserFromLDAPContext(t *testing.T, requestURL string, searchOrgRst []*org.OrgDTO) *scenarioContext {
|
||||
t.Helper()
|
||||
|
||||
sc := setupScenarioContext(t, requestURL)
|
||||
@ -67,7 +68,7 @@ func getUserFromLDAPContext(t *testing.T, requestURL string, searchOrgRst []*mod
|
||||
setting.LDAPEnabled = true
|
||||
t.Cleanup(func() { setting.LDAPEnabled = origLDAP })
|
||||
|
||||
hs := &HTTPServer{Cfg: setting.NewCfg(), ldapGroups: ldap.ProvideGroupsService(), SQLStore: &mockstore.SQLStoreMock{ExpectedSearchOrgList: searchOrgRst}}
|
||||
hs := &HTTPServer{Cfg: setting.NewCfg(), ldapGroups: ldap.ProvideGroupsService(), orgService: &orgtest.FakeOrgService{ExpectedOrgs: searchOrgRst}}
|
||||
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
sc.context = c
|
||||
@ -95,7 +96,7 @@ func TestGetUserFromLDAPAPIEndpoint_UserNotFound(t *testing.T) {
|
||||
|
||||
userSearchResult = nil
|
||||
|
||||
sc := getUserFromLDAPContext(t, "/api/admin/ldap/user-that-does-not-exist", []*models.OrgDTO{})
|
||||
sc := getUserFromLDAPContext(t, "/api/admin/ldap/user-that-does-not-exist", []*org.OrgDTO{})
|
||||
|
||||
require.Equal(t, sc.resp.Code, http.StatusNotFound)
|
||||
assert.JSONEq(t, "{\"message\":\"No user was found in the LDAP server(s) with that username\"}", sc.resp.Body.String())
|
||||
@ -133,8 +134,8 @@ func TestGetUserFromLDAPAPIEndpoint_OrgNotfound(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mockOrgSearchResult := []*models.OrgDTO{
|
||||
{Id: 1, Name: "Main Org."},
|
||||
mockOrgSearchResult := []*org.OrgDTO{
|
||||
{ID: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
getLDAPConfig = func(*setting.Cfg) (*ldap.Config, error) {
|
||||
@ -188,8 +189,8 @@ func TestGetUserFromLDAPAPIEndpoint(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mockOrgSearchResult := []*models.OrgDTO{
|
||||
{Id: 1, Name: "Main Org."},
|
||||
mockOrgSearchResult := []*org.OrgDTO{
|
||||
{ID: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
getLDAPConfig = func(*setting.Cfg) (*ldap.Config, error) {
|
||||
@ -258,8 +259,8 @@ func TestGetUserFromLDAPAPIEndpoint_WithTeamHandler(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mockOrgSearchResult := []*models.OrgDTO{
|
||||
{Id: 1, Name: "Main Org."},
|
||||
mockOrgSearchResult := []*org.OrgDTO{
|
||||
{ID: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
getLDAPConfig = func(*setting.Cfg) (*ldap.Config, error) {
|
||||
@ -610,6 +611,7 @@ func TestLDAP_AccessControl(t *testing.T) {
|
||||
hs.userService = &usertest.FakeUserService{ExpectedUser: &user.User{}}
|
||||
hs.authInfoService = &logintest.AuthInfoServiceFake{}
|
||||
hs.Login = &loginservice.LoginServiceMock{}
|
||||
hs.orgService = &orgtest.FakeOrgService{}
|
||||
sc.resp = httptest.NewRecorder()
|
||||
sc.req, err = http.NewRequest(test.method, test.url, nil)
|
||||
assert.NoError(t, err)
|
||||
|
@ -320,18 +320,19 @@ func (hs *HTTPServer) SearchOrgs(c *models.ReqContext) response.Response {
|
||||
|
||||
page := c.QueryInt("page")
|
||||
|
||||
query := models.SearchOrgsQuery{
|
||||
query := org.SearchOrgsQuery{
|
||||
Query: c.Query("query"),
|
||||
Name: c.Query("name"),
|
||||
Page: page,
|
||||
Limit: perPage,
|
||||
}
|
||||
|
||||
if err := hs.SQLStore.SearchOrgs(c.Req.Context(), &query); err != nil {
|
||||
result, err := hs.orgService.Search(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to search orgs", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, query.Result)
|
||||
return response.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// swagger:parameters updateCurrentOrgAddress
|
||||
|
@ -103,7 +103,7 @@ func TestIntegrationPluginManager_Run(t *testing.T) {
|
||||
pg := postgres.ProvideService(cfg)
|
||||
my := mysql.ProvideService(cfg, hcp)
|
||||
ms := mssql.ProvideService(cfg)
|
||||
sv2 := searchV2.ProvideService(cfg, sqlstore.InitTestDB(t), nil, nil)
|
||||
sv2 := searchV2.ProvideService(cfg, sqlstore.InitTestDB(t), nil, nil, nil)
|
||||
graf := grafanads.ProvideService(cfg, sv2, nil)
|
||||
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(am, cw, cm, es, grap, idb, lk, otsdb, pr, tmpo, td, pg, my, ms, graf)
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
@ -27,6 +27,7 @@ type gitExportJob struct {
|
||||
dashboardsnapshotsService dashboardsnapshots.Service
|
||||
datasourceService datasources.DataSourceService
|
||||
playlistService playlist.Service
|
||||
orgService org.Service
|
||||
rootDir string
|
||||
|
||||
statusMu sync.Mutex
|
||||
@ -38,13 +39,15 @@ type gitExportJob struct {
|
||||
|
||||
func startGitExportJob(cfg ExportConfig, sql *sqlstore.SQLStore,
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, rootDir string, orgID int64,
|
||||
broadcaster statusBroadcaster, playlistService playlist.Service, datasourceService datasources.DataSourceService) (Job, error) {
|
||||
broadcaster statusBroadcaster, playlistService playlist.Service, orgService org.Service,
|
||||
datasourceService datasources.DataSourceService) (Job, error) {
|
||||
job := &gitExportJob{
|
||||
logger: log.New("git_export_job"),
|
||||
cfg: cfg,
|
||||
sql: sql,
|
||||
dashboardsnapshotsService: dashboardsnapshotsService,
|
||||
playlistService: playlistService,
|
||||
orgService: orgService,
|
||||
datasourceService: datasourceService,
|
||||
rootDir: rootDir,
|
||||
broadcaster: broadcaster,
|
||||
@ -142,19 +145,19 @@ func (e *gitExportJob) doExportWithHistory() error {
|
||||
},
|
||||
}
|
||||
|
||||
cmd := &models.SearchOrgsQuery{}
|
||||
err = e.sql.SearchOrgs(e.helper.ctx, cmd)
|
||||
cmd := &org.SearchOrgsQuery{}
|
||||
result, err := e.orgService.Search(e.helper.ctx, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Export each org
|
||||
for _, org := range cmd.Result {
|
||||
if len(cmd.Result) > 1 {
|
||||
e.helper.orgDir = path.Join(e.rootDir, fmt.Sprintf("org_%d", org.Id))
|
||||
for _, org := range result {
|
||||
if len(result) > 1 {
|
||||
e.helper.orgDir = path.Join(e.rootDir, fmt.Sprintf("org_%d", org.ID))
|
||||
e.status.Count["orgs"] += 1
|
||||
}
|
||||
err = e.helper.initOrg(e.sql, org.Id)
|
||||
err = e.helper.initOrg(e.sql, org.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@ -153,6 +154,7 @@ type StandardExport struct {
|
||||
sql *sqlstore.SQLStore
|
||||
dashboardsnapshotsService dashboardsnapshots.Service
|
||||
playlistService playlist.Service
|
||||
orgService org.Service
|
||||
datasourceService datasources.DataSourceService
|
||||
|
||||
// updated with mutex
|
||||
@ -160,7 +162,8 @@ type StandardExport struct {
|
||||
}
|
||||
|
||||
func ProvideService(sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles, gl *live.GrafanaLive, cfg *setting.Cfg,
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, playlistService playlist.Service, datasourceService datasources.DataSourceService) ExportService {
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, playlistService playlist.Service, orgService org.Service,
|
||||
datasourceService datasources.DataSourceService) ExportService {
|
||||
if !features.IsEnabled(featuremgmt.FlagExport) {
|
||||
return &StubExport{}
|
||||
}
|
||||
@ -171,6 +174,7 @@ func ProvideService(sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles,
|
||||
logger: log.New("export_service"),
|
||||
dashboardsnapshotsService: dashboardsnapshotsService,
|
||||
playlistService: playlistService,
|
||||
orgService: orgService,
|
||||
datasourceService: datasourceService,
|
||||
exportJob: &stoppedJob{},
|
||||
dataDir: cfg.DataPath,
|
||||
@ -228,7 +232,7 @@ func (ex *StandardExport) HandleRequestExport(c *models.ReqContext) response.Res
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Error creating export folder", nil)
|
||||
}
|
||||
job, err = startGitExportJob(cfg, ex.sql, ex.dashboardsnapshotsService, dir, c.OrgID, broadcast, ex.playlistService, ex.datasourceService)
|
||||
job, err = startGitExportJob(cfg, ex.sql, ex.dashboardsnapshotsService, dir, c.OrgID, broadcast, ex.playlistService, ex.orgService, ex.datasourceService)
|
||||
default:
|
||||
return response.Error(http.StatusBadRequest, "Unsupported job format", nil)
|
||||
}
|
||||
|
@ -76,7 +76,8 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
pluginStore plugins.Store, cacheService *localcache.CacheService,
|
||||
dataSourceCache datasources.CacheService, sqlStore *sqlstore.SQLStore, secretsService secrets.Service,
|
||||
usageStatsService usagestats.Service, queryDataService *query.Service, toggles featuremgmt.FeatureToggles,
|
||||
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService, annotationsRepo annotations.Repository) (*GrafanaLive, error) {
|
||||
accessControl accesscontrol.AccessControl, dashboardService dashboards.DashboardService, annotationsRepo annotations.Repository,
|
||||
orgService org.Service) (*GrafanaLive, error) {
|
||||
g := &GrafanaLive{
|
||||
Cfg: cfg,
|
||||
Features: toggles,
|
||||
@ -93,6 +94,7 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
Features: make(map[string]models.ChannelHandlerFactory),
|
||||
},
|
||||
usageStatsService: usageStatsService,
|
||||
orgService: orgService,
|
||||
}
|
||||
|
||||
logger.Debug("GrafanaLive initialization", "ha", g.IsHA())
|
||||
@ -213,16 +215,16 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
|
||||
// Pre-build/validate channel rules for all organizations on start.
|
||||
// This can be unreasonable to have in production scenario with many
|
||||
// organizations.
|
||||
orgQuery := &models.SearchOrgsQuery{}
|
||||
orgQuery := &org.SearchOrgsQuery{}
|
||||
|
||||
err := sqlStore.SearchOrgs(context.Background(), orgQuery)
|
||||
result, err := orgService.Search(context.Background(), orgQuery)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't get org list: %w", err)
|
||||
}
|
||||
for _, org := range orgQuery.Result {
|
||||
_, _, err := channelRuleGetter.Get(org.Id, "")
|
||||
for _, org := range result {
|
||||
_, _, err := channelRuleGetter.Get(org.ID, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error building channel rules for org %d: %w", org.Id, err)
|
||||
return nil, fmt.Errorf("error building channel rules for org %d: %w", org.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,6 +415,7 @@ type GrafanaLive struct {
|
||||
SecretsService secrets.Service
|
||||
pluginStore plugins.Store
|
||||
queryDataService *query.Service
|
||||
orgService org.Service
|
||||
|
||||
node *centrifuge.Node
|
||||
surveyCaller *survey.Caller
|
||||
|
@ -76,6 +76,19 @@ type UpdateOrgCommand struct {
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
type SearchOrgsQuery struct {
|
||||
Query string
|
||||
Name string
|
||||
Limit int
|
||||
Page int
|
||||
IDs []int64
|
||||
}
|
||||
|
||||
type OrgDTO struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ type Service interface {
|
||||
InsertOrgUser(context.Context, *OrgUser) (int64, error)
|
||||
DeleteUserFromAll(context.Context, int64) error
|
||||
GetUserOrgList(context.Context, *GetUserOrgListQuery) ([]*UserOrgDTO, error)
|
||||
UpdateOrg(ctx context.Context, cmd *UpdateOrgCommand) error
|
||||
UpdateOrg(context.Context, *UpdateOrgCommand) error
|
||||
Search(context.Context, *SearchOrgsQuery) ([]*OrgDTO, error)
|
||||
}
|
||||
|
@ -108,3 +108,27 @@ func (s *Service) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQ
|
||||
func (s *Service) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
|
||||
return s.store.Update(ctx, cmd)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
|
||||
var res []*org.OrgDTO
|
||||
q := &models.SearchOrgsQuery{
|
||||
Query: query.Query,
|
||||
Name: query.Name,
|
||||
Limit: query.Limit,
|
||||
Page: query.Page,
|
||||
Ids: query.IDs,
|
||||
}
|
||||
err := s.sqlStore.SearchOrgs(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, r := range q.Result {
|
||||
res = append(res, &org.OrgDTO{
|
||||
ID: r.Id,
|
||||
Name: r.Name,
|
||||
})
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ type FakeOrgService struct {
|
||||
ExpectedOrgUserID int64
|
||||
ExpectedError error
|
||||
ExpectedUserOrgDTO []*org.UserOrgDTO
|
||||
ExpectedOrgs []*org.OrgDTO
|
||||
}
|
||||
|
||||
func NewOrgServiceFake() *FakeOrgService {
|
||||
@ -39,3 +40,7 @@ func (f *FakeOrgService) GetUserOrgList(ctx context.Context, query *org.GetUserO
|
||||
func (f *FakeOrgService) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
|
||||
return f.ExpectedOrgs, f.ExpectedError
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ var (
|
||||
)
|
||||
|
||||
func service(t *testing.T) *StandardSearchService {
|
||||
service, ok := ProvideService(nil, nil, nil, accesscontrolmock.New()).(*StandardSearchService)
|
||||
service, ok := ProvideService(nil, nil, nil, accesscontrolmock.New(), nil).(*StandardSearchService)
|
||||
require.True(t, ok)
|
||||
return service
|
||||
}
|
||||
|
@ -53,10 +53,11 @@ var (
|
||||
type StandardSearchService struct {
|
||||
registry.BackgroundService
|
||||
|
||||
cfg *setting.Cfg
|
||||
sql *sqlstore.SQLStore
|
||||
auth FutureAuthService // eventually injected from elsewhere
|
||||
ac accesscontrol.Service
|
||||
cfg *setting.Cfg
|
||||
sql *sqlstore.SQLStore
|
||||
auth FutureAuthService // eventually injected from elsewhere
|
||||
ac accesscontrol.Service
|
||||
orgService org.Service
|
||||
|
||||
logger log.Logger
|
||||
dashboardIndex *searchIndex
|
||||
@ -68,7 +69,8 @@ func (s *StandardSearchService) IsReady(ctx context.Context, orgId int64) IsSear
|
||||
return s.dashboardIndex.isInitialized(ctx, orgId)
|
||||
}
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, sql *sqlstore.SQLStore, entityEventStore store.EntityEventsService, ac accesscontrol.Service) SearchService {
|
||||
func ProvideService(cfg *setting.Cfg, sql *sqlstore.SQLStore, entityEventStore store.EntityEventsService,
|
||||
ac accesscontrol.Service, orgService org.Service) SearchService {
|
||||
extender := &NoopExtender{}
|
||||
s := &StandardSearchService{
|
||||
cfg: cfg,
|
||||
@ -84,9 +86,10 @@ func ProvideService(cfg *setting.Cfg, sql *sqlstore.SQLStore, entityEventStore s
|
||||
extender.GetDocumentExtender(),
|
||||
newFolderIDLookup(sql),
|
||||
),
|
||||
logger: log.New("searchV2"),
|
||||
extender: extender,
|
||||
reIndexCh: make(chan struct{}, 1),
|
||||
logger: log.New("searchV2"),
|
||||
extender: extender,
|
||||
reIndexCh: make(chan struct{}, 1),
|
||||
orgService: orgService,
|
||||
}
|
||||
return s
|
||||
}
|
||||
@ -99,14 +102,14 @@ func (s *StandardSearchService) IsDisabled() bool {
|
||||
}
|
||||
|
||||
func (s *StandardSearchService) Run(ctx context.Context) error {
|
||||
orgQuery := &models.SearchOrgsQuery{}
|
||||
err := s.sql.SearchOrgs(ctx, orgQuery)
|
||||
orgQuery := &org.SearchOrgsQuery{}
|
||||
result, err := s.orgService.Search(ctx, orgQuery)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't get org list: %w", err)
|
||||
}
|
||||
orgIDs := make([]int64, 0, len(orgQuery.Result))
|
||||
for _, org := range orgQuery.Result {
|
||||
orgIDs = append(orgIDs, org.Id)
|
||||
orgIDs := make([]int64, 0, len(result))
|
||||
for _, org := range result {
|
||||
orgIDs = append(orgIDs, org.ID)
|
||||
}
|
||||
return s.dashboardIndex.run(ctx, orgIDs, s.reIndexCh)
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ type Store interface {
|
||||
GetTempUserByCode(ctx context.Context, query *models.GetTempUserByCodeQuery) error
|
||||
ExpireOldUserInvites(ctx context.Context, cmd *models.ExpireTempUsersCommand) error
|
||||
GetDBHealthQuery(ctx context.Context, query *models.GetDBHealthQuery) error
|
||||
SearchOrgs(ctx context.Context, query *models.SearchOrgsQuery) error
|
||||
IsAdminOfTeams(ctx context.Context, query *models.IsAdminOfTeamsQuery) error
|
||||
GetSqlxSession() *session.SessionDB
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"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/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
@ -17,7 +16,8 @@ type CrawlerAuthSetupService interface {
|
||||
Setup(ctx context.Context) (CrawlerAuth, error)
|
||||
}
|
||||
|
||||
func ProvideCrawlerAuthSetupService(serviceAccounts serviceaccounts.Service, serviceAccountsStore serviceaccounts.Store, sqlStore *sqlstore.SQLStore) *OSSCrawlerAuthSetupService {
|
||||
func ProvideCrawlerAuthSetupService(serviceAccounts serviceaccounts.Service, serviceAccountsStore serviceaccounts.Store,
|
||||
sqlStore *sqlstore.SQLStore, orgService org.Service) *OSSCrawlerAuthSetupService {
|
||||
return &OSSCrawlerAuthSetupService{
|
||||
serviceAccountNamePrefix: "dashboard-previews-crawler-org-",
|
||||
serviceAccounts: serviceAccounts,
|
||||
@ -33,6 +33,7 @@ type OSSCrawlerAuthSetupService struct {
|
||||
serviceAccounts serviceaccounts.Service
|
||||
serviceAccountsStore serviceaccounts.Store
|
||||
sqlStore *sqlstore.SQLStore
|
||||
orgService org.Service
|
||||
}
|
||||
|
||||
type CrawlerAuth interface {
|
||||
@ -42,15 +43,16 @@ type CrawlerAuth interface {
|
||||
}
|
||||
|
||||
func (o *OSSCrawlerAuthSetupService) findAllOrgIds(ctx context.Context) ([]int64, error) {
|
||||
searchAllOrgsQuery := &models.SearchOrgsQuery{}
|
||||
if err := o.sqlStore.SearchOrgs(ctx, searchAllOrgsQuery); err != nil {
|
||||
searchAllOrgsQuery := &org.SearchOrgsQuery{}
|
||||
result, err := o.orgService.Search(ctx, searchAllOrgsQuery)
|
||||
if err != nil {
|
||||
o.log.Error("Error when searching for orgs", "err", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orgIds := make([]int64, 0)
|
||||
for i := range searchAllOrgsQuery.Result {
|
||||
orgIds = append(orgIds, searchAllOrgsQuery.Result[i].Id)
|
||||
for i := range result {
|
||||
orgIds = append(orgIds, result[i].ID)
|
||||
}
|
||||
|
||||
return orgIds, nil
|
||||
|
Loading…
Reference in New Issue
Block a user