PublicDashboards: Add setting to disable the feature (#78894)
* Replace feature toggle with configuration setting * Fix permission alert * Update documentation * Add back feature toggle * revert unwanted commited changes * fix tests * run prettier * Update SharePublicDashboard.test.tsx * fix linter and frontend tests * Update api.go * Apply docs edit from code review Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> * Update index.md * Update docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com> * Update docs/sources/setup-grafana/configure-grafana/_index.md Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com> * add isPublicDashboardsEnabled + test * fix test * update ff description in registry * move isPublicDashboardsEnabled * revert getConfig() update --------- Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
This commit is contained in:
co-authored by
Isabel
Christopher Moyer
parent
ef60c90dfa
commit
fdaf6e3f2e
@@ -17,16 +17,19 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards/validation"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type Api struct {
|
||||
PublicDashboardService publicdashboards.Service
|
||||
RouteRegister routing.RouteRegister
|
||||
AccessControl accesscontrol.AccessControl
|
||||
Features *featuremgmt.FeatureManager
|
||||
Log log.Logger
|
||||
Middleware publicdashboards.Middleware
|
||||
|
||||
accessControl accesscontrol.AccessControl
|
||||
cfg *setting.Cfg
|
||||
features *featuremgmt.FeatureManager
|
||||
log log.Logger
|
||||
routeRegister routing.RouteRegister
|
||||
}
|
||||
|
||||
func ProvideApi(
|
||||
@@ -35,21 +38,27 @@ func ProvideApi(
|
||||
ac accesscontrol.AccessControl,
|
||||
features *featuremgmt.FeatureManager,
|
||||
md publicdashboards.Middleware,
|
||||
cfg *setting.Cfg,
|
||||
) *Api {
|
||||
api := &Api{
|
||||
PublicDashboardService: pd,
|
||||
RouteRegister: rr,
|
||||
AccessControl: ac,
|
||||
Features: features,
|
||||
Log: log.New("publicdashboards.api"),
|
||||
Middleware: md,
|
||||
accessControl: ac,
|
||||
cfg: cfg,
|
||||
features: features,
|
||||
log: log.New("publicdashboards.api"),
|
||||
routeRegister: rr,
|
||||
}
|
||||
|
||||
// attach api if PublicDashboards feature flag is enabled
|
||||
if features.IsEnabledGlobally(featuremgmt.FlagPublicDashboards) {
|
||||
// register endpoints if the feature is enabled
|
||||
if features.IsEnabledGlobally(featuremgmt.FlagPublicDashboards) && cfg.PublicDashboardsEnabled {
|
||||
api.RegisterAPIEndpoints()
|
||||
}
|
||||
|
||||
if !features.IsEnabledGlobally(featuremgmt.FlagPublicDashboards) {
|
||||
api.log.Warn("[Deprecated] The publicDashboards feature toggle will be removed in Grafana v11. To disable the public dashboards feature, use the public_dashboards.enabled setting.")
|
||||
}
|
||||
|
||||
return api
|
||||
}
|
||||
|
||||
@@ -59,35 +68,35 @@ func (api *Api) RegisterAPIEndpoints() {
|
||||
// Anonymous access to public dashboard route is configured in pkg/api/api.go
|
||||
// because it is deeply dependent on the HTTPServer.Index() method and would result in a
|
||||
// circular dependency
|
||||
api.RouteRegister.Group("/api/public/dashboards/:accessToken", func(apiRoute routing.RouteRegister) {
|
||||
api.routeRegister.Group("/api/public/dashboards/:accessToken", func(apiRoute routing.RouteRegister) {
|
||||
apiRoute.Get("/", routing.Wrap(api.ViewPublicDashboard))
|
||||
apiRoute.Get("/annotations", routing.Wrap(api.GetPublicAnnotations))
|
||||
apiRoute.Post("/panels/:panelId/query", routing.Wrap(api.QueryPublicDashboard))
|
||||
}, api.Middleware.HandleApi)
|
||||
|
||||
// Auth endpoints
|
||||
auth := accesscontrol.Middleware(api.AccessControl)
|
||||
auth := accesscontrol.Middleware(api.accessControl)
|
||||
uidScope := dashboards.ScopeDashboardsProvider.GetResourceScopeUID(accesscontrol.Parameter(":dashboardUid"))
|
||||
|
||||
// List public dashboards for org
|
||||
api.RouteRegister.Get("/api/dashboards/public-dashboards", middleware.ReqSignedIn, routing.Wrap(api.ListPublicDashboards))
|
||||
api.routeRegister.Get("/api/dashboards/public-dashboards", middleware.ReqSignedIn, routing.Wrap(api.ListPublicDashboards))
|
||||
// Get public dashboard
|
||||
api.RouteRegister.Get("/api/dashboards/uid/:dashboardUid/public-dashboards",
|
||||
api.routeRegister.Get("/api/dashboards/uid/:dashboardUid/public-dashboards",
|
||||
auth(accesscontrol.EvalPermission(dashboards.ActionDashboardsRead, uidScope)),
|
||||
routing.Wrap(api.GetPublicDashboard))
|
||||
|
||||
// Create Public Dashboard
|
||||
api.RouteRegister.Post("/api/dashboards/uid/:dashboardUid/public-dashboards",
|
||||
api.routeRegister.Post("/api/dashboards/uid/:dashboardUid/public-dashboards",
|
||||
auth(accesscontrol.EvalPermission(dashboards.ActionDashboardsPublicWrite, uidScope)),
|
||||
routing.Wrap(api.CreatePublicDashboard))
|
||||
|
||||
// Update Public Dashboard
|
||||
api.RouteRegister.Patch("/api/dashboards/uid/:dashboardUid/public-dashboards/:uid",
|
||||
api.routeRegister.Patch("/api/dashboards/uid/:dashboardUid/public-dashboards/:uid",
|
||||
auth(accesscontrol.EvalPermission(dashboards.ActionDashboardsPublicWrite, uidScope)),
|
||||
routing.Wrap(api.UpdatePublicDashboard))
|
||||
|
||||
// Delete Public dashboard
|
||||
api.RouteRegister.Delete("/api/dashboards/uid/:dashboardUid/public-dashboards/:uid",
|
||||
api.routeRegister.Delete("/api/dashboards/uid/:dashboardUid/public-dashboards/:uid",
|
||||
auth(accesscontrol.EvalPermission(dashboards.ActionDashboardsPublicWrite, uidScope)),
|
||||
routing.Wrap(api.DeletePublicDashboard))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user