PLT-7537: Move channel CLI command posts system message to channel. (#8161)
* [PTL-7537] implement feature and test * [PTL-7537] Update feature to post the the room requiring a username flag to be used * [PTL-7537] update tests with username * update test to remove changes to the test helper struct * use the basic team and user
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
d3e934d07a
Коммит
7bd298ceaa
@@ -1359,7 +1359,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
|
||||
@@ -1378,11 +1378,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
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestMoveChannel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err == nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestMoveChannel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err != nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1, th.BasicUser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user