Add config setting to configure plugins directory (#7725)

This commit is contained in:
Joram Wilander
2017-10-26 13:21:35 -04:00
committed by GitHub
parent 6f6005c617
commit a0bfd2885d
4 changed files with 22 additions and 8 deletions
+6 -5
View File
@@ -5,6 +5,7 @@ package api4
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"testing"
@@ -29,11 +30,16 @@ func TestPlugin(t *testing.T) {
enablePlugins := *th.App.Config().PluginSettings.Enable
enableUploadPlugins := *th.App.Config().PluginSettings.EnableUploads
statesJson, _ := json.Marshal(th.App.Config().PluginSettings.PluginStates)
states := map[string]*model.PluginState{}
json.Unmarshal(statesJson, &states)
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugins
*cfg.PluginSettings.EnableUploads = enableUploadPlugins
cfg.PluginSettings.PluginStates = states
})
th.App.SaveConfig(th.App.Config(), false)
}()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
@@ -101,11 +107,6 @@ func TestPlugin(t *testing.T) {
assert.False(t, found)
states := th.App.Config().PluginSettings.PluginStates
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PluginSettings.PluginStates = states })
}()
// Successful activate
ok, resp := th.SystemAdminClient.ActivatePlugin(manifest.Id)
CheckNoError(t, resp)
+1 -1
View File
@@ -74,7 +74,7 @@ func runServer(configFileLocation string) {
a.InitBuiltInPlugins()
if webappDir, ok := utils.FindDir(model.CLIENT_DIR); ok {
a.InitPlugins("plugins", webappDir+"/plugins")
a.InitPlugins(*a.Config().PluginSettings.Directory, webappDir+"/plugins")
} else {
l4g.Error("Unable to find webapp directory, could not initialize plugins")
}
+3 -1
View File
@@ -335,6 +335,8 @@
"PluginSettings": {
"Enable": true,
"EnableUploads": false,
"Plugins": {}
"Directory": "./plugins",
"Plugins": {},
"PluginStates": {}
}
}
+12 -1
View File
@@ -147,6 +147,8 @@ const (
DATA_RETENTION_SETTINGS_DEFAULT_MESSAGE_RETENTION_DAYS = 365
DATA_RETENTION_SETTINGS_DEFAULT_FILE_RETENTION_DAYS = 365
DATA_RETENTION_SETTINGS_DEFAULT_DELETION_JOB_START_TIME = "02:00"
PLUGIN_SETTINGS_DEFAULT_DIRECTORY = "./plugins"
)
type ServiceSettings struct {
@@ -515,6 +517,7 @@ type PluginState struct {
type PluginSettings struct {
Enable *bool
EnableUploads *bool
Directory *string
Plugins map[string]interface{}
PluginStates map[string]*PluginState
}
@@ -1470,7 +1473,15 @@ func (o *Config) SetDefaults() {
}
if o.PluginSettings.EnableUploads == nil {
o.PluginSettings.Enable = NewBool(false)
o.PluginSettings.EnableUploads = NewBool(false)
}
if o.PluginSettings.Directory == nil {
o.PluginSettings.Directory = NewString(PLUGIN_SETTINGS_DEFAULT_DIRECTORY)
}
if *o.PluginSettings.Directory == "" {
*o.PluginSettings.Directory = PLUGIN_SETTINGS_DEFAULT_DIRECTORY
}
if o.PluginSettings.Plugins == nil {