Added SearchPostsInTeamForUser for plugin API (#14807)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7c4c038a96
Коммит
668a2aa856
@@ -415,6 +415,40 @@ func (api *PluginAPI) SearchPostsInTeam(teamId string, paramsList []*model.Searc
|
||||
return postList.ToSlice(), nil
|
||||
}
|
||||
|
||||
func (api *PluginAPI) SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError) {
|
||||
var terms string
|
||||
if searchParams.Terms != nil {
|
||||
terms = *searchParams.Terms
|
||||
}
|
||||
|
||||
timeZoneOffset := 0
|
||||
if searchParams.TimeZoneOffset != nil {
|
||||
timeZoneOffset = *searchParams.TimeZoneOffset
|
||||
}
|
||||
|
||||
isOrSearch := false
|
||||
if searchParams.IsOrSearch != nil {
|
||||
isOrSearch = *searchParams.IsOrSearch
|
||||
}
|
||||
|
||||
page := 0
|
||||
if searchParams.Page != nil {
|
||||
page = *searchParams.Page
|
||||
}
|
||||
|
||||
perPage := 100
|
||||
if searchParams.PerPage != nil {
|
||||
perPage = *searchParams.PerPage
|
||||
}
|
||||
|
||||
includeDeletedChannels := false
|
||||
if searchParams.IncludeDeletedChannels != nil {
|
||||
includeDeletedChannels = *searchParams.IncludeDeletedChannels
|
||||
}
|
||||
|
||||
return api.app.SearchPostsInTeamForUser(terms, userId, teamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
||||
}
|
||||
|
||||
func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
// For now, don't allow overriding these via the plugin API.
|
||||
userRequestorId := ""
|
||||
|
||||
@@ -1577,3 +1577,50 @@ func TestPluginAPIGetPostsForChannel(t *testing.T) {
|
||||
require.Nil(err)
|
||||
require.Equal(expectedPosts, postList.ToSlice())
|
||||
}
|
||||
|
||||
func TestPluginAPISearchPostsInTeamByUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
basicPostText := &th.BasicPost.Message
|
||||
unknwonTerm := "Unknown Message"
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
teamId string
|
||||
userId string
|
||||
params model.SearchParameter
|
||||
expectedPostsLen int
|
||||
}{
|
||||
{
|
||||
"empty params",
|
||||
th.BasicTeam.Id,
|
||||
th.BasicUser.Id,
|
||||
model.SearchParameter{},
|
||||
0,
|
||||
},
|
||||
{
|
||||
"doesn't match any posts",
|
||||
th.BasicTeam.Id,
|
||||
th.BasicUser.Id,
|
||||
model.SearchParameter{Terms: &unknwonTerm},
|
||||
0,
|
||||
},
|
||||
{
|
||||
"matched posts",
|
||||
th.BasicTeam.Id,
|
||||
th.BasicUser.Id,
|
||||
model.SearchParameter{Terms: basicPostText},
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
searchResults, err := api.SearchPostsInTeamForUser(testCase.teamId, testCase.userId, testCase.params)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, testCase.expectedPostsLen, len(searchResults.Posts))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user