diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/plugin_commands.go | 3 | ||||
-rw-r--r-- | app/plugin_requests.go | 5 | ||||
-rw-r--r-- | app/plugin_test.go | 3 | ||||
-rw-r--r-- | app/post.go | 12 |
4 files changed, 15 insertions, 8 deletions
diff --git a/app/plugin_commands.go b/app/plugin_commands.go index 0f361f410..060defc86 100644 --- a/app/plugin_commands.go +++ b/app/plugin_commands.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" ) type PluginCommand struct { @@ -104,7 +105,7 @@ func (a *App) ExecutePluginCommand(args *model.CommandArgs) (*model.Command, *mo if err != nil { return pc.Command, nil, model.NewAppError("ExecutePluginCommand", "model.plugin_command.error.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) } - response, appErr := pluginHooks.ExecuteCommand(args) + response, appErr := pluginHooks.ExecuteCommand(plugin.NewBlankContext(), args) return pc.Command, response, appErr } } diff --git a/app/plugin_requests.go b/app/plugin_requests.go index b7515d950..10ef758b4 100644 --- a/app/plugin_requests.go +++ b/app/plugin_requests.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" ) func (a *App) ServePluginRequest(w http.ResponseWriter, r *http.Request) { @@ -33,7 +34,7 @@ func (a *App) ServePluginRequest(w http.ResponseWriter, r *http.Request) { a.servePluginRequest(w, r, hooks.ServeHTTP) } -func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler http.HandlerFunc) { +func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler func(*plugin.Context, http.ResponseWriter, *http.Request)) { token := "" authHeader := r.Header.Get(model.HEADER_AUTH) @@ -71,5 +72,5 @@ func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler r.URL.RawQuery = newQuery.Encode() r.URL.Path = strings.TrimPrefix(r.URL.Path, "/plugins/"+params["plugin_id"]) - handler(w, r) + handler(plugin.NewBlankContext(), w, r) } diff --git a/app/plugin_test.go b/app/plugin_test.go index b0b6e9c1b..02b492d28 100644 --- a/app/plugin_test.go +++ b/app/plugin_test.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/mux" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -68,7 +69,7 @@ func TestHandlePluginRequest(t *testing.T) { var assertions func(*http.Request) router := mux.NewRouter() router.HandleFunc("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}/{anything:.*}", func(_ http.ResponseWriter, r *http.Request) { - th.App.servePluginRequest(nil, r, func(_ http.ResponseWriter, r *http.Request) { + th.App.servePluginRequest(nil, r, func(_ *plugin.Context, _ http.ResponseWriter, r *http.Request) { assertions(r) }) }) diff --git a/app/post.go b/app/post.go index 7e53de2f9..8d94aba2e 100644 --- a/app/post.go +++ b/app/post.go @@ -163,8 +163,9 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo if a.PluginsReady() { var rejectionReason string + pluginContext := &plugin.Context{} a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - post, rejectionReason = hooks.MessageWillBePosted(post) + post, rejectionReason = hooks.MessageWillBePosted(pluginContext, post) return post != nil }, plugin.MessageWillBePostedId) if post == nil { @@ -181,8 +182,9 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo if a.PluginsReady() { a.Go(func() { + pluginContext := &plugin.Context{} a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - hooks.MessageHasBeenPosted(rpost) + hooks.MessageHasBeenPosted(pluginContext, rpost) return true }, plugin.MessageHasBeenPostedId) }) @@ -394,8 +396,9 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model if a.PluginsReady() { var rejectionReason string + pluginContext := &plugin.Context{} a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - newPost, rejectionReason = hooks.MessageWillBeUpdated(newPost, oldPost) + newPost, rejectionReason = hooks.MessageWillBeUpdated(pluginContext, newPost, oldPost) return post != nil }, plugin.MessageWillBeUpdatedId) if newPost == nil { @@ -410,8 +413,9 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model if a.PluginsReady() { a.Go(func() { + pluginContext := &plugin.Context{} a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - hooks.MessageHasBeenUpdated(newPost, oldPost) + hooks.MessageHasBeenUpdated(pluginContext, newPost, oldPost) return true }, plugin.MessageHasBeenUpdatedId) }) |