Adding 'MessageHasBeenDeleted' hook to plugins (#22476)
* Adding 'MessageHasBeenDeleted' hook to plugins * Remove debug logs * Add unit test * Bumping the required version * Fix CI problems * Increasing the minimum version * go fmt --------- Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c731630e88
Коммит
17ff2049ec
@@ -429,6 +429,50 @@ func TestHookMessageHasBeenUpdated(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestHookMessageHasBeenDeleted(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
var mockAPI plugintest.API
|
||||
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
|
||||
mockAPI.On("LogDebug", "message").Return(nil).Times(1)
|
||||
|
||||
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
|
||||
[]string{
|
||||
`
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func (p *MyPlugin) MessageHasBeenDeleted(c *plugin.Context, post *model.Post) {
|
||||
p.API.LogDebug(post.Message)
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
|
||||
defer tearDown()
|
||||
|
||||
post := &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "message",
|
||||
CreateAt: model.GetMillis() - 10000,
|
||||
}
|
||||
_, err := th.App.CreatePost(th.Context, post, th.BasicChannel, false, true)
|
||||
require.Nil(t, err)
|
||||
_, err = th.App.DeletePost(th.Context, post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestHookFileWillBeUploaded(t *testing.T) {
|
||||
t.Run("rejected", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
|
||||
@@ -1339,6 +1339,15 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
|
||||
a.deleteFlaggedPosts(post.Id)
|
||||
})
|
||||
|
||||
pluginPost := post.ForPlugin()
|
||||
pluginContext := pluginContext(c)
|
||||
a.Srv().Go(func() {
|
||||
a.ch.RunMultiHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.MessageHasBeenDeleted(pluginContext, pluginPost)
|
||||
return true
|
||||
}, plugin.MessageHasBeenDeletedID)
|
||||
})
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err = a.RemoveNotifications(c, post, channel); err != nil {
|
||||
a.Log().Error("DeletePost failed to delete notification", mlog.Err(err))
|
||||
|
||||
Ссылка в новой задаче
Block a user