PLT-6226 Fixing races with licensing (#7213)

* PLT-6226 Fixing races with licensing

* Fixing build issue

* Fixing licensing issue

* removing commented code
Этот коммит содержится в:
Corey Hulen
2017-08-16 09:51:45 -07:00
коммит произвёл Christopher Speller
родитель 32265df8be
Коммит 0ab490845a
36 изменённых файлов: 403 добавлений и 361 удалений

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

@@ -39,7 +39,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
*utils.Cfg.RateLimitSettings.Enable = false *utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
app.NewServer() app.NewServer()
app.InitStores() app.InitStores()
InitRouter() InitRouter()

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

@@ -95,23 +95,23 @@ func TestCreateChannel(t *testing.T) {
t.Fatal("Should have errored out on direct channel type") t.Fatal("Should have errored out on direct channel type")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} 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} 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. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel4 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} 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") t.Fatal("should have failed - channel deleted")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel2 := th.CreateChannel(Client, team) 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.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
MakeUserChannelUser(th.BasicUser, channel2) MakeUserChannelUser(th.BasicUser, channel2)
MakeUserChannelUser(th.BasicUser, channel3) MakeUserChannelUser(th.BasicUser, channel3)
@@ -427,9 +427,9 @@ func TestUpdateChannel(t *testing.T) {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err == nil { 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.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err == nil { 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. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err != nil { 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") t.Fatal("should have errored non-channel member trying to update header")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -697,8 +697,8 @@ func TestUpdateChannelHeader(t *testing.T) {
} }
// Check that if unlicensed the policy restriction is not enforced. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil { 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") t.Fatal("should have errored non-channel member trying to update purpose")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -879,8 +879,8 @@ func TestUpdateChannelPurpose(t *testing.T) {
} }
// Check that if unlicensed the policy restriction is not enforced. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil { if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1324,22 +1324,22 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal("should have failed - channel already deleted") t.Fatal("should have failed - channel already deleted")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginSystemAdmin() th.LoginSystemAdmin()
@@ -1362,9 +1362,9 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
@@ -1418,9 +1418,9 @@ func TestDeleteChannel(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, team) UpdateUserToNonTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
@@ -1453,9 +1453,9 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
@@ -1490,8 +1490,8 @@ func TestDeleteChannel(t *testing.T) {
} }
// Check that if unlicensed the policy restriction is not enforced. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel2 = th.CreateChannel(Client, team) channel2 = th.CreateChannel(Client, team)
@@ -1598,17 +1598,17 @@ func TestAddChannelMember(t *testing.T) {
} }
// Add a license // Add a license
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can add other users. // 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. // Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} 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) MakeUserChannelAdmin(user1, channel5)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.AddChannelMember(channel5.Id, user2.Id); err != nil { 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. // Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} 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) UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.AddChannelMember(channel6.Id, user2.Id); err != nil { 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. // Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} 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 // Add a license
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can remove other users. // 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. // Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} 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) MakeUserChannelAdmin(user1, channel5)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil { if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -1821,9 +1821,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with TEAM_ADMIN level permission. // Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} 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) UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.RemoveChannelMember(channel6.Id, user2.Id); err != nil { 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. // Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id} channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}

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

@@ -149,7 +149,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host) c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host)
w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId)
w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed)) w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed()))
// Instruct the browser not to display us in an iframe unless is the same origin for anti-clickjacking // Instruct the browser not to display us in an iframe unless is the same origin for anti-clickjacking
if !h.isApi { if !h.isApi {
@@ -321,7 +321,7 @@ func (c *Context) UserRequired() {
func (c *Context) MfaRequired() { func (c *Context) MfaRequired() {
// Must be licensed for MFA and have it configured for enforcement // Must be licensed for MFA and have it configured for enforcement
if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication { if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication {
return return
} }

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

@@ -97,7 +97,7 @@ func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request)
var clientLicense map[string]string var clientLicense map[string]string
if useSanitizedLicense { if useSanitizedLicense {
clientLicense = utils.ClientLicense clientLicense = utils.ClientLicense()
} else { } else {
clientLicense = utils.GetSanitizedClientLicense() clientLicense = utils.GetSanitizedClientLicense()
} }

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

@@ -29,7 +29,7 @@ func TestGetLicenceConfig(t *testing.T) {
t.Fatal("cache should be empty") t.Fatal("cache should be empty")
} }
utils.ClientLicense["IsLicensed"] = "true" utils.SetClientLicense(map[string]string{"IsLicensed": "true"})
if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil { if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -37,7 +37,7 @@ func TestGetLicenceConfig(t *testing.T) {
t.Fatal("result should not be empty") t.Fatal("result should not be empty")
} }
utils.ClientLicense["SomeFeature"] = "true" utils.SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "true"})
if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil { if cache_result, err := Client.GetClientLicenceConfig(result.Etag); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -45,6 +45,6 @@ func TestGetLicenceConfig(t *testing.T) {
t.Fatal("result should not be empty") t.Fatal("result should not be empty")
} }
utils.ClientLicense = map[string]string{"IsLicensed": "false"} utils.SetClientLicense(map[string]string{"IsLicensed": "false"})
} }
} }

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

