Add GetChannelMember method to plugin API (#7930)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
46f51197fb
Коммит
7a1f81cd52
@@ -115,6 +115,10 @@ func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo
|
|||||||
return api.app.UpdateChannel(channel)
|
return api.app.UpdateChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *PluginAPI) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||||
|
return api.app.GetChannelMember(channelId, userId)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
return api.app.CreatePostMissingChannel(post, true)
|
return api.app.CreatePostMissingChannel(post, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ type API interface {
|
|||||||
// UpdateChannel updates a channel.
|
// UpdateChannel updates a channel.
|
||||||
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
|
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||||
|
|
||||||
|
// GetChannelMember gets a channel membership for a user.
|
||||||
|
GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
|
||||||
|
|
||||||
// CreatePost creates a post.
|
// CreatePost creates a post.
|
||||||
CreatePost(post *model.Post) (*model.Post, *model.AppError)
|
CreatePost(post *model.Post) (*model.Post, *model.AppError)
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,16 @@ func (m *API) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
|
|||||||
return channelOut, err
|
return channelOut, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *API) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||||
|
ret := m.Called(channelId, userId)
|
||||||
|
if f, ok := ret.Get(0).(func(_, _ string) (*model.ChannelMember, *model.AppError)); ok {
|
||||||
|
return f(channelId, userId)
|
||||||
|
}
|
||||||
|
member, _ := ret.Get(0).(*model.ChannelMember)
|
||||||
|
err, _ := ret.Get(1).(*model.AppError)
|
||||||
|
return member, err
|
||||||
|
}
|
||||||
|
|
||||||
func (m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (m *API) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
ret := m.Called(post)
|
ret := m.Called(post)
|
||||||
if f, ok := ret.Get(0).(func(*model.Post) (*model.Post, *model.AppError)); ok {
|
if f, ok := ret.Get(0).(func(*model.Post) (*model.Post, *model.AppError)); ok {
|
||||||
|
|||||||
@@ -154,11 +154,21 @@ type APIGetGroupChannelArgs struct {
|
|||||||
UserIds []string
|
UserIds []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type APIGetChannelMemberArgs struct {
|
||||||
|
ChannelId string
|
||||||
|
UserId string
|
||||||
|
}
|
||||||
|
|
||||||
type APIChannelReply struct {
|
type APIChannelReply struct {
|
||||||
Channel *model.Channel
|
Channel *model.Channel
|
||||||
Error *model.AppError
|
Error *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type APIChannelMemberReply struct {
|
||||||
|
ChannelMember *model.ChannelMember
|
||||||
|
Error *model.AppError
|
||||||
|
}
|
||||||
|
|
||||||
func (api *LocalAPI) CreateChannel(args *model.Channel, reply *APIChannelReply) error {
|
func (api *LocalAPI) CreateChannel(args *model.Channel, reply *APIChannelReply) error {
|
||||||
channel, err := api.api.CreateChannel(args)
|
channel, err := api.api.CreateChannel(args)
|
||||||
*reply = APIChannelReply{
|
*reply = APIChannelReply{
|
||||||
@@ -220,6 +230,15 @@ func (api *LocalAPI) UpdateChannel(args *model.Channel, reply *APIChannelReply)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *LocalAPI) GetChannelMember(args *APIGetChannelMemberArgs, reply *APIChannelMemberReply) error {
|
||||||
|
member, err := api.api.GetChannelMember(args.ChannelId, args.UserId)
|
||||||
|
*reply = APIChannelMemberReply{
|
||||||
|
ChannelMember: member,
|
||||||
|
Error: err,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type APIPostReply struct {
|
type APIPostReply struct {
|
||||||
Post *model.Post
|
Post *model.Post
|
||||||
Error *model.AppError
|
Error *model.AppError
|
||||||
@@ -476,6 +495,17 @@ func (api *RemoteAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo
|
|||||||
return reply.Channel, reply.Error
|
return reply.Channel, reply.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *RemoteAPI) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
|
||||||
|
var reply APIChannelMemberReply
|
||||||
|
if err := api.client.Call("LocalAPI.GetChannelMember", &APIGetChannelMemberArgs{
|
||||||
|
ChannelId: channelId,
|
||||||
|
UserId: userId,
|
||||||
|
}, &reply); err != nil {
|
||||||
|
return nil, model.NewAppError("RemoteAPI.GetChannelMember", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
return reply.ChannelMember, reply.Error
|
||||||
|
}
|
||||||
|
|
||||||
func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||||
var reply APIPostReply
|
var reply APIPostReply
|
||||||
if err := api.client.Call("LocalAPI.CreatePost", post, &reply); err != nil {
|
if err := api.client.Call("LocalAPI.CreatePost", post, &reply); err != nil {
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ func TestAPI(t *testing.T) {
|
|||||||
Id: "thechannelid",
|
Id: "thechannelid",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testChannelMember := &model.ChannelMember{
|
||||||
|
ChannelId: "thechannelid",
|
||||||
|
UserId: "theuserid",
|
||||||
|
}
|
||||||
|
|
||||||
testTeam := &model.Team{
|
testTeam := &model.Team{
|
||||||
Id: "theteamid",
|
Id: "theteamid",
|
||||||
}
|
}
|
||||||
@@ -111,6 +116,11 @@ func TestAPI(t *testing.T) {
|
|||||||
assert.Equal(t, testChannel, channel)
|
assert.Equal(t, testChannel, channel)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
api.On("GetChannelMember", "thechannelid", "theuserid").Return(testChannelMember, nil).Once()
|
||||||
|
member, err := remote.GetChannelMember("thechannelid", "theuserid")
|
||||||
|
assert.Equal(t, testChannelMember, member)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
api.On("CreateUser", mock.AnythingOfType("*model.User")).Return(func(u *model.User) (*model.User, *model.AppError) {
|
api.On("CreateUser", mock.AnythingOfType("*model.User")).Return(func(u *model.User) (*model.User, *model.AppError) {
|
||||||
u.Id = "theuserid"
|
u.Id = "theuserid"
|
||||||
return u, nil
|
return u, nil
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user