summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-08-18 20:14:52 +0100
committerChristopher Speller <crspeller@gmail.com>2017-08-18 12:14:52 -0700
commit42c6686602885ad04ae91ab33f82029a0455b3c7 (patch)
tree9f21e30d1ce33c5ced4a8cead0238890213b3d4a /cmd
parente40fd0b3b515be5c7482ca48a4e70f8f61dbd435 (diff)
downloadchat-42c6686602885ad04ae91ab33f82029a0455b3c7.tar.gz
chat-42c6686602885ad04ae91ab33f82029a0455b3c7.tar.bz2
chat-42c6686602885ad04ae91ab33f82029a0455b3c7.zip
PLT-7217: CLI command to change channel public/private type. (#7225)
This adds a channel modify CLI command, with the one property that it can modify being the channel public/private type.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/platform/channel.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/cmd/platform/channel.go b/cmd/platform/channel.go
index ed8a0b817..f228e09fe 100644
--- a/cmd/platform/channel.go
+++ b/cmd/platform/channel.go
@@ -80,6 +80,15 @@ Channels can be specified by [team]:[channel]. ie. myteam:mychannel or by channe
RunE: restoreChannelsCmdF,
}
+var modifyChannelCmd = &cobra.Command{
+ Use: "modify [channel]",
+ Short: "Modify a channel's public/private type",
+ Long: `Change the public/private type of a channel.
+Channel can be specified by [team]:[channel]. ie. myteam:mychannel or by channel ID.`,
+ Example: " channel modify myteam:mychannel --private",
+ RunE: modifyChannelCmdF,
+}
+
func init() {
channelCreateCmd.Flags().String("name", "", "Channel Name")
channelCreateCmd.Flags().String("display_name", "", "Channel Display Name")
@@ -90,6 +99,9 @@ func init() {
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")
+ modifyChannelCmd.Flags().Bool("public", false, "Convert the channel to a public channel")
+
channelCmd.AddCommand(
channelCreateCmd,
removeChannelUsersCmd,
@@ -98,6 +110,7 @@ func init() {
deleteChannelsCmd,
listChannelsCmd,
restoreChannelsCmd,
+ modifyChannelCmd,
)
}
@@ -350,3 +363,44 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
return nil
}
+
+func modifyChannelCmdF(cmd *cobra.Command, args []string) error {
+ if err := initDBCommandContextCobra(cmd); err != nil {
+ return err
+ }
+
+ if !utils.IsLicensed {
+ return errors.New(utils.T("cli.license.critical"))
+ }
+
+ if len(args) != 1 {
+ return errors.New("Enter at one channel to modify.")
+ }
+
+ public, _ := cmd.Flags().GetBool("public")
+ private, _ := cmd.Flags().GetBool("private")
+
+ if public == private {
+ return errors.New("You must specify only one of --public or --private")
+ }
+
+ channel := getChannelFromChannelArg(args[0])
+ if channel == nil {
+ return errors.New("Unable to find channel '" + args[0] + "'")
+ }
+
+ if !(channel.Type == model.CHANNEL_OPEN || channel.Type == model.CHANNEL_PRIVATE) {
+ return errors.New("You can only change the type of public/private channels.")
+ }
+
+ channel.Type = model.CHANNEL_OPEN
+ if private {
+ channel.Type = model.CHANNEL_PRIVATE
+ }
+
+ if _, err := app.UpdateChannel(channel); err != nil {
+ return errors.New("Failed to update channel '" + args[0] + "' - " + err.Error())
+ }
+
+ return nil
+}