MM-19574 Don't return metadata for deleted posts (#12878)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
23aa193f28
Коммит
1234e68575
@@ -87,6 +87,11 @@ func (a *App) PreparePostForClient(originalPost *model.Post, isNewPost bool, isE
|
||||
|
||||
post.Metadata = &model.PostMetadata{}
|
||||
|
||||
if post.DeleteAt > 0 {
|
||||
// Don't fill out metadata for deleted posts
|
||||
return post
|
||||
}
|
||||
|
||||
// Emojis and reaction counts
|
||||
if emojis, reactions, err := a.getEmojisAndReactionsForPost(post); err != nil {
|
||||
mlog.Warn("Failed to get emojis and reactions for a post", mlog.String("post_id", post.Id), mlog.Err(err))
|
||||
|
||||
@@ -477,6 +477,36 @@ func TestPreparePostForClient(t *testing.T) {
|
||||
}, imageDimensions[server.URL+"/test-image1.png"])
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("no metadata for deleted posts", func(t *testing.T) {
|
||||
th := setup()
|
||||
defer th.TearDown()
|
||||
|
||||
fileInfo, err := th.App.DoUploadFile(time.Now(), th.BasicTeam.Id, th.BasicChannel.Id, th.BasicUser.Id, "test.txt", []byte("test"))
|
||||
require.Nil(t, err)
|
||||
|
||||
post, err := th.App.CreatePost(&model.Post{
|
||||
Message: "test",
|
||||
FileIds: []string{fileInfo.Id},
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
}, th.BasicChannel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.AddReactionToPost(post, th.BasicUser, "taco")
|
||||
|
||||
post, err = th.App.DeletePost(post.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
// DeleteAt isn't set on the post returned by App.DeletePost
|
||||
post.DeleteAt = model.GetMillis()
|
||||
|
||||
clientPost := th.App.PreparePostForClient(post, false, false)
|
||||
|
||||
assert.NotEqual(t, nil, clientPost.Metadata, "should've populated Metadata“")
|
||||
assert.Nil(t, clientPost.Metadata.Reactions, "should not have populated Reactions")
|
||||
assert.Nil(t, clientPost.Metadata.Files, "should not have populated Files")
|
||||
})
|
||||
}
|
||||
|
||||
func TestPreparePostForClientWithImageProxy(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user