From f7476b2fb6a01d50868a128c1d1f77c14691482d Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Thu, 26 Jan 2017 02:14:12 +0000 Subject: PLT-4378 Slack import when channel name is deleted (#4649) This fixes the issue where the channel fails to Import from Slack if there is already a channel with the same name on Mattermost that has been deleted. --- app/slackimport.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'app/slackimport.go') diff --git a/app/slackimport.go b/app/slackimport.go index 53f455069..508803126 100644 --- a/app/slackimport.go +++ b/app/slackimport.go @@ -470,18 +470,28 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str Header: sChannel.Topic["value"], } newChannel = SlackSanitiseChannelProperties(newChannel) - mChannel := ImportChannel(&newChannel) + + var mChannel *model.Channel + if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err == nil { + // The channel already exists as an active channel. Merge with the existing one. + mChannel = result.Data.(*model.Channel) + log.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName})) + } else if result := <-Srv.Store.Channel().GetDeletedByName(teamId, sChannel.Name); result.Err == nil { + // The channel already exists but has been deleted. Generate a random string for the handle instead. + newChannel.Name = model.NewId() + newChannel = SlackSanitiseChannelProperties(newChannel) + } + if mChannel == nil { - // Maybe it already exists? - if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil { + // Haven't found an existing channel to merge with. Try importing it as a new one. + mChannel = ImportChannel(&newChannel) + if mChannel == nil { l4g.Warn(utils.T("api.slackimport.slack_add_channels.import_failed.warn"), newChannel.DisplayName) log.WriteString(utils.T("api.slackimport.slack_add_channels.import_failed", map[string]interface{}{"DisplayName": newChannel.DisplayName})) continue - } else { - mChannel = result.Data.(*model.Channel) - log.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName})) } } + addSlackUsersToChannel(sChannel.Members, users, mChannel, log) log.WriteString(newChannel.DisplayName + "\r\n") addedChannels[sChannel.Id] = mChannel -- cgit v1.2.3-1-g7c22