summaryrefslogtreecommitdiffstats
path: root/app/post.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-05-15 13:33:47 -0700
committerGitHub <noreply@github.com>2018-05-15 13:33:47 -0700
commitdf6a7f8b19e2381ee57f946d5b184185653b2ee1 (patch)
tree622ff6b13b23bf4506ea41eb010141930e143815 /app/post.go
parentfbbe1f7cefd52a27fd52893509b5365d275f9bee (diff)
downloadchat-df6a7f8b19e2381ee57f946d5b184185653b2ee1.tar.gz
chat-df6a7f8b19e2381ee57f946d5b184185653b2ee1.tar.bz2
chat-df6a7f8b19e2381ee57f946d5b184185653b2ee1.zip
MM-10249 Adding plugin ability to intercept posts before they reach the DB. (#8791)
* Adding plugin ability to intercept posts before they reach the DB. * s/envoked/invoked/
Diffstat (limited to 'app/post.go')
-rw-r--r--app/post.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/post.go b/app/post.go
index bc31aee44..2efa4c90e 100644
--- a/app/post.go
+++ b/app/post.go
@@ -160,6 +160,14 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
return nil, err
}
+ if a.PluginsReady() {
+ if newPost, rejectionReason := a.PluginEnv.Hooks().MessageWillBePosted(post); newPost == nil {
+ return nil, model.NewAppError("createPost", "Post rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest)
+ } else {
+ post = newPost
+ }
+ }
+
var rpost *model.Post
if result := <-a.Srv.Store.Post().Save(post); result.Err != nil {
return nil, result.Err
@@ -167,6 +175,12 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
rpost = result.Data.(*model.Post)
}
+ if a.PluginsReady() {
+ a.Go(func() {
+ a.PluginEnv.Hooks().MessageHasBeenPosted(rpost)
+ })
+ }
+
esInterface := a.Elasticsearch
if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() {
@@ -371,11 +385,25 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
return nil, err
}
+ 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
+ }
+ }
+
if result := <-a.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil {
return nil, result.Err
} else {
rpost := result.Data.(*model.Post)
+ if a.PluginsReady() {
+ a.Go(func() {
+ a.PluginEnv.Hooks().MessageHasBeenUpdated(newPost, oldPost)
+ })
+ }
+
esInterface := a.Elasticsearch
if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() {