From e2bbde932eb8f9c6faeabfbca5a2b2c4aaec8576 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 29 Apr 2026 11:43:08 +0300 Subject: [PATCH] Preferences: Remove unused/undocumented preferences api (#123784) --- pkg/api/api.go | 5 ----- pkg/api/preferences.go | 48 ------------------------------------------ 2 files changed, 53 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 257b4840f25..29ba3826c0a 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -396,11 +396,6 @@ func (hs *HTTPServer) registerRoutes() { // orgs (admin routes) apiRoute.Get("/orgs/name/:name/", authorizeInOrg(ac.UseGlobalOrg, ac.EvalPermission(ac.ActionOrgsRead)), routing.Wrap(hs.GetOrgByName)) - // Preferences - apiRoute.Group("/preferences", func(prefRoute routing.RouteRegister) { - prefRoute.Post("/set-home-dash", routing.Wrap(hs.SetHomeDashboard)) - }) - // Data sources apiRoute.Group("/datasources", func(datasourceRoute routing.RouteRegister) { idScope := datasources.ScopeProvider.GetResourceScope(ac.Parameter(":id")) diff --git a/pkg/api/preferences.go b/pkg/api/preferences.go index f5760209c53..4189cae528b 100644 --- a/pkg/api/preferences.go +++ b/pkg/api/preferences.go @@ -15,54 +15,6 @@ import ( "github.com/grafana/grafana/pkg/web" ) -// POST /api/preferences/set-home-dash -func (hs *HTTPServer) SetHomeDashboard(c *contextmodel.ReqContext) response.Response { - cmd := pref.SavePreferenceCommand{} - if err := web.Bind(c.Req, &cmd); err != nil { - return response.Error(http.StatusBadRequest, "bad request data", err) - } - - userID, err := identity.UserIdentifier(c.GetID()) - if err != nil { - return response.Error(http.StatusInternalServerError, "Failed to set home dashboard", err) - } - - cmd.UserID = userID - cmd.OrgID = c.GetOrgID() - - // convert dashboard UID to ID in order to store internally if it exists in the query, otherwise take the id from query - // nolint:staticcheck - dashboardID := cmd.HomeDashboardID - if cmd.HomeDashboardUID != nil { - query := dashboards.GetDashboardQuery{UID: *cmd.HomeDashboardUID} - if query.UID == "" { - dashboardID = 0 // clear the value - } else { - queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query) - if err != nil { - return response.Error(http.StatusNotFound, "Dashboard not found", err) - } - dashboardID = queryResult.ID - } - } else if cmd.HomeDashboardID != 0 { // nolint:staticcheck - // make sure uid is always set if id is set - queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &dashboards.GetDashboardQuery{ID: cmd.HomeDashboardID, OrgID: cmd.OrgID}) // nolint:staticcheck - if err != nil { - return response.Error(http.StatusNotFound, "Dashboard not found", err) - } - cmd.HomeDashboardUID = &queryResult.UID - } - - // nolint:staticcheck - cmd.HomeDashboardID = dashboardID - - if err := hs.preferenceService.Save(c.Req.Context(), &cmd); err != nil { - return response.ErrOrFallback(http.StatusInternalServerError, "Failed to set home dashboard", err) - } - - return response.Success("Home dashboard set") -} - // swagger:route GET /user/preferences signed_in_user preferences getUserPreferences // // Get user preferences.