summaryrefslogtreecommitdiffstats
path: root/api4
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 /api4
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 'api4')
-rw-r--r--api4/plugin.go24
-rw-r--r--api4/plugin_test.go26
-rw-r--r--api4/system.go1
3 files changed, 41 insertions, 10 deletions
diff --git a/api4/plugin.go b/api4/plugin.go
index 5b030e71d..ac1620335 100644
--- a/api4/plugin.go
+++ b/api4/plugin.go
@@ -25,6 +25,8 @@ func InitPlugin() {
BaseRoutes.Plugins.Handle("", ApiSessionRequired(getPlugins)).Methods("GET")
BaseRoutes.Plugin.Handle("", ApiSessionRequired(removePlugin)).Methods("DELETE")
+ BaseRoutes.Plugins.Handle("/webapp", ApiHandler(getWebappPlugins)).Methods("GET")
+
}
func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -118,3 +120,25 @@ func removePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}
+
+func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
+ if !*utils.Cfg.PluginSettings.Enable {
+ c.Err = model.NewAppError("getWebappPlugins", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
+ return
+ }
+
+ manifests, err := c.App.GetActivePluginManifests()
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ clientManifests := []*model.Manifest{}
+ for _, m := range manifests {
+ if m.HasClient() {
+ clientManifests = append(clientManifests, m.ClientManifest())
+ }
+ }
+
+ w.Write([]byte(model.ManifestListToJson(clientManifests)))
+}
diff --git a/api4/plugin_test.go b/api4/plugin_test.go
index f92e58ea0..9cedccfe7 100644
--- a/api4/plugin_test.go
+++ b/api4/plugin_test.go
@@ -17,14 +17,11 @@ import (
func TestPlugin(t *testing.T) {
pluginDir, err := ioutil.TempDir("", "mm-plugin-test")
require.NoError(t, err)
- defer func() {
- os.RemoveAll(pluginDir)
- }()
+ defer os.RemoveAll(pluginDir)
+
webappDir, err := ioutil.TempDir("", "mm-webapp-test")
require.NoError(t, err)
- defer func() {
- os.RemoveAll(webappDir)
- }()
+ defer os.RemoveAll(webappDir)
th := SetupEnterprise().InitBasic().InitSystemAdmin()
defer TearDown()
@@ -50,9 +47,7 @@ func TestPlugin(t *testing.T) {
// Successful upload
manifest, resp := th.SystemAdminClient.UploadPlugin(file)
- defer func() {
- os.RemoveAll("plugins/testplugin")
- }()
+ defer os.RemoveAll("plugins/testplugin")
CheckNoError(t, resp)
assert.Equal(t, "testplugin", manifest.Id)
@@ -91,6 +86,19 @@ func TestPlugin(t *testing.T) {
_, resp = th.Client.GetPlugins()
CheckForbiddenStatus(t, resp)
+ // Successful webapp get
+ manifests, resp = th.Client.GetWebappPlugins()
+ CheckNoError(t, resp)
+
+ found = false
+ for _, m := range manifests {
+ if m.Id == manifest.Id {
+ found = true
+ }
+ }
+
+ assert.True(t, found)
+
// Successful remove
ok, resp := th.SystemAdminClient.RemovePlugin(manifest.Id)
CheckNoError(t, resp)
diff --git a/api4/system.go b/api4/system.go
index fbfbd0ef2..b50dc97a5 100644
--- a/api4/system.go
+++ b/api4/system.go
@@ -244,7 +244,6 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
respCfg["NoAccounts"] = strconv.FormatBool(c.App.IsFirstUserAccount())
- respCfg["Plugins"] = c.App.GetPluginsForClientConfig()
w.Write([]byte(model.MapToJson(respCfg)))
}