mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-13253/MM-13254 Call PreparePostForClient in app.UpdatePost (#9983)
This commit is contained in:
@@ -435,8 +435,6 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rpost = c.App.PreparePostForClient(rpost)
|
||||
|
||||
w.Write([]byte(rpost.ToJson()))
|
||||
}
|
||||
|
||||
@@ -477,8 +475,6 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
patchedPost = c.App.PreparePostForClient(patchedPost)
|
||||
|
||||
w.Write([]byte(patchedPost.ToJson()))
|
||||
}
|
||||
|
||||
|
||||
@@ -409,6 +409,8 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
|
||||
})
|
||||
}
|
||||
|
||||
rpost = a.PreparePostForClient(rpost)
|
||||
|
||||
a.sendUpdatedPostEvent(rpost)
|
||||
|
||||
a.InvalidateCacheForChannelPosts(rpost.ChannelId)
|
||||
@@ -434,7 +436,7 @@ func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *mo
|
||||
|
||||
func (a *App) sendUpdatedPostEvent(post *model.Post) {
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", post.ChannelId, "", nil)
|
||||
message.Add("post", a.PreparePostForClient(post).ToJson())
|
||||
message.Add("post", post.ToJson())
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
|
||||
@@ -340,3 +340,99 @@ func TestDeletePostWithFileAttachments(t *testing.T) {
|
||||
_, err = th.App.GetFileInfo(info1.Id)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestCreatePost(t *testing.T) {
|
||||
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ExperimentalSettings.EnablePostMetadata = false
|
||||
*cfg.ServiceSettings.ImageProxyType = "atmos/camo"
|
||||
*cfg.ServiceSettings.ImageProxyURL = "https://127.0.0.1"
|
||||
*cfg.ServiceSettings.ImageProxyOptions = "foo"
|
||||
})
|
||||
|
||||
imageURL := "http://mydomain.com/myimage"
|
||||
proxiedImageURL := "https://127.0.0.1/f8dace906d23689e8d5b12c3cefbedbf7b9b72f5/687474703a2f2f6d79646f6d61696e2e636f6d2f6d79696d616765"
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPatchPost(t *testing.T) {
|
||||
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ExperimentalSettings.EnablePostMetadata = false
|
||||
*cfg.ServiceSettings.ImageProxyType = "atmos/camo"
|
||||
*cfg.ServiceSettings.ImageProxyURL = "https://127.0.0.1"
|
||||
*cfg.ServiceSettings.ImageProxyOptions = "foo"
|
||||
})
|
||||
|
||||
imageURL := "http://mydomain.com/myimage"
|
||||
proxiedImageURL := "https://127.0.0.1/f8dace906d23689e8d5b12c3cefbedbf7b9b72f5/687474703a2f2f6d79646f6d61696e2e636f6d2f6d79696d616765"
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
patch := &model.PostPatch{
|
||||
Message: model.NewString(""),
|
||||
}
|
||||
|
||||
rpost, err = th.App.PatchPost(rpost.Id, patch)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdatePost(t *testing.T) {
|
||||
t.Run("call PreparePostForClient before returning", func(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ExperimentalSettings.EnablePostMetadata = false
|
||||
*cfg.ServiceSettings.ImageProxyType = "atmos/camo"
|
||||
*cfg.ServiceSettings.ImageProxyURL = "https://127.0.0.1"
|
||||
*cfg.ServiceSettings.ImageProxyOptions = "foo"
|
||||
})
|
||||
|
||||
imageURL := "http://mydomain.com/myimage"
|
||||
proxiedImageURL := "https://127.0.0.1/f8dace906d23689e8d5b12c3cefbedbf7b9b72f5/687474703a2f2f6d79646f6d61696e2e636f6d2f6d79696d616765"
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "",
|
||||
UserId: th.BasicUser.Id,
|
||||
}
|
||||
|
||||
rpost, err := th.App.CreatePost(post, th.BasicChannel, false)
|
||||
require.Nil(t, err)
|
||||
assert.NotEqual(t, "", rpost.Message)
|
||||
|
||||
post.Id = rpost.Id
|
||||
post.Message = ""
|
||||
|
||||
rpost, err = th.App.UpdatePost(post, false)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "", rpost.Message)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user