summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorVordimous <gsoi7vzireeyokoprf@thrott.com>2018-02-07 09:17:18 -0500
committerGeorge Goldberg <george@gberg.me>2018-02-07 14:17:18 +0000
commit7bd298ceaa24c0721e0acd65692cb2d1ca4983f3 (patch)
tree870013c04c31b293e64404a8e74e16c2b1a94c33 /cmd
parentd3e934d07ac0a58a24a435ea7c5b3bd222ef509a (diff)
downloadchat-7bd298ceaa24c0721e0acd65692cb2d1ca4983f3.tar.gz
chat-7bd298ceaa24c0721e0acd65692cb2d1ca4983f3.tar.bz2
chat-7bd298ceaa24c0721e0acd65692cb2d1ca4983f3.zip
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
Diffstat (limited to 'cmd')
-rw-r--r--cmd/platform/channel.go17
-rw-r--r--cmd/platform/channel_test.go27
2 files changed, 40 insertions, 4 deletions
diff --git a/cmd/platform/channel.go b/cmd/platform/channel.go
index 98bdcebb8..5d86ad9da 100644
--- a/cmd/platform/channel.go
+++ b/cmd/platform/channel.go
@@ -106,6 +106,8 @@ func init() {
channelCreateCmd.Flags().String("purpose", "", "Channel purpose")
channelCreateCmd.Flags().Bool("private", false, "Create a private channel.")
+ moveChannelsCmd.Flags().String("username", "", "Required. Username who is moving the channel.")
+
deleteChannelsCmd.Flags().Bool("confirm", false, "Confirm you really want to delete the channels.")
modifyChannelCmd.Flags().Bool("private", false, "Convert the channel to a private channel")
@@ -319,26 +321,33 @@ func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
return errors.New("Unable to find destination team '" + args[0] + "'")
}
+ username, erru := cmd.Flags().GetString("username")
+ if erru != nil || username == "" {
+ return errors.New("Username is required")
+ }
+ user := getUserFromUserArg(a, username)
+
channels := getChannelsFromChannelArgs(a, args[1:])
for i, channel := range channels {
if channel == nil {
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
- if err := moveChannel(a, team, channel); err != nil {
+ originTeamID := channel.TeamId
+ if err := moveChannel(a, team, channel, user); err != nil {
CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
} else {
- CommandPrettyPrintln("Moved channel '" + channel.Name + "'")
+ CommandPrettyPrintln("Moved channel '" + channel.Name + "' to " + team.Name + "(" + team.Id + ") from " + originTeamID + ".")
}
}
return nil
}
-func moveChannel(a *app.App, team *model.Team, channel *model.Channel) *model.AppError {
+func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
oldTeamId := channel.TeamId
- if err := a.MoveChannel(team, channel); err != nil {
+ if err := a.MoveChannel(team, channel, user); err != nil {
return err
}
diff --git a/cmd/platform/channel_test.go b/cmd/platform/channel_test.go
index 1e6915679..cf8603cf3 100644
--- a/cmd/platform/channel_test.go
+++ b/cmd/platform/channel_test.go
@@ -44,6 +44,33 @@ func TestRemoveChannel(t *testing.T) {
checkCommand(t, "channel", "remove", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
}
+func TestMoveChannel(t *testing.T) {
+ th := api.Setup().InitBasic()
+ defer th.TearDown()
+
+ client := th.BasicClient
+ team1 := th.BasicTeam
+ team2 := th.CreateTeam(client)
+ user1 := th.BasicUser
+ th.LinkUserToTeam(user1, team2)
+ channel := th.BasicChannel
+
+ th.LinkUserToTeam(user1, team1)
+ th.LinkUserToTeam(user1, team2)
+
+ adminEmail := user1.Email
+ adminUsername := user1.Username
+ origin := team1.Name + ":" + channel.Name
+ dest := team2.Name
+
+ checkCommand(t, "channel", "add", origin, adminEmail)
+
+ // should fail with nill because errors are logged instead of returned when a channel does not exist
+ require.Nil(t, runCommand(t, "channel", "move", dest, team1.Name+":doesnotexist", "--username", adminUsername))
+
+ checkCommand(t, "channel", "move", dest, origin, "--username", adminUsername)
+}
+
func TestListChannels(t *testing.T) {
th := api.Setup().InitBasic()
defer th.TearDown()