MM-18816 Adding ability to add users as another user to the plugin API. (#12562)

* Adding ability to add users as anouther user to the plugin API.

* Documentation feedback.
This commit is contained in:
Christopher Speller
2019-10-17 16:11:26 -07:00
committed by GitHub
parent d7ee3553fa
commit e62471dff6
5 changed files with 87 additions and 1 deletions
+11
View File
@@ -406,6 +406,17 @@ func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.Channel
return api.app.AddChannelMember(userId, channel, userRequestorId, postRootId)
}
func (api *PluginAPI) AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError) {
postRootId := ""
channel, err := api.GetChannel(channelId)
if err != nil {
return nil, err
}
return api.app.AddChannelMember(userId, channel, asUserId, postRootId)
}
func (api *PluginAPI) GetChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {
return api.app.GetChannelMember(channelId, userId)
}
+12
View File
@@ -1439,3 +1439,15 @@ func TestPluginAPIGetUnsanitizedConfig(t *testing.T) {
assert.NotEqual(t, config.SqlSettings.DataSourceSearchReplicas[i], model.FAKE_SETTING)
}
}
func TestPluginAddUserToChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
member, err := api.AddUserToChannel(th.BasicChannel.Id, th.BasicUser.Id, th.BasicUser2.Id)
require.Nil(t, err)
require.NotNil(t, member)
require.Equal(t, th.BasicChannel.Id, member.ChannelId)
require.Equal(t, th.BasicUser.Id, member.UserId)
}
+8 -1
View File
@@ -336,11 +336,18 @@ type API interface {
// Minimum server version: 5.10
SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) ([]*model.Post, *model.AppError)
// AddChannelMember creates a channel membership for a user.
// AddChannelMember joins a user to a channel (as if they joined themselves)
// This means the user will not receive notifications for joining the channel.
//
// Minimum server version: 5.2
AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)
// AddUserToChannel adds a user to a channel as if the specified user had invited them.
// This means the user will receive the regular notifications for being added to the channel.
//
// Minimum server version: 5.18
AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError)
// GetChannelMember gets a channel membership for a user.
//
// Minimum server version: 5.2
+31
View File
@@ -2282,6 +2282,37 @@ func (s *apiRPCServer) AddChannelMember(args *Z_AddChannelMemberArgs, returns *Z
return nil
}
type Z_AddUserToChannelArgs struct {
A string
B string
C string
}
type Z_AddUserToChannelReturns struct {
A *model.ChannelMember
B *model.AppError
}
func (g *apiRPCClient) AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError) {
_args := &Z_AddUserToChannelArgs{channelId, userId, asUserId}
_returns := &Z_AddUserToChannelReturns{}
if err := g.client.Call("Plugin.AddUserToChannel", _args, _returns); err != nil {
log.Printf("RPC call to AddUserToChannel API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) AddUserToChannel(args *Z_AddUserToChannelArgs, returns *Z_AddUserToChannelReturns) error {
if hook, ok := s.impl.(interface {
AddUserToChannel(channelId, userId, asUserId string) (*model.ChannelMember, *model.AppError)
}); ok {
returns.A, returns.B = hook.AddUserToChannel(args.A, args.B, args.C)
} else {
return encodableError(fmt.Errorf("API AddUserToChannel called but not implemented."))
}
return nil
}
type Z_GetChannelMemberArgs struct {
A string
B string
+25
View File
@@ -66,6 +66,31 @@ func (_m *API) AddReaction(reaction *model.Reaction) (*model.Reaction, *model.Ap
return r0, r1
}
// AddUserToChannel provides a mock function with given fields: channelId, userId, asUserId
func (_m *API) AddUserToChannel(channelId string, userId string, asUserId string) (*model.ChannelMember, *model.AppError) {
ret := _m.Called(channelId, userId, asUserId)
var r0 *model.ChannelMember
if rf, ok := ret.Get(0).(func(string, string, string) *model.ChannelMember); ok {
r0 = rf(channelId, userId, asUserId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.ChannelMember)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string, string) *model.AppError); ok {
r1 = rf(channelId, userId, asUserId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// CopyFileInfos provides a mock function with given fields: userId, fileIds
func (_m *API) CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError) {
ret := _m.Called(userId, fileIds)