@@ -409,15 +409,15 @@ func TestUpdatePost(t *testing.T) {
} }
// Test licensed policy controls for edit post // Test licensed policy controls for edit post
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER
@@ -951,15 +951,15 @@ func TestDeletePosts(t *testing.T) {
} }
// Test licensed policy controls for delete post // Test licensed policy controls for delete post
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
UpdateUserToTeamAdmin(th.BasicUser2, th.BasicTeam) UpdateUserToTeamAdmin(th.BasicUser2, th.BasicTeam)
@@ -1014,8 +1014,8 @@ func TestDeletePosts(t *testing.T) {
} }
// Check that if unlicensed the policy restriction is not enforced. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)

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

@@ -118,7 +118,7 @@ func getAll(c *Context, w http.ResponseWriter, r *http.Request) {
func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) { func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
invites := model.InvitesFromJson(r.Body) invites := model.InvitesFromJson(r.Body)
if utils.IsLicensed && !app.SessionHasPermissionToTeam(c.Session, c.TeamId, model.PERMISSION_INVITE_USER) { if utils.IsLicensed() && !app.SessionHasPermissionToTeam(c.Session, c.TeamId, model.PERMISSION_INVITE_USER) {
errorId := "" errorId := ""
if *utils.Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_SYSTEM_ADMIN { if *utils.Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_SYSTEM_ADMIN {
errorId = "api.team.invite_members.restricted_system_admin.app_error" errorId = "api.team.invite_members.restricted_system_admin.app_error"

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

@@ -95,12 +95,12 @@ func TestAddUserToTeam(t *testing.T) {
// Restore config/license at end of test case. // Restore config/license at end of test case.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
@@ -115,9 +115,9 @@ func TestAddUserToTeam(t *testing.T) {
} }
// Add an EE license. // Add an EE license.
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
// Check that a regular user can't add someone to the team. // Check that a regular user can't add someone to the team.
@@ -130,9 +130,9 @@ func TestAddUserToTeam(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches() app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
user5 := th.CreateUser(th.BasicClient) user5 := th.CreateUser(th.BasicClient)
@@ -381,16 +381,16 @@ func TestInviteMembers(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.InviteMembers(invites); err == nil { if _, err := Client.InviteMembers(invites); err == nil {

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

@@ -302,7 +302,7 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) {
il.ClientCfg = utils.ClientCfg il.ClientCfg = utils.ClientCfg
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
il.LicenseCfg = utils.ClientLicense il.LicenseCfg = utils.ClientLicense()
} else { } else {
il.LicenseCfg = utils.GetSanitizedClientLicense() il.LicenseCfg = utils.GetSanitizedClientLicense()
} }
@@ -1108,7 +1108,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) { func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
rdata := map[string]string{} rdata := map[string]string{}
rdata["mfa_required"] = "false" rdata["mfa_required"] = "false"
w.Write([]byte(model.MapToJson(rdata))) w.Write([]byte(model.MapToJson(rdata)))

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

@@ -1836,18 +1836,18 @@ func TestUpdateMfa(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
Client := th.BasicClient Client := th.BasicClient
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}() }()
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
if utils.License.Features.MFA == nil { if utils.License().Features.MFA == nil {
utils.License.Features.MFA = new(bool) utils.License().Features.MFA = new(bool)
} }
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
@@ -1874,8 +1874,8 @@ func TestUpdateMfa(t *testing.T) {
t.Fatal("should have failed - not licensed") t.Fatal("should have failed - not licensed")
} }
utils.IsLicensed = true utils.SetIsLicensed(true)
*utils.License.Features.MFA = true *utils.License().Features.MFA = true
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
if _, err := Client.UpdateMfa(true, "123456"); err == nil { if _, err := Client.UpdateMfa(true, "123456"); err == nil {

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

@@ -55,7 +55,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.EmailSettings.SMTPPort = "2500" utils.Cfg.EmailSettings.SMTPPort = "2500"
utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com" utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
app.NewServer() app.NewServer()
app.InitStores() app.InitStores()
InitRouter() InitRouter()

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

@@ -82,22 +82,22 @@ func TestCreateChannel(t *testing.T) {
th.LoginBasic() th.LoginBasic()
// Check permissions with policy config changes // Check permissions with policy config changes
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelCreation restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelCreation
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelCreation = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel.Name = GenerateTestChannelName() channel.Name = GenerateTestChannelName()
@@ -165,8 +165,8 @@ func TestCreateChannel(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
// Check that if unlicensed the policy restriction is not enforced. // Check that if unlicensed the policy restriction is not enforced.
utils.IsLicensed = false utils.SetIsLicensed(false)
utils.License = nil utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
channel.Name = GenerateTestChannelName() channel.Name = GenerateTestChannelName()
@@ -879,22 +879,22 @@ func TestDeleteChannel(t *testing.T) {
_, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id) _, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th = Setup().InitBasic().InitSystemAdmin() th = Setup().InitBasic().InitSystemAdmin()
@@ -956,9 +956,9 @@ func TestDeleteChannel(t *testing.T) {
// successful delete by team admin // successful delete by team admin
UpdateUserToTeamAdmin(user, team) UpdateUserToTeamAdmin(user, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id) _, resp = Client.DeleteChannel(publicChannel6.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -971,9 +971,9 @@ func TestDeleteChannel(t *testing.T) {
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
UpdateUserToNonTeamAdmin(user, team) UpdateUserToNonTeamAdmin(user, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
// channels created by SystemAdmin // channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN) publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
@@ -1003,9 +1003,9 @@ func TestDeleteChannel(t *testing.T) {
// successful delete by team admin // successful delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team) UpdateUserToTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id) _, resp = Client.DeleteChannel(publicChannel6.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -1045,9 +1045,9 @@ func TestDeleteChannel(t *testing.T) {
// cannot delete by team admin // cannot delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team) UpdateUserToTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id) _, resp = Client.DeleteChannel(publicChannel6.Id)
CheckForbiddenStatus(t, resp) CheckForbiddenStatus(t, resp)
@@ -1796,17 +1796,17 @@ func TestAddChannelMember(t *testing.T) {
Client.Logout() Client.Logout()
// Add a license // Add a license
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can add other users. // Check that a regular channel user can add other users.
@@ -1823,9 +1823,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission. // Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password) Client.Login(user2.Username, user2.Password)
@@ -1841,9 +1841,9 @@ func TestAddChannelMember(t *testing.T) {
MakeUserChannelAdmin(user, privateChannel) MakeUserChannelAdmin(user, privateChannel)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
Client.Login(user.Username, user.Password) Client.Login(user.Username, user.Password)
@@ -1853,9 +1853,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with TEAM_ADMIN level permission. // Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password) Client.Login(user2.Username, user2.Password)
@@ -1871,9 +1871,9 @@ func TestAddChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user, team) UpdateUserToTeamAdmin(user, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
Client.Login(user.Username, user.Password) Client.Login(user.Username, user.Password)
@@ -1883,9 +1883,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with SYSTEM_ADMIN level permission. // Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password) Client.Login(user2.Username, user2.Password)
@@ -1980,17 +1980,17 @@ func TestRemoveChannelMember(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
// Add a license // Add a license
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can remove other users. // Check that a regular channel user can remove other users.
@@ -2005,9 +2005,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission. // Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
@@ -2021,18 +2021,18 @@ func TestRemoveChannelMember(t *testing.T) {
MakeUserChannelAdmin(user1, privateChannel) MakeUserChannelAdmin(user1, privateChannel)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id) _, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
// Test with TEAM_ADMIN level permission. // Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
@@ -2046,18 +2046,18 @@ func TestRemoveChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user1, team) UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches() app.InvalidateAllCaches()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id) _, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp) CheckNoError(t, resp)
// Test with SYSTEM_ADMIN level permission. // Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE) privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)

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

@@ -129,7 +129,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host) c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host)
w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId) w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId)
w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed)) w.Header().Set(model.HEADER_VERSION_ID, fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed()))
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
@@ -252,7 +252,7 @@ func (c *Context) SessionRequired() {
func (c *Context) MfaRequired() { func (c *Context) MfaRequired() {
// Must be licensed for MFA and have it configured for enforcement // Must be licensed for MFA and have it configured for enforcement
if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication { if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication || !*utils.Cfg.ServiceSettings.EnforceMultifactorAuthentication {
return return
} }

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

@@ -366,18 +366,18 @@ func TestUpdatePost(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
*utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost *utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
@@ -445,18 +445,18 @@ func TestPatchPost(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
*utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost *utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS *utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()

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

@@ -258,7 +258,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
var clientLicense map[string]string var clientLicense map[string]string
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
clientLicense = utils.ClientLicense clientLicense = utils.ClientLicense()
} else { } else {
clientLicense = utils.GetSanitizedClientLicense() clientLicense = utils.GetSanitizedClientLicense()
} }

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

@@ -826,12 +826,12 @@ func TestAddTeamMember(t *testing.T) {
// Check effects of config and license changes. // Check effects of config and license changes.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
@@ -845,9 +845,9 @@ func TestAddTeamMember(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
// Add an EE license. // Add an EE license.
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -859,9 +859,9 @@ func TestAddTeamMember(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches() app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -885,9 +885,9 @@ func TestAddTeamMember(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam) UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches() app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -897,8 +897,8 @@ func TestAddTeamMember(t *testing.T) {
// Reset config and license. // Reset config and license.
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -1040,12 +1040,12 @@ func TestAddTeamMembers(t *testing.T) {
// Check effects of config and license changes. // Check effects of config and license changes.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
defer func() { defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite *utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
}() }()
@@ -1059,9 +1059,9 @@ func TestAddTeamMembers(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
// Add an EE license. // Add an EE license.
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -1073,9 +1073,9 @@ func TestAddTeamMembers(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches() app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()
@@ -1099,9 +1099,9 @@ func TestAddTeamMembers(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam) UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches() app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig() utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic() th.LoginBasic()

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

@@ -675,7 +675,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
resp := map[string]interface{}{} resp := map[string]interface{}{}
resp["mfa_required"] = false resp["mfa_required"] = false
if !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { if !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
w.Write([]byte(model.StringInterfaceToJson(resp))) w.Write([]byte(model.StringInterfaceToJson(resp)))
return return
} }

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

@@ -1513,17 +1513,17 @@ func TestGetUsersNotInChannel(t *testing.T) {
defer TearDown() defer TearDown()
Client := th.Client Client := th.Client
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}() }()
utils.IsLicensed = true utils.IsLicensed()= true
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN} team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
rteam, _ := Client.CreateTeam(&team) rteam, _ := Client.CreateTeam(&team)
@@ -1574,18 +1574,18 @@ func TestCheckUserMfa(t *testing.T) {
t.Fatal("should be false - mfa not active") t.Fatal("should be false - mfa not active")
} }
isLicensed := utils.IsLicensed isLicensed := utils.IsLicensed()
license := utils.License license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() { defer func() {
utils.IsLicensed = isLicensed utils.SetIsLicensed(isLicensed)
utils.License = license utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}() }()
utils.IsLicensed = true utils.SetIsLicensed(true)
utils.License = &model.License{Features: &model.Features{}} utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
*utils.License.Features.MFA = true *utils.License().Features.MFA = true
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
th.LoginBasic() th.LoginBasic()

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

@@ -28,7 +28,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
*utils.Cfg.RateLimitSettings.Enable = false *utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
utils.License.Features.SetDefaults() utils.License().Features.SetDefaults()
NewServer() NewServer()
InitStores() InitStores()
StartServer() StartServer()

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

@@ -102,7 +102,7 @@ func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string
} }
func CheckUserMfa(user *model.User, token string) *model.AppError { func CheckUserMfa(user *model.User, token string) *model.AppError {
if !user.MfaActive || !utils.IsLicensed || !*utils.License.Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
return nil return nil
} }
@@ -143,7 +143,7 @@ func checkUserNotDisabled(user *model.User) *model.AppError {
} }
func authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) { func authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed && *utils.License.Features.LDAP ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP
if user.AuthService == model.USER_AUTH_SERVICE_LDAP { if user.AuthService == model.USER_AUTH_SERVICE_LDAP {
if !ldapAvailable { if !ldapAvailable {

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

@@ -12,7 +12,7 @@ import (
) )
func GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) { func GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance { if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance {
return nil, model.NewLocAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "") return nil, model.NewLocAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "")
} }
@@ -24,7 +24,7 @@ func GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError
} }
func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) { func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance || einterfaces.GetComplianceInterface() == nil { if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
return nil, model.NewLocAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "") return nil, model.NewLocAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "")
} }
@@ -41,7 +41,7 @@ func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppE
} }
func GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) { func GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed || !*utils.License.Features.Compliance || einterfaces.GetComplianceInterface() == nil { if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
return nil, model.NewLocAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "") return nil, model.NewLocAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "")
} }

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

