grafana/pkg/middleware/dashboard_redirect.go
Dimitris Sotirakis 1c49986b2f
Chore: Remove endpoints that contain the slug field (#35104)
* Chore: Remove endpoints that contain the slug field

* More cleanups

* Lint fixes

* Remove unnecessary funcs

* Cleanup frontend code

* Remove deprecated endpoints from docs

* Revert change according to reviewer's comments
2021-06-03 16:20:13 +03:00

37 lines
985 B
Go

package middleware
import (
"fmt"
"strings"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
// In Grafana v7.0 we changed panel edit & view query parameters.
// This middleware tries to detect those old url parameters and direct to the new url query params
func RedirectFromLegacyPanelEditURL(cfg *setting.Cfg) func(c *models.ReqContext) {
return func(c *models.ReqContext) {
queryParams := c.Req.URL.Query()
panelID, hasPanelID := queryParams["panelId"]
_, hasFullscreen := queryParams["fullscreen"]
_, hasEdit := queryParams["edit"]
if hasPanelID && hasFullscreen {
delete(queryParams, "panelId")
delete(queryParams, "fullscreen")
delete(queryParams, "edit")
if hasEdit {
queryParams["editPanel"] = panelID
} else {
queryParams["viewPanel"] = panelID
}
newURL := fmt.Sprintf("%s%s?%s", cfg.AppURL, strings.TrimPrefix(c.Req.URL.Path, "/"), queryParams.Encode())
c.Redirect(newURL, 301)
}
}
}