summaryrefslogtreecommitdiffstats
path: root/app/plugin_api.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-07-09 07:25:57 -0700
committerGitHub <noreply@github.com>2018-07-09 07:25:57 -0700
commite3c26a0e89253fb626515831d8468050e6235d89 (patch)
treee2e79be4a59bbb2ae198ac8c52456f831f452ff1 /app/plugin_api.go
parentb78b216a3c8eb354085f97f33dac5e7661ac9188 (diff)
downloadchat-e3c26a0e89253fb626515831d8468050e6235d89.tar.gz
chat-e3c26a0e89253fb626515831d8468050e6235d89.tar.bz2
chat-e3c26a0e89253fb626515831d8468050e6235d89.zip
Adding ability for plugin system to respect the defaults listed in the plugin manifest. (#9066)
Diffstat (limited to 'app/plugin_api.go')
-rw-r--r--app/plugin_api.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/app/plugin_api.go b/app/plugin_api.go
index d76cb83e3..279694c44 100644
--- a/app/plugin_api.go
+++ b/app/plugin_api.go
@@ -6,30 +6,45 @@ package app
import (
"encoding/json"
"fmt"
+ "strings"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
)
type PluginAPI struct {
- id string
- app *App
- logger *mlog.SugarLogger
+ id string
+ app *App
+ logger *mlog.SugarLogger
+ manifest *model.Manifest
}
func NewPluginAPI(a *App, manifest *model.Manifest) *PluginAPI {
return &PluginAPI{
- id: manifest.Id,
- app: a,
- logger: a.Log.With(mlog.String("plugin_id", manifest.Id)).Sugar(),
+ id: manifest.Id,
+ manifest: manifest,
+ app: a,
+ logger: a.Log.With(mlog.String("plugin_id", manifest.Id)).Sugar(),
}
}
func (api *PluginAPI) LoadPluginConfiguration(dest interface{}) error {
- if b, err := json.Marshal(api.app.Config().PluginSettings.Plugins[api.id]); err != nil {
+ finalConfig := make(map[string]interface{})
+
+ // First set final config to defaults
+ for _, setting := range api.manifest.SettingsSchema.Settings {
+ finalConfig[strings.ToLower(setting.Key)] = setting.Default
+ }
+
+ // If we have settings given we override the defaults with them
+ for setting, value := range api.app.Config().PluginSettings.Plugins[api.id] {
+ finalConfig[strings.ToLower(setting)] = value
+ }
+
+ if pluginSettingsJsonBytes, err := json.Marshal(finalConfig); err != nil {
return err
} else {
- return json.Unmarshal(b, dest)
+ return json.Unmarshal(pluginSettingsJsonBytes, dest)
}
}