MM-8662: Preserve plugin's enabled state when overwriting (#10005)

If a plugin upload overwrites an exiosting plugin, the new one will be
immediately enabled if the old one was enabled.
This commit is contained in:
Lev
2018-12-17 05:35:12 -08:00
committed by Joram Wilander
parent 6c2e216c3f
commit 829f183bb0

View File

@@ -56,6 +56,9 @@ func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest
return nil, model.NewAppError("installPlugin", "app.plugin.invalid_id.app_error", map[string]interface{}{"Min": plugin.MinIdLength, "Max": plugin.MaxIdLength, "Regex": plugin.ValidIdRegex}, "", http.StatusBadRequest)
}
// Stash the previous state of the plugin, if available
stashed := a.Config().PluginSettings.PluginStates[manifest.Id]
bundles, err := pluginsEnvironment.Available()
if err != nil {
return nil, model.NewAppError("installPlugin", "app.plugin.install.app_error", nil, err.Error(), http.StatusInternalServerError)
@@ -80,6 +83,10 @@ func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest
return nil, model.NewAppError("installPlugin", "app.plugin.mvdir.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if stashed != nil && stashed.Enable {
a.EnablePlugin(manifest.Id)
}
if err := a.notifyPluginStatusesChanged(); err != nil {
mlog.Error("failed to notify plugin status changed", mlog.Err(err))
}