[MM-42192] Include deleted posts in GetPost (#20358)

* Introduced include_deleted query param on get posts endpoint

* Update the correct func name in the comment.

Co-authored-by: santoniriccardo <santoni.riccardo@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Vishal
2022-06-06 13:29:42 +05:30
коммит произвёл GitHub
родитель 456299841a
Коммит 27fc14201f
16 изменённых файлов: 85 добавлений и 38 удалений

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

@@ -680,7 +680,7 @@ type AppIface interface {
GetPostAfterTime(channelID string, time int64, collapsedThreads bool) (*model.Post, *model.AppError)
GetPostIdAfterTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
GetPostIdBeforeTime(channelID string, time int64, collapsedThreads bool) (string, *model.AppError)
GetPostIfAuthorized(postID string, session *model.Session) (*model.Post, *model.AppError)
GetPostIfAuthorized(postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError)
GetPostThread(postID string, opts model.GetPostsOptions, userID string) (*model.PostList, *model.AppError)
GetPosts(channelID string, offset int, limit int) (*model.PostList, *model.AppError)
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
@@ -735,7 +735,7 @@ type AppIface interface {
GetSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError)
GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError)
GetSidebarCategoryOrder(userID, teamID string) ([]string, *model.AppError)
GetSinglePost(postID string) (*model.Post, *model.AppError)
GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError)
GetSiteURL() string
GetStatus(userID string) (*model.Status, *model.AppError)
GetStatusFromCache(userID string) *model.Status

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

