diff --git a/cmd/mattermost/commands/group.go b/cmd/mattermost/commands/group.go index 25bce5c4c6..df44dea7c9 100644 --- a/cmd/mattermost/commands/group.go +++ b/cmd/mattermost/commands/group.go @@ -128,6 +128,10 @@ func channelGroupEnableCmdF(command *cobra.Command, args []string) error { return errors.New("Unable to find channel '" + args[0] + "'") } + if channel.Type != model.CHANNEL_PRIVATE { + return errors.New("Channel '" + args[0] + "' is not private. It cannot be group-constrained") + } + groups, _, appErr := a.GetGroupsByChannel(channel.Id, model.GroupSearchOpts{}) if appErr != nil { return appErr diff --git a/cmd/mattermost/commands/group_test.go b/cmd/mattermost/commands/group_test.go index a4dcb4b4e8..7569de2a13 100644 --- a/cmd/mattermost/commands/group_test.go +++ b/cmd/mattermost/commands/group_test.go @@ -17,6 +17,11 @@ func TestChannelGroupEnable(t *testing.T) { // create public channel channel := th.CreatePublicChannel() + // try to enable, should fail it is private + require.Error(t, th.RunCommand(t, "group", "channel", "enable", th.BasicTeam.Name+":"+channel.Name)) + + channel = th.CreatePrivateChannel() + // try to enable, should fail because channel has no groups require.Error(t, th.RunCommand(t, "group", "channel", "enable", th.BasicTeam.Name+":"+channel.Name)) @@ -54,8 +59,8 @@ func TestChannelGroupDisable(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() - // create public channel - channel := th.CreatePublicChannel() + // create private channel + channel := th.CreatePrivateChannel() // try to disable, should work th.CheckCommand(t, "group", "channel", "disable", th.BasicTeam.Name+":"+channel.Name) @@ -104,8 +109,8 @@ func TestChannelGroupStatus(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() - // create public channel - channel := th.CreatePublicChannel() + // create private channel + channel := th.CreatePrivateChannel() // get status, should be Disabled output := th.CheckCommand(t, "group", "channel", "status", th.BasicTeam.Name+":"+channel.Name) @@ -148,8 +153,8 @@ func TestChannelGroupList(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() - // create public channel - channel := th.CreatePublicChannel() + // create private channel + channel := th.CreatePrivateChannel() // list groups for a channel with none, should work th.CheckCommand(t, "group", "channel", "list", th.BasicTeam.Name+":"+channel.Name)