mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Allow to retrieve dashboards by uid (#48522)
* Add the possibility to get the dashboards by uid * Fix
This commit is contained in:
parent
84d4ce51ad
commit
43e34f3086
@ -435,8 +435,9 @@ type GetDashboardTagsQuery struct {
|
||||
}
|
||||
|
||||
type GetDashboardsQuery struct {
|
||||
DashboardIds []int64
|
||||
Result []*Dashboard
|
||||
DashboardIds []int64
|
||||
DashboardUIds []string
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
type GetDashboardPermissionsForUserQuery struct {
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@ -223,13 +225,19 @@ func (ss *SQLStore) GetDashboardTags(ctx context.Context, query *models.GetDashb
|
||||
|
||||
func (ss *SQLStore) GetDashboards(ctx context.Context, query *models.GetDashboardsQuery) error {
|
||||
return ss.WithDbSession(ctx, func(dbSession *DBSession) error {
|
||||
if len(query.DashboardIds) == 0 {
|
||||
if len(query.DashboardIds) == 0 && len(query.DashboardUIds) == 0 {
|
||||
return models.ErrCommandValidationFailed
|
||||
}
|
||||
|
||||
var dashboards = make([]*models.Dashboard, 0)
|
||||
var session *xorm.Session
|
||||
if len(query.DashboardIds) > 0 {
|
||||
session = dbSession.In("id", query.DashboardIds)
|
||||
} else {
|
||||
session = dbSession.In("uid", query.DashboardUIds)
|
||||
}
|
||||
|
||||
err := dbSession.In("id", query.DashboardIds).Find(&dashboards)
|
||||
err := session.Find(&dashboards)
|
||||
query.Result = dashboards
|
||||
return err
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user