From 04749027f62a6c830bdc33b793c24c13b9fb8ba2 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Fri, 3 Aug 2018 13:15:51 -0400 Subject: MM-11575: change plugin nil semantics (#9212) * change MessageWillBePosted nil return semantics * change FileWillBeUploaded nil return semantics * use LogDebug to verify plugin inputs vs. the confusing Delete(User|Team) --- app/post.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'app/post.go') diff --git a/app/post.go b/app/post.go index 8c44436aa..299c9ce3a 100644 --- a/app/post.go +++ b/app/post.go @@ -162,14 +162,22 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo } if a.PluginsReady() { - var rejectionReason string + var rejectionError *model.AppError pluginContext := &plugin.Context{} a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { - post, rejectionReason = hooks.MessageWillBePosted(pluginContext, post) - return post != nil + replacementPost, rejectionReason := hooks.MessageWillBePosted(pluginContext, post) + if rejectionReason != "" { + rejectionError = model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + return false + } + if replacementPost != nil { + post = replacementPost + } + + return true }, plugin.MessageWillBePostedId) - if post == nil { - return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + if rejectionError != nil { + return nil, rejectionError } } -- cgit v1.2.3-1-g7c22