[PLT-7362] Option to add user to channel if mentioned user is not currently in the channel (#7619)

* Option to add user to channel if mentioned user is not currently in the channel

* instead of link from server, just add component on client side to add channel member

* change implementation using post.props

* do clean up and add test

* sanitize post.props['add_channel_member'] on post creation

* move sanitize to app.CreatePost and also apply to app.UpdatePost
Этот коммит содержится в:
Saturnino Abril
2017-10-21 01:38:26 +08:00
коммит произвёл GitHub
родитель cbb18479e9
Коммит 18ee375860
7 изменённых файлов: 185 добавлений и 8 удалений

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

@@ -39,7 +39,7 @@ func TestCreatePost(t *testing.T) {
adminUser := th.CreateUser(th.SystemAdminClient)
th.LinkUserToTeam(adminUser, adminTeam)
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a", Props: model.StringInterface{model.PROPS_ADD_CHANNEL_MEMBER: "no good"}}
rpost1, err := Client.CreatePost(post1)
if err != nil {
t.Fatal(err)
@@ -61,6 +61,10 @@ func TestCreatePost(t *testing.T) {
t.Fatal("Newly craeted post shouldn't have EditAt set")
}
if rpost1.Data.(*model.Post).Props[model.PROPS_ADD_CHANNEL_MEMBER] != nil {
t.Fatal("newly created post shouldn't have Props['add_channel_member'] set")
}
_, err = Client.CreatePost(&model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a", Type: model.POST_SYSTEM_GENERIC})
if err == nil {
t.Fatal("should have failed - bad post type")
@@ -433,6 +437,7 @@ func TestUpdatePost(t *testing.T) {
msg2 := "zz" + model.NewId() + " update post 1"
rpost2.Data.(*model.Post).Message = msg2
rpost2.Data.(*model.Post).Props[model.PROPS_ADD_CHANNEL_MEMBER] = "no good"
if rupost2, err := Client.UpdatePost(rpost2.Data.(*model.Post)); err != nil {
t.Fatal(err)
} else {
@@ -442,6 +447,9 @@ func TestUpdatePost(t *testing.T) {
if rupost2.Data.(*model.Post).EditAt == 0 {
t.Fatal("EditAt not updated for post")
}
if rupost2.Data.(*model.Post).Props[model.PROPS_ADD_CHANNEL_MEMBER] != nil {
t.Fatal("failed to sanitize Props['add_channel_member'], should be nil")
}
}
msg1 := "#hashtag a" + model.NewId() + " update post 2"