summaryrefslogtreecommitdiffstats
path: root/app/plugins.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-09-15 08:51:46 -0400
committerGitHub <noreply@github.com>2017-09-15 08:51:46 -0400
commit2628022275ef64fde95545abe4634b4bd7177844 (patch)
tree25d451b81d720f44aa09b20389be7fbb75b7864e /app/plugins.go
parent2a6cd44f23e1b3207debaa73801f0c63a2c81126 (diff)
downloadchat-2628022275ef64fde95545abe4634b4bd7177844.tar.gz
chat-2628022275ef64fde95545abe4634b4bd7177844.tar.bz2
chat-2628022275ef64fde95545abe4634b4bd7177844.zip
PLT-7622 Improvements to server handling of webapp plugins (#7445)
* Improvements to server handling of webapp plugins * Fix newline * Update manifest function names
Diffstat (limited to 'app/plugins.go')
-rw-r--r--app/plugins.go62
1 files changed, 27 insertions, 35 deletions
diff --git a/app/plugins.go b/app/plugins.go
index f00308a86..fb8182823 100644
--- a/app/plugins.go
+++ b/app/plugins.go
@@ -252,6 +252,12 @@ func (a *App) UnpackAndActivatePlugin(pluginFile io.Reader) (*model.Manifest, *m
return nil, model.NewAppError("UnpackAndActivatePlugin", "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())
+ Publish(message)
+ }
+
return manifest, nil
}
@@ -260,10 +266,7 @@ func (a *App) GetActivePluginManifests() ([]*model.Manifest, *model.AppError) {
return nil, model.NewAppError("GetActivePluginManifests", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
- plugins, err := a.PluginEnv.ActivePlugins()
- if err != nil {
- return nil, model.NewAppError("GetActivePluginManifests", "app.plugin.get_plugins.app_error", nil, err.Error(), http.StatusInternalServerError)
- }
+ plugins := a.PluginEnv.ActivePlugins()
manifests := make([]*model.Manifest, len(plugins))
for i, plugin := range plugins {
@@ -278,6 +281,15 @@ func (a *App) RemovePlugin(id string) *model.AppError {
return model.NewAppError("RemovePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
+ plugins := a.PluginEnv.ActivePlugins()
+ manifest := &model.Manifest{}
+ for _, p := range plugins {
+ if p.Manifest.Id == id {
+ manifest = p.Manifest
+ break
+ }
+ }
+
err := a.PluginEnv.DeactivatePlugin(id)
if err != nil {
return model.NewAppError("RemovePlugin", "app.plugin.deactivate.app_error", nil, err.Error(), http.StatusBadRequest)
@@ -288,39 +300,13 @@ func (a *App) RemovePlugin(id string) *model.AppError {
return model.NewAppError("RemovePlugin", "app.plugin.remove.app_error", nil, err.Error(), http.StatusInternalServerError)
}
- return nil
-}
-
-// Temporary WIP function/type for experimental webapp plugins
-type ClientConfigPlugin struct {
- Id string `json:"id"`
- BundlePath string `json:"bundle_path"`
-}
-
-func (a *App) GetPluginsForClientConfig() string {
- if a.PluginEnv == nil || !*utils.Cfg.PluginSettings.Enable {
- return ""
- }
-
- plugins, err := a.PluginEnv.ActivePlugins()
- if err != nil {
- return ""
- }
-
- pluginsConfig := []ClientConfigPlugin{}
- for _, plugin := range plugins {
- if plugin.Manifest.Webapp == nil {
- continue
- }
- pluginsConfig = append(pluginsConfig, ClientConfigPlugin{Id: plugin.Manifest.Id, BundlePath: plugin.Manifest.Webapp.BundlePath})
+ if manifest.HasClient() {
+ message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_PLUGIN_DEACTIVATED, "", "", "", nil)
+ message.Add("manifest", manifest.ClientManifest())
+ Publish(message)
}
- b, err := json.Marshal(pluginsConfig)
- if err != nil {
- return ""
- }
-
- return string(b)
+ return nil
}
func (a *App) InitPlugins(pluginPath, webappPath string) {
@@ -338,6 +324,12 @@ func (a *App) InitPlugins(pluginPath, webappPath string) {
return
}
+ err = os.Mkdir(webappPath, 0744)
+ if err != nil && !os.IsExist(err) {
+ l4g.Error("failed to start up plugins: " + err.Error())
+ return
+ }
+
a.PluginEnv, err = pluginenv.New(
pluginenv.SearchPath(pluginPath),
pluginenv.WebappPath(webappPath),