MM-8662: Added force flag to uploadPlugin http API (#9969)
MM-8662: Added `force` flag to uploadPlugin http API
Этот коммит содержится в:
@@ -66,7 +66,11 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
manifest, unpackErr := c.App.InstallPlugin(file, false)
|
force := false
|
||||||
|
if len(m.Value["force"]) > 0 && m.Value["force"][0] == "true" {
|
||||||
|
force = true
|
||||||
|
}
|
||||||
|
manifest, unpackErr := c.App.InstallPlugin(file, force)
|
||||||
|
|
||||||
if unpackErr != nil {
|
if unpackErr != nil {
|
||||||
c.Err = unpackErr
|
c.Err = unpackErr
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package api4
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -38,14 +39,15 @@ func TestPlugin(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
path, _ := utils.FindDir("tests")
|
path, _ := utils.FindDir("tests")
|
||||||
file, err := os.Open(filepath.Join(path, "testplugin.tar.gz"))
|
tarData, err := ioutil.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
// Successful upload
|
// Successful upload
|
||||||
manifest, resp := th.SystemAdminClient.UploadPlugin(file)
|
manifest, resp := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
manifest, resp = th.SystemAdminClient.UploadPluginForced(bytes.NewReader(tarData))
|
||||||
defer os.RemoveAll("plugins/testplugin")
|
defer os.RemoveAll("plugins/testplugin")
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
@@ -56,18 +58,18 @@ func TestPlugin(t *testing.T) {
|
|||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||||
_, resp = th.SystemAdminClient.UploadPlugin(file)
|
_, resp = th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.PluginSettings.Enable = true
|
*cfg.PluginSettings.Enable = true
|
||||||
*cfg.PluginSettings.EnableUploads = false
|
*cfg.PluginSettings.EnableUploads = false
|
||||||
})
|
})
|
||||||
_, resp = th.SystemAdminClient.UploadPlugin(file)
|
_, resp = th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
||||||
_, resp = th.Client.UploadPlugin(file)
|
_, resp = th.Client.UploadPlugin(bytes.NewReader(tarData))
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
// Successful gets
|
// Successful gets
|
||||||
|
|||||||
@@ -3783,9 +3783,24 @@ func (c *Client4) GetChannelsForScheme(schemeId string, page int, perPage int) (
|
|||||||
// UploadPlugin takes an io.Reader stream pointing to the contents of a .tar.gz plugin.
|
// UploadPlugin takes an io.Reader stream pointing to the contents of a .tar.gz plugin.
|
||||||
// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE.
|
// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE.
|
||||||
func (c *Client4) UploadPlugin(file io.Reader) (*Manifest, *Response) {
|
func (c *Client4) UploadPlugin(file io.Reader) (*Manifest, *Response) {
|
||||||
|
return c.uploadPlugin(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client4) UploadPluginForced(file io.Reader) (*Manifest, *Response) {
|
||||||
|
return c.uploadPlugin(file, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client4) uploadPlugin(file io.Reader, force bool) (*Manifest, *Response) {
|
||||||
body := new(bytes.Buffer)
|
body := new(bytes.Buffer)
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
|
|
||||||
|
if force {
|
||||||
|
err := writer.WriteField("force", "true")
|
||||||
|
if err != nil {
|
||||||
|
return nil, &Response{Error: NewAppError("UploadPlugin", "model.client.writer.app_error", nil, err.Error(), 0)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
part, err := writer.CreateFormFile("plugin", "plugin.tar.gz")
|
part, err := writer.CreateFormFile("plugin", "plugin.tar.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &Response{Error: NewAppError("UploadPlugin", "model.client.writer.app_error", nil, err.Error(), 0)}
|
return nil, &Response{Error: NewAppError("UploadPlugin", "model.client.writer.app_error", nil, err.Error(), 0)}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user