[MM-38239 & MM-39788] Recent files causing crash (#18942)

* wip

* adding tests for new endpoint

* tool updates

* new function for getting postsByIds

* fixing test

* adding limit of 1000 to post query

* fixing PR comments

* fixing permission logic

Co-authored-by: Collin <collineng@gmail.com>
Co-authored-by: Collin Eng <eng.engineereng@gmail.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MBP.ht.home>
Этот коммит содержится в:
Ben Cooke
2021-11-26 11:51:32 -05:00
коммит произвёл GitHub
родитель 44d324a45f
Коммит 27dacb82ce
8 изменённых файлов: 141 добавлений и 0 удалений

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

@@ -670,6 +670,7 @@ type AppIface interface {
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError)
GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
GetPostsByIds(postIDs []string) ([]*model.Post, *model.AppError)
GetPostsEtag(channelID string, collapsedThreads bool) string
GetPostsForChannelAroundLastUnread(channelID, userID string, limitBefore, limitAfter int, skipFetchThreads bool, collapsedThreads, collapsedThreadsExtended bool) (*model.PostList, *model.AppError)
GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError)

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

@@ -7570,6 +7570,28 @@ func (a *OpenTracingAppLayer) GetPostsBeforePost(options model.GetPostsOptions)
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPostsByIds(postIDs []string) ([]*model.Post, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostsByIds")
a.ctx = newCtx
a.app.Srv().Store.SetContext(newCtx)
defer func() {
a.app.Srv().Store.SetContext(origCtx)
a.ctx = origCtx
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetPostsByIds(postIDs)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetPostsEtag(channelID string, collapsedThreads bool) string {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetPostsEtag")

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

@@ -1670,3 +1670,18 @@ func (a *App) GetPostIfAuthorized(postID string, session *model.Session) (*model
return post, nil
}
func (a *App) GetPostsByIds(postIDs []string) ([]*model.Post, *model.AppError) {
posts, err := a.Srv().Store.Post().GetPostsByIds(postIDs)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetPostsByIds", "app.post.get.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return posts, nil
}