summaryrefslogtreecommitdiffstats
path: root/app/channel.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-04 18:54:24 +0100
committerGitHub <noreply@github.com>2017-09-04 18:54:24 +0100
commitba2868775d2476813fb8f48156d5f232a101f39d (patch)
tree78dfe43062f63a34a1749854ea99fb5a8e4542ff /app/channel.go
parent1e78ff831e8aba2ff98dcd85709f06eca006f0a4 (diff)
downloadchat-ba2868775d2476813fb8f48156d5f232a101f39d.tar.gz
chat-ba2868775d2476813fb8f48156d5f232a101f39d.tar.bz2
chat-ba2868775d2476813fb8f48156d5f232a101f39d.zip
PLT-7216: CLI Command to move channels between teams. (#7149)
* PLT-7216: CLI Command to move channels between teams. * Add comment
Diffstat (limited to 'app/channel.go')
-rw-r--r--app/channel.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 3c8eaf771..8da0ca61c 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -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