ShortURL: Fix tests and small refactor (#108871)
This commit is contained in:
+3
-4
@@ -176,7 +176,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
r.Get("/import/dashboard", reqSignedIn, hs.Index)
|
||||
r.Get("/dashboards/", reqSignedIn, hs.Index)
|
||||
r.Get("/dashboards/*", reqSignedIn, hs.Index)
|
||||
r.Get("/goto/:uid", reqSignedIn, hs.redirectFromShortURL, hs.Index)
|
||||
|
||||
if hs.Cfg.PublicDashboardsEnabled {
|
||||
// list public dashboards
|
||||
@@ -264,6 +263,9 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
providerParam := ac.Parameter(":provider")
|
||||
r.Get("/admin/authentication/:provider", authorize(ac.EvalPermission(ac.ActionSettingsRead, ac.ScopeSettingsOAuth(providerParam))), hs.Index)
|
||||
|
||||
// ShortURL API
|
||||
hs.registerShortURLAPI(r)
|
||||
|
||||
// authed api
|
||||
r.Group("/api", func(apiRoute routing.RouteRegister) {
|
||||
// user (signed in)
|
||||
@@ -549,9 +551,6 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
// Some channels may have info
|
||||
liveRoute.Get("/info/*", routing.Wrap(hs.Live.HandleInfoHTTP))
|
||||
}, requestmeta.SetSLOGroup(requestmeta.SLOGroupNone))
|
||||
|
||||
// short urls
|
||||
apiRoute.Post("/short-urls", routing.Wrap(hs.createShortURL))
|
||||
}, reqSignedIn)
|
||||
|
||||
// admin api
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -14,6 +16,12 @@ import (
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
func (hs *HTTPServer) registerShortURLAPI(apiRoute routing.RouteRegister) {
|
||||
reqSignedIn := middleware.ReqSignedIn
|
||||
apiRoute.Post("/api/short-urls", reqSignedIn, hs.createShortURL)
|
||||
apiRoute.Get("/goto/:uid", reqSignedIn, hs.redirectFromShortURL, hs.Index)
|
||||
}
|
||||
|
||||
// createShortURL handles requests to create short URLs.
|
||||
func (hs *HTTPServer) createShortURL(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := dtos.CreateShortURLCmd{}
|
||||
|
||||
Reference in New Issue
Block a user