@@ -2570,7 +2570,7 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string, collapse
if !collapsedThreadsSupported || !a.IsCRTEnabledForUser(userID) {
return a.markChannelAsUnreadFromPostCRTUnsupported(postID, userID)
}
post, err := a.GetSinglePost(postID)
post, err := a.GetSinglePost(postID, false)
if err != nil {
return nil, err
}
@@ -2597,7 +2597,7 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string, collapse
}
func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID string) (*model.ChannelUnreadAt, *model.AppError) {
post, err := a.GetSinglePost(postID)
post, err := a.GetSinglePost(postID, false)
if err != nil {
return nil, err
}
@@ -2636,7 +2636,7 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(postID string, userID st
// If there are replies with mentions below the marked reply in the thread, then sum the mentions for the threads mention badge.
// In CRT Unsupported Client: Channel is marked as unread and new messages line inserted above the marked post.
// Badge on channel sums mentions in all posts (root & replies) including and below the post that was marked unread.
rootPost, err := a.GetSinglePost(post.RootId)
rootPost, err := a.GetSinglePost(post.RootId, false)
if err != nil {
return nil, err
}

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

@@ -7683,7 +7683,7 @@ func (a *OpenTracingAppLayer) GetPostIdBeforeTime(channelID string, time int64,
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPostIfAuthorized(postID string, session *model.Session) (*model.Post, *model.AppError) {
func (a *OpenTracingAppLayer) GetPostIfAuthorized(postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostIfAuthorized")
@@ -7695,7 +7695,7 @@ func (a *OpenTracingAppLayer) GetPostIfAuthorized(postID string, session *model.
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetPostIfAuthorized(postID, session)
resultVar0, resultVar1 := a.app.GetPostIfAuthorized(postID, session, includeDeleted)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -8995,7 +8995,7 @@ func (a *OpenTracingAppLayer) GetSidebarCategoryOrder(userID string, teamID stri
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetSinglePost(postID string) (*model.Post, *model.AppError) {
func (a *OpenTracingAppLayer) GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSinglePost")
@@ -9007,7 +9007,7 @@ func (a *OpenTracingAppLayer) GetSinglePost(postID string) (*model.Post, *model.
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetSinglePost(postID)
resultVar0, resultVar1 := a.app.GetSinglePost(postID, includeDeleted)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))

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

@@ -665,7 +665,7 @@ func (api *PluginAPI) GetPostThread(postID string) (*model.PostList, *model.AppE
}
func (api *PluginAPI) GetPost(postID string) (*model.Post, *model.AppError) {
return api.app.GetSinglePost(postID)
return api.app.GetSinglePost(postID, false)
}
func (api *PluginAPI) GetPostsSince(channelID string, time int64) (*model.PostList, *model.AppError) {

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

@@ -136,7 +136,7 @@ func (a *App) deduplicateCreatePost(post *model.Post) (foundPost *model.Post, er
// If the other thread finished creating the post, return the created post back to the
// client, making the API call feel idempotent.
actualPost, err := a.GetSinglePost(postID)
actualPost, err := a.GetSinglePost(postID, false)
if err != nil {
return nil, model.NewAppError("deduplicateCreatePost", "api.post.deduplicate_create_post.failed_to_get", nil, err.Error(), http.StatusInternalServerError)
}
@@ -718,7 +718,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
return false, nil
}
previewedPost, err := a.GetSinglePost(previewedPostID)
previewedPost, err := a.GetSinglePost(previewedPostID, false)
if err != nil {
if err.StatusCode == http.StatusNotFound {
mlog.Warn("permalinked post not found", mlog.String("referenced_post_id", previewedPostID))
@@ -768,7 +768,7 @@ func (a *App) publishWebsocketEventForPermalinkPost(post *model.Post, message *m
}
func (a *App) PatchPost(c *request.Context, postID string, patch *model.PostPatch) (*model.Post, *model.AppError) {
post, err := a.GetSinglePost(postID)
post, err := a.GetSinglePost(postID, false)
if err != nil {
return nil, err
}
@@ -840,8 +840,8 @@ func (a *App) GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList
return postList, nil
}
func (a *App) GetSinglePost(postID string) (*model.Post, *model.AppError) {
post, err := a.Srv().Store.Post().GetSingle(postID, false)
func (a *App) GetSinglePost(postID string, includeDeleted bool) (*model.Post, *model.AppError) {
post, err := a.Srv().Store.Post().GetSingle(postID, includeDeleted)
if err != nil {
var nfErr *store.ErrNotFound
switch {
@@ -1678,8 +1678,8 @@ func (a *App) GetThreadMembershipsForUser(userID, teamID string) ([]*model.Threa
return a.Srv().Store.Thread().GetMembershipsForUser(userID, teamID)
}
func (a *App) GetPostIfAuthorized(postID string, session *model.Session) (*model.Post, *model.AppError) {
post, err := a.GetSinglePost(postID)
func (a *App) GetPostIfAuthorized(postID string, session *model.Session, includeDeleted bool) (*model.Post, *model.AppError) {
post, err := a.GetSinglePost(postID, includeDeleted)
if err != nil {
return nil, err
}

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

@@ -540,7 +540,7 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool
if looksLikeAPermalink(requestURL, a.GetSiteURL()) && *a.Config().ServiceSettings.EnablePermalinkPreviews && a.Config().FeatureFlags.PermalinkPreviews {
referencedPostID := requestURL[len(requestURL)-26:]
referencedPost, appErr := a.GetSinglePost(referencedPostID)
referencedPost, appErr := a.GetSinglePost(referencedPostID, false)
// TODO: Look into saving a value in the LinkMetadata.Data field to prevent perpetually re-querying for the deleted post.
if appErr != nil {
return nil, nil, nil, appErr

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

@@ -250,7 +250,7 @@ func TestAttachFilesToPost(t *testing.T) {
assert.Len(t, infos, 1)
assert.Equal(t, info2.Id, infos[0].Id)
updated, appErr := th.App.GetSinglePost(post.Id)
updated, appErr := th.App.GetSinglePost(post.Id, false)
require.Nil(t, appErr)
assert.Len(t, updated.FileIds, 1)
assert.Contains(t, updated.FileIds, info2.Id)
@@ -2761,11 +2761,11 @@ func TestGetPostIfAuthorized(t *testing.T) {
require.NotNil(t, session2)
// User is not authorized to get post
_, err = th.App.GetPostIfAuthorized(post.Id, session2)
_, err = th.App.GetPostIfAuthorized(post.Id, session2, false)
require.NotNil(t, err)
// User is authorized to get post
_, err = th.App.GetPostIfAuthorized(post.Id, session1)
_, err = th.App.GetPostIfAuthorized(post.Id, session1, false)
require.Nil(t, err)
}

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

@@ -15,7 +15,7 @@ import (
)
func (a *App) SaveReactionForPost(c *request.Context, reaction *model.Reaction) (*model.Reaction, *model.AppError) {
post, err := a.GetSinglePost(reaction.PostId)
post, err := a.GetSinglePost(reaction.PostId, false)
if err != nil {
return nil, err
}
@@ -121,7 +121,7 @@ func (a *App) GetTopReactionsForUserSince(userID string, teamID string, opts *mo
}
func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction) *model.AppError {
post, err := a.GetSinglePost(reaction.PostId)
post, err := a.GetSinglePost(reaction.PostId, false)
if err != nil {
return err
}

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

@@ -2449,7 +2449,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID s
return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
post, appErr := a.GetSinglePost(threadID)
post, appErr := a.GetSinglePost(threadID, false)
if appErr != nil {
return appErr
}
@@ -2495,7 +2495,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID s
}
func (a *App) UpdateThreadReadForUserByPost(currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError) {
post, err := a.GetSinglePost(postID)
post, err := a.GetSinglePost(postID, false)
if err != nil {
return nil, err
}
@@ -2528,7 +2528,7 @@ func (a *App) UpdateThreadReadForUser(currentSessionId, userID, teamID, threadID
return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
post, err := a.GetSinglePost(threadID)
post, err := a.GetSinglePost(threadID, false)
if err != nil {
return nil, err
}