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:
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -127,3 +127,7 @@ type FeatureToggleDTO struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
ReadOnly bool `json:"readOnly,omitempty"`
|
||||
}
|
||||
|
||||
type FeatureManagerState struct {
|
||||
RestartRequired bool `json:"restartRequired"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user