@@ -423,17 +423,17 @@ func trackConfig() {
} }
func trackLicense() { func trackLicense() {
if utils.IsLicensed { if utils.IsLicensed() {
data := map[string]interface{}{ data := map[string]interface{}{
"customer_id": utils.License.Customer.Id, "customer_id": utils.License().Customer.Id,
"license_id": utils.License.Id, "license_id": utils.License().Id,
"issued": utils.License.IssuedAt, "issued": utils.License().IssuedAt,
"start": utils.License.StartsAt, "start": utils.License().StartsAt,
"expire": utils.License.ExpiresAt, "expire": utils.License().ExpiresAt,
"users": *utils.License.Features.Users, "users": *utils.License().Features.Users,
} }
features := utils.License.Features.ToMap() features := utils.License().Features.ToMap()
for featureName, featureValue := range features { for featureName, featureValue := range features {
data["feature_"+featureName] = featureValue data["feature_"+featureName] = featureValue
} }

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

@@ -196,7 +196,7 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
} }
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed && *utils.License.Features.EmailNotificationContents { if utils.IsLicensed() && *utils.License().Features.EmailNotificationContents {
emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
} }

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

@@ -14,7 +14,7 @@ import (
func SyncLdap() { func SyncLdap() {
go func() { go func() {
if utils.IsLicensed && *utils.License.Features.LDAP && *utils.Cfg.LdapSettings.Enable { if utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { if ldapI := einterfaces.GetLdapInterface(); ldapI != nil {
ldapI.SyncNow() ldapI.SyncNow()
} else { } else {
@@ -25,7 +25,7 @@ func SyncLdap() {
} }
func TestLdap() *model.AppError { func TestLdap() *model.AppError {
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil && utils.IsLicensed && *utils.License.Features.LDAP && *utils.Cfg.LdapSettings.Enable { if ldapI := einterfaces.GetLdapInterface(); ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
if err := ldapI.RunTest(); err != nil { if err := ldapI.RunTest(); err != nil {
err.StatusCode = 500 err.StatusCode = 500
return err return err

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

@@ -13,7 +13,7 @@ func TestLoadLicense(t *testing.T) {
Setup() Setup()
LoadLicense() LoadLicense()
if utils.IsLicensed { if utils.IsLicensed() {
t.Fatal("shouldn't have a valid license") t.Fatal("shouldn't have a valid license")
} }
} }

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

@@ -236,7 +236,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
sendPushNotifications := false sendPushNotifications := false
if *utils.Cfg.EmailSettings.SendPushNotifications { if *utils.Cfg.EmailSettings.SendPushNotifications {
pushServer := *utils.Cfg.EmailSettings.PushNotificationServer pushServer := *utils.Cfg.EmailSettings.PushNotificationServer
if pushServer == model.MHPNS && (!utils.IsLicensed || !*utils.License.Features.MHPNS) { if pushServer == model.MHPNS && (!utils.IsLicensed() || !*utils.License().Features.MHPNS) {
l4g.Warn(utils.T("api.post.send_notifications_and_forget.push_notification.mhpnsWarn")) l4g.Warn(utils.T("api.post.send_notifications_and_forget.push_notification.mhpnsWarn"))
sendPushNotifications = false sendPushNotifications = false
} else { } else {
@@ -359,7 +359,7 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
} }
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed && *utils.License.Features.EmailNotificationContents { if utils.IsLicensed() && *utils.License().Features.EmailNotificationContents {
emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
} }

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

@@ -233,7 +233,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
} else { } else {
oldPost = result.Data.(*model.PostList).Posts[post.Id] oldPost = result.Data.(*model.PostList).Posts[post.Id]
if utils.IsLicensed { if utils.IsLicensed() {
if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_NEVER && post.Message != oldPost.Message { if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_NEVER && post.Message != oldPost.Message {
err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_denied.app_error", nil, "", http.StatusForbidden) err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_denied.app_error", nil, "", http.StatusForbidden)
return nil, err return nil, err
@@ -255,7 +255,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
return nil, err return nil, err
} }
if utils.IsLicensed { if utils.IsLicensed() {
if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_TIME_LIMIT && model.GetMillis() > oldPost.CreateAt+int64(*utils.Cfg.ServiceSettings.PostEditTimeLimit*1000) && post.Message != oldPost.Message { if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_TIME_LIMIT && model.GetMillis() > oldPost.CreateAt+int64(*utils.Cfg.ServiceSettings.PostEditTimeLimit*1000) && post.Message != oldPost.Message {
err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_time_limit.app_error", map[string]interface{}{"timeLimit": *utils.Cfg.ServiceSettings.PostEditTimeLimit}, "", http.StatusBadRequest) err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_time_limit.app_error", map[string]interface{}{"timeLimit": *utils.Cfg.ServiceSettings.PostEditTimeLimit}, "", http.StatusBadRequest)
return nil, err return nil, err
@@ -503,7 +503,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
paramsList := model.ParseSearchParams(terms) paramsList := model.ParseSearchParams(terms)
esInterface := einterfaces.GetElasticsearchInterface() esInterface := einterfaces.GetElasticsearchInterface()
if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.Elasticsearch { if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch {
finalParamsList := []*model.SearchParams{} finalParamsList := []*model.SearchParams{}
for _, params := range paramsList { for _, params := range paramsList {

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

@@ -376,7 +376,7 @@ func GetUserByAuth(authData *string, authService string) (*model.User, *model.Ap
} }
func GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *model.AppError) { func GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *model.AppError) {
ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed && *utils.License.Features.LDAP ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP
if result := <-Srv.Store.User().GetForLogin( if result := <-Srv.Store.User().GetForLogin(
loginId, loginId,

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

@@ -217,7 +217,7 @@ func (webCon *WebConn) IsAuthenticated() bool {
func (webCon *WebConn) SendHello() { func (webCon *WebConn) SendHello() {
msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", webCon.UserId, nil) msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", webCon.UserId, nil)
msg.Add("server_version", fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed)) msg.Add("server_version", fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, utils.ClientCfgHash, utils.IsLicensed()))
webCon.Send <- msg webCon.Send <- msg
} }

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

@@ -106,7 +106,7 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
return err return err
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical")) return errors.New(utils.T("cli.license.critical"))
} }
@@ -158,7 +158,7 @@ func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
return err return err
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical")) return errors.New(utils.T("cli.license.critical"))
} }
@@ -194,7 +194,7 @@ func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
return err return err
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical")) return errors.New(utils.T("cli.license.critical"))
} }
@@ -292,7 +292,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
return err return err
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical")) return errors.New(utils.T("cli.license.critical"))
} }
@@ -329,7 +329,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
return err return err
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical")) return errors.New(utils.T("cli.license.critical"))
} }

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

@@ -81,12 +81,12 @@ func runServer(configFileLocation string) {
app.LoadLicense() app.LoadLicense()
} }
if !utils.IsLicensed && len(utils.Cfg.SqlSettings.DataSourceReplicas) > 1 { if !utils.IsLicensed() && len(utils.Cfg.SqlSettings.DataSourceReplicas) > 1 {
l4g.Warn(utils.T("store.sql.read_replicas_not_licensed.critical")) l4g.Warn(utils.T("store.sql.read_replicas_not_licensed.critical"))
utils.Cfg.SqlSettings.DataSourceReplicas = utils.Cfg.SqlSettings.DataSourceReplicas[:1] utils.Cfg.SqlSettings.DataSourceReplicas = utils.Cfg.SqlSettings.DataSourceReplicas[:1]
} }
if !utils.IsLicensed { if !utils.IsLicensed() {
utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
} }

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

@@ -11,7 +11,7 @@ func SetDefaultRolesBasedOnConfig() {
// Reset the roles to default to make this logic easier // Reset the roles to default to make this logic easier
model.InitalizeRoles() model.InitalizeRoles()
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelCreation { switch *Cfg.TeamSettings.RestrictPublicChannelCreation {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -33,7 +33,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelManagement { switch *Cfg.TeamSettings.RestrictPublicChannelManagement {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -65,7 +65,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelDeletion { switch *Cfg.TeamSettings.RestrictPublicChannelDeletion {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -97,7 +97,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelCreation { switch *Cfg.TeamSettings.RestrictPrivateChannelCreation {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -119,7 +119,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelManagement { switch *Cfg.TeamSettings.RestrictPrivateChannelManagement {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -151,7 +151,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelDeletion { switch *Cfg.TeamSettings.RestrictPrivateChannelDeletion {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append( model.ROLE_TEAM_USER.Permissions = append(
@@ -184,7 +184,7 @@ func SetDefaultRolesBasedOnConfig() {
} }
// Restrict permissions for Private Channel Manage Members // Restrict permissions for Private Channel Manage Members
if IsLicensed { if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelManageMembers { switch *Cfg.TeamSettings.RestrictPrivateChannelManageMembers {
case model.PERMISSIONS_ALL: case model.PERMISSIONS_ALL:
model.ROLE_CHANNEL_USER.Permissions = append( model.ROLE_CHANNEL_USER.Permissions = append(
@@ -229,7 +229,7 @@ func SetDefaultRolesBasedOnConfig() {
} }
// Grant permissions for inviting and adding users to a team. // Grant permissions for inviting and adding users to a team.
if IsLicensed { if IsLicensed() {
if *Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_TEAM_ADMIN { if *Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_TEAM_ADMIN {
model.ROLE_TEAM_ADMIN.Permissions = append( model.ROLE_TEAM_ADMIN.Permissions = append(
model.ROLE_TEAM_ADMIN.Permissions, model.ROLE_TEAM_ADMIN.Permissions,
@@ -251,7 +251,7 @@ func SetDefaultRolesBasedOnConfig() {
) )
} }
if IsLicensed { if IsLicensed() {
switch *Cfg.ServiceSettings.RestrictPostDelete { switch *Cfg.ServiceSettings.RestrictPostDelete {
case model.PERMISSIONS_DELETE_POST_ALL: case model.PERMISSIONS_DELETE_POST_ALL:
model.ROLE_CHANNEL_USER.Permissions = append( model.ROLE_CHANNEL_USER.Permissions = append(

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

@@ -489,7 +489,10 @@ func getClientConfig(c *model.Config) map[string]string {
props["DiagnosticId"] = CfgDiagnosticId props["DiagnosticId"] = CfgDiagnosticId
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
if IsLicensed { if IsLicensed() {
License := License()
if *License.Features.CustomBrand { if *License.Features.CustomBrand {
props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand)
props["CustomBrandText"] = *c.TeamSettings.CustomBrandText props["CustomBrandText"] = *c.TeamSettings.CustomBrandText

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

@@ -16,17 +16,16 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
l4g "github.com/alecthomas/log4go" l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
) )
var IsLicensed bool = false var isLicensedInt32 int32
var License *model.License = &model.License{ var licenseValue atomic.Value
Features: new(model.Features), var clientLicenseValue atomic.Value
}
var ClientLicense map[string]string = map[string]string{"IsLicensed": "false"}
var publicKey []byte = []byte(`-----BEGIN PUBLIC KEY----- var publicKey []byte = []byte(`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyZmShlU8Z8HdG0IWSZ8r MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyZmShlU8Z8HdG0IWSZ8r
@@ -38,6 +37,34 @@ a0v85XL6i9ote2P+fLZ3wX9EoioHzgdgB7arOxY50QRJO7OyCqpKFKv6lRWTXuSt
hwIDAQAB hwIDAQAB
-----END PUBLIC KEY-----`) -----END PUBLIC KEY-----`)
func init() {
SetLicense(nil)
}
func IsLicensed() bool {
return atomic.LoadInt32(&isLicensedInt32) == 1
}
func SetIsLicensed(v bool) {
if v {
atomic.StoreInt32(&isLicensedInt32, 1)
} else {
atomic.StoreInt32(&isLicensedInt32, 0)
}
}
func License() *model.License {
return licenseValue.Load().(*model.License)
}
func SetClientLicense(m map[string]string) {
clientLicenseValue.Store(m)
}
func ClientLicense() map[string]string {
return clientLicenseValue.Load().(map[string]string)
}
func LoadLicense(licenseBytes []byte) { func LoadLicense(licenseBytes []byte) {
if success, licenseStr := ValidateLicense(licenseBytes); success { if success, licenseStr := ValidateLicense(licenseBytes); success {
license := model.LicenseFromJson(strings.NewReader(licenseStr)) license := model.LicenseFromJson(strings.NewReader(licenseStr))
@@ -49,23 +76,35 @@ func LoadLicense(licenseBytes []byte) {
} }
func SetLicense(license *model.License) bool { func SetLicense(license *model.License) bool {
license.Features.SetDefaults()
if !license.IsExpired() { if license == nil {
License = license SetIsLicensed(false)
IsLicensed = true license = &model.License{
ClientLicense = getClientLicense(license) Features: new(model.Features),
ClientCfg = getClientConfig(Cfg) }
return true license.Features.SetDefaults()
licenseValue.Store(license)
SetClientLicense(map[string]string{"IsLicensed": "false"})
return false
} else {
license.Features.SetDefaults()
if !license.IsExpired() {
licenseValue.Store(license)
SetIsLicensed(true)
clientLicenseValue.Store(getClientLicense(license))
ClientCfg = getClientConfig(Cfg)
return true
}
return false
} }
return false
} }
func RemoveLicense() { func RemoveLicense() {
License = &model.License{} SetLicense(nil)
IsLicensed = false
ClientLicense = getClientLicense(License)
ClientCfg = getClientConfig(Cfg) ClientCfg = getClientConfig(Cfg)
} }
@@ -162,9 +201,9 @@ func GetLicenseFileLocation(fileLocation string) string {
func getClientLicense(l *model.License) map[string]string { func getClientLicense(l *model.License) map[string]string {
props := make(map[string]string) props := make(map[string]string)
props["IsLicensed"] = strconv.FormatBool(IsLicensed) props["IsLicensed"] = strconv.FormatBool(IsLicensed())
if IsLicensed { if IsLicensed() {
props["Id"] = l.Id props["Id"] = l.Id
props["Users"] = strconv.Itoa(*l.Features.Users) props["Users"] = strconv.Itoa(*l.Features.Users)
props["LDAP"] = strconv.FormatBool(*l.Features.LDAP) props["LDAP"] = strconv.FormatBool(*l.Features.LDAP)
@@ -195,7 +234,7 @@ func getClientLicense(l *model.License) map[string]string {
func GetClientLicenseEtag(useSanitized bool) string { func GetClientLicenseEtag(useSanitized bool) string {
value := "" value := ""
lic := ClientLicense lic := ClientLicense()
if useSanitized { if useSanitized {
lic = GetSanitizedClientLicense() lic = GetSanitizedClientLicense()
@@ -211,11 +250,11 @@ func GetClientLicenseEtag(useSanitized bool) string {
func GetSanitizedClientLicense() map[string]string { func GetSanitizedClientLicense() map[string]string {
sanitizedLicense := make(map[string]string) sanitizedLicense := make(map[string]string)
for k, v := range ClientLicense { for k, v := range ClientLicense() {
sanitizedLicense[k] = v sanitizedLicense[k] = v
} }
if IsLicensed { if IsLicensed() {
delete(sanitizedLicense, "Id") delete(sanitizedLicense, "Id")
delete(sanitizedLicense, "Name") delete(sanitizedLicense, "Name")
delete(sanitizedLicense, "Email") delete(sanitizedLicense, "Email")

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

@@ -54,14 +54,14 @@ func TestValidateLicense(t *testing.T) {
func TestClientLicenseEtag(t *testing.T) { func TestClientLicenseEtag(t *testing.T) {
etag1 := GetClientLicenseEtag(false) etag1 := GetClientLicenseEtag(false)
ClientLicense["SomeFeature"] = "true" SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "true"})
etag2 := GetClientLicenseEtag(false) etag2 := GetClientLicenseEtag(false)
if etag1 == etag2 { if etag1 == etag2 {
t.Fatal("etags should not match") t.Fatal("etags should not match")
} }
ClientLicense["SomeFeature"] = "false" SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "false"})
etag3 := GetClientLicenseEtag(false) etag3 := GetClientLicenseEtag(false)
if etag2 == etag3 { if etag2 == etag3 {

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

@@ -15,7 +15,7 @@ func IsPasswordValid(password string) *model.AppError {
isError := false isError := false
min := model.PASSWORD_MINIMUM_LENGTH min := model.PASSWORD_MINIMUM_LENGTH
if IsLicensed && *License.Features.PasswordRequirements { if IsLicensed() && *License().Features.PasswordRequirements {
if len(password) < *Cfg.PasswordSettings.MinimumLength || len(password) > model.PASSWORD_MAXIMUM_LENGTH { if len(password) < *Cfg.PasswordSettings.MinimumLength || len(password) > model.PASSWORD_MAXIMUM_LENGTH {
isError = true isError = true
} }