[MM-62004] update threads after a channel gets moved (#29624)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3aaa379687
Коммит
a3f22bd349
@@ -3276,6 +3276,11 @@ func (a *App) MoveChannel(c request.CTX, team *model.Team, channel *model.Channe
|
||||
}
|
||||
}
|
||||
|
||||
// Update the threads within this channel to the new team
|
||||
if err := a.Srv().Store().Thread().UpdateTeamIdForChannelThreads(channel.Id, team.Id); err != nil {
|
||||
c.Logger().Warn("error while updating threads after channel move", mlog.Err(err))
|
||||
}
|
||||
|
||||
if err := a.RemoveUsersFromChannelNotMemberOfTeam(c, user, channel, team); err != nil {
|
||||
c.Logger().Warn("error while removing non-team member users", mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -247,6 +247,59 @@ func TestMoveChannel(t *testing.T) {
|
||||
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
|
||||
assert.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
})
|
||||
|
||||
t.Run("should update threads when moving channels between teams", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
sourceTeam := th.CreateTeam()
|
||||
targetTeam := th.CreateTeam()
|
||||
channel := th.CreateChannel(th.Context, sourceTeam)
|
||||
|
||||
th.LinkUserToTeam(th.BasicUser, sourceTeam)
|
||||
th.LinkUserToTeam(th.BasicUser, targetTeam)
|
||||
th.AddUserToChannel(th.BasicUser, channel)
|
||||
|
||||
// Create a thread in the channel
|
||||
post := &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test",
|
||||
}
|
||||
post, appErr := th.App.CreatePost(th.Context, post, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Post a reply to the thread
|
||||
reply := &model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: channel.Id,
|
||||
RootId: post.Id,
|
||||
Message: "reply",
|
||||
}
|
||||
_, appErr = th.App.CreatePost(th.Context, reply, channel, model.CreatePostFlags{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that the thread count before move
|
||||
threads, appErr := th.App.GetThreadsForUser(th.BasicUser.Id, targetTeam.Id, model.GetUserThreadsOpts{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
require.Zero(t, threads.Total)
|
||||
|
||||
// Move the channel to the target team
|
||||
appErr = th.App.MoveChannel(th.Context, targetTeam, channel, th.BasicUser)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Check that the thread was moved
|
||||
threads, appErr = th.App.GetThreadsForUser(th.BasicUser.Id, targetTeam.Id, model.GetUserThreadsOpts{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
require.Equal(t, int64(1), threads.Total)
|
||||
// Check that the thread count after move
|
||||
threads, appErr = th.App.GetThreadsForUser(th.BasicUser.Id, sourceTeam.Id, model.GetUserThreadsOpts{})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
require.Zero(t, threads.Total)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemoveUsersFromChannelNotMemberOfTeam(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user