MM-15784: Prevents non-private channels from being group-constrained … (#10950)

* MM-15784: Prevents non-private channels from being group-constrained via CLI.

* MM-15786: Fixes tests.
This commit is contained in:
Martin Kraft
2019-05-28 10:55:54 -04:00
committed by GitHub
parent bb2e52ee68
commit b7fcddb0fc
2 changed files with 15 additions and 6 deletions

View File

@@ -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

View File

@@ -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)