/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/services/star/api/api.go
128 строк
4 KB
Mustafa Sencer Özcan
fix: starred dashboards nav tree display (#124841)
14 май 2026, 14:54
Не верифицирован
14 май 2026, 14:54
4453ac1
Код
Авторство
О чём код?
package api import ( "net/http" "github.com/grafana/grafana-app-sdk/logging" "github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model" "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/star" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/web" ) type API struct { client K8sClients } func ProvideApi( cfg *setting.Cfg, // for namespacer features featuremgmt.FeatureToggles, _ star.Service, client K8sClients, ) *API { return &API{ client: client, } } // ProvideK8sClients constructs the K8sClients used by the legacy /api/user/stars // HTTP handlers. It is exposed as a separate provider so other services (e.g. // navtree) can read stars through the collections API rather than the legacy // SQL `star` table — the SQL table is empty when the stars resource is in // dual-writer mode 5 (unified storage). func ProvideK8sClients(cfg *setting.Cfg, configProvider apiserver.DirectRestConfigProvider) K8sClients { return &k8sClients{ namespacer: request.GetNamespaceMapper(cfg), configProvider: configProvider, } } func (api *API) GetStars(c *contextmodel.ReqContext) response.Response { stars, err := api.client.GetStars(c) if err != nil { logging.FromContext(c.Req.Context()).With("logger", "star.api").Warn("error", "err", err) } return response.JSON(http.StatusOK, stars) } // swagger:route POST /user/stars/dashboard/uid/{dashboard_uid} signed_in_user starDashboardByUID // // Star a dashboard. // // Stars the given Dashboard for the actual user. // // Responses: // 200: okResponse // 400: badRequestError // 401: unauthorisedError // 403: forbiddenError // 500: internalServerError func (api *API) StarDashboardByUID(c *contextmodel.ReqContext) response.Response { uid := web.Params(c.Req)[":uid"] if uid == "" { return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil) } err := api.client.AddStar(c, uid) if err != nil { return response.Error(http.StatusInternalServerError, "Failed to star dashboard", err) } return response.Success("Dashboard starred!") } // swagger:route DELETE /user/stars/dashboard/uid/{dashboard_uid} signed_in_user unstarDashboardByUID // // Unstar a dashboard. // // Deletes the starring of the given Dashboard for the actual user. // // Responses: // 200: okResponse // 400: badRequestError // 401: unauthorisedError // 403: forbiddenError // 500: internalServerError func (api *API) UnstarDashboardByUID(c *contextmodel.ReqContext) response.Response { uid := web.Params(c.Req)[":uid"] if uid == "" { return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil) } err := api.client.RemoveStar(c, uid) if err != nil { return response.Error(http.StatusInternalServerError, "Failed to unstar dashboard", err) } return response.Success("Dashboard unstarred") } // swagger:parameters starDashboard type StarDashboardParams struct { // in:path // required:true DashboardID string `json:"dashboard_id"` } // swagger:parameters starDashboardByUID type StarDashboardByUIDParams struct { // in:path // required:true DashboardUID string `json:"dashboard_uid"` } // swagger:parameters unstarDashboard type UnstarDashboardParams struct { // in:path // required:true DashboardID string `json:"dashboard_id"` } // swagger:parameters unstarDashboardByUID type UnstarDashboardByUIDParams struct { // in:path // required:true DashboardUID string `json:"dashboard_uid"` }