MM-12251: Add flag to MoveChannel to remove all deactivated users. (#9515)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7b338c161b
Коммит
9a4f3ce1e5
@@ -1670,7 +1670,13 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
|
||||
// This function is intended for use from the CLI. It is not robust against people joining the channel while the move
|
||||
// is in progress, and therefore should not be used from the API without first fixing this potential race condition.
|
||||
func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
|
||||
func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.User, removeDeactivatedMembers bool) *model.AppError {
|
||||
if removeDeactivatedMembers {
|
||||
if result := <-a.Srv.Store.Channel().RemoveAllDeactivatedMembers(channel.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
}
|
||||
|
||||
// Check that all channel members are in the destination team.
|
||||
channelMembers, err := a.GetChannelMembersPage(channel.Id, 0, 10000000)
|
||||
if err != nil {
|
||||
|
||||
@@ -98,7 +98,7 @@ func TestMoveChannel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser); err == nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser, false); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
@@ -106,7 +106,34 @@ func TestMoveChannel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser); err != nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test moving a channel with a deactivated user who isn't in the destination team.
|
||||
// It should fail, unless removeDeactivatedMembers is true.
|
||||
deacivatedUser := th.CreateUser()
|
||||
channel2 := th.CreateChannel(sourceTeam)
|
||||
|
||||
if _, err := th.App.AddUserToTeam(sourceTeam.Id, deacivatedUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser, channel2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := th.App.AddUserToChannel(deacivatedUser, channel2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := th.App.UpdateActive(deacivatedUser, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel2, th.BasicUser, false); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched deacivated member.")
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel2, th.BasicUser, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user