Stars: Add dashboard_uid and org_id to table (#96408)
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
@@ -16,15 +18,18 @@ import (
|
||||
type API struct {
|
||||
starService star.Service
|
||||
dashboardService dashboards.DashboardService
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func ProvideApi(
|
||||
starService star.Service,
|
||||
dashboardService dashboards.DashboardService,
|
||||
) *API {
|
||||
starLogger := log.New("stars.api")
|
||||
api := &API{
|
||||
starService: starService,
|
||||
dashboardService: dashboardService,
|
||||
logger: starLogger,
|
||||
}
|
||||
return api
|
||||
}
|
||||
@@ -63,11 +68,11 @@ func (api *API) GetStars(c *contextmodel.ReqContext) response.Response {
|
||||
|
||||
uids := []string{}
|
||||
if len(iuserstars.UserStars) > 0 {
|
||||
var ids []int64
|
||||
for id := range iuserstars.UserStars {
|
||||
ids = append(ids, id)
|
||||
var uids []string
|
||||
for uid := range iuserstars.UserStars {
|
||||
uids = append(uids, uid)
|
||||
}
|
||||
starredDashboards, err := api.dashboardService.GetDashboards(c.Req.Context(), &dashboards.GetDashboardsQuery{DashboardIDs: ids, OrgID: c.SignedInUser.GetOrgID()})
|
||||
starredDashboards, err := api.dashboardService.GetDashboards(c.Req.Context(), &dashboards.GetDashboardsQuery{DashboardUIDs: uids, OrgID: c.SignedInUser.GetOrgID()})
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to fetch dashboards", err)
|
||||
}
|
||||
@@ -106,7 +111,10 @@ func (api *API) StarDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard ID", nil)
|
||||
}
|
||||
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: id}
|
||||
api.logger.Warn("POST /user/stars/dashboard/{dashboard_id} is deprecated, please use POST /user/stars/dashboard/uid/{dashboard_uid} instead")
|
||||
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: id, Updated: time.Now()}
|
||||
// nolint:staticcheck
|
||||
if cmd.DashboardID <= 0 {
|
||||
return response.Error(http.StatusBadRequest, "Missing dashboard id", nil)
|
||||
}
|
||||
@@ -146,7 +154,7 @@ func (api *API) StarDashboardByUID(c *contextmodel.ReqContext) response.Response
|
||||
return rsp
|
||||
}
|
||||
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: dash.ID}
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: dash.ID, DashboardUID: uid, OrgID: c.SignedInUser.GetOrgID(), Updated: time.Now()}
|
||||
|
||||
if err := api.starService.Add(c.Req.Context(), &cmd); err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to star dashboard", err)
|
||||
@@ -182,7 +190,10 @@ func (api *API) UnstarDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
return response.Error(http.StatusBadRequest, "Only users and service accounts can star dashboards", nil)
|
||||
}
|
||||
|
||||
api.logger.Warn("DELETE /user/stars/dashboard/{dashboard_id} is deprecated, please use DELETE /user/stars/dashboard/uid/{dashboard_uid} instead")
|
||||
|
||||
cmd := star.UnstarDashboardCommand{UserID: userID, DashboardID: id}
|
||||
// nolint:staticcheck
|
||||
if cmd.DashboardID <= 0 {
|
||||
return response.Error(http.StatusBadRequest, "Missing dashboard id", nil)
|
||||
}
|
||||
@@ -217,12 +228,7 @@ func (api *API) UnstarDashboardByUID(c *contextmodel.ReqContext) response.Respon
|
||||
return response.Error(http.StatusBadRequest, "Only users and service accounts can star dashboards", nil)
|
||||
}
|
||||
|
||||
dash, rsp := api.getDashboardHelper(c.Req.Context(), c.SignedInUser.GetOrgID(), 0, uid)
|
||||
if rsp != nil {
|
||||
return rsp
|
||||
}
|
||||
|
||||
cmd := star.UnstarDashboardCommand{UserID: userID, DashboardID: dash.ID}
|
||||
cmd := star.UnstarDashboardCommand{UserID: userID, DashboardUID: uid, OrgID: c.SignedInUser.GetOrgID()}
|
||||
|
||||
if err := api.starService.Delete(c.Req.Context(), &cmd); err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to unstar dashboard", err)
|
||||
|
||||
Reference in New Issue
Block a user