Commit 7c741111 by Daniel Lee

search: add expanded folders

parent f47673ab
......@@ -54,15 +54,16 @@ type Query struct {
}
type FindPersistedDashboardsQuery struct {
Title string
OrgId int64
SignedInUser *models.SignedInUser
IsStarred bool
DashboardIds []int64
Type string
FolderId int64
Tags []string
Limit int
Title string
OrgId int64
SignedInUser *models.SignedInUser
IsStarred bool
DashboardIds []int64
Type string
FolderId int64
Tags []string
ExpandedFolders []int64
Limit int
Result HitList
}
......@@ -191,7 +191,9 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
limit = 1000
}
sb := NewSearchBuilder(query.SignedInUser, limit).WithTags(query.Tags).WithDashboardIdsIn(query.DashboardIds)
sb := NewSearchBuilder(query.SignedInUser, limit).
WithTags(query.Tags).
WithDashboardIdsIn(query.DashboardIds)
if query.IsStarred {
sb.IsStarred()
......@@ -209,6 +211,10 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
sb.WithFolderId(query.FolderId)
}
if len(query.ExpandedFolders) > 0 {
sb.WithExpandedFolders(query.ExpandedFolders)
}
var res []DashboardSearchProjection
sql, params := sb.ToSql()
......
......@@ -382,6 +382,19 @@ func TestDashboardDataAccess(t *testing.T) {
currentUser := createUser("viewer", "Viewer", false)
Convey("and one folder is expanded, the other collapsed", func() {
Convey("should return dashboards in root and expanded folder", func() {
query := &search.FindPersistedDashboardsQuery{ExpandedFolders: []int64{folder1.Id}, SignedInUser: &m.SignedInUser{UserId: currentUser.Id, OrgId: 1}, OrgId: 1}
err := SearchDashboards(query)
So(err, ShouldBeNil)
So(len(query.Result), ShouldEqual, 4)
So(query.Result[0].Id, ShouldEqual, folder1.Id)
So(query.Result[1].Id, ShouldEqual, folder2.Id)
So(query.Result[2].Id, ShouldEqual, childDash1.Id)
So(query.Result[3].Id, ShouldEqual, dashInRoot.Id)
})
})
Convey("and acl is set for one dashboard folder", func() {
var otherUser int64 = 999
updateTestDashboardWithAcl(folder1.Id, otherUser, m.PERMISSION_EDIT)
......
......@@ -18,6 +18,7 @@ type SearchBuilder struct {
whereTypeFolder bool
whereTypeDash bool
whereFolderId int64
expandedFolders []int64
sql bytes.Buffer
params []interface{}
}
......@@ -77,6 +78,12 @@ func (sb *SearchBuilder) WithFolderId(folderId int64) *SearchBuilder {
return sb
}
func (sb *SearchBuilder) WithExpandedFolders(expandedFolders []int64) *SearchBuilder {
sb.expandedFolders = expandedFolders
return sb
}
// ToSql builds the sql and returns it as a string, together with the params.
func (sb *SearchBuilder) ToSql() (string, []interface{}) {
sb.params = make([]interface{}, 0)
......@@ -209,4 +216,13 @@ func (sb *SearchBuilder) buildSearchWhereClause() {
sb.sql.WriteString(" AND dashboard.folder_id = ?")
sb.params = append(sb.params, sb.whereFolderId)
}
if len(sb.expandedFolders) > 0 {
sb.sql.WriteString(` AND (dashboard.folder_id IN (?` + strings.Repeat(",?", len(sb.expandedFolders)-1) + `) `)
sb.sql.WriteString(` OR dashboard.folder_id IS NULL OR dashboard.folder_id = 0)`)
for _, ef := range sb.expandedFolders {
sb.params = append(sb.params, ef)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment