mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-8086 Fix plugin config watcher for enabling and disabling (#7770)
* Fix plugin config watcher for enabling and disabling * Make sure HTTP routes are served * Set content-type explicitly
This commit is contained in:
@@ -93,6 +93,9 @@ func New(options ...Option) *App {
|
||||
app.Srv.Store = app.newStore()
|
||||
app.initJobs()
|
||||
|
||||
app.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}", app.ServePluginRequest)
|
||||
app.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}/{anything:.*}", app.ServePluginRequest)
|
||||
|
||||
app.Srv.Router.NotFoundHandler = http.HandlerFunc(app.Handle404)
|
||||
|
||||
app.Srv.WebSocketRouter = &WebSocketRouter{
|
||||
|
||||
@@ -557,30 +557,33 @@ func (a *App) InitPlugins(pluginPath, webappPath string) {
|
||||
|
||||
utils.RemoveConfigListener(a.PluginConfigListenerId)
|
||||
a.PluginConfigListenerId = utils.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||
if !*prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
||||
a.InitPlugins(pluginPath, webappPath)
|
||||
} else if *prevCfg.PluginSettings.Enable && !*cfg.PluginSettings.Enable {
|
||||
a.ShutDownPlugins()
|
||||
} else if *prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
||||
a.ActivatePlugins()
|
||||
}
|
||||
|
||||
if a.PluginEnv == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if *prevCfg.PluginSettings.Enable && *cfg.PluginSettings.Enable {
|
||||
a.ActivatePlugins()
|
||||
}
|
||||
|
||||
for _, err := range a.PluginEnv.Hooks().OnConfigurationChange() {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
a.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}", a.ServePluginRequest)
|
||||
a.Srv.Router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}/{anything:.*}", a.ServePluginRequest)
|
||||
|
||||
a.ActivatePlugins()
|
||||
}
|
||||
|
||||
func (a *App) ServePluginRequest(w http.ResponseWriter, r *http.Request) {
|
||||
if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
|
||||
err := model.NewAppError("ServePluginRequest", "app.plugin.disabled.app_error", nil, "Enable plugins to serve plugin requests", http.StatusNotImplemented)
|
||||
err.Translate(utils.T)
|
||||
l4g.Error(err.Error())
|
||||
w.WriteHeader(err.StatusCode)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(err.ToJson()))
|
||||
return
|
||||
}
|
||||
|
||||
token := ""
|
||||
|
||||
authHeader := r.Header.Get(model.HEADER_AUTH)
|
||||
|
||||
@@ -75,6 +75,13 @@ func runServer(configFileLocation string) {
|
||||
|
||||
if webappDir, ok := utils.FindDir(model.CLIENT_DIR); ok {
|
||||
a.InitPlugins(*a.Config().PluginSettings.Directory, webappDir+"/plugins")
|
||||
utils.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||
if *cfg.PluginSettings.Enable {
|
||||
a.InitPlugins(*cfg.PluginSettings.Directory, webappDir+"/plugins")
|
||||
} else {
|
||||
a.ShutDownPlugins()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
l4g.Error("Unable to find webapp directory, could not initialize plugins")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user