[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>
Этот коммит содержится в:
Orlando Romo
2022-09-27 13:00:42 -05:00
коммит произвёл GitHub
родитель 1d8bb0605c
Коммит b9834a2fc2
9 изменённых файлов: 269 добавлений и 77 удалений

Просмотреть файл

@@ -3925,11 +3925,15 @@ func (c *Client4) GetPostThreadWithOpts(postID string, etag string, opts GetPost
}
// GetPostsForChannel gets a page of posts with an array for ordering for a channel.
func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response, error) {
func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag string, collapsedThreads bool, includeDeleted bool) (*PostList, *Response, error) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
if collapsedThreads {
query += "&collapsedThreads=true"
}
if includeDeleted {
query += "&include_deleted=true"
}
r, err := c.DoAPIGet(c.channelRoute(channelId)+"/posts"+query, etag)
if err != nil {
return nil, BuildResponse(r), err
@@ -4050,11 +4054,14 @@ func (c *Client4) GetPostsSince(channelId string, time int64, collapsedThreads b
}
// GetPostsAfter gets a page of posts that were posted after the post provided.
func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response, error) {
func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, etag string, collapsedThreads bool, includeDeleted bool) (*PostList, *Response, error) {
query := fmt.Sprintf("?page=%v&per_page=%v&after=%v", page, perPage, postId)
if collapsedThreads {
query += "&collapsedThreads=true"
}
if includeDeleted {
query += "&include_deleted=true"
}
r, err := c.DoAPIGet(c.channelRoute(channelId)+"/posts"+query, etag)
if err != nil {
return nil, BuildResponse(r), err
@@ -4071,11 +4078,14 @@ func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, eta
}
// GetPostsBefore gets a page of posts that were posted before the post provided.
func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response, error) {
func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, etag string, collapsedThreads bool, includeDeleted bool) (*PostList, *Response, error) {
query := fmt.Sprintf("?page=%v&per_page=%v&before=%v", page, perPage, postId)
if collapsedThreads {
query += "&collapsedThreads=true"
}
if includeDeleted {
query += "&include_deleted=true"
}
r, err := c.DoAPIGet(c.channelRoute(channelId)+"/posts"+query, etag)
if err != nil {
return nil, BuildResponse(r), err

Просмотреть файл

@@ -73,6 +73,7 @@ var PermissionDeleteOthersEmojis *Permission
var PermissionCreatePost *Permission
var PermissionCreatePostPublic *Permission
var PermissionCreatePostEphemeral *Permission
var PermissionReadDeletedPosts *Permission
var PermissionEditPost *Permission
var PermissionEditOthersPosts *Permission
var PermissionDeletePost *Permission
@@ -708,6 +709,12 @@ func initializePermissions() {
"authentication.permissions.create_post_ephemeral.description",
PermissionScopeChannel,
}
PermissionReadDeletedPosts = &Permission{
"read_deleted_posts",
"authentication.permissions.read_deleted_posts.name",
"authentication.permissions.read_deleted_posts.description",
PermissionScopeChannel,
}
PermissionEditPost = &Permission{
"edit_post",
"authentication.permissions.edit_post.name",
@@ -2302,6 +2309,7 @@ func initializePermissions() {
PermissionCreatePost,
PermissionCreatePostPublic,
PermissionCreatePostEphemeral,
PermissionReadDeletedPosts,
PermissionEditPost,
PermissionEditOthersPosts,
PermissionDeletePost,

Просмотреть файл

@@ -304,6 +304,7 @@ type GetPostsOptions struct {
FromPost string // PostId after which to send the items
FromCreateAt int64 // CreateAt after which to send the items
Direction string // Only accepts up|down. Indicates the order in which to send the items.
IncludeDeleted bool
}
type PostCountOptions struct {