From 1e5c432e1029601a664454388ae366ef69618d62 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 25 Jun 2018 12:33:13 -0700 Subject: MM-10702 Moving plugins to use hashicorp go-plugin. (#8978) * Moving plugins to use hashicorp go-plugin. * Tweaks from feedback. --- app/post.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'app/post.go') diff --git a/app/post.go b/app/post.go index e24018995..7e53de2f9 100644 --- a/app/post.go +++ b/app/post.go @@ -18,6 +18,7 @@ import ( "github.com/dyatlov/go-opengraph/opengraph" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/plugin" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" "golang.org/x/net/html/charset" @@ -161,10 +162,13 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo } if a.PluginsReady() { - if newPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBePosted(post); newPost == nil { + var rejectionReason string + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + post, rejectionReason = hooks.MessageWillBePosted(post) + return post != nil + }, plugin.MessageWillBePostedId) + if post == nil { return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) - } else { - post = newPost } } @@ -177,7 +181,10 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo if a.PluginsReady() { a.Go(func() { - a.PluginEnv.Hooks().MessageHasBeenPosted(rpost) + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + hooks.MessageHasBeenPosted(rpost) + return true + }, plugin.MessageHasBeenPostedId) }) } @@ -386,10 +393,13 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model } if a.PluginsReady() { - if pluginModifiedPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBeUpdated(newPost, oldPost); pluginModifiedPost == nil { - return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) - } else { - newPost = pluginModifiedPost + var rejectionReason string + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + newPost, rejectionReason = hooks.MessageWillBeUpdated(newPost, oldPost) + return post != nil + }, plugin.MessageWillBeUpdatedId) + if newPost == nil { + return nil, model.NewAppError("UpdatePost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) } } @@ -400,7 +410,10 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model if a.PluginsReady() { a.Go(func() { - a.PluginEnv.Hooks().MessageHasBeenUpdated(newPost, oldPost) + a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { + hooks.MessageHasBeenUpdated(newPost, oldPost) + return true + }, plugin.MessageHasBeenUpdatedId) }) } -- cgit v1.2.3-1-g7c22 From 4c1ddcff10b359baf5728b334acb60cc3e1b1123 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 6 Jul 2018 06:07:09 -0700 Subject: MM-10703 Adding blank request context to plugin hooks for future use. (#9043) * Adding blank request context to plugin hooks for future use. * Rename RequestContext to Context * Adding context to ServeHTTP and ExecuteCommand * Fixing import cycle in test. --- app/post.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/post.go') 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) }) -- cgit v1.2.3-1-g7c22