diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-10-25 08:17:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-25 08:17:17 -0400 |
commit | 16b845c0d77535ea306339f7a8bd22fc72f8a3c5 (patch) | |
tree | e768b8d1ca5cc3f2e55207ea73c5954b37f708ed /api4/plugin.go | |
parent | 9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae (diff) | |
download | chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.gz chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.bz2 chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.zip |
Differentiate between installed and activated states for plugins (#7706)
Diffstat (limited to 'api4/plugin.go')
-rw-r--r-- | api4/plugin.go | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/api4/plugin.go b/api4/plugin.go index 2045a35a8..c1ee986da 100644 --- a/api4/plugin.go +++ b/api4/plugin.go @@ -24,6 +24,9 @@ func (api *API) InitPlugin() { api.BaseRoutes.Plugins.Handle("", api.ApiSessionRequired(getPlugins)).Methods("GET") api.BaseRoutes.Plugin.Handle("", api.ApiSessionRequired(removePlugin)).Methods("DELETE") + api.BaseRoutes.Plugin.Handle("/activate", api.ApiSessionRequired(activatePlugin)).Methods("POST") + api.BaseRoutes.Plugin.Handle("/deactivate", api.ApiSessionRequired(deactivatePlugin)).Methods("POST") + api.BaseRoutes.Plugins.Handle("/webapp", api.ApiHandler(getWebappPlugins)).Methods("GET") } @@ -64,7 +67,7 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) { } defer file.Close() - manifest, unpackErr := c.App.UnpackAndActivatePlugin(file) + manifest, unpackErr := c.App.InstallPlugin(file) if unpackErr != nil { c.Err = unpackErr @@ -86,13 +89,13 @@ func getPlugins(c *Context, w http.ResponseWriter, r *http.Request) { return } - manifests, err := c.App.GetActivePluginManifests() + response, err := c.App.GetPluginManifests() if err != nil { c.Err = err return } - w.Write([]byte(model.ManifestListToJson(manifests))) + w.Write([]byte(response.ToJson())) } func removePlugin(c *Context, w http.ResponseWriter, r *http.Request) { @@ -141,3 +144,51 @@ func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.ManifestListToJson(clientManifests))) } + +func activatePlugin(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePluginId() + if c.Err != nil { + return + } + + if !*c.App.Config().PluginSettings.Enable { + c.Err = model.NewAppError("activatePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented) + return + } + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + if err := c.App.EnablePlugin(c.Params.PluginId); err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} + +func deactivatePlugin(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePluginId() + if c.Err != nil { + return + } + + if !*c.App.Config().PluginSettings.Enable { + c.Err = model.NewAppError("deactivatePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented) + return + } + + if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { + c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) + return + } + + if err := c.App.DisablePlugin(c.Params.PluginId); err != nil { + c.Err = err + return + } + + ReturnStatusOK(w) +} |