Feature Management: Update admin page UI after a successful update (#76380)

* Feature Management: Update admin page UI after a successful update

* lint

* lint

* refactor
This commit is contained in:
João Calisto
2023-10-13 11:54:34 +01:00
committed by GitHub
parent 2857870bfb
commit 9fc0e1566e
7 changed files with 101 additions and 19 deletions
+1
View File
@@ -412,6 +412,7 @@ func (hs *HTTPServer) registerRoutes() {
if hs.Features.IsEnabled(featuremgmt.FlagFeatureToggleAdminPage) {
apiRoute.Group("/featuremgmt", func(featuremgmtRoute routing.RouteRegister) {
featuremgmtRoute.Get("/state", authorize(ac.EvalPermission(ac.ActionFeatureManagementRead)), hs.GetFeatureMgmtState)
featuremgmtRoute.Get("/", authorize(ac.EvalPermission(ac.ActionFeatureManagementRead)), hs.GetFeatureToggles)
featuremgmtRoute.Post("/", authorize(ac.EvalPermission(ac.ActionFeatureManagementWrite)), hs.UpdateFeatureToggle)
})
+7
View File
@@ -78,9 +78,16 @@ func (hs *HTTPServer) UpdateFeatureToggle(ctx *contextmodel.ReqContext) response
return response.Respond(http.StatusBadRequest, "Failed to perform webhook request")
}
hs.Features.SetRestartRequired()
return response.Respond(http.StatusOK, "feature toggles updated successfully")
}
func (hs *HTTPServer) GetFeatureMgmtState(ctx *contextmodel.ReqContext) response.Response {
fmState := hs.Features.GetState()
return response.Respond(http.StatusOK, fmState)
}
// isFeatureHidden returns whether a toggle should be hidden from the admin page.
// filters out statuses Unknown, Experimental, and Private Preview
func isFeatureHidden(flag featuremgmt.FeatureFlag, hideCfg map[string]struct{}) bool {
+16 -7
View File
@@ -14,13 +14,14 @@ var (
)
type FeatureManager struct {
isDevMod bool
licensing licensing.Licensing
flags map[string]*FeatureFlag
enabled map[string]bool // only the "on" values
config string // path to config file
vars map[string]any
log log.Logger
isDevMod bool
restartRequired bool
licensing licensing.Licensing
flags map[string]*FeatureFlag
enabled map[string]bool // only the "on" values
config string // path to config file
vars map[string]any
log log.Logger
}
// This will merge the flags with the current configuration
@@ -148,6 +149,14 @@ func (fm *FeatureManager) GetFlags() []FeatureFlag {
return v
}
func (fm *FeatureManager) GetState() *FeatureManagerState {
return &FeatureManagerState{RestartRequired: fm.restartRequired}
}
func (fm *FeatureManager) SetRestartRequired() {
fm.restartRequired = true
}
// Check to see if a feature toggle exists by name
func (fm *FeatureManager) LookupFlag(name string) (FeatureFlag, bool) {
f, ok := fm.flags[name]
+4
View File
@@ -127,3 +127,7 @@ type FeatureToggleDTO struct {
Enabled bool `json:"enabled"`
ReadOnly bool `json:"readOnly,omitempty"`
}
type FeatureManagerState struct {
RestartRequired bool `json:"restartRequired"`
}