diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-02 01:36:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 01:36:54 -0700 |
commit | 65817e13c7900ea81947e40e177459cfea8acee4 (patch) | |
tree | 8dfc88db36844e4186b4110753be8de976da6371 /app/plugins.go | |
parent | c6bf235ec2a8613d8ef35607e2aeb8c0cb629f45 (diff) | |
download | chat-65817e13c7900ea81947e40e177459cfea8acee4.tar.gz chat-65817e13c7900ea81947e40e177459cfea8acee4.tar.bz2 chat-65817e13c7900ea81947e40e177459cfea8acee4.zip |
PLT-6965 jira integration (plus plugin scaffolding) (#6918)
* plugin scaffolding / jira integration
* add vendored testify packages
* webhook fix
* don't change i18n ids
* support configuration watching
* add basic jira plugin configuration to admin console
* fix eslint errors
* fix another eslint warning
* polish
* undo unintentional config.json commit >:(
* test fix
* add jira plugin diagnostics, remove dm support, add bot tag, generate web-safe secrets
* rebase, implement requested changes
* requested changes
* remove tests and minimize makefile change
* add missing license headers
* add missing comma
* remove bad line from Makefile
Diffstat (limited to 'app/plugins.go')
-rw-r--r-- | app/plugins.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/app/plugins.go b/app/plugins.go new file mode 100644 index 000000000..d569dcba2 --- /dev/null +++ b/app/plugins.go @@ -0,0 +1,86 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "encoding/json" + "net/http" + + l4g "github.com/alecthomas/log4go" + + "github.com/gorilla/mux" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" + + "github.com/mattermost/platform/app/plugin" + "github.com/mattermost/platform/app/plugin/jira" +) + +type PluginAPI struct { + id string + router *mux.Router +} + +func (api *PluginAPI) LoadPluginConfiguration(dest interface{}) error { + if b, err := json.Marshal(utils.Cfg.PluginSettings.Plugins[api.id]); err != nil { + return err + } else { + return json.Unmarshal(b, dest) + } +} + +func (api *PluginAPI) PluginRouter() *mux.Router { + return api.router +} + +func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError) { + return GetTeamByName(name) +} + +func (api *PluginAPI) GetUserByName(name string) (*model.User, *model.AppError) { + return GetUserByUsername(name) +} + +func (api *PluginAPI) GetChannelByName(teamId, name string) (*model.Channel, *model.AppError) { + return GetChannelByName(name, teamId) +} + +func (api *PluginAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) { + return GetDirectChannel(userId1, userId2) +} + +func (api *PluginAPI) CreatePost(post *model.Post, teamId string) (*model.Post, *model.AppError) { + return CreatePost(post, teamId, true) +} + +func (api *PluginAPI) I18n(id string, r *http.Request) string { + if r != nil { + f, _ := utils.GetTranslationsAndLocale(nil, r) + return f(id) + } + f, _ := utils.GetTranslationsBySystemLocale() + return f(id) +} + +func InitPlugins() { + plugins := map[string]plugin.Plugin{ + "jira": &jira.Plugin{}, + } + for id, p := range plugins { + l4g.Info("Initializing plugin: " + id) + api := &PluginAPI{ + id: id, + router: Srv.Router.PathPrefix("/plugins/" + id).Subrouter(), + } + p.Initialize(api) + } + utils.AddConfigListener(func(before, after *model.Config) { + for _, p := range plugins { + p.OnConfigurationChange() + } + }) + for _, p := range plugins { + p.OnConfigurationChange() + } +} |