summaryrefslogtreecommitdiffstats
path: root/app/channel.go
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-02-07 18:05:23 +0100
committerJesús Espino <jespinog@gmail.com>2018-02-07 18:05:23 +0100
commita04b02081a77497ecfc7a5ae9ffb0ca28404dd0e (patch)
tree985cb699d278f68522b08b60b1e7b84e0bd243fc /app/channel.go
parent7941c30117efe1b957ac0458c2f0479e3824196d (diff)
parent7bd298ceaa24c0721e0acd65692cb2d1ca4983f3 (diff)
downloadchat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.tar.gz
chat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.tar.bz2
chat-a04b02081a77497ecfc7a5ae9ffb0ca28404dd0e.zip
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-1
Diffstat (limited to 'app/channel.go')
-rw-r--r--app/channel.go30
1 files changed, 28 insertions, 2 deletions
diff --git a/app/channel.go b/app/channel.go
index 21bb386f3..af36774de 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -1363,7 +1363,7 @@ 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) *model.AppError {
+func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
// Check that all channel members are in the destination team.
if channelMembers, err := a.GetChannelMembersPage(channel.Id, 0, 10000000); err != nil {
return err
@@ -1382,11 +1382,37 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel) *model.AppEr
}
}
- // Change the Team ID of the channel.
+ // keep instance of the previous team
+ var previousTeam *model.Team
+ if result := <-a.Srv.Store.Team().Get(channel.TeamId); result.Err != nil {
+ return result.Err
+ } else {
+ previousTeam = result.Data.(*model.Team)
+ }
channel.TeamId = team.Id
if result := <-a.Srv.Store.Channel().Update(channel); result.Err != nil {
return result.Err
}
+ a.postChannelMoveMessage(user, channel, previousTeam)
+
+ return nil
+}
+
+func (a *App) postChannelMoveMessage(user *model.User, channel *model.Channel, previousTeam *model.Team) *model.AppError {
+
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.team.move_channel.success"), previousTeam.Name),
+ Type: model.POST_MOVE_CHANNEL,
+ UserId: user.Id,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
+ }
+
+ if _, err := a.CreatePost(post, channel, false); err != nil {
+ return model.NewAppError("postChannelMoveMessage", "api.team.move_channel.post.error", nil, err.Error(), http.StatusInternalServerError)
+ }
return nil
}