Plugin framework: add ability to install other plugins to the… (#12232)
* add ability to upload other plugins to the plugin API * generated client rpc glue code * fix UploadPlugin API signature * generated plugin mocks * added upload plugin test * removed unused comment * using single line to call InstallPlugin with file Reader * fix minimum server version * added successful plugin upload test * renamed UploadPlugin to InstallPlugin
Этот коммит содержится в:
коммит произвёл
Ali Farooq
родитель
db97b49e7a
Коммит
d7ee3553fa
@@ -7,6 +7,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -655,6 +657,19 @@ func (api *PluginAPI) GetPluginStatus(id string) (*model.PluginStatus, *model.Ap
|
||||
return api.app.GetPluginStatus(id)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *model.AppError) {
|
||||
if !*api.app.Config().PluginSettings.Enable || !*api.app.Config().PluginSettings.EnableUploads {
|
||||
return nil, model.NewAppError("installPlugin", "app.plugin.upload_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
fileBuffer, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("InstallPlugin", "api.plugin.upload.file.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return api.app.InstallPlugin(bytes.NewReader(fileBuffer), replace)
|
||||
}
|
||||
|
||||
// KV Store Section
|
||||
|
||||
func (api *PluginAPI) KVSet(key string, value []byte) *model.AppError {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
"github.com/mattermost/mattermost-server/services/mailservice"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/utils/fileutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -684,6 +685,43 @@ func TestPluginAPIGetPlugins(t *testing.T) {
|
||||
assert.Equal(t, pluginManifests, plugins)
|
||||
}
|
||||
|
||||
func TestPluginAPIInstallPlugin(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
tarData, err := ioutil.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = api.InstallPlugin(bytes.NewReader(tarData), true)
|
||||
assert.NotNil(t, err, "should not allow upload if upload disabled")
|
||||
assert.Equal(t, err.Error(), "installPlugin: Plugins and/or plugin uploads have been disabled., ")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
*cfg.PluginSettings.EnableUploads = true
|
||||
})
|
||||
|
||||
manifest, err := api.InstallPlugin(bytes.NewReader(tarData), true)
|
||||
defer os.RemoveAll("plugins/testplugin")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
// Successfully installed
|
||||
pluginsResp, err := api.GetPlugins()
|
||||
require.Nil(t, err)
|
||||
|
||||
found := false
|
||||
for _, m := range pluginsResp {
|
||||
if m.Id == manifest.Id {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
assert.True(t, found)
|
||||
}
|
||||
|
||||
func TestPluginAPIGetTeamIcon(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user