summaryrefslogtreecommitdiffstats
path: root/app/post.go
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-08-03 13:15:51 -0400
committerGitHub <noreply@github.com>2018-08-03 13:15:51 -0400
commit04749027f62a6c830bdc33b793c24c13b9fb8ba2 (patch)
tree6b26ba82453ba6ccc2dcab0a721d0539ae19a351 /app/post.go
parent1ecb98d9f5a6053a1ee1ce262b6a3306192f6616 (diff)
downloadchat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.tar.gz
chat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.tar.bz2
chat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.zip
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)
Diffstat (limited to 'app/post.go')
-rw-r--r--app/post.go18
1 files changed, 13 insertions, 5 deletions
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
}
}