Preferences: Remove unused/undocumented preferences api (#123784)

This commit is contained in:
Ryan McKinley 2026-04-29 11:43:08 +03:00 committed by GitHub
parent 63a8a027e8
commit e2bbde932e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 0 additions and 53 deletions

View file

@ -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"))

View file

@ -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.