MM-35298: Follow thread when added to channel (#19311)
* MM-35298: Follow thread when added to channel * return better error if thread doesn't exist * update test for possible race * use correct comparision operator
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e2e049e05e
Коммит
7026818f80
@@ -1698,6 +1698,14 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if postRootId != "" {
|
||||
err := c.App.UpdateThreadFollowForUserFromChannelAdd(cm.UserId, channel.TeamId, postRootId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
auditRec.AddMeta("add_user_id", cm.UserId)
|
||||
c.LogAudit("name=" + channel.Name + " user_id=" + cm.UserId)
|
||||
|
||||
@@ -3012,6 +3012,63 @@ func TestAddChannelMember(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAddChannelMemberFromThread(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
team := th.BasicTeam
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
user3 := th.CreateUserWithClient(th.SystemAdminClient)
|
||||
_, _, err := th.SystemAdminClient.AddTeamMember(team.Id, user3.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
publicChannel := th.CreatePublicChannel()
|
||||
|
||||
_, resp, err := th.Client.AddChannelMember(publicChannel.Id, user.Id)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
_, resp, err = th.Client.AddChannelMember(publicChannel.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "A root post",
|
||||
UserId: user.Id,
|
||||
}
|
||||
rpost, _, err := th.SystemAdminClient.CreatePost(post)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.CreatePost(
|
||||
&model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "A reply post with mention @" + user3.Username,
|
||||
UserId: user2.Id,
|
||||
RootId: rpost.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.CreatePost(
|
||||
&model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "Another reply post with mention @" + user3.Username,
|
||||
UserId: user2.Id,
|
||||
RootId: rpost.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Simulate adding a user to a channel from a thread
|
||||
_, _, err = th.SystemAdminClient.AddChannelMemberWithRootId(publicChannel.Id, user3.Id, rpost.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Threadmembership should exist for added user
|
||||
ut, _, err := th.SystemAdminClient.GetUserThread(user3.Id, team.Id, rpost.Id, false)
|
||||
require.NoError(t, err)
|
||||
// Should have two mentions. There might be a race condition
|
||||
// here between the "added user to the channel" message and the GetUserThread call
|
||||
require.LessOrEqual(t, int64(2), ut.UnreadMentions)
|
||||
}
|
||||
|
||||
func TestAddChannelMemberAddMyself(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user