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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,6 +444,12 @@ type API interface {
|
||||
// Minimum server version: 5.10
|
||||
SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError)
|
||||
|
||||
// SearchPostsInTeamForUser returns a list of posts by team and user that match the given
|
||||
// search parameters.
|
||||
// @tag Post
|
||||
// Minimum server version: 5.26
|
||||
SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError)
|
||||
|
||||
// AddChannelMember joins a user to a channel (as if they joined themselves)
|
||||
// This means the user will not receive notifications for joining the channel.
|
||||
//
|
||||
|
||||
@@ -490,6 +490,13 @@ func (api *apiTimerLayer) SearchPostsInTeam(teamId string, paramsList []*model.S
|
||||
return _returnsA, _returnsB
|
||||
}
|
||||
|
||||
func (api *apiTimerLayer) SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError) {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA, _returnsB := api.apiImpl.SearchPostsInTeamForUser(teamId, userId, searchParams)
|
||||
api.recordTime(startTime, "SearchPostsInTeamForUser", _returnsB == nil)
|
||||
return _returnsA, _returnsB
|
||||
}
|
||||
|
||||
func (api *apiTimerLayer) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
startTime := timePkg.Now()
|
||||
_returnsA, _returnsB := api.apiImpl.AddChannelMember(channelId, userId)
|
||||
|
||||
@@ -2361,6 +2361,37 @@ func (s *apiRPCServer) SearchPostsInTeam(args *Z_SearchPostsInTeamArgs, returns
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_SearchPostsInTeamForUserArgs struct {
|
||||
A string
|
||||
B string
|
||||
C model.SearchParameter
|
||||
}
|
||||
|
||||
type Z_SearchPostsInTeamForUserReturns struct {
|
||||
A *model.PostSearchResults
|
||||
B *model.AppError
|
||||
}
|
||||
|
||||
func (g *apiRPCClient) SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError) {
|
||||
_args := &Z_SearchPostsInTeamForUserArgs{teamId, userId, searchParams}
|
||||
_returns := &Z_SearchPostsInTeamForUserReturns{}
|
||||
if err := g.client.Call("Plugin.SearchPostsInTeamForUser", _args, _returns); err != nil {
|
||||
log.Printf("RPC call to SearchPostsInTeamForUser API failed: %s", err.Error())
|
||||
}
|
||||
return _returns.A, _returns.B
|
||||
}
|
||||
|
||||
func (s *apiRPCServer) SearchPostsInTeamForUser(args *Z_SearchPostsInTeamForUserArgs, returns *Z_SearchPostsInTeamForUserReturns) error {
|
||||
if hook, ok := s.impl.(interface {
|
||||
SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError)
|
||||
}); ok {
|
||||
returns.A, returns.B = hook.SearchPostsInTeamForUser(args.A, args.B, args.C)
|
||||
} else {
|
||||
return encodableError(fmt.Errorf("API SearchPostsInTeamForUser called but not implemented."))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Z_AddChannelMemberArgs struct {
|
||||
A string
|
||||
B string
|
||||
|
||||
@@ -2633,6 +2633,31 @@ func (_m *API) SearchPostsInTeam(teamId string, paramsList []*model.SearchParams
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchPostsInTeamForUser provides a mock function with given fields: teamId, userId, searchParams
|
||||
func (_m *API) SearchPostsInTeamForUser(teamId string, userId string, searchParams model.SearchParameter) (*model.PostSearchResults, *model.AppError) {
|
||||
ret := _m.Called(teamId, userId, searchParams)
|
||||
|
||||
var r0 *model.PostSearchResults
|
||||
if rf, ok := ret.Get(0).(func(string, string, model.SearchParameter) *model.PostSearchResults); ok {
|
||||
r0 = rf(teamId, userId, searchParams)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.PostSearchResults)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, string, model.SearchParameter) *model.AppError); ok {
|
||||
r1 = rf(teamId, userId, searchParams)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchTeams provides a mock function with given fields: term
|
||||
func (_m *API) SearchTeams(term string) ([]*model.Team, *model.AppError) {
|
||||
ret := _m.Called(term)
|
||||
|
||||
Ссылка в новой задаче
Block a user