Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
d6ed8c52
Unverified
Commit
d6ed8c52
authored
Jun 17, 2020
by
Torkel Ödegaard
Committed by
GitHub
Jun 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dashboard: Redirects for old edit & view panel urls (#25653)
parent
d1b230f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
2 deletions
+47
-2
pkg/api/api.go
+3
-2
pkg/middleware/dashboard_redirect.go
+27
-0
pkg/middleware/dashboard_redirect_test.go
+17
-0
No files found.
pkg/api/api.go
View file @
d6ed8c52
...
...
@@ -18,6 +18,7 @@ func (hs *HTTPServer) registerRoutes() {
reqSnapshotPublicModeOrSignedIn
:=
middleware
.
SnapshotPublicModeOrSignedIn
()
redirectFromLegacyDashboardURL
:=
middleware
.
RedirectFromLegacyDashboardURL
()
redirectFromLegacyDashboardSoloURL
:=
middleware
.
RedirectFromLegacyDashboardSoloURL
()
redirectFromLegacyPanelEditURL
:=
middleware
.
RedirectFromLegacyPanelEditURL
()
quota
:=
middleware
.
Quota
(
hs
.
QuotaService
)
bind
:=
binding
.
Bind
...
...
@@ -65,8 +66,8 @@ func (hs *HTTPServer) registerRoutes() {
r
.
Get
(
"/plugins/:id/page/:page"
,
reqSignedIn
,
hs
.
Index
)
r
.
Get
(
"/a/:id/*"
,
reqSignedIn
,
hs
.
Index
)
// App Root Page
r
.
Get
(
"/d/:uid/:slug"
,
reqSignedIn
,
hs
.
Index
)
r
.
Get
(
"/d/:uid"
,
reqSignedIn
,
hs
.
Index
)
r
.
Get
(
"/d/:uid/:slug"
,
reqSignedIn
,
redirectFromLegacyPanelEditURL
,
hs
.
Index
)
r
.
Get
(
"/d/:uid"
,
reqSignedIn
,
redirectFromLegacyPanelEditURL
,
hs
.
Index
)
r
.
Get
(
"/dashboard/db/:slug"
,
reqSignedIn
,
redirectFromLegacyDashboardURL
,
hs
.
Index
)
r
.
Get
(
"/dashboard/script/*"
,
reqSignedIn
,
hs
.
Index
)
r
.
Get
(
"/dashboard-solo/snapshot/*"
,
hs
.
Index
)
...
...
pkg/middleware/dashboard_redirect.go
View file @
d6ed8c52
...
...
@@ -34,6 +34,33 @@ func RedirectFromLegacyDashboardURL() macaron.Handler {
}
}
// 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
()
macaron
.
Handler
{
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
:=
setting
.
ToAbsUrl
(
fmt
.
Sprintf
(
"%s?%s"
,
strings
.
TrimPrefix
(
c
.
Req
.
URL
.
Path
,
"/"
),
queryParams
.
Encode
()))
c
.
Redirect
(
newURL
,
301
)
}
}
}
func
RedirectFromLegacyDashboardSoloURL
()
macaron
.
Handler
{
return
func
(
c
*
models
.
ReqContext
)
{
slug
:=
c
.
Params
(
"slug"
)
...
...
pkg/middleware/dashboard_redirect_test.go
View file @
d6ed8c52
...
...
@@ -55,4 +55,21 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
})
})
})
Convey
(
"Given the dashboard legacy edit panel middleware"
,
t
,
func
()
{
bus
.
ClearBusHandlers
()
middlewareScenario
(
t
,
"GET dashboard by legacy edit url"
,
func
(
sc
*
scenarioContext
)
{
sc
.
m
.
Get
(
"/d/:uid/:slug"
,
RedirectFromLegacyPanelEditURL
(),
sc
.
defaultHandler
)
sc
.
fakeReqWithParams
(
"GET"
,
"/d/asd/dash?orgId=1&panelId=12&fullscreen&edit"
,
map
[
string
]
string
{})
.
exec
()
Convey
(
"Should redirect to new dashboard edit url with a 301 Moved Permanently"
,
func
()
{
So
(
sc
.
resp
.
Code
,
ShouldEqual
,
301
)
redirectURL
,
_
:=
sc
.
resp
.
Result
()
.
Location
()
So
(
redirectURL
.
String
(),
ShouldEqual
,
"/d/asd/d/asd/dash?editPanel=12&orgId=1"
)
})
})
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment