Cherry picker search-api-filter-guest-permission to release-10.11 (#35018)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3b1b8d9114
Коммит
4b8b1e5ca0
@@ -8,8 +8,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -1764,9 +1766,67 @@ func (a *App) SearchPostsForUser(c request.CTX, terms string, userID string, tea
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if appErr := a.FilterPostsByChannelPermissions(c, postSearchResults.PostList, userID); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
return postSearchResults, nil
|
||||
}
|
||||
|
||||
func (a *App) FilterPostsByChannelPermissions(rctx request.CTX, postList *model.PostList, userID string) *model.AppError {
|
||||
if postList == nil || postList.Posts == nil || len(postList.Posts) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
channels := make(map[string]*model.Channel)
|
||||
for _, post := range postList.Posts {
|
||||
if post.ChannelId != "" {
|
||||
channels[post.ChannelId] = nil
|
||||
}
|
||||
}
|
||||
|
||||
if len(channels) > 0 {
|
||||
channelIDs := slices.Collect(maps.Keys(channels))
|
||||
channelList, err := a.GetChannels(rctx, channelIDs)
|
||||
if err != nil && err.StatusCode != http.StatusNotFound {
|
||||
return err
|
||||
}
|
||||
for _, channel := range channelList {
|
||||
channels[channel.Id] = channel
|
||||
}
|
||||
}
|
||||
|
||||
channelReadPermission := make(map[string]bool)
|
||||
filteredPosts := make(map[string]*model.Post)
|
||||
filteredOrder := []string{}
|
||||
|
||||
for _, postID := range postList.Order {
|
||||
post, ok := postList.Posts[postID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := channelReadPermission[post.ChannelId]; !ok {
|
||||
channel := channels[post.ChannelId]
|
||||
allowed := false
|
||||
if channel != nil {
|
||||
allowed = a.HasPermissionToReadChannel(rctx, userID, channel)
|
||||
}
|
||||
channelReadPermission[post.ChannelId] = allowed
|
||||
}
|
||||
|
||||
if channelReadPermission[post.ChannelId] {
|
||||
filteredPosts[postID] = post
|
||||
filteredOrder = append(filteredOrder, postID)
|
||||
}
|
||||
}
|
||||
|
||||
postList.Posts = filteredPosts
|
||||
postList.Order = filteredOrder
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfosForPostWithMigration(rctx request.CTX, postID string, includeDeleted bool) ([]*model.FileInfo, *model.AppError) {
|
||||
pchan := make(chan store.StoreResult[*model.Post], 1)
|
||||
go func() {
|
||||
|
||||
Ссылка в новой задаче
Block a user