diff options
Diffstat (limited to 'api/channel_test.go')
-rw-r--r-- | api/channel_test.go | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/api/channel_test.go b/api/channel_test.go index bdb62677f..c6fa23282 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -95,23 +95,23 @@ func TestCreateChannel(t *testing.T) { t.Fatal("Should have errored out on direct channel type") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL utils.SetDefaultRolesBasedOnConfig() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() channel2 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel3 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -171,8 +171,8 @@ func TestCreateChannel(t *testing.T) { } // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() channel4 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} @@ -351,22 +351,22 @@ func TestUpdateChannel(t *testing.T) { t.Fatal("should have failed - channel deleted") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel2 := th.CreateChannel(Client, team) @@ -388,9 +388,9 @@ func TestUpdateChannel(t *testing.T) { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() MakeUserChannelUser(th.BasicUser, channel2) MakeUserChannelUser(th.BasicUser, channel3) @@ -427,9 +427,9 @@ func TestUpdateChannel(t *testing.T) { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() if _, err := Client.UpdateChannel(channel2); err == nil { @@ -453,9 +453,9 @@ func TestUpdateChannel(t *testing.T) { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() if _, err := Client.UpdateChannel(channel2); err == nil { @@ -475,8 +475,8 @@ func TestUpdateChannel(t *testing.T) { } // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() if _, err := Client.UpdateChannel(channel2); err != nil { @@ -586,22 +586,22 @@ func TestUpdateChannelHeader(t *testing.T) { t.Fatal("should have errored non-channel member trying to update header") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -697,8 +697,8 @@ func TestUpdateChannelHeader(t *testing.T) { } // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil { @@ -768,22 +768,22 @@ func TestUpdateChannelPurpose(t *testing.T) { t.Fatal("should have errored non-channel member trying to update purpose") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginBasic() @@ -879,8 +879,8 @@ func TestUpdateChannelPurpose(t *testing.T) { } // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil { t.Fatal(err) @@ -1324,22 +1324,22 @@ func TestDeleteChannel(t *testing.T) { t.Fatal("should have failed - channel already deleted") } - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement defer func() { *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() th.LoginSystemAdmin() @@ -1362,9 +1362,9 @@ func TestDeleteChannel(t *testing.T) { t.Fatal(err) } - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN utils.SetDefaultRolesBasedOnConfig() @@ -1418,9 +1418,9 @@ func TestDeleteChannel(t *testing.T) { UpdateUserToNonTeamAdmin(th.BasicUser, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN utils.SetDefaultRolesBasedOnConfig() @@ -1453,9 +1453,9 @@ func TestDeleteChannel(t *testing.T) { t.Fatal(err) } - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN utils.SetDefaultRolesBasedOnConfig() @@ -1490,8 +1490,8 @@ func TestDeleteChannel(t *testing.T) { } // Check that if unlicensed the policy restriction is not enforced. - utils.IsLicensed = false - utils.License = nil + utils.SetIsLicensed(false) + utils.SetLicense(nil) utils.SetDefaultRolesBasedOnConfig() channel2 = th.CreateChannel(Client, team) @@ -1598,17 +1598,17 @@ func TestAddChannelMember(t *testing.T) { } // Add a license - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() // Check that a regular channel user can add other users. @@ -1621,9 +1621,9 @@ func TestAddChannelMember(t *testing.T) { // Test with CHANNEL_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -1635,9 +1635,9 @@ func TestAddChannelMember(t *testing.T) { MakeUserChannelAdmin(user1, channel5) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() if _, err := Client.AddChannelMember(channel5.Id, user2.Id); err != nil { @@ -1646,9 +1646,9 @@ func TestAddChannelMember(t *testing.T) { // Test with TEAM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -1660,9 +1660,9 @@ func TestAddChannelMember(t *testing.T) { UpdateUserToTeamAdmin(user1, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() if _, err := Client.AddChannelMember(channel6.Id, user2.Id); err != nil { @@ -1671,9 +1671,9 @@ func TestAddChannelMember(t *testing.T) { // Test with SYSTEM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -1772,17 +1772,17 @@ func TestRemoveChannelMember(t *testing.T) { } // Add a license - isLicensed := utils.IsLicensed - license := utils.License + isLicensed := utils.IsLicensed() + license := utils.License() defer func() { - utils.IsLicensed = isLicensed - utils.License = license + utils.SetIsLicensed(isLicensed) + utils.SetLicense(license) utils.SetDefaultRolesBasedOnConfig() }() *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() // Check that a regular channel user can remove other users. @@ -1796,9 +1796,9 @@ func TestRemoveChannelMember(t *testing.T) { // Test with CHANNEL_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -1811,9 +1811,9 @@ func TestRemoveChannelMember(t *testing.T) { MakeUserChannelAdmin(user1, channel5) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil { t.Fatal(err) @@ -1821,9 +1821,9 @@ func TestRemoveChannelMember(t *testing.T) { // Test with TEAM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} @@ -1836,9 +1836,9 @@ func TestRemoveChannelMember(t *testing.T) { UpdateUserToTeamAdmin(user1, team) app.InvalidateAllCaches() - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() if _, err := Client.RemoveChannelMember(channel6.Id, user2.Id); err != nil { @@ -1847,9 +1847,9 @@ func TestRemoveChannelMember(t *testing.T) { // Test with SYSTEM_ADMIN level permission. *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN - utils.IsLicensed = true - utils.License = &model.License{Features: &model.Features{}} - utils.License.Features.SetDefaults() + utils.SetIsLicensed(true) + utils.SetLicense(&model.License{Features: &model.Features{}}) + utils.License().Features.SetDefaults() utils.SetDefaultRolesBasedOnConfig() channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} |