summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-09-10 12:42:15 +0100
committerMartin Kraft <martinkraft@gmail.com>2018-09-10 07:42:15 -0400
commit504591e7d69ba37aed48393c467d32a998a76751 (patch)
treea013f38bc459ef55bd1eccc76c19201088da4d2f /cmd
parente39ab5c7dcfd6f16264b4a601aca7fa5a572dccf (diff)
downloadchat-504591e7d69ba37aed48393c467d32a998a76751.tar.gz
chat-504591e7d69ba37aed48393c467d32a998a76751.tar.bz2
chat-504591e7d69ba37aed48393c467d32a998a76751.zip
MM-11882: Remove all users from a channel via CLI. (#9381)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mattermost/commands/channel.go39
1 files changed, 29 insertions, 10 deletions
diff --git a/cmd/mattermost/commands/channel.go b/cmd/mattermost/commands/channel.go
index c57a0702d..270ed6586 100644
--- a/cmd/mattermost/commands/channel.go
+++ b/cmd/mattermost/commands/channel.go
@@ -35,11 +35,12 @@ var ChannelRenameCmd = &cobra.Command{
}
var RemoveChannelUsersCmd = &cobra.Command{
- Use: "remove [channel] [users]",
- Short: "Remove users from channel",
- Long: "Remove some users from channel",
- Example: " channel remove myteam:mychannel user@example.com username",
- RunE: removeChannelUsersCmdF,
+ Use: "remove [channel] [users]",
+ Short: "Remove users from channel",
+ Long: "Remove some users from channel",
+ Example: ` channel remove myteam:mychannel user@example.com username
+ channel remove myteam:mychannel --all-users`,
+ RunE: removeChannelUsersCmdF,
}
var AddChannelUsersCmd = &cobra.Command{
@@ -125,6 +126,8 @@ func init() {
ChannelRenameCmd.Flags().String("display_name", "", "Channel Display Name")
+ RemoveChannelUsersCmd.Flags().Bool("all-users", false, "Remove all users from the indicated channel.")
+
ChannelCmd.AddCommand(
ChannelCreateCmd,
RemoveChannelUsersCmd,
@@ -198,8 +201,14 @@ func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
}
defer a.Shutdown()
- if len(args) < 2 {
- return errors.New("Not enough arguments.")
+ allUsers, _ := command.Flags().GetBool("all-users")
+
+ if allUsers && len(args) != 1 {
+ return errors.New("individual users must not be specified in conjunction with the --all-users flag")
+ }
+
+ if !allUsers && len(args) < 2 {
+ return errors.New("you must specify some users to remove from the channel, or use the --all-users flag to remove them all")
}
channel := getChannelFromChannelArg(a, args[0])
@@ -207,9 +216,13 @@ func removeChannelUsersCmdF(command *cobra.Command, args []string) error {
return errors.New("Unable to find channel '" + args[0] + "'")
}
- users := getUsersFromUserArgs(a, args[1:])
- for i, user := range users {
- removeUserFromChannel(a, channel, user, args[i+1])
+ if allUsers {
+ removeAllUsersFromChannel(a, channel)
+ } else {
+ users := getUsersFromUserArgs(a, args[1:])
+ for i, user := range users {
+ removeUserFromChannel(a, channel, user, args[i+1])
+ }
}
return nil
@@ -225,6 +238,12 @@ func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User,
}
}
+func removeAllUsersFromChannel(a *app.App, channel *model.Channel) {
+ if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); result.Err != nil {
+ CommandPrintErrorln("Unable to remove all users from " + channel.Name + ". Error: " + result.Err.Error())
+ }
+}
+
func addChannelUsersCmdF(command *cobra.Command, args []string) error {
a, err := InitDBCommandContextCobra(command)
if err != nil {