[MM-42191]: Include deleted posts (#19985)
* MM-42191: Include deleted posts: Add includeDeleted query parameter for getPostsForChannel * MM-42191: Fix error typo for includeDeleted query parameter * MM-42191: Include deleted posts: Set permission error when deleted posts are requested by non system admins * MM-42191: Include deleted posts: Refactor replyCountSubQuery and conditions when includeDeleted is not presented, refactor getRootPosts * MM-42191: Include deleted posts: Refactor getRootPosts function along with skipFetchThreads and includeDeleted * MM-42191: Include deleted posts: Rename includeDeleted to include_deleted param * MM-42191: Include deleted posts: Fix failed posts unit tests * MM-42191: Include deleted posts: Add missing include deleted option in multiple queries * MM-42191: Include deleted posts: Add tests for include deleted option in TestGetPostsForChannel, TestGetPostsBefore, TestGetPostsAfter * MM-42191: include deleted posts: Add tests cases for post store test * MM-42191: Include deleted posts: Add extra unit test to ensure not returning deleted posts when IncludeDelete is false Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1d8bb0605c
Коммит
b9834a2fc2
@@ -1946,6 +1946,73 @@ func testPostStoreGetPosts(t *testing.T, ss store.Store) {
|
||||
assert.Equal(t, int64(1), postList.Posts[post5.Id].ReplyCount)
|
||||
assert.Equal(t, int64(1), postList.Posts[post6.Id].ReplyCount)
|
||||
})
|
||||
|
||||
t.Run("should return all posts in a channel included deleted posts", func(t *testing.T) {
|
||||
err := ss.Post().Delete(post1.Id, 1, userId)
|
||||
require.NoError(t, err)
|
||||
|
||||
postList, err := ss.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: 0, PerPage: 30, SkipFetchThreads: false, IncludeDeleted: true}, false, map[string]bool{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
post6.Id,
|
||||
post5.Id,
|
||||
post4.Id,
|
||||
post3.Id,
|
||||
post2.Id,
|
||||
post1.Id,
|
||||
}, postList.Order)
|
||||
|
||||
assert.Len(t, postList.Posts, 6)
|
||||
assert.NotNil(t, postList.Posts[post1.Id])
|
||||
assert.NotNil(t, postList.Posts[post2.Id])
|
||||
assert.NotNil(t, postList.Posts[post3.Id])
|
||||
assert.NotNil(t, postList.Posts[post4.Id])
|
||||
assert.NotNil(t, postList.Posts[post5.Id])
|
||||
assert.NotNil(t, postList.Posts[post6.Id])
|
||||
})
|
||||
|
||||
t.Run("should return all posts in a channel included deleted posts without threads", func(t *testing.T) {
|
||||
err := ss.Post().Delete(post5.Id, 1, userId)
|
||||
require.NoError(t, err)
|
||||
|
||||
postList, err := ss.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: 0, PerPage: 30, SkipFetchThreads: true, IncludeDeleted: true}, false, map[string]bool{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
post6.Id,
|
||||
post5.Id,
|
||||
post4.Id,
|
||||
post3.Id,
|
||||
post2.Id,
|
||||
post1.Id,
|
||||
}, postList.Order)
|
||||
|
||||
assert.Len(t, postList.Posts, 6)
|
||||
assert.NotNil(t, postList.Posts[post5.Id])
|
||||
assert.NotNil(t, postList.Posts[post6.Id])
|
||||
assert.Equal(t, int64(1), postList.Posts[post5.Id].ReplyCount)
|
||||
assert.Equal(t, int64(1), postList.Posts[post6.Id].ReplyCount)
|
||||
})
|
||||
|
||||
t.Run("should return the lasts posts created in channel without include deleted posts", func(t *testing.T) {
|
||||
err := ss.Post().Delete(post6.Id, 1, userId)
|
||||
require.NoError(t, err)
|
||||
|
||||
postList, err := ss.Post().GetPosts(model.GetPostsOptions{ChannelId: channelId, Page: 0, PerPage: 30, SkipFetchThreads: true, IncludeDeleted: false}, false, map[string]bool{})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []string{
|
||||
post4.Id,
|
||||
post3.Id,
|
||||
post2.Id,
|
||||
}, postList.Order)
|
||||
|
||||
assert.Len(t, postList.Posts, 3)
|
||||
assert.NotNil(t, postList.Posts[post2.Id])
|
||||
assert.NotNil(t, postList.Posts[post3.Id])
|
||||
assert.NotNil(t, postList.Posts[post4.Id])
|
||||
})
|
||||
}
|
||||
|
||||
func testPostStoreGetPostBeforeAfter(t *testing.T, ss store.Store) {
|
||||
|
||||
Ссылка в новой задаче
Block a user