PLT-7849 Add config setting to disable plugin uploads (#7666)

* Add config setting to disable plugin uploads

* Update unit test
This commit is contained in:
Joram Wilander
2017-10-25 08:52:50 -04:00
committed by GitHub
parent 5474cff0eb
commit 1d968eb55e
5 changed files with 34 additions and 10 deletions

View File

@@ -32,8 +32,8 @@ func (api *API) InitPlugin() {
}
func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
if !*c.App.Config().PluginSettings.Enable {
c.Err = model.NewAppError("uploadPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
if !*c.App.Config().PluginSettings.Enable || !*c.App.Config().PluginSettings.EnableUploads {
c.Err = model.NewAppError("uploadPlugin", "app.plugin.upload_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}

View File

@@ -28,10 +28,17 @@ func TestPlugin(t *testing.T) {
defer th.TearDown()
enablePlugins := *th.App.Config().PluginSettings.Enable
enableUploadPlugins := *th.App.Config().PluginSettings.EnableUploads
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)
defer func() {
@@ -61,7 +68,14 @@ func TestPlugin(t *testing.T) {
_, resp = th.SystemAdminClient.UploadPlugin(file)
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)
CheckForbiddenStatus(t, resp)

View File

@@ -332,7 +332,8 @@
"RunScheduler": true
},
"PluginSettings": {
"Enable": false,
"Enable": true,
"EnableUploads": false,
"Plugins": {}
}
}

View File

@@ -3489,7 +3489,11 @@
},
{
"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",

View File

@@ -511,9 +511,10 @@ type PluginState struct {
}
type PluginSettings struct {
Enable *bool
Plugins map[string]interface{}
PluginStates map[string]*PluginState
Enable *bool
EnableUploads *bool
Plugins map[string]interface{}
PluginStates map[string]*PluginState
}
type Config struct {
@@ -1459,6 +1460,10 @@ func (o *Config) SetDefaults() {
}
if o.PluginSettings.Enable == nil {
o.PluginSettings.Enable = NewBool(true)
}
if o.PluginSettings.EnableUploads == nil {
o.PluginSettings.Enable = NewBool(false)
}