mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
Search: Fix only searching for folder id zero (#44175)
Fixes so that searching for folder id zero in folder/dashboard search returns dashboards located in the general folder and not including all folders as it did before. Fixes #40273
This commit is contained in:
parent
da98ebdcdf
commit
007cd144a9
@ -305,7 +305,7 @@ func (ss *SQLStore) findDashboards(ctx context.Context, query *search.FindPersis
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(query.FolderIds) > 0 {
|
if len(query.FolderIds) > 0 {
|
||||||
filters = append(filters, searchstore.FolderFilter{IDs: query.FolderIds})
|
filters = append(filters, searchstore.FolderFilter{Dialect: dialect, IDs: query.FolderIds})
|
||||||
}
|
}
|
||||||
|
|
||||||
var res []DashboardSearchProjection
|
var res []DashboardSearchProjection
|
||||||
|
@ -384,6 +384,24 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
require.Equal(t, hit.FolderURL, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
require.Equal(t, hit.FolderURL, fmt.Sprintf("/dashboards/f/%s/%s", savedFolder.Uid, savedFolder.Slug))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Should be able to search for general folder's children", func(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
query := search.FindPersistedDashboardsQuery{
|
||||||
|
OrgId: 1,
|
||||||
|
FolderIds: []int64{0},
|
||||||
|
SignedInUser: &models.SignedInUser{OrgId: 1, OrgRole: models.ROLE_EDITOR},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := sqlStore.SearchDashboards(context.Background(), &query)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, len(query.Result), 1)
|
||||||
|
hit := query.Result[0]
|
||||||
|
require.Equal(t, savedDash2.Id, hit.ID)
|
||||||
|
require.Equal(t, fmt.Sprintf("/d/%s/%s", savedDash2.Uid, savedDash2.Slug), hit.URL)
|
||||||
|
require.Equal(t, int64(0), hit.FolderID)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Should be able to search for dashboard by dashboard ids", func(t *testing.T) {
|
t.Run("Should be able to search for dashboard by dashboard ids", func(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
query := search.FindPersistedDashboardsQuery{
|
query := search.FindPersistedDashboardsQuery{
|
||||||
|
@ -87,10 +87,16 @@ func (f TitleFilter) Where() (string, []interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FolderFilter struct {
|
type FolderFilter struct {
|
||||||
IDs []int64
|
Dialect migrator.Dialect
|
||||||
|
IDs []int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FolderFilter) Where() (string, []interface{}) {
|
func (f FolderFilter) Where() (string, []interface{}) {
|
||||||
|
if len(f.IDs) == 1 && f.IDs[0] == 0 {
|
||||||
|
sql := fmt.Sprintf("dashboard.folder_id = 0 AND dashboard.is_folder = %s", f.Dialect.BooleanStr(false))
|
||||||
|
return sql, []interface{}{}
|
||||||
|
}
|
||||||
|
|
||||||
return sqlIDin("dashboard.folder_id", f.IDs)
|
return sqlIDin("dashboard.folder_id", f.IDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user