MM-8678: add CUD support for channel members via plugins (#8565)
* add CUD support for channel members via plugins This effectively exposes AddChannelMember, UpdateChannelMemberRoles, UpdateChannelMemberNotifyProps and LeaveChannel via the plugin API. It also modifies the semantics of AddChannelMember to explicitly allow for an empty user requestor, left as such for now via the plugin API. * change the signature of AddChannelMember to accept a channel id instead of a channel
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
ff077c6761
Коммит
116849842b
@@ -340,3 +340,44 @@ func TestRemoveUserFromChannelUpdatesChannelMemberHistoryRecord(t *testing.T) {
|
||||
assert.Equal(t, publicChannel.Id, histories[0].ChannelId)
|
||||
assert.NotNil(t, histories[0].LeaveTime)
|
||||
}
|
||||
|
||||
func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// create a user and add it to a channel
|
||||
user := th.CreateUser()
|
||||
if _, err := th.App.AddTeamMember(th.BasicTeam.Id, user.Id); err != nil {
|
||||
t.Fatal("Failed to add user to team. Error: " + err.Message)
|
||||
}
|
||||
|
||||
groupUserIds := make([]string, 0)
|
||||
groupUserIds = append(groupUserIds, th.BasicUser.Id)
|
||||
groupUserIds = append(groupUserIds, user.Id)
|
||||
|
||||
channel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
|
||||
userRequestorId := ""
|
||||
postRootId := ""
|
||||
if _, err := th.App.AddChannelMember(user.Id, channel, userRequestorId, postRootId); err != nil {
|
||||
t.Fatal("Failed to add user to channel. Error: " + err.Message)
|
||||
}
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories := store.Must(th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)).([]*model.ChannelMemberHistoryResult)
|
||||
assert.Len(t, histories, 2)
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
for _, history := range histories {
|
||||
assert.Equal(t, channel.Id, history.ChannelId)
|
||||
channelMemberHistoryUserIds = append(channelMemberHistoryUserIds, history.UserId)
|
||||
}
|
||||
assert.Equal(t, groupUserIds, channelMemberHistoryUserIds)
|
||||
|
||||
postList := store.Must(th.App.Srv.Store.Post().GetPosts(channel.Id, 0, 1, false)).(*model.PostList)
|
||||
if assert.Len(t, postList.Order, 1) {
|
||||
post := postList.Posts[postList.Order[0]]
|
||||
|
||||
assert.Equal(t, model.POST_JOIN_CHANNEL, post.Type)
|
||||
assert.Equal(t, user.Id, post.UserId)
|
||||
assert.Equal(t, user.Username, post.Props["username"])
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user