mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add dashboard retrieval by FolderUID (#80288)
* Add dashboard retrieval by uid Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>
This commit is contained in:
parent
12135998e6
commit
1947919516
@ -813,7 +813,7 @@ func (d *dashboardStore) GetDashboard(ctx context.Context, query *dashboards.Get
|
|||||||
var queryResult *dashboards.Dashboard
|
var queryResult *dashboards.Dashboard
|
||||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
if query.ID == 0 && len(query.UID) == 0 && (query.Title == nil || query.FolderID == nil) {
|
if query.ID == 0 && len(query.UID) == 0 && (query.Title == nil || (query.FolderID == nil && query.FolderUID == "")) {
|
||||||
return dashboards.ErrDashboardIdentifierNotSet
|
return dashboards.ErrDashboardIdentifierNotSet
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,15 +823,17 @@ func (d *dashboardStore) GetDashboard(ctx context.Context, query *dashboards.Get
|
|||||||
dashboard.Title = *query.Title
|
dashboard.Title = *query.Title
|
||||||
mustCols = append(mustCols, "title")
|
mustCols = append(mustCols, "title")
|
||||||
}
|
}
|
||||||
// nolint:staticcheck
|
|
||||||
if query.FolderID != nil {
|
if query.FolderUID != "" {
|
||||||
|
dashboard.FolderUID = query.FolderUID
|
||||||
|
mustCols = append(mustCols, "folder_uid")
|
||||||
|
} else if query.FolderID != nil { // nolint:staticcheck
|
||||||
// nolint:staticcheck
|
// nolint:staticcheck
|
||||||
dashboard.FolderID = *query.FolderID
|
dashboard.FolderID = *query.FolderID
|
||||||
mustCols = append(mustCols, "folder_id")
|
mustCols = append(mustCols, "folder_id")
|
||||||
}
|
}
|
||||||
|
|
||||||
has, err := sess.MustCols(mustCols...).Get(&dashboard)
|
has, err := sess.MustCols(mustCols...).Get(&dashboard)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
|
@ -108,6 +108,23 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
|||||||
require.False(t, queryResult.IsFolder)
|
require.False(t, queryResult.IsFolder)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Should be able to get dashboard by title and folderUID", func(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
query := dashboards.GetDashboardQuery{
|
||||||
|
Title: util.Pointer("test dash 23"),
|
||||||
|
FolderUID: savedFolder.UID,
|
||||||
|
OrgID: 1,
|
||||||
|
}
|
||||||
|
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, queryResult.Title, "test dash 23")
|
||||||
|
require.Equal(t, queryResult.Slug, "test-dash-23")
|
||||||
|
require.Equal(t, queryResult.ID, savedDash.ID)
|
||||||
|
require.Equal(t, queryResult.UID, savedDash.UID)
|
||||||
|
require.False(t, queryResult.IsFolder)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Should not be able to get dashboard by title alone", func(t *testing.T) {
|
t.Run("Should not be able to get dashboard by title alone", func(t *testing.T) {
|
||||||
setup()
|
setup()
|
||||||
query := dashboards.GetDashboardQuery{
|
query := dashboards.GetDashboardQuery{
|
||||||
|
@ -249,6 +249,7 @@ type GetDashboardQuery struct {
|
|||||||
Title *string
|
Title *string
|
||||||
// Deprecated: use FolderUID instead
|
// Deprecated: use FolderUID instead
|
||||||
FolderID *int64
|
FolderID *int64
|
||||||
|
FolderUID string
|
||||||
OrgID int64
|
OrgID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user