diff --git a/api4/channel.go b/api4/channel.go index 1be513b2b0..8128acf646 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -167,6 +167,10 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { oldChannel.Type = channel.Type } + if channel.GroupConstrained != nil { + oldChannel.GroupConstrained = channel.GroupConstrained + } + if _, err := c.App.UpdateChannel(oldChannel); err != nil { c.Err = err return diff --git a/api4/channel_test.go b/api4/channel_test.go index 5c2781e7cf..baa4ef96cf 100644 --- a/api4/channel_test.go +++ b/api4/channel_test.go @@ -139,6 +139,15 @@ func TestCreateChannel(t *testing.T) { t.Fatal("wrong status code") } } + + // Test GroupConstrained flag + groupConstrainedChannel := &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.CHANNEL_OPEN, TeamId: team.Id, GroupConstrained: model.NewBool(true)} + rchannel, resp = Client.CreateChannel(groupConstrainedChannel) + CheckNoError(t, resp) + + if *rchannel.GroupConstrained != *groupConstrainedChannel.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } } func TestUpdateChannel(t *testing.T) { @@ -173,6 +182,16 @@ func TestUpdateChannel(t *testing.T) { t.Fatal("Update failed for Purpose") } + // Test GroupConstrained flag + channel.GroupConstrained = model.NewBool(true) + rchannel, resp := Client.UpdateChannel(channel) + CheckNoError(t, resp) + CheckOKStatus(t, resp) + + if *rchannel.GroupConstrained != *channel.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } + //Update a private channel private.DisplayName = "My new display name for private channel" private.Header = "My fancy private header" @@ -281,6 +300,17 @@ func TestPatchChannel(t *testing.T) { t.Fatal("should not have updated") } + // Test GroupConstrained flag + patch.GroupConstrained = model.NewBool(true) + rchannel, resp := Client.PatchChannel(th.BasicChannel.Id, patch) + CheckNoError(t, resp) + CheckOKStatus(t, resp) + + if *rchannel.GroupConstrained != *patch.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } + patch.GroupConstrained = nil + _, resp = Client.PatchChannel("junk", patch) CheckBadRequestStatus(t, resp) diff --git a/api4/team_test.go b/api4/team_test.go index bc21578b90..b5db47a636 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -72,6 +72,18 @@ func TestCreateTeam(t *testing.T) { _, resp = Client.CreateTeam(rteam) CheckUnauthorizedStatus(t, resp) + th.LoginBasic() + + // Test GroupConstrained flag + groupConstrainedTeam := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN, GroupConstrained: model.NewBool(true)} + rteam, resp = Client.CreateTeam(groupConstrainedTeam) + CheckNoError(t, resp) + CheckCreatedStatus(t, resp) + + if *rteam.GroupConstrained != *groupConstrainedTeam.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } + // Check the appropriate permissions are enforced. defaultRolePermissions := th.SaveDefaultRolePermissions() defer func() { @@ -81,7 +93,6 @@ func TestCreateTeam(t *testing.T) { th.RemovePermissionFromRole(model.PERMISSION_CREATE_TEAM.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_CREATE_TEAM.Id, model.SYSTEM_ADMIN_ROLE_ID) - th.LoginBasic() _, resp = Client.CreateTeam(team) CheckForbiddenStatus(t, resp) } @@ -273,6 +284,17 @@ func TestUpdateTeam(t *testing.T) { t.Fatal("Update failed") } + // Test GroupConstrained flag + team.GroupConstrained = model.NewBool(true) + rteam, resp := Client.UpdateTeam(team) + CheckNoError(t, resp) + CheckOKStatus(t, resp) + + if *rteam.GroupConstrained != *team.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } + team.GroupConstrained = nil + team.AllowOpenInvite = true uteam, resp = Client.UpdateTeam(team) CheckNoError(t, resp) @@ -411,6 +433,17 @@ func TestPatchTeam(t *testing.T) { t.Fatal("AllowOpenInvite did not update properly") } + // Test GroupConstrained flag + patch.GroupConstrained = model.NewBool(true) + rteam, resp = Client.PatchTeam(team.Id, patch) + CheckNoError(t, resp) + CheckOKStatus(t, resp) + + if *rteam.GroupConstrained != *patch.GroupConstrained { + t.Fatal("GroupConstrained flags do not match") + } + patch.GroupConstrained = nil + _, resp = Client.PatchTeam("junk", patch) CheckBadRequestStatus(t, resp)