PLT-7849 Add config setting to disable plugin uploads (#7666)
* Add config setting to disable plugin uploads * Update unit test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5474cff0eb
Коммит
1d968eb55e
@@ -32,8 +32,8 @@ func (api *API) InitPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
if !*c.App.Config().PluginSettings.Enable {
|
if !*c.App.Config().PluginSettings.Enable || !*c.App.Config().PluginSettings.EnableUploads {
|
||||||
c.Err = model.NewAppError("uploadPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
|
c.Err = model.NewAppError("uploadPlugin", "app.plugin.upload_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,17 @@ func TestPlugin(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
enablePlugins := *th.App.Config().PluginSettings.Enable
|
enablePlugins := *th.App.Config().PluginSettings.Enable
|
||||||
|
enableUploadPlugins := *th.App.Config().PluginSettings.EnableUploads
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = enablePlugins })
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.Enable = enablePlugins
|
||||||
|
*cfg.PluginSettings.EnableUploads = enableUploadPlugins
|
||||||
|
})
|
||||||
}()
|
}()
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.Enable = true
|
||||||
|
*cfg.PluginSettings.EnableUploads = true
|
||||||
|
})
|
||||||
|
|
||||||
th.App.InitPlugins(pluginDir, webappDir)
|
th.App.InitPlugins(pluginDir, webappDir)
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -61,7 +68,14 @@ func TestPlugin(t *testing.T) {
|
|||||||
_, resp = th.SystemAdminClient.UploadPlugin(file)
|
_, resp = th.SystemAdminClient.UploadPlugin(file)
|
||||||
CheckNotImplementedStatus(t, resp)
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.PluginSettings.Enable = true
|
||||||
|
*cfg.PluginSettings.EnableUploads = false
|
||||||
|
})
|
||||||
|
_, resp = th.SystemAdminClient.UploadPlugin(file)
|
||||||
|
CheckNotImplementedStatus(t, resp)
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
||||||
_, resp = th.Client.UploadPlugin(file)
|
_, resp = th.Client.UploadPlugin(file)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
|
|
||||||
|
|||||||
@@ -332,7 +332,8 @@
|
|||||||
"RunScheduler": true
|
"RunScheduler": true
|
||||||
},
|
},
|
||||||
"PluginSettings": {
|
"PluginSettings": {
|
||||||
"Enable": false,
|
"Enable": true,
|
||||||
|
"EnableUploads": false,
|
||||||
"Plugins": {}
|
"Plugins": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3489,7 +3489,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "app.plugin.disabled.app_error",
|
"id": "app.plugin.disabled.app_error",
|
||||||
"translation": "Plugins have been disabled by the system admin or the server has not been restarted since they were enabled."
|
"translation": "Plugins have been disabled."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "app.plugin.upload_disabled.app_error",
|
||||||
|
"translation": "Plugins and/or plugin uploads have been disabled."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "app.plugin.extract.app_error",
|
"id": "app.plugin.extract.app_error",
|
||||||
|
|||||||
@@ -511,9 +511,10 @@ type PluginState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PluginSettings struct {
|
type PluginSettings struct {
|
||||||
Enable *bool
|
Enable *bool
|
||||||
Plugins map[string]interface{}
|
EnableUploads *bool
|
||||||
PluginStates map[string]*PluginState
|
Plugins map[string]interface{}
|
||||||
|
PluginStates map[string]*PluginState
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -1459,6 +1460,10 @@ func (o *Config) SetDefaults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if o.PluginSettings.Enable == nil {
|
if o.PluginSettings.Enable == nil {
|
||||||
|
o.PluginSettings.Enable = NewBool(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.PluginSettings.EnableUploads == nil {
|
||||||
o.PluginSettings.Enable = NewBool(false)
|
o.PluginSettings.Enable = NewBool(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user