Expose GroupConstrained flag where needed and add tests (#10604)

Этот коммит содержится в:
Miguel de la Cruz
2019-04-15 16:13:11 +01:00
коммит произвёл Jesús Espino
родитель 5db62c20c5
Коммит 4c52f91997
3 изменённых файлов: 68 добавлений и 1 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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