PLT-7216: CLI Command to move channels between teams. (#7149)
* PLT-7216: CLI Command to move channels between teams. * Add comment
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1e78ff831e
Коммит
ba2868775d
@@ -1201,6 +1201,36 @@ func PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 MoveChannel(team *model.Team, channel *model.Channel) *model.AppError {
|
||||
// Check that all channel members are in the destination team.
|
||||
if channelMembers, err := GetChannelMembersPage(channel.Id, 0, 10000000); err != nil {
|
||||
return err
|
||||
} else {
|
||||
channelMemberIds := []string{}
|
||||
for _, channelMember := range *channelMembers {
|
||||
channelMemberIds = append(channelMemberIds, channelMember.UserId)
|
||||
}
|
||||
|
||||
if teamMembers, err2 := GetTeamMembersByIds(team.Id, channelMemberIds); err != nil {
|
||||
return err2
|
||||
} else {
|
||||
if len(teamMembers) != len(*channelMembers) {
|
||||
return model.NewAppError("MoveChannel", "app.channel.move_channel.members_do_not_match.error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change the Team ID of the channel.
|
||||
channel.TeamId = team.Id
|
||||
if result := <-Srv.Store.Channel().Update(channel); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||
if result := <-Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
|
||||
@@ -64,3 +64,46 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
t.Error("outgoing webhook wasn't deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveChannel(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
sourceTeam := th.CreateTeam()
|
||||
targetTeam := th.CreateTeam()
|
||||
channel1 := th.CreateChannel(sourceTeam)
|
||||
defer func() {
|
||||
PermanentDeleteChannel(channel1)
|
||||
PermanentDeleteTeam(sourceTeam)
|
||||
PermanentDeleteTeam(targetTeam)
|
||||
}()
|
||||
|
||||
if _, err := AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := MoveChannel(targetTeam, channel1); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
if _, err := AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := MoveChannel(targetTeam, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user