mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: add sort information in dashboard results (#30609)
* Search: add SortMeta in dashboard results * fix integration tests * trim SortMeta * fix searchstore tests * Update pkg/services/sqlstore/dashboard.go Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
parent
25117f5af5
commit
3303e28b38
@ -91,8 +91,8 @@ func GetAlerts(c *models.ReqContext) response.Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range searchQuery.Result {
|
for _, d := range searchQuery.Result {
|
||||||
if d.Type == search.DashHitDB && d.Id > 0 {
|
if d.Type == search.DashHitDB && d.ID > 0 {
|
||||||
dashboardIDs = append(dashboardIDs, d.Id)
|
dashboardIDs = append(dashboardIDs, d.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +112,8 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
|||||||
bus.AddHandler("test", func(query *search.Query) error {
|
bus.AddHandler("test", func(query *search.Query) error {
|
||||||
searchQuery = query
|
searchQuery = query
|
||||||
query.Result = search.HitList{
|
query.Result = search.HitList{
|
||||||
&search.Hit{Id: 1},
|
&search.Hit{ID: 1},
|
||||||
&search.Hit{Id: 2},
|
&search.Hit{ID: 2},
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -51,11 +51,11 @@ func populateDashboardsByTag(orgID int64, signedInUser *models.SignedInUser, das
|
|||||||
if err := bus.Dispatch(&searchQuery); err == nil {
|
if err := bus.Dispatch(&searchQuery); err == nil {
|
||||||
for _, item := range searchQuery.Result {
|
for _, item := range searchQuery.Result {
|
||||||
result = append(result, dtos.PlaylistDashboard{
|
result = append(result, dtos.PlaylistDashboard{
|
||||||
Id: item.Id,
|
Id: item.ID,
|
||||||
Slug: item.Slug,
|
Slug: item.Slug,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Uri: item.Uri,
|
Uri: item.URI,
|
||||||
Url: item.Url,
|
Url: item.URL,
|
||||||
Order: dashboardTagOrder[tag],
|
Order: dashboardTagOrder[tag],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ func (hs *HTTPServer) ListSortOptions(c *models.ReqContext) response.Response {
|
|||||||
"name": o.Name,
|
"name": o.Name,
|
||||||
"displayName": o.DisplayName,
|
"displayName": o.DisplayName,
|
||||||
"description": o.Description,
|
"description": o.Description,
|
||||||
|
"meta": o.MetaName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ func (dr *dashboardServiceImpl) GetFolders(limit int64) ([]*models.Folder, error
|
|||||||
|
|
||||||
for _, hit := range searchQuery.Result {
|
for _, hit := range searchQuery.Result {
|
||||||
folders = append(folders, &models.Folder{
|
folders = append(folders, &models.Folder{
|
||||||
Id: hit.Id,
|
Id: hit.ID,
|
||||||
Uid: hit.Uid,
|
Uid: hit.UID,
|
||||||
Title: hit.Title,
|
Title: hit.Title,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Hit struct {
|
type Hit struct {
|
||||||
Id int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Uid string `json:"uid"`
|
UID string `json:"uid"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Uri string `json:"uri"`
|
URI string `json:"uri"`
|
||||||
Url string `json:"url"`
|
URL string `json:"url"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Type HitType `json:"type"`
|
Type HitType `json:"type"`
|
||||||
Tags []string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
IsStarred bool `json:"isStarred"`
|
IsStarred bool `json:"isStarred"`
|
||||||
FolderId int64 `json:"folderId,omitempty"`
|
FolderID int64 `json:"folderId,omitempty"`
|
||||||
FolderUid string `json:"folderUid,omitempty"`
|
FolderUID string `json:"folderUid,omitempty"`
|
||||||
FolderTitle string `json:"folderTitle,omitempty"`
|
FolderTitle string `json:"folderTitle,omitempty"`
|
||||||
FolderUrl string `json:"folderUrl,omitempty"`
|
FolderURL string `json:"folderUrl,omitempty"`
|
||||||
|
SortMeta string `json:"sortMeta,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type HitList []*Hit
|
type HitList []*Hit
|
||||||
|
@ -43,6 +43,7 @@ type FindPersistedDashboardsQuery struct {
|
|||||||
Limit int64
|
Limit int64
|
||||||
Page int64
|
Page int64
|
||||||
Permission models.PermissionType
|
Permission models.PermissionType
|
||||||
|
Sort SortOption
|
||||||
|
|
||||||
Filters []interface{}
|
Filters []interface{}
|
||||||
|
|
||||||
@ -81,9 +82,7 @@ func (s *SearchService) searchHandler(query *Query) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sortOpt, exists := s.sortOptions[query.Sort]; exists {
|
if sortOpt, exists := s.sortOptions[query.Sort]; exists {
|
||||||
for _, filter := range sortOpt.Filter {
|
dashboardQuery.Sort = sortOpt
|
||||||
dashboardQuery.Filters = append(dashboardQuery.Filters, filter)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := bus.Dispatch(&dashboardQuery); err != nil {
|
if err := bus.Dispatch(&dashboardQuery); err != nil {
|
||||||
@ -127,7 +126,7 @@ func setStarredDashboards(userID int64, hits []*Hit) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, dashboard := range hits {
|
for _, dashboard := range hits {
|
||||||
if _, ok := query.Result[dashboard.Id]; ok {
|
if _, ok := query.Result[dashboard.ID]; ok {
|
||||||
dashboard.IsStarred = true
|
dashboard.IsStarred = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ import (
|
|||||||
func TestSearch_SortedResults(t *testing.T) {
|
func TestSearch_SortedResults(t *testing.T) {
|
||||||
bus.AddHandler("test", func(query *FindPersistedDashboardsQuery) error {
|
bus.AddHandler("test", func(query *FindPersistedDashboardsQuery) error {
|
||||||
query.Result = HitList{
|
query.Result = HitList{
|
||||||
&Hit{Id: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}},
|
&Hit{ID: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}},
|
||||||
&Hit{Id: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}},
|
&Hit{ID: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}},
|
||||||
&Hit{Id: 15, Title: "BBAA", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
&Hit{ID: 15, Title: "BBAA", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
||||||
&Hit{Id: 25, Title: "bbAAa", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
&Hit{ID: 25, Title: "bbAAa", Type: "dash-db", Tags: []string{"EE", "AA", "BB"}},
|
||||||
&Hit{Id: 17, Title: "FOLDER", Type: "dash-folder"},
|
&Hit{ID: 17, Title: "FOLDER", Type: "dash-folder"},
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -9,16 +9,18 @@ import (
|
|||||||
var (
|
var (
|
||||||
sortAlphaAsc = SortOption{
|
sortAlphaAsc = SortOption{
|
||||||
Name: "alpha-asc",
|
Name: "alpha-asc",
|
||||||
DisplayName: "Alphabetically (A-Z)",
|
DisplayName: "Alphabetically (A–Z)",
|
||||||
Description: "Sort results in an alphabetically ascending order",
|
Description: "Sort results in an alphabetically ascending order",
|
||||||
|
Index: 0,
|
||||||
Filter: []SortOptionFilter{
|
Filter: []SortOptionFilter{
|
||||||
searchstore.TitleSorter{},
|
searchstore.TitleSorter{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
sortAlphaDesc = SortOption{
|
sortAlphaDesc = SortOption{
|
||||||
Name: "alpha-desc",
|
Name: "alpha-desc",
|
||||||
DisplayName: "Alphabetically (Z-A)",
|
DisplayName: "Alphabetically (Z–A)",
|
||||||
Description: "Sort results in an alphabetically descending order",
|
Description: "Sort results in an alphabetically descending order",
|
||||||
|
Index: 0,
|
||||||
Filter: []SortOptionFilter{
|
Filter: []SortOptionFilter{
|
||||||
searchstore.TitleSorter{Descending: true},
|
searchstore.TitleSorter{Descending: true},
|
||||||
},
|
},
|
||||||
@ -29,6 +31,8 @@ type SortOption struct {
|
|||||||
Name string
|
Name string
|
||||||
DisplayName string
|
DisplayName string
|
||||||
Description string
|
Description string
|
||||||
|
Index int
|
||||||
|
MetaName string
|
||||||
Filter []SortOptionFilter
|
Filter []SortOptionFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +52,7 @@ func (s *SearchService) SortOptions() []SortOption {
|
|||||||
opts = append(opts, o)
|
opts = append(opts, o)
|
||||||
}
|
}
|
||||||
sort.Slice(opts, func(i, j int) bool {
|
sort.Slice(opts, func(i, j int) bool {
|
||||||
return opts[i].Name < opts[j].Name
|
return opts[i].Index < opts[j].Index || (opts[i].Index == opts[j].Index && opts[i].Name < opts[j].Name)
|
||||||
})
|
})
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sqlstore
|
package sqlstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -203,16 +204,17 @@ func GetDashboard(query *models.GetDashboardQuery) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DashboardSearchProjection struct {
|
type DashboardSearchProjection struct {
|
||||||
Id int64
|
ID int64 `xorm:"id"`
|
||||||
Uid string
|
UID string `xorm:"uid"`
|
||||||
Title string
|
Title string
|
||||||
Slug string
|
Slug string
|
||||||
Term string
|
Term string
|
||||||
IsFolder bool
|
IsFolder bool
|
||||||
FolderId int64
|
FolderID int64 `xorm:"folder_id"`
|
||||||
FolderUid string
|
FolderUID string `xorm:"folder_uid"`
|
||||||
FolderSlug string
|
FolderSlug string
|
||||||
FolderTitle string
|
FolderTitle string
|
||||||
|
SortMeta int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
|
func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error) {
|
||||||
@ -226,7 +228,9 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
filters = append(filters, query.Filters...)
|
for _, filter := range query.Sort.Filter {
|
||||||
|
filters = append(filters, filter)
|
||||||
|
}
|
||||||
|
|
||||||
if query.OrgId != 0 {
|
if query.OrgId != 0 {
|
||||||
filters = append(filters, searchstore.OrgFilter{OrgId: query.OrgId})
|
filters = append(filters, searchstore.OrgFilter{OrgId: query.OrgId})
|
||||||
@ -307,27 +311,31 @@ func makeQueryResult(query *search.FindPersistedDashboardsQuery, res []Dashboard
|
|||||||
hits := make(map[int64]*search.Hit)
|
hits := make(map[int64]*search.Hit)
|
||||||
|
|
||||||
for _, item := range res {
|
for _, item := range res {
|
||||||
hit, exists := hits[item.Id]
|
hit, exists := hits[item.ID]
|
||||||
if !exists {
|
if !exists {
|
||||||
hit = &search.Hit{
|
hit = &search.Hit{
|
||||||
Id: item.Id,
|
ID: item.ID,
|
||||||
Uid: item.Uid,
|
UID: item.UID,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Uri: "db/" + item.Slug,
|
URI: "db/" + item.Slug,
|
||||||
Url: models.GetDashboardFolderUrl(item.IsFolder, item.Uid, item.Slug),
|
URL: models.GetDashboardFolderUrl(item.IsFolder, item.UID, item.Slug),
|
||||||
Type: getHitType(item),
|
Type: getHitType(item),
|
||||||
FolderId: item.FolderId,
|
FolderID: item.FolderID,
|
||||||
FolderUid: item.FolderUid,
|
FolderUID: item.FolderUID,
|
||||||
FolderTitle: item.FolderTitle,
|
FolderTitle: item.FolderTitle,
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.FolderId > 0 {
|
if item.FolderID > 0 {
|
||||||
hit.FolderUrl = models.GetFolderUrl(item.FolderUid, item.FolderSlug)
|
hit.FolderURL = models.GetFolderUrl(item.FolderUID, item.FolderSlug)
|
||||||
|
}
|
||||||
|
|
||||||
|
if query.Sort.MetaName != "" {
|
||||||
|
hit.SortMeta = strings.TrimSpace(fmt.Sprintf("%d %s", item.SortMeta, query.Sort.MetaName))
|
||||||
}
|
}
|
||||||
|
|
||||||
query.Result = append(query.Result, hit)
|
query.Result = append(query.Result, hit)
|
||||||
hits[item.Id] = hit
|
hits[item.ID] = hit
|
||||||
}
|
}
|
||||||
if len(item.Term) > 0 {
|
if len(item.Term) > 0 {
|
||||||
hit.Tags = append(hit.Tags, item.Term)
|
hit.Tags = append(hit.Tags, item.Term)
|
||||||
|
@ -33,8 +33,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder.Id)
|
So(query.Result[0].ID, ShouldEqual, folder.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[1].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
So(query.Result[0].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[0].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("when the user is given permission", func() {
|
Convey("when the user is given permission", func() {
|
||||||
@ -75,8 +75,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder.Id)
|
So(query.Result[0].ID, ShouldEqual, folder.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[1].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -94,8 +94,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder.Id)
|
So(query.Result[0].ID, ShouldEqual, folder.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[1].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -116,7 +116,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
So(query.Result[0].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[0].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("when the user is given permission to child", func() {
|
Convey("when the user is given permission to child", func() {
|
||||||
@ -128,8 +128,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, childDash.Id)
|
So(query.Result[0].ID, ShouldEqual, childDash.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[1].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -147,9 +147,9 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 3)
|
So(len(query.Result), ShouldEqual, 3)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder.Id)
|
So(query.Result[0].ID, ShouldEqual, folder.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, childDash.Id)
|
So(query.Result[1].ID, ShouldEqual, childDash.Id)
|
||||||
So(query.Result[2].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[2].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -171,10 +171,10 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 4)
|
So(len(query.Result), ShouldEqual, 4)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder1.Id)
|
So(query.Result[0].ID, ShouldEqual, folder1.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, folder2.Id)
|
So(query.Result[1].ID, ShouldEqual, folder2.Id)
|
||||||
So(query.Result[2].Id, ShouldEqual, childDash1.Id)
|
So(query.Result[2].ID, ShouldEqual, childDash1.Id)
|
||||||
So(query.Result[3].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[3].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
So(query.Result[0].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[0].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("and a dashboard is moved from folder with acl to the folder without an acl", func() {
|
Convey("and a dashboard is moved from folder with acl to the folder without an acl", func() {
|
||||||
@ -212,10 +212,10 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 4)
|
So(len(query.Result), ShouldEqual, 4)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder2.Id)
|
So(query.Result[0].ID, ShouldEqual, folder2.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, childDash1.Id)
|
So(query.Result[1].ID, ShouldEqual, childDash1.Id)
|
||||||
So(query.Result[2].Id, ShouldEqual, childDash2.Id)
|
So(query.Result[2].ID, ShouldEqual, childDash2.Id)
|
||||||
So(query.Result[3].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[3].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -236,10 +236,10 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
err := SearchDashboards(query)
|
err := SearchDashboards(query)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(len(query.Result), ShouldEqual, 4)
|
So(len(query.Result), ShouldEqual, 4)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder2.Id)
|
So(query.Result[0].ID, ShouldEqual, folder2.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, childDash1.Id)
|
So(query.Result[1].ID, ShouldEqual, childDash1.Id)
|
||||||
So(query.Result[2].Id, ShouldEqual, childDash2.Id)
|
So(query.Result[2].ID, ShouldEqual, childDash2.Id)
|
||||||
So(query.Result[3].Id, ShouldEqual, dashInRoot.Id)
|
So(query.Result[3].ID, ShouldEqual, dashInRoot.Id)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -267,8 +267,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder1.Id)
|
So(query.Result[0].ID, ShouldEqual, folder1.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, folder2.Id)
|
So(query.Result[1].ID, ShouldEqual, folder2.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("should have write access to all folders and dashboards", func() {
|
Convey("should have write access to all folders and dashboards", func() {
|
||||||
@ -320,8 +320,8 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder1.Id)
|
So(query.Result[0].ID, ShouldEqual, folder1.Id)
|
||||||
So(query.Result[1].Id, ShouldEqual, folder2.Id)
|
So(query.Result[1].ID, ShouldEqual, folder2.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("should have edit access to folders with default ACL", func() {
|
Convey("should have edit access to folders with default ACL", func() {
|
||||||
@ -352,7 +352,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder2.Id)
|
So(query.Result[0].ID, ShouldEqual, folder2.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("should have edit permission in folders", func() {
|
Convey("should have edit permission in folders", func() {
|
||||||
@ -416,7 +416,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
|
|||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
So(query.Result[0].Id, ShouldEqual, folder1.Id)
|
So(query.Result[0].ID, ShouldEqual, folder1.Id)
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("should not have edit permission in folders", func() {
|
Convey("should not have edit permission in folders", func() {
|
||||||
|
@ -277,7 +277,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
So(len(query.Result), ShouldEqual, 1)
|
So(len(query.Result), ShouldEqual, 1)
|
||||||
hit := query.Result[0]
|
hit := query.Result[0]
|
||||||
So(hit.Type, ShouldEqual, search.DashHitFolder)
|
So(hit.Type, ShouldEqual, search.DashHitFolder)
|
||||||
So(hit.Url, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
So(hit.URL, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
||||||
So(hit.FolderTitle, ShouldEqual, "")
|
So(hit.FolderTitle, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -337,12 +337,12 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
|
|
||||||
So(len(query.Result), ShouldEqual, 2)
|
So(len(query.Result), ShouldEqual, 2)
|
||||||
hit := query.Result[0]
|
hit := query.Result[0]
|
||||||
So(hit.Id, ShouldEqual, savedDash.Id)
|
So(hit.ID, ShouldEqual, savedDash.Id)
|
||||||
So(hit.Url, ShouldEqual, fmt.Sprintf("/d/%s/%s", savedDash.Uid, savedDash.Slug))
|
So(hit.URL, ShouldEqual, fmt.Sprintf("/d/%s/%s", savedDash.Uid, savedDash.Slug))
|
||||||
So(hit.FolderId, ShouldEqual, savedFolder.Id)
|
So(hit.FolderID, ShouldEqual, savedFolder.Id)
|
||||||
So(hit.FolderUid, ShouldEqual, savedFolder.Uid)
|
So(hit.FolderUID, ShouldEqual, savedFolder.Uid)
|
||||||
So(hit.FolderTitle, ShouldEqual, savedFolder.Title)
|
So(hit.FolderTitle, ShouldEqual, savedFolder.Title)
|
||||||
So(hit.FolderUrl, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
So(hit.FolderURL, ShouldEqual, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to search for dashboard by dashboard ids", func() {
|
Convey("Should be able to search for dashboard by dashboard ids", func() {
|
||||||
@ -436,8 +436,8 @@ func TestDashboard_SortingOptions(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Len(t, dashboards, 2)
|
require.Len(t, dashboards, 2)
|
||||||
assert.Equal(t, dashA.Id, dashboards[0].Id)
|
assert.Equal(t, dashA.Id, dashboards[0].ID)
|
||||||
assert.Equal(t, dashB.Id, dashboards[1].Id)
|
assert.Equal(t, dashB.Id, dashboards[1].ID)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +55,15 @@ func (b *Builder) buildSelect() {
|
|||||||
dashboard.folder_id,
|
dashboard.folder_id,
|
||||||
folder.uid AS folder_uid,
|
folder.uid AS folder_uid,
|
||||||
folder.slug AS folder_slug,
|
folder.slug AS folder_slug,
|
||||||
folder.title AS folder_title
|
folder.title AS folder_title `)
|
||||||
FROM `)
|
|
||||||
|
for _, f := range b.Filters {
|
||||||
|
if f, ok := f.(FilterSelect); ok {
|
||||||
|
b.sql.WriteString(fmt.Sprintf(", %s", f.Select()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.sql.WriteString(` FROM `)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) applyFilters() (ordering string) {
|
func (b *Builder) applyFilters() (ordering string) {
|
||||||
|
@ -33,6 +33,10 @@ type FilterLeftJoin interface {
|
|||||||
LeftJoin() string
|
LeftJoin() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FilterSelect interface {
|
||||||
|
Select() string
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeFolder = "dash-folder"
|
TypeFolder = "dash-folder"
|
||||||
TypeDashboard = "dash-db"
|
TypeDashboard = "dash-db"
|
||||||
|
@ -58,10 +58,10 @@ func TestBuilder_EqualResults_Basic(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Len(t, res, 1)
|
assert.Len(t, res, 1)
|
||||||
res[0].Uid = ""
|
res[0].UID = ""
|
||||||
assert.EqualValues(t, []sqlstore.DashboardSearchProjection{
|
assert.EqualValues(t, []sqlstore.DashboardSearchProjection{
|
||||||
{
|
{
|
||||||
Id: 1,
|
ID: 1,
|
||||||
Title: "A",
|
Title: "A",
|
||||||
Slug: "a",
|
Slug: "a",
|
||||||
Term: "templated",
|
Term: "templated",
|
||||||
|
Loading…
Reference in New Issue
Block a user