mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
DashboardAPI: convert internal ids to uids (#48990)
This commit is contained in:
parent
ea1001f1f5
commit
ff844f0599
@ -391,6 +391,9 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
dashboardRoute.Get("/home", routing.Wrap(hs.GetHomeDashboard))
|
dashboardRoute.Get("/home", routing.Wrap(hs.GetHomeDashboard))
|
||||||
dashboardRoute.Get("/tags", hs.GetDashboardTags)
|
dashboardRoute.Get("/tags", hs.GetDashboardTags)
|
||||||
|
|
||||||
|
// Deprecated: used to convert internal IDs to UIDs
|
||||||
|
dashboardRoute.Get("/ids/:ids", authorize(reqSignedIn, ac.EvalPermission(dashboards.ActionDashboardsRead)), hs.GetDashboardUIDs)
|
||||||
|
|
||||||
// Deprecated: use /uid/:uid API instead.
|
// Deprecated: use /uid/:uid API instead.
|
||||||
dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
|
dashboardRoute.Group("/id/:dashboardId", func(dashIdRoute routing.RouteRegister) {
|
||||||
dashIdRoute.Get("/versions", authorize(reqSignedIn, ac.EvalPermission(dashboards.ActionDashboardsWrite)), routing.Wrap(hs.GetDashboardVersions))
|
dashIdRoute.Get("/versions", authorize(reqSignedIn, ac.EvalPermission(dashboards.ActionDashboardsWrite)), routing.Wrap(hs.GetDashboardVersions))
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
@ -727,3 +728,24 @@ func (hs *HTTPServer) GetDashboardTags(c *models.ReqContext) {
|
|||||||
|
|
||||||
c.JSON(http.StatusOK, query.Result)
|
c.JSON(http.StatusOK, query.Result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDashboardUIDs converts internal ids to UIDs
|
||||||
|
func (hs *HTTPServer) GetDashboardUIDs(c *models.ReqContext) {
|
||||||
|
ids := strings.Split(web.Params(c.Req)[":ids"], ",")
|
||||||
|
uids := make([]string, 0, len(ids))
|
||||||
|
|
||||||
|
q := &models.GetDashboardRefByIdQuery{}
|
||||||
|
for _, idstr := range ids {
|
||||||
|
id, err := strconv.ParseInt(idstr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
q.Id = id
|
||||||
|
err = hs.SQLStore.GetDashboardUIDById(c.Req.Context(), q)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uids = append(uids, q.Result.Uid)
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, uids)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user