Chore: Move search model from models package to search service (#62215)
* Chore: Move search model from models package to search service * Remove unused imports * Cleanup after merge
This commit is contained in:
+3
-3
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
alertmodels "github.com/grafana/grafana/pkg/services/alerting/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
@@ -19,6 +18,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels_config"
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -109,7 +109,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
Limit: 1000,
|
||||
OrgId: c.OrgID,
|
||||
DashboardIds: dashboardIDs,
|
||||
Type: string(models.DashHitDB),
|
||||
Type: string(model.DashHitDB),
|
||||
FolderIds: folderIDs,
|
||||
Permission: dashboards.PERMISSION_VIEW,
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (hs *HTTPServer) GetAlerts(c *contextmodel.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
for _, d := range searchQuery.Result {
|
||||
if d.Type == models.DashHitDB && d.ID > 0 {
|
||||
if d.Type == model.DashHitDB && d.ID > 0 {
|
||||
dashboardIDs = append(dashboardIDs, d.ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/remotecache"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
@@ -53,6 +52,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/services/searchusers"
|
||||
"github.com/grafana/grafana/pkg/services/searchusers/filters"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
@@ -524,13 +524,13 @@ type setUpConf struct {
|
||||
aclMockResp []*dashboards.DashboardACLInfoDTO
|
||||
}
|
||||
|
||||
type mockSearchService struct{ ExpectedResult models.HitList }
|
||||
type mockSearchService struct{ ExpectedResult model.HitList }
|
||||
|
||||
func (mss *mockSearchService) SearchHandler(_ context.Context, q *search.Query) error {
|
||||
q.Result = mss.ExpectedResult
|
||||
return nil
|
||||
}
|
||||
func (mss *mockSearchService) SortOptions() []models.SortOption { return nil }
|
||||
func (mss *mockSearchService) SortOptions() []model.SortOption { return nil }
|
||||
|
||||
func setUp(confs ...setUpConf) *HTTPServer {
|
||||
store := dbtest.NewFakeDB()
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/db/dbtest"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/actest"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/services/team/teamtest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -151,7 +151,7 @@ func TestHTTPServer_FolderMetadata(t *testing.T) {
|
||||
hs.AccessControl = acmock.New()
|
||||
hs.QuotaService = quotatest.New(false, nil)
|
||||
hs.SearchService = &mockSearchService{
|
||||
ExpectedResult: models.HitList{},
|
||||
ExpectedResult: model.HitList{},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+6
-6
@@ -6,11 +6,11 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -95,12 +95,12 @@ func (hs *HTTPServer) Search(c *contextmodel.ReqContext) response.Response {
|
||||
return hs.searchHitsWithMetadata(c, searchQuery.Result)
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits models.HitList) response.Response {
|
||||
func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits model.HitList) response.Response {
|
||||
folderUIDs := make(map[string]bool)
|
||||
dashboardUIDs := make(map[string]bool)
|
||||
|
||||
for _, hit := range hits {
|
||||
if hit.Type == models.DashHitFolder {
|
||||
if hit.Type == model.DashHitFolder {
|
||||
folderUIDs[hit.UID] = true
|
||||
} else {
|
||||
dashboardUIDs[hit.UID] = true
|
||||
@@ -113,13 +113,13 @@ func (hs *HTTPServer) searchHitsWithMetadata(c *contextmodel.ReqContext, hits mo
|
||||
|
||||
// search hit with access control metadata attached
|
||||
type hitWithMeta struct {
|
||||
*models.Hit
|
||||
*model.Hit
|
||||
AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"`
|
||||
}
|
||||
hitsWithMeta := make([]hitWithMeta, 0, len(hits))
|
||||
for _, hit := range hits {
|
||||
var meta accesscontrol.Metadata
|
||||
if hit.Type == models.DashHitFolder {
|
||||
if hit.Type == model.DashHitFolder {
|
||||
meta = folderMeta[hit.UID]
|
||||
} else {
|
||||
meta = accesscontrol.MergeMeta("dashboards", dashboardMeta[hit.UID], folderMeta[hit.FolderUID])
|
||||
@@ -216,7 +216,7 @@ type SearchParams struct {
|
||||
// swagger:response searchResponse
|
||||
type SearchResponse struct {
|
||||
// in: body
|
||||
Body models.HitList `json:"body"`
|
||||
Body model.HitList `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response listSortOptionsResponse
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/search/model"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
@@ -21,10 +21,10 @@ func TestHTTPServer_Search(t *testing.T) {
|
||||
sc.initCtx.SignedInUser = &user.SignedInUser{}
|
||||
|
||||
sc.hs.SearchService = &mockSearchService{
|
||||
ExpectedResult: models.HitList{
|
||||
{ID: 1, UID: "folder1", Title: "folder1", Type: models.DashHitFolder},
|
||||
{ID: 2, UID: "folder2", Title: "folder2", Type: models.DashHitFolder},
|
||||
{ID: 3, UID: "dash3", Title: "dash3", FolderUID: "folder2", Type: models.DashHitDB},
|
||||
ExpectedResult: model.HitList{
|
||||
{ID: 1, UID: "folder1", Title: "folder1", Type: model.DashHitFolder},
|
||||
{ID: 2, UID: "folder2", Title: "folder2", Type: model.DashHitFolder},
|
||||
{ID: 3, UID: "dash3", Title: "dash3", FolderUID: "folder2", Type: model.DashHitDB},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestHTTPServer_Search(t *testing.T) {
|
||||
}
|
||||
|
||||
type withMeta struct {
|
||||
models.Hit
|
||||
model.Hit
|
||||
AccessControl accesscontrol.Metadata `json:"accessControl,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user