Remove *model.ChannelList from plugin API return parameter (#9844)
* Remove *model.ChannelList from plugin API return parametern * Fix panic * Add tests * Changes as requested * Fix panic in GetPublicChannelsForTeam()
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8cfca681b0
Коммит
0a73690537
@@ -262,6 +262,9 @@ func (api *PluginAPI) DeleteChannel(channelId string) *model.AppError {
|
|||||||
|
|
||||||
func (api *PluginAPI) GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError) {
|
func (api *PluginAPI) GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError) {
|
||||||
channels, err := api.app.GetPublicChannelsForTeam(teamId, page*perPage, perPage)
|
channels, err := api.app.GetPublicChannelsForTeam(teamId, page*perPage, perPage)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return *channels, err
|
return *channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,8 +280,12 @@ func (api *PluginAPI) GetChannelByNameForTeamName(teamName, channelName string,
|
|||||||
return api.app.GetChannelByNameForTeamName(channelName, teamName, includeDeleted)
|
return api.app.GetChannelByNameForTeamName(channelName, teamName, includeDeleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
|
||||||
return api.app.GetChannelsForUser(teamId, userId, includeDeleted)
|
channels, err := api.app.GetChannelsForUser(teamId, userId, includeDeleted)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return *channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
|
func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
|
||||||
@@ -301,8 +308,12 @@ func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo
|
|||||||
return api.app.UpdateChannel(channel)
|
return api.app.UpdateChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
func (api *PluginAPI) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
|
||||||
return api.app.SearchChannels(teamId, term)
|
channels, err := api.app.SearchChannels(teamId, term)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return *channels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||||
|
|||||||
@@ -450,3 +450,39 @@ func TestPluginAPISetTeamIcon(t *testing.T) {
|
|||||||
require.Nil(t, err2)
|
require.Nil(t, err2)
|
||||||
require.Equal(t, img2.At(2, 3), colorful)
|
require.Equal(t, img2.At(2, 3), colorful)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPluginAPISearchChannels(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
api := th.SetupPluginAPI()
|
||||||
|
|
||||||
|
t.Run("all fine", func(t *testing.T) {
|
||||||
|
channels, err := api.SearchChannels(th.BasicTeam.Id, th.BasicChannel.Name)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Len(t, channels, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid team id", func(t *testing.T) {
|
||||||
|
channels, err := api.SearchChannels("invalidid", th.BasicChannel.Name)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Empty(t, channels)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPluginAPIGetChannelsForTeamForUser(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
api := th.SetupPluginAPI()
|
||||||
|
|
||||||
|
t.Run("all fine", func(t *testing.T) {
|
||||||
|
channels, err := api.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Len(t, channels, 3)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid team id", func(t *testing.T) {
|
||||||
|
channels, err := api.GetChannelsForTeamForUser("invalidid", th.BasicUser.Id, false)
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
assert.Empty(t, channels)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ type API interface {
|
|||||||
// GetChannelsForTeamForUser gets a list of channels for given user ID in given team ID.
|
// GetChannelsForTeamForUser gets a list of channels for given user ID in given team ID.
|
||||||
//
|
//
|
||||||
// Minimum server version: 5.6
|
// Minimum server version: 5.6
|
||||||
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)
|
||||||
|
|
||||||
// GetChannelStats gets statistics for a channel.
|
// GetChannelStats gets statistics for a channel.
|
||||||
//
|
//
|
||||||
@@ -197,7 +197,7 @@ type API interface {
|
|||||||
// SearchChannels returns the channels on a team matching the provided search term.
|
// SearchChannels returns the channels on a team matching the provided search term.
|
||||||
//
|
//
|
||||||
// Minimum server version: 5.6
|
// Minimum server version: 5.6
|
||||||
SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
|
SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)
|
||||||
|
|
||||||
// AddChannelMember creates a channel membership for a user.
|
// AddChannelMember creates a channel membership for a user.
|
||||||
AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
|
AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
|
||||||
|
|||||||
@@ -1778,11 +1778,11 @@ type Z_GetChannelsForTeamForUserArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Z_GetChannelsForTeamForUserReturns struct {
|
type Z_GetChannelsForTeamForUserReturns struct {
|
||||||
A *model.ChannelList
|
A []*model.Channel
|
||||||
B *model.AppError
|
B *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
|
||||||
_args := &Z_GetChannelsForTeamForUserArgs{teamId, userId, includeDeleted}
|
_args := &Z_GetChannelsForTeamForUserArgs{teamId, userId, includeDeleted}
|
||||||
_returns := &Z_GetChannelsForTeamForUserReturns{}
|
_returns := &Z_GetChannelsForTeamForUserReturns{}
|
||||||
if err := g.client.Call("Plugin.GetChannelsForTeamForUser", _args, _returns); err != nil {
|
if err := g.client.Call("Plugin.GetChannelsForTeamForUser", _args, _returns); err != nil {
|
||||||
@@ -1793,7 +1793,7 @@ func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeD
|
|||||||
|
|
||||||
func (s *apiRPCServer) GetChannelsForTeamForUser(args *Z_GetChannelsForTeamForUserArgs, returns *Z_GetChannelsForTeamForUserReturns) error {
|
func (s *apiRPCServer) GetChannelsForTeamForUser(args *Z_GetChannelsForTeamForUserArgs, returns *Z_GetChannelsForTeamForUserReturns) error {
|
||||||
if hook, ok := s.impl.(interface {
|
if hook, ok := s.impl.(interface {
|
||||||
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)
|
||||||
}); ok {
|
}); ok {
|
||||||
returns.A, returns.B = hook.GetChannelsForTeamForUser(args.A, args.B, args.C)
|
returns.A, returns.B = hook.GetChannelsForTeamForUser(args.A, args.B, args.C)
|
||||||
} else {
|
} else {
|
||||||
@@ -1925,11 +1925,11 @@ type Z_SearchChannelsArgs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Z_SearchChannelsReturns struct {
|
type Z_SearchChannelsReturns struct {
|
||||||
A *model.ChannelList
|
A []*model.Channel
|
||||||
B *model.AppError
|
B *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *apiRPCClient) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
func (g *apiRPCClient) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
|
||||||
_args := &Z_SearchChannelsArgs{teamId, term}
|
_args := &Z_SearchChannelsArgs{teamId, term}
|
||||||
_returns := &Z_SearchChannelsReturns{}
|
_returns := &Z_SearchChannelsReturns{}
|
||||||
if err := g.client.Call("Plugin.SearchChannels", _args, _returns); err != nil {
|
if err := g.client.Call("Plugin.SearchChannels", _args, _returns); err != nil {
|
||||||
@@ -1940,7 +1940,7 @@ func (g *apiRPCClient) SearchChannels(teamId string, term string) (*model.Channe
|
|||||||
|
|
||||||
func (s *apiRPCServer) SearchChannels(args *Z_SearchChannelsArgs, returns *Z_SearchChannelsReturns) error {
|
func (s *apiRPCServer) SearchChannels(args *Z_SearchChannelsArgs, returns *Z_SearchChannelsReturns) error {
|
||||||
if hook, ok := s.impl.(interface {
|
if hook, ok := s.impl.(interface {
|
||||||
SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
|
SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)
|
||||||
}); ok {
|
}); ok {
|
||||||
returns.A, returns.B = hook.SearchChannels(args.A, args.B)
|
returns.A, returns.B = hook.SearchChannels(args.A, args.B)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -541,15 +541,15 @@ func (_m *API) GetChannelStats(channelId string) (*model.ChannelStats, *model.Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelsForTeamForUser provides a mock function with given fields: teamId, userId, includeDeleted
|
// GetChannelsForTeamForUser provides a mock function with given fields: teamId, userId, includeDeleted
|
||||||
func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(teamId, userId, includeDeleted)
|
ret := _m.Called(teamId, userId, includeDeleted)
|
||||||
|
|
||||||
var r0 *model.ChannelList
|
var r0 []*model.Channel
|
||||||
if rf, ok := ret.Get(0).(func(string, string, bool) *model.ChannelList); ok {
|
if rf, ok := ret.Get(0).(func(string, string, bool) []*model.Channel); ok {
|
||||||
r0 = rf(teamId, userId, includeDeleted)
|
r0 = rf(teamId, userId, includeDeleted)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.ChannelList)
|
r0 = ret.Get(0).([]*model.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1866,15 +1866,15 @@ func (_m *API) SavePluginConfig(pluginConfig map[string]interface{}) *model.AppE
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SearchChannels provides a mock function with given fields: teamId, term
|
// SearchChannels provides a mock function with given fields: teamId, term
|
||||||
func (_m *API) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
func (_m *API) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(teamId, term)
|
ret := _m.Called(teamId, term)
|
||||||
|
|
||||||
var r0 *model.ChannelList
|
var r0 []*model.Channel
|
||||||
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelList); ok {
|
if rf, ok := ret.Get(0).(func(string, string) []*model.Channel); ok {
|
||||||
r0 = rf(teamId, term)
|
r0 = rf(teamId, term)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.ChannelList)
|
r0 = ret.Get(0).([]*model.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user