Skip to content

Commit eacee08

Browse files
jalevinpianohackerowensmallwood
authored
public dashboards: move into into its own service (grafana#51358)
This PR moves public dashboards into its own self contained service including API, Service, Database, and Models. Routes are mounted on the Grafana HTTPServer by the API service at injection time with wire.go. The main route that loads the frontend for public dashboards is still handled by the API package. Co-authored-by: Jesse Weaver <[email protected]> Co-authored-by: Owen Smallwood <[email protected]>
1 parent ba2d8cd commit eacee08

23 files changed

+1631
-1197
lines changed

pkg/api/api.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/grafana/grafana/pkg/services/dashboards"
1414
"github.com/grafana/grafana/pkg/services/datasources"
1515
"github.com/grafana/grafana/pkg/services/featuremgmt"
16+
publicdashboardsapi "github.com/grafana/grafana/pkg/services/publicdashboards/api"
1617
"github.com/grafana/grafana/pkg/services/serviceaccounts"
1718
"github.com/grafana/grafana/pkg/web"
1819
)
@@ -103,6 +104,10 @@ func (hs *HTTPServer) registerRoutes() {
103104
r.Get("/dashboards/*", reqSignedIn, hs.Index)
104105
r.Get("/goto/:uid", reqSignedIn, hs.redirectFromShortURL, hs.Index)
105106

107+
if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) {
108+
r.Get("/public-dashboards/:accessToken", publicdashboardsapi.SetPublicDashboardFlag(), hs.Index)
109+
}
110+
106111
r.Get("/explore", authorize(func(c *models.ReqContext) {
107112
if f, ok := reqSignedIn.(func(c *models.ReqContext)); ok {
108113
f(c)
@@ -391,11 +396,6 @@ func (hs *HTTPServer) registerRoutes() {
391396
})
392397

393398
dashboardRoute.Group("/uid/:uid", func(dashUidRoute routing.RouteRegister) {
394-
if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) {
395-
dashUidRoute.Get("/public-config", authorize(reqSignedIn, ac.EvalPermission(dashboards.ActionDashboardsWrite)), routing.Wrap(hs.GetPublicDashboardConfig))
396-
dashUidRoute.Post("/public-config", authorize(reqSignedIn, ac.EvalPermission(dashboards.ActionDashboardsWrite)), routing.Wrap(hs.SavePublicDashboardConfig))
397-
}
398-
399399
if hs.ThumbService != nil {
400400
dashUidRoute.Get("/img/:kind/:theme", hs.ThumbService.GetImage)
401401
if hs.Features.IsEnabled(featuremgmt.FlagDashboardPreviewsAdmin) {
@@ -598,7 +598,7 @@ func (hs *HTTPServer) registerRoutes() {
598598
// grafana.net proxy
599599
r.Any("/api/gnet/*", reqSignedIn, hs.ProxyGnetRequest)
600600

601-
// Gravatar service.
601+
// Gravatar service
602602
r.Get("/avatar/:hash", hs.AvatarCacheServer.Handler)
603603

604604
// Snapshots
@@ -608,13 +608,6 @@ func (hs *HTTPServer) registerRoutes() {
608608
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, routing.Wrap(hs.DeleteDashboardSnapshotByDeleteKey))
609609
r.Delete("/api/snapshots/:key", reqEditorRole, routing.Wrap(hs.DeleteDashboardSnapshot))
610610

611-
// Public API
612-
if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) {
613-
r.Get("/public-dashboards/:accessToken", middleware.SetPublicDashboardFlag(), hs.Index)
614-
r.Get("/api/public/dashboards/:accessToken", routing.Wrap(hs.GetPublicDashboard))
615-
r.Post("/api/public/dashboards/:accessToken/panels/:panelId/query", routing.Wrap(hs.QueryPublicDashboard))
616-
}
617-
618611
// Frontend logs
619612
sourceMapStore := frontendlogging.NewSourceMapStore(hs.Cfg, hs.pluginStaticRouteResolver, frontendlogging.ReadSourceMapFromFS)
620613
r.Post("/log", middleware.RateLimit(hs.Cfg.Sentry.EndpointRPS, hs.Cfg.Sentry.EndpointBurst, time.Now),

pkg/api/common_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import (
4343
"github.com/grafana/grafana/pkg/services/searchusers"
4444
"github.com/grafana/grafana/pkg/services/searchusers/filters"
4545
"github.com/grafana/grafana/pkg/services/sqlstore"
46-
"github.com/grafana/grafana/pkg/services/sqlstore/mockstore"
4746
"github.com/grafana/grafana/pkg/setting"
4847
"github.com/grafana/grafana/pkg/web"
4948
"github.com/grafana/grafana/pkg/web/webtest"
@@ -341,15 +340,6 @@ func setupHTTPServerWithCfg(t *testing.T, useFakeAccessControl, enableAccessCont
341340
return setupHTTPServerWithCfgDb(t, useFakeAccessControl, enableAccessControl, cfg, db, db, featuremgmt.WithFeatures())
342341
}
343342

344-
func setupHTTPServerWithMockDb(t *testing.T, useFakeAccessControl, enableAccessControl bool, features *featuremgmt.FeatureManager) accessControlScenarioContext {
345-
// Use a new conf
346-
cfg := setting.NewCfg()
347-
db := sqlstore.InitTestDB(t)
348-
db.Cfg = setting.NewCfg()
349-
350-
return setupHTTPServerWithCfgDb(t, useFakeAccessControl, enableAccessControl, cfg, db, mockstore.NewSQLStoreMock(), features)
351-
}
352-
353343
func setupHTTPServerWithCfgDb(t *testing.T, useFakeAccessControl, enableAccessControl bool, cfg *setting.Cfg, db *sqlstore.SQLStore, store sqlstore.Store, features *featuremgmt.FeatureManager) accessControlScenarioContext {
354344
t.Helper()
355345

pkg/api/dashboard_public.go

-141
This file was deleted.

0 commit comments

Comments
 (0)