Playlist: Remove unused/deprecated api and unused wrapper (#75503)
This commit is contained in:
@@ -520,7 +520,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
playlistRoute.Get("/", routing.Wrap(hs.SearchPlaylists))
|
||||
playlistRoute.Get("/:uid", hs.ValidateOrgPlaylist, routing.Wrap(hs.GetPlaylist))
|
||||
playlistRoute.Get("/:uid/items", hs.ValidateOrgPlaylist, routing.Wrap(hs.GetPlaylistItems))
|
||||
playlistRoute.Get("/:uid/dashboards", hs.ValidateOrgPlaylist, routing.Wrap(hs.GetPlaylistDashboards))
|
||||
playlistRoute.Delete("/:uid", reqEditorRole, hs.ValidateOrgPlaylist, routing.Wrap(hs.DeletePlaylist))
|
||||
playlistRoute.Put("/:uid", reqEditorRole, hs.ValidateOrgPlaylist, routing.Wrap(hs.UpdatePlaylist))
|
||||
playlistRoute.Post("/", reqEditorRole, routing.Wrap(hs.CreatePlaylist))
|
||||
|
||||
@@ -104,27 +104,6 @@ func (hs *HTTPServer) GetPlaylistItems(c *contextmodel.ReqContext) response.Resp
|
||||
return response.JSON(http.StatusOK, dto.Items)
|
||||
}
|
||||
|
||||
// swagger:route GET /playlists/{uid}/dashboards playlists getPlaylistDashboards
|
||||
//
|
||||
// Get playlist dashboards.
|
||||
//
|
||||
// Responses:
|
||||
// 200: getPlaylistDashboardsResponse
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetPlaylistDashboards(c *contextmodel.ReqContext) response.Response {
|
||||
playlistUID := web.Params(c.Req)[":uid"]
|
||||
|
||||
playlists, err := hs.LoadPlaylistDashboards(c.Req.Context(), c.OrgID, c.SignedInUser, playlistUID)
|
||||
if err != nil {
|
||||
return response.Error(500, "Could not load dashboards", err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, playlists)
|
||||
}
|
||||
|
||||
// swagger:route DELETE /playlists/{uid} playlists deletePlaylist
|
||||
//
|
||||
// Delete playlist.
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
_ "github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/search"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
)
|
||||
|
||||
func (hs *HTTPServer) populateDashboardsByID(ctx context.Context, dashboardByIDs []int64, dashboardIDOrder map[int64]int) (dtos.PlaylistDashboardsSlice, error) {
|
||||
result := make(dtos.PlaylistDashboardsSlice, 0)
|
||||
|
||||
if len(dashboardByIDs) > 0 {
|
||||
dashboardQuery := dashboards.GetDashboardsQuery{DashboardIDs: dashboardByIDs}
|
||||
dashboardQueryResult, err := hs.DashboardService.GetDashboards(ctx, &dashboardQuery)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
for _, item := range dashboardQueryResult {
|
||||
result = append(result, dtos.PlaylistDashboard{
|
||||
Id: item.ID,
|
||||
Slug: item.Slug,
|
||||
Title: item.Title,
|
||||
Uri: "db/" + item.Slug,
|
||||
Url: dashboards.GetDashboardURL(item.UID, item.Slug),
|
||||
Order: dashboardIDOrder[item.ID],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) populateDashboardsByTag(ctx context.Context, orgID int64, signedInUser *user.SignedInUser, dashboardByTag []string, dashboardTagOrder map[string]int) dtos.PlaylistDashboardsSlice {
|
||||
result := make(dtos.PlaylistDashboardsSlice, 0)
|
||||
|
||||
for _, tag := range dashboardByTag {
|
||||
searchQuery := search.Query{
|
||||
Title: "",
|
||||
Tags: []string{tag},
|
||||
SignedInUser: signedInUser,
|
||||
Limit: 100,
|
||||
IsStarred: false,
|
||||
OrgId: orgID,
|
||||
}
|
||||
|
||||
hits, err := hs.SearchService.SearchHandler(ctx, &searchQuery)
|
||||
if err == nil {
|
||||
for _, item := range hits {
|
||||
result = append(result, dtos.PlaylistDashboard{
|
||||
Id: item.ID,
|
||||
Slug: item.Slug,
|
||||
Title: item.Title,
|
||||
Uri: item.URI,
|
||||
Url: item.URL,
|
||||
Order: dashboardTagOrder[tag],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Deprecated -- the frontend can do this better
|
||||
func (hs *HTTPServer) LoadPlaylistDashboards(ctx context.Context, orgID int64, signedInUser *user.SignedInUser, playlistUID string) (dtos.PlaylistDashboardsSlice, error) {
|
||||
result := make(dtos.PlaylistDashboardsSlice, 0)
|
||||
dto, err := hs.playlistService.Get(ctx,
|
||||
&playlist.GetPlaylistByUidQuery{UID: playlistUID, OrgId: orgID})
|
||||
if err != nil || dto == nil || dto.Items == nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
playlistItems := dto.Items
|
||||
|
||||
dashboardByIDs := make([]int64, 0)
|
||||
dashboardByTag := make([]string, 0)
|
||||
dashboardIDOrder := make(map[int64]int)
|
||||
dashboardTagOrder := make(map[string]int)
|
||||
|
||||
for i, item := range playlistItems {
|
||||
switch item.Type {
|
||||
case "dashboard_by_id":
|
||||
dashboardID, _ := strconv.ParseInt(item.Value, 10, 64)
|
||||
dashboardByIDs = append(dashboardByIDs, dashboardID)
|
||||
dashboardIDOrder[dashboardID] = i
|
||||
case "dashboard_by_tag":
|
||||
dashboardByTag = append(dashboardByTag, item.Value)
|
||||
dashboardTagOrder[item.Value] = i
|
||||
case "dashboard_by_uid":
|
||||
return nil, errors.New("dashboard_by_uid not supported by this deprecated API")
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
k, _ := hs.populateDashboardsByID(ctx, dashboardByIDs, dashboardIDOrder)
|
||||
result = append(result, k...)
|
||||
result = append(result, hs.populateDashboardsByTag(ctx, orgID, signedInUser, dashboardByTag, dashboardTagOrder)...)
|
||||
|
||||
sort.Sort(result)
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user