[MM-13750] Add ability to search teams to plugin API (#10116)

Add SearchTeams in plugin/api,
Этот коммит содержится в:
Adzim Zul Fahmi
2019-01-16 15:13:15 +07:00
коммит произвёл Hanzei
родитель ae76d27b7d
Коммит dfb9241e82
5 изменённых файлов: 90 добавлений и 0 удалений

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

@@ -118,6 +118,10 @@ func (api *PluginAPI) GetTeam(teamId string) (*model.Team, *model.AppError) {
return api.app.GetTeam(teamId)
}
func (api *PluginAPI) SearchTeams(term string) ([]*model.Team, *model.AppError) {
return api.app.SearchAllTeams(term)
}
func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError) {
return api.app.GetTeamByName(name)
}

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

@@ -721,3 +721,30 @@ func TestPluginAPISendMail(t *testing.T) {
require.Equal(t, resultsEmail.Body.Text, body)
}
func TestPluginAPI_SearchTeams(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
t.Run("all fine", func(t *testing.T) {
teams, err := api.SearchTeams(th.BasicTeam.Name)
assert.Nil(t, err)
assert.Len(t, teams, 1)
teams, err = api.SearchTeams(th.BasicTeam.DisplayName)
assert.Nil(t, err)
assert.Len(t, teams, 1)
teams, err = api.SearchTeams(th.BasicTeam.Name[:3])
assert.Nil(t, err)
assert.Len(t, teams, 1)
})
t.Run("invalid team name", func(t *testing.T) {
teams, err := api.SearchTeams("not found")
assert.Nil(t, err)
assert.Empty(t, teams)
})
}

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

@@ -144,6 +144,11 @@ type API interface {
// UpdateTeam updates a team.
UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
// SearchTeams search a team.
//
// Minimum server version: 5.8
SearchTeams(term string) ([]*model.Team, *model.AppError)
// GetTeamsForUser returns list of teams of given user ID.
//
// Minimum server version: 5.6

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

@@ -1362,6 +1362,35 @@ func (s *apiRPCServer) UpdateTeam(args *Z_UpdateTeamArgs, returns *Z_UpdateTeamR
return nil
}
type Z_SearchTeamsArgs struct {
A string
}
type Z_SearchTeamsReturns struct {
A []*model.Team
B *model.AppError
}
func (g *apiRPCClient) SearchTeams(term string) ([]*model.Team, *model.AppError) {
_args := &Z_SearchTeamsArgs{term}
_returns := &Z_SearchTeamsReturns{}
if err := g.client.Call("Plugin.SearchTeams", _args, _returns); err != nil {
log.Printf("RPC call to SearchTeams API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) SearchTeams(args *Z_SearchTeamsArgs, returns *Z_SearchTeamsReturns) error {
if hook, ok := s.impl.(interface {
SearchTeams(term string) ([]*model.Team, *model.AppError)
}); ok {
returns.A, returns.B = hook.SearchTeams(args.A)
} else {
return encodableError(fmt.Errorf("API SearchTeams called but not implemented."))
}
return nil
}
type Z_GetTeamsForUserArgs struct {
A string
}

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

@@ -1958,6 +1958,31 @@ func (_m *API) SearchChannels(teamId string, term string) ([]*model.Channel, *mo
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)
var r0 []*model.Team
if rf, ok := ret.Get(0).(func(string) []*model.Team); ok {
r0 = rf(term)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]*model.Team)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
r1 = rf(term)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// SearchUsers provides a mock function with given fields: search
func (_m *API) SearchUsers(search *model.UserSearch) ([]*model.User, *model.AppError) {
ret := _m.Called(search)