MM-12957: Fix moving a channel with no members. (#9841)

This commit is contained in:
George Goldberg
2018-11-22 11:19:47 +00:00
committed by GitHub
parent ffd92d5d48
commit 877e1b7f9a
2 changed files with 27 additions and 8 deletions

View File

@@ -1709,13 +1709,15 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.
channelMemberIds = append(channelMemberIds, channelMember.UserId)
}
teamMembers, err2 := a.GetTeamMembersByIds(team.Id, channelMemberIds)
if err2 != nil {
return err2
}
if len(channelMemberIds) > 0 {
teamMembers, err2 := a.GetTeamMembersByIds(team.Id, channelMemberIds)
if err2 != nil {
return err2
}
if len(teamMembers) != len(*channelMembers) {
return model.NewAppError("MoveChannel", "app.channel.move_channel.members_do_not_match.error", nil, "", http.StatusInternalServerError)
if len(teamMembers) != len(*channelMembers) {
return model.NewAppError("MoveChannel", "app.channel.move_channel.members_do_not_match.error", nil, "", http.StatusInternalServerError)
}
}
// keep instance of the previous team

View File

@@ -8,10 +8,11 @@ import (
"strings"
"testing"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
)
func TestPermanentDeleteChannel(t *testing.T) {
@@ -138,6 +139,22 @@ func TestMoveChannel(t *testing.T) {
if err := th.App.MoveChannel(targetTeam, channel2, th.BasicUser, true); err != nil {
t.Fatal(err)
}
// Test moving a channel with no members.
channel3 := &model.Channel{
DisplayName: "dn_" + model.NewId(),
Name: "name_" + model.NewId(),
Type: model.CHANNEL_OPEN,
TeamId: sourceTeam.Id,
CreatorId: th.BasicUser.Id,
}
var err *model.AppError
channel3, err = th.App.CreateChannel(channel3, false)
require.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser, false)
assert.Nil(t, err)
}
func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testing.T) {