remove bus from search and avoid import cycle (#46789)
* fix the import cicle * fix some unittest * fix removal bus from search
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -82,7 +81,7 @@ type DashboardSearchProjection struct {
|
||||
SortMeta int64
|
||||
}
|
||||
|
||||
func (ss *SQLStore) FindDashboards(ctx context.Context, query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
|
||||
func (ss *SQLStore) FindDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
|
||||
filters := []interface{}{
|
||||
permissions.DashboardPermissionFilter{
|
||||
OrgRole: query.SignedInUser.OrgRole,
|
||||
@@ -162,7 +161,7 @@ func (ss *SQLStore) FindDashboards(ctx context.Context, query *search.FindPersis
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (ss *SQLStore) SearchDashboards(ctx context.Context, query *search.FindPersistedDashboardsQuery) error {
|
||||
func (ss *SQLStore) SearchDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) error {
|
||||
res, err := ss.FindDashboards(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -173,25 +172,25 @@ func (ss *SQLStore) SearchDashboards(ctx context.Context, query *search.FindPers
|
||||
return nil
|
||||
}
|
||||
|
||||
func getHitType(item DashboardSearchProjection) search.HitType {
|
||||
var hitType search.HitType
|
||||
func getHitType(item DashboardSearchProjection) models.HitType {
|
||||
var hitType models.HitType
|
||||
if item.IsFolder {
|
||||
hitType = search.DashHitFolder
|
||||
hitType = models.DashHitFolder
|
||||
} else {
|
||||
hitType = search.DashHitDB
|
||||
hitType = models.DashHitDB
|
||||
}
|
||||
|
||||
return hitType
|
||||
}
|
||||
|
||||
func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []DashboardSearchProjection) {
|
||||
query.Result = make([]*search.Hit, 0)
|
||||
hits := make(map[int64]*search.Hit)
|
||||
func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []DashboardSearchProjection) {
|
||||
query.Result = make([]*models.Hit, 0)
|
||||
hits := make(map[int64]*models.Hit)
|
||||
|
||||
for _, item := range res {
|
||||
hit, exists := hits[item.ID]
|
||||
if !exists {
|
||||
hit = &search.Hit{
|
||||
hit = &models.Hit{
|
||||
ID: item.ID,
|
||||
UID: item.UID,
|
||||
Title: item.Title,
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
|
||||
@@ -38,8 +37,10 @@ type SQLStoreMock struct {
|
||||
ExpectedDataSources []*models.DataSource
|
||||
ExpectedDataSourcesAccessStats []*models.DataSourceAccessStats
|
||||
ExpectedNotifierUsageStats []*models.NotifierUsageStats
|
||||
|
||||
ExpectedError error
|
||||
ExpectedPersistedDashboards models.HitList
|
||||
ExpectedSignedInUser *models.SignedInUser
|
||||
ExpectedUserStars map[int64]bool
|
||||
ExpectedError error
|
||||
}
|
||||
|
||||
func NewSQLStoreMock() *SQLStoreMock {
|
||||
@@ -179,10 +180,12 @@ func (m *SQLStoreMock) GetUserOrgList(ctx context.Context, query *models.GetUser
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) GetSignedInUserWithCacheCtx(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = m.ExpectedSignedInUser
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) GetSignedInUser(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = m.ExpectedSignedInUser
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
@@ -322,6 +325,7 @@ func (m *SQLStoreMock) UnstarDashboard(ctx context.Context, cmd *models.UnstarDa
|
||||
}
|
||||
|
||||
func (m *SQLStoreMock) GetUserStars(ctx context.Context, query *models.GetUserStarsQuery) error {
|
||||
query.Result = m.ExpectedUserStars
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
@@ -469,7 +473,8 @@ func (m *SQLStoreMock) GetDashboard(ctx context.Context, query *models.GetDashbo
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
func (m SQLStoreMock) SearchDashboards(ctx context.Context, query *search.FindPersistedDashboardsQuery) error {
|
||||
func (m SQLStoreMock) SearchDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) error {
|
||||
query.Result = m.ExpectedPersistedDashboards
|
||||
return m.ExpectedError
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
)
|
||||
|
||||
type Store interface {
|
||||
@@ -105,7 +104,7 @@ type Store interface {
|
||||
RemoveOrgUser(ctx context.Context, cmd *models.RemoveOrgUserCommand) error
|
||||
GetDashboard(ctx context.Context, query *models.GetDashboardQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *models.GetDashboardTagsQuery) error
|
||||
SearchDashboards(ctx context.Context, query *search.FindPersistedDashboardsQuery) error
|
||||
SearchDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) error
|
||||
DeleteDashboard(ctx context.Context, cmd *models.DeleteDashboardCommand) error
|
||||
GetDashboards(ctx context.Context, query *models.GetDashboardsQuery) error
|
||||
GetDashboardUIDById(ctx context.Context, query *models.GetDashboardRefByIdQuery) error
|
||||
|
||||
Reference in New Issue
Block a user