summaryrefslogtreecommitdiffstats
path: root/app/plugin.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-03-19 10:53:37 +0000
committerGeorge Goldberg <george@gberg.me>2018-03-19 10:53:37 +0000
commit37f0e5e0ebc0595efe2c65ffb84fa096dc8c5493 (patch)
tree4b791b279109a10a66b62aaeeeae3d5243d2961b /app/plugin.go
parentfadcdd271a68b38571b75d1d38ab023f940ac83a (diff)
parent4b675b347b5241def7807fab5e01ce9b98531815 (diff)
downloadchat-37f0e5e0ebc0595efe2c65ffb84fa096dc8c5493.tar.gz
chat-37f0e5e0ebc0595efe2c65ffb84fa096dc8c5493.tar.bz2
chat-37f0e5e0ebc0595efe2c65ffb84fa096dc8c5493.zip
Merge branch 'master' into advanced-permissions-phase-1
Diffstat (limited to 'app/plugin.go')
-rw-r--r--app/plugin.go33
1 files changed, 24 insertions, 9 deletions
diff --git a/app/plugin.go b/app/plugin.go
index fe671d26a..6702e9227 100644
--- a/app/plugin.go
+++ b/app/plugin.go
@@ -91,18 +91,11 @@ func (a *App) ActivatePlugins() {
active := a.PluginEnv.IsPluginActive(id)
if pluginState.Enable && !active {
- if err := a.PluginEnv.ActivatePlugin(id); err != nil {
- l4g.Error(err.Error())
+ if err := a.activatePlugin(plugin.Manifest); err != nil {
+ l4g.Error("%v plugin enabled in config.json but failing to activate err=%v", plugin.Manifest.Id, err.DetailedError)
continue
}
- if plugin.Manifest.HasClient() {
- message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_ACTIVATED, "", "", "", nil)
- message.Add("manifest", plugin.Manifest.ClientManifest())
- a.Publish(message)
- }
-
- l4g.Info("Activated %v plugin", id)
} else if !pluginState.Enable && active {
if err := a.deactivatePlugin(plugin.Manifest); err != nil {
l4g.Error(err.Error())
@@ -111,6 +104,21 @@ func (a *App) ActivatePlugins() {
}
}
+func (a *App) activatePlugin(manifest *model.Manifest) *model.AppError {
+ if err := a.PluginEnv.ActivatePlugin(manifest.Id); err != nil {
+ return model.NewAppError("activatePlugin", "app.plugin.activate.app_error", nil, err.Error(), http.StatusBadRequest)
+ }
+
+ if manifest.HasClient() {
+ message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_ACTIVATED, "", "", "", nil)
+ message.Add("manifest", manifest.ClientManifest())
+ a.Publish(message)
+ }
+
+ l4g.Info("Activated %v plugin", manifest.Id)
+ return nil
+}
+
func (a *App) deactivatePlugin(manifest *model.Manifest) *model.AppError {
if err := a.PluginEnv.DeactivatePlugin(manifest.Id); err != nil {
return model.NewAppError("removePlugin", "app.plugin.deactivate.app_error", nil, err.Error(), http.StatusBadRequest)
@@ -301,11 +309,18 @@ func (a *App) EnablePlugin(id string) *model.AppError {
return model.NewAppError("EnablePlugin", "app.plugin.not_installed.app_error", nil, "", http.StatusBadRequest)
}
+ if err := a.activatePlugin(manifest); err != nil {
+ return err
+ }
+
a.UpdateConfig(func(cfg *model.Config) {
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
})
if err := a.SaveConfig(a.Config(), true); err != nil {
+ if err.Id == "ent.cluster.save_config.error" {
+ return model.NewAppError("EnablePlugin", "app.plugin.cluster.save_config.app_error", nil, "", http.StatusInternalServerError)
+ }
return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError)
}