summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-08-16 09:51:45 -0700
committerChristopher Speller <crspeller@gmail.com>2017-08-16 09:51:45 -0700
commit0ab490845aed0ce3b58cbffd8ec35be237abda1c (patch)
tree5310cce7e546f5a03f97245af473b62d382028e8
parent32265df8be5d530f5b79284792afb9451464ad3a (diff)
downloadchat-0ab490845aed0ce3b58cbffd8ec35be237abda1c.tar.gz
chat-0ab490845aed0ce3b58cbffd8ec35be237abda1c.tar.bz2
chat-0ab490845aed0ce3b58cbffd8ec35be237abda1c.zip
PLT-6226 Fixing races with licensing (#7213)
* PLT-6226 Fixing races with licensing * Fixing build issue * Fixing licensing issue * removing commented code
-rw-r--r--api/apitestlib.go2
-rw-r--r--api/channel_test.go214
-rw-r--r--api/context.go4
-rw-r--r--api/license.go2
-rw-r--r--api/license_test.go6
-rw-r--r--api/post_test.go32
-rw-r--r--api/team.go2
-rw-r--r--api/team_test.go34
-rw-r--r--api/user.go4
-rw-r--r--api/user_test.go20
-rw-r--r--api4/apitestlib.go2
-rw-r--r--api4/channel_test.go144
-rw-r--r--api4/context.go4
-rw-r--r--api4/post_test.go28
-rw-r--r--api4/system.go2
-rw-r--r--api4/team_test.go56
-rw-r--r--api4/user.go2
-rw-r--r--api4/user_test.go30
-rw-r--r--app/apptestlib.go2
-rw-r--r--app/authentication.go4
-rw-r--r--app/compliance.go6
-rw-r--r--app/diagnostics.go16
-rw-r--r--app/email_batching.go2
-rw-r--r--app/ldap.go4
-rw-r--r--app/license_test.go2
-rw-r--r--app/notification.go4
-rw-r--r--app/post.go6
-rw-r--r--app/user.go2
-rw-r--r--app/web_conn.go2
-rw-r--r--cmd/platform/channel.go10
-rw-r--r--cmd/platform/server.go4
-rw-r--r--utils/authorization.go18
-rw-r--r--utils/config.go5
-rw-r--r--utils/license.go83
-rw-r--r--utils/license_test.go4
-rw-r--r--utils/password.go2
36 files changed, 403 insertions, 361 deletions
diff --git a/api/apitestlib.go b/api/apitestlib.go
index e857a5080..94cd5a926 100644
--- a/api/apitestlib.go
+++ b/api/apitestlib.go
@@ -39,7 +39,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
*utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest()
- utils.License.Features.SetDefaults()
+ utils.License().Features.SetDefaults()
app.NewServer()
app.InitStores()
InitRouter()
diff --git a/api/channel_test.go b/api/channel_test.go
index bdb62677f..c6fa23282 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -95,23 +95,23 @@ func TestCreateChannel(t *testing.T) {
t.Fatal("Should have errored out on direct channel type")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
utils.SetDefaultRolesBasedOnConfig()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel3 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -171,8 +171,8 @@ func TestCreateChannel(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
channel4 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
@@ -351,22 +351,22 @@ func TestUpdateChannel(t *testing.T) {
t.Fatal("should have failed - channel deleted")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel2 := th.CreateChannel(Client, team)
@@ -388,9 +388,9 @@ func TestUpdateChannel(t *testing.T) {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
MakeUserChannelUser(th.BasicUser, channel2)
MakeUserChannelUser(th.BasicUser, channel3)
@@ -427,9 +427,9 @@ func TestUpdateChannel(t *testing.T) {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err == nil {
@@ -453,9 +453,9 @@ func TestUpdateChannel(t *testing.T) {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err == nil {
@@ -475,8 +475,8 @@ func TestUpdateChannel(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.UpdateChannel(channel2); err != nil {
@@ -586,22 +586,22 @@ func TestUpdateChannelHeader(t *testing.T) {
t.Fatal("should have errored non-channel member trying to update header")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -697,8 +697,8 @@ func TestUpdateChannelHeader(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
@@ -768,22 +768,22 @@ func TestUpdateChannelPurpose(t *testing.T) {
t.Fatal("should have errored non-channel member trying to update purpose")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -879,8 +879,8 @@ func TestUpdateChannelPurpose(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
t.Fatal(err)
@@ -1324,22 +1324,22 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal("should have failed - channel already deleted")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginSystemAdmin()
@@ -1362,9 +1362,9 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal(err)
}
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
utils.SetDefaultRolesBasedOnConfig()
@@ -1418,9 +1418,9 @@ func TestDeleteChannel(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
@@ -1453,9 +1453,9 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal(err)
}
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
@@ -1490,8 +1490,8 @@ func TestDeleteChannel(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
channel2 = th.CreateChannel(Client, team)
@@ -1598,17 +1598,17 @@ func TestAddChannelMember(t *testing.T) {
}
// Add a license
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can add other users.
@@ -1621,9 +1621,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1635,9 +1635,9 @@ func TestAddChannelMember(t *testing.T) {
MakeUserChannelAdmin(user1, channel5)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.AddChannelMember(channel5.Id, user2.Id); err != nil {
@@ -1646,9 +1646,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1660,9 +1660,9 @@ func TestAddChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.AddChannelMember(channel6.Id, user2.Id); err != nil {
@@ -1671,9 +1671,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1772,17 +1772,17 @@ func TestRemoveChannelMember(t *testing.T) {
}
// Add a license
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can remove other users.
@@ -1796,9 +1796,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1811,9 +1811,9 @@ func TestRemoveChannelMember(t *testing.T) {
MakeUserChannelAdmin(user1, channel5)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil {
t.Fatal(err)
@@ -1821,9 +1821,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
@@ -1836,9 +1836,9 @@ func TestRemoveChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.RemoveChannelMember(channel6.Id, user2.Id); err != nil {
@@ -1847,9 +1847,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
diff --git a/api/context.go b/api/context.go
index d0036d077..286221092 100644
--- a/api/context.go
+++ b/api/context.go
@@ -149,7 +149,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host)
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
if !h.isApi {
@@ -321,7 +321,7 @@ func (c *Context) UserRequired() {
func (c *Context) MfaRequired() {
// 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
}
diff --git a/api/license.go b/api/license.go
index 7a9e57677..162dd6762 100644
--- a/api/license.go
+++ b/api/license.go
@@ -97,7 +97,7 @@ func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request)
var clientLicense map[string]string
if useSanitizedLicense {
- clientLicense = utils.ClientLicense
+ clientLicense = utils.ClientLicense()
} else {
clientLicense = utils.GetSanitizedClientLicense()
}
diff --git a/api/license_test.go b/api/license_test.go
index 978e044cc..15d3b9eef 100644
--- a/api/license_test.go
+++ b/api/license_test.go
@@ -29,7 +29,7 @@ func TestGetLicenceConfig(t *testing.T) {
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 {
t.Fatal(err)
@@ -37,7 +37,7 @@ func TestGetLicenceConfig(t *testing.T) {
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 {
t.Fatal(err)
@@ -45,6 +45,6 @@ func TestGetLicenceConfig(t *testing.T) {
t.Fatal("result should not be empty")
}
- utils.ClientLicense = map[string]string{"IsLicensed": "false"}
+ utils.SetClientLicense(map[string]string{"IsLicensed": "false"})
}
}
diff --git a/api/post_test.go b/api/post_test.go
index a48ad4f51..29c1f791a 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -409,15 +409,15 @@ func TestUpdatePost(t *testing.T) {
}
// Test licensed policy controls for edit post
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER
@@ -951,15 +951,15 @@ func TestDeletePosts(t *testing.T) {
}
// Test licensed policy controls for delete post
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
UpdateUserToTeamAdmin(th.BasicUser2, th.BasicTeam)
@@ -1014,8 +1014,8 @@ func TestDeletePosts(t *testing.T) {
}
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
time.Sleep(10 * time.Millisecond)
diff --git a/api/team.go b/api/team.go
index c7fa61df6..c6db68418 100644
--- a/api/team.go
+++ b/api/team.go
@@ -118,7 +118,7 @@ func getAll(c *Context, w http.ResponseWriter, r *http.Request) {
func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
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 := ""
if *utils.Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_SYSTEM_ADMIN {
errorId = "api.team.invite_members.restricted_system_admin.app_error"
diff --git a/api/team_test.go b/api/team_test.go
index e09bf42ef..7d10ca6e3 100644
--- a/api/team_test.go
+++ b/api/team_test.go
@@ -95,12 +95,12 @@ func TestAddUserToTeam(t *testing.T) {
// Restore config/license at end of test case.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
@@ -115,9 +115,9 @@ func TestAddUserToTeam(t *testing.T) {
}
// Add an EE license.
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
// Check that a regular user can't add someone to the team.
@@ -130,9 +130,9 @@ func TestAddUserToTeam(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
user5 := th.CreateUser(th.BasicClient)
@@ -381,16 +381,16 @@ func TestInviteMembers(t *testing.T) {
t.Fatal(err)
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
if _, err := Client.InviteMembers(invites); err == nil {
diff --git a/api/user.go b/api/user.go
index bb63cc7e2..8843a3730 100644
--- a/api/user.go
+++ b/api/user.go
@@ -302,7 +302,7 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) {
il.ClientCfg = utils.ClientCfg
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- il.LicenseCfg = utils.ClientLicense
+ il.LicenseCfg = utils.ClientLicense()
} else {
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) {
- 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["mfa_required"] = "false"
w.Write([]byte(model.MapToJson(rdata)))
diff --git a/api/user_test.go b/api/user_test.go
index f76403ee1..8669a7bbe 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -1836,18 +1836,18 @@ func TestUpdateMfa(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}()
- utils.IsLicensed = false
- utils.License = &model.License{Features: &model.Features{}}
- if utils.License.Features.MFA == nil {
- utils.License.Features.MFA = new(bool)
+ utils.SetIsLicensed(false)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ if utils.License().Features.MFA == nil {
+ 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}
@@ -1874,8 +1874,8 @@ func TestUpdateMfa(t *testing.T) {
t.Fatal("should have failed - not licensed")
}
- utils.IsLicensed = true
- *utils.License.Features.MFA = true
+ utils.SetIsLicensed(true)
+ *utils.License().Features.MFA = true
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
if _, err := Client.UpdateMfa(true, "123456"); err == nil {
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index 7f69b3690..b10e639e3 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -55,7 +55,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.EmailSettings.SMTPPort = "2500"
utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
utils.DisableDebugLogForTest()
- utils.License.Features.SetDefaults()
+ utils.License().Features.SetDefaults()
app.NewServer()
app.InitStores()
InitRouter()
diff --git a/api4/channel_test.go b/api4/channel_test.go
index 5cc770332..1747d79b9 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -82,22 +82,22 @@ func TestCreateChannel(t *testing.T) {
th.LoginBasic()
// Check permissions with policy config changes
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelCreation
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelCreation
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelCreation = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
channel.Name = GenerateTestChannelName()
@@ -165,8 +165,8 @@ func TestCreateChannel(t *testing.T) {
CheckNoError(t, resp)
// Check that if unlicensed the policy restriction is not enforced.
- utils.IsLicensed = false
- utils.License = nil
+ utils.SetIsLicensed(false)
+ utils.SetLicense(nil)
utils.SetDefaultRolesBasedOnConfig()
channel.Name = GenerateTestChannelName()
@@ -879,22 +879,22 @@ func TestDeleteChannel(t *testing.T) {
_, resp = th.SystemAdminClient.DeleteChannel(publicChannel5.Id)
CheckNoError(t, resp)
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
restrictPublicChannel := *utils.Cfg.TeamSettings.RestrictPublicChannelManagement
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManagement
defer func() {
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL
*utils.Cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th = Setup().InitBasic().InitSystemAdmin()
@@ -956,9 +956,9 @@ func TestDeleteChannel(t *testing.T) {
// successful delete by team admin
UpdateUserToTeamAdmin(user, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id)
CheckNoError(t, resp)
@@ -971,9 +971,9 @@ func TestDeleteChannel(t *testing.T) {
utils.SetDefaultRolesBasedOnConfig()
UpdateUserToNonTeamAdmin(user, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
// channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
@@ -1003,9 +1003,9 @@ func TestDeleteChannel(t *testing.T) {
// successful delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id)
CheckNoError(t, resp)
@@ -1045,9 +1045,9 @@ func TestDeleteChannel(t *testing.T) {
// cannot delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
_, resp = Client.DeleteChannel(publicChannel6.Id)
CheckForbiddenStatus(t, resp)
@@ -1796,17 +1796,17 @@ func TestAddChannelMember(t *testing.T) {
Client.Logout()
// Add a license
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can add other users.
@@ -1823,9 +1823,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password)
@@ -1841,9 +1841,9 @@ func TestAddChannelMember(t *testing.T) {
MakeUserChannelAdmin(user, privateChannel)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
Client.Login(user.Username, user.Password)
@@ -1853,9 +1853,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password)
@@ -1871,9 +1871,9 @@ func TestAddChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
Client.Login(user.Username, user.Password)
@@ -1883,9 +1883,9 @@ func TestAddChannelMember(t *testing.T) {
// Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
Client.Login(user2.Username, user2.Password)
@@ -1980,17 +1980,17 @@ func TestRemoveChannelMember(t *testing.T) {
CheckNoError(t, resp)
// Add a license
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
// Check that a regular channel user can remove other users.
@@ -2005,9 +2005,9 @@ func TestRemoveChannelMember(t *testing.T) {
// Test with CHANNEL_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
@@ -2021,18 +2021,18 @@ func TestRemoveChannelMember(t *testing.T) {
MakeUserChannelAdmin(user1, privateChannel)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp)
// Test with TEAM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
@@ -2046,18 +2046,18 @@ func TestRemoveChannelMember(t *testing.T) {
UpdateUserToTeamAdmin(user1, team)
app.InvalidateAllCaches()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
CheckNoError(t, resp)
// Test with SYSTEM_ADMIN level permission.
*utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
diff --git a/api4/context.go b/api4/context.go
index d72b3593d..69351a098 100644
--- a/api4/context.go
+++ b/api4/context.go
@@ -129,7 +129,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.SetSiteURLHeader(app.GetProtocol(r) + "://" + r.Host)
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")
@@ -252,7 +252,7 @@ func (c *Context) SessionRequired() {
func (c *Context) MfaRequired() {
// 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
}
diff --git a/api4/post_test.go b/api4/post_test.go
index b7ed06bd4..c09cb77d1 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -366,18 +366,18 @@ func TestUpdatePost(t *testing.T) {
Client := th.Client
channel := th.BasicChannel
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
*utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS
utils.SetDefaultRolesBasedOnConfig()
@@ -445,18 +445,18 @@ func TestPatchPost(t *testing.T) {
Client := th.Client
channel := th.BasicChannel
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
allowEditPost := *utils.Cfg.ServiceSettings.AllowEditPost
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
*utils.Cfg.ServiceSettings.AllowEditPost = allowEditPost
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
*utils.Cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS
utils.SetDefaultRolesBasedOnConfig()
diff --git a/api4/system.go b/api4/system.go
index ff3aab0d0..0c0fc7d12 100644
--- a/api4/system.go
+++ b/api4/system.go
@@ -258,7 +258,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
var clientLicense map[string]string
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- clientLicense = utils.ClientLicense
+ clientLicense = utils.ClientLicense()
} else {
clientLicense = utils.GetSanitizedClientLicense()
}
diff --git a/api4/team_test.go b/api4/team_test.go
index 421428afa..a498d1e04 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -826,12 +826,12 @@ func TestAddTeamMember(t *testing.T) {
// Check effects of config and license changes.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
@@ -845,9 +845,9 @@ func TestAddTeamMember(t *testing.T) {
CheckNoError(t, resp)
// Add an EE license.
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -859,9 +859,9 @@ func TestAddTeamMember(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -885,9 +885,9 @@ func TestAddTeamMember(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -897,8 +897,8 @@ func TestAddTeamMember(t *testing.T) {
// Reset config and license.
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -1040,12 +1040,12 @@ func TestAddTeamMembers(t *testing.T) {
// Check effects of config and license changes.
restrictTeamInvite := *utils.Cfg.TeamSettings.RestrictTeamInvite
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
defer func() {
*utils.Cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
utils.SetDefaultRolesBasedOnConfig()
}()
@@ -1059,9 +1059,9 @@ func TestAddTeamMembers(t *testing.T) {
CheckNoError(t, resp)
// Add an EE license.
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -1073,9 +1073,9 @@ func TestAddTeamMembers(t *testing.T) {
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
@@ -1099,9 +1099,9 @@ func TestAddTeamMembers(t *testing.T) {
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
app.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
diff --git a/api4/user.go b/api4/user.go
index b0192592c..365248c0f 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -675,7 +675,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
resp := map[string]interface{}{}
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)))
return
}
diff --git a/api4/user_test.go b/api4/user_test.go
index 37ecd660d..894187469 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -1513,17 +1513,17 @@ func TestGetUsersNotInChannel(t *testing.T) {
defer TearDown()
Client := th.Client
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
+ utils.IsLicensed()= true
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
rteam, _ := Client.CreateTeam(&team)
@@ -1574,18 +1574,18 @@ func TestCheckUserMfa(t *testing.T) {
t.Fatal("should be false - mfa not active")
}
- isLicensed := utils.IsLicensed
- license := utils.License
+ isLicensed := utils.IsLicensed()
+ license := utils.License()
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() {
- utils.IsLicensed = isLicensed
- utils.License = license
+ utils.SetIsLicensed(isLicensed)
+ utils.SetLicense(license)
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}()
- utils.IsLicensed = true
- utils.License = &model.License{Features: &model.Features{}}
- utils.License.Features.SetDefaults()
- *utils.License.Features.MFA = true
+ utils.SetIsLicensed(true)
+ utils.SetLicense(&model.License{Features: &model.Features{}})
+ utils.License().Features.SetDefaults()
+ *utils.License().Features.MFA = true
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
th.LoginBasic()
diff --git a/app/apptestlib.go b/app/apptestlib.go
index 0c7086c64..3966bdeea 100644
--- a/app/apptestlib.go
+++ b/app/apptestlib.go
@@ -28,7 +28,7 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
*utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest()
- utils.License.Features.SetDefaults()
+ utils.License().Features.SetDefaults()
NewServer()
InitStores()
StartServer()
diff --git a/app/authentication.go b/app/authentication.go
index 5e1b4461f..b09234d5f 100644
--- a/app/authentication.go
+++ b/app/authentication.go
@@ -102,7 +102,7 @@ func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string
}
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
}
@@ -143,7 +143,7 @@ func checkUserNotDisabled(user *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 !ldapAvailable {
diff --git a/app/compliance.go b/app/compliance.go
index cb1eece70..5b4f9de67 100644
--- a/app/compliance.go
+++ b/app/compliance.go
@@ -12,7 +12,7 @@ import (
)
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, "")
}
@@ -24,7 +24,7 @@ func GetComplianceReports(page, perPage int) (model.Compliances, *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, "")
}
@@ -41,7 +41,7 @@ func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppE
}
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, "")
}
diff --git a/app/diagnostics.go b/app/diagnostics.go
index aff223855..2eae5871d 100644
--- a/app/diagnostics.go
+++ b/app/diagnostics.go
@@ -423,17 +423,17 @@ func trackConfig() {
}
func trackLicense() {
- if utils.IsLicensed {
+ if utils.IsLicensed() {
data := map[string]interface{}{
- "customer_id": utils.License.Customer.Id,
- "license_id": utils.License.Id,
- "issued": utils.License.IssuedAt,
- "start": utils.License.StartsAt,
- "expire": utils.License.ExpiresAt,
- "users": *utils.License.Features.Users,
+ "customer_id": utils.License().Customer.Id,
+ "license_id": utils.License().Id,
+ "issued": utils.License().IssuedAt,
+ "start": utils.License().StartsAt,
+ "expire": utils.License().ExpiresAt,
+ "users": *utils.License().Features.Users,
}
- features := utils.License.Features.ToMap()
+ features := utils.License().Features.ToMap()
for featureName, featureValue := range features {
data["feature_"+featureName] = featureValue
}
diff --git a/app/email_batching.go b/app/email_batching.go
index a578daf04..b37963a94 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -196,7 +196,7 @@ func sendBatchedEmailNotification(userId string, notifications []*batchedNotific
}
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
}
diff --git a/app/ldap.go b/app/ldap.go
index 1b823dc47..17c24db8f 100644
--- a/app/ldap.go
+++ b/app/ldap.go
@@ -14,7 +14,7 @@ import (
func SyncLdap() {
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 {
ldapI.SyncNow()
} else {
@@ -25,7 +25,7 @@ func SyncLdap() {
}
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 {
err.StatusCode = 500
return err
diff --git a/app/license_test.go b/app/license_test.go
index a7761b204..07805992a 100644
--- a/app/license_test.go
+++ b/app/license_test.go
@@ -13,7 +13,7 @@ func TestLoadLicense(t *testing.T) {
Setup()
LoadLicense()
- if utils.IsLicensed {
+ if utils.IsLicensed() {
t.Fatal("shouldn't have a valid license")
}
}
diff --git a/app/notification.go b/app/notification.go
index 4fec40040..69bfa3b7a 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -236,7 +236,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
sendPushNotifications := false
if *utils.Cfg.EmailSettings.SendPushNotifications {
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"))
sendPushNotifications = false
} else {
@@ -359,7 +359,7 @@ func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Ch
}
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
}
diff --git a/app/post.go b/app/post.go
index a4b177859..068266120 100644
--- a/app/post.go
+++ b/app/post.go
@@ -233,7 +233,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
} else {
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 {
err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_denied.app_error", nil, "", http.StatusForbidden)
return nil, err
@@ -255,7 +255,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
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 {
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
@@ -503,7 +503,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
paramsList := model.ParseSearchParams(terms)
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{}
for _, params := range paramsList {
diff --git a/app/user.go b/app/user.go
index 426a11bcb..813421a5c 100644
--- a/app/user.go
+++ b/app/user.go
@@ -376,7 +376,7 @@ func GetUserByAuth(authData *string, authService string) (*model.User, *model.Ap
}
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(
loginId,
diff --git a/app/web_conn.go b/app/web_conn.go
index 43047a881..24b7166c0 100644
--- a/app/web_conn.go
+++ b/app/web_conn.go
@@ -217,7 +217,7 @@ func (webCon *WebConn) IsAuthenticated() bool {
func (webCon *WebConn) SendHello() {
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
}
diff --git a/cmd/platform/channel.go b/cmd/platform/channel.go
index 0ff2a1b5f..ed8a0b817 100644
--- a/cmd/platform/channel.go
+++ b/cmd/platform/channel.go
@@ -106,7 +106,7 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
return err
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical"))
}
@@ -158,7 +158,7 @@ func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
return err
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical"))
}
@@ -194,7 +194,7 @@ func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
return err
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical"))
}
@@ -292,7 +292,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
return err
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical"))
}
@@ -329,7 +329,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
return err
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
return errors.New(utils.T("cli.license.critical"))
}
diff --git a/cmd/platform/server.go b/cmd/platform/server.go
index 79193cd0f..77fedccf4 100644
--- a/cmd/platform/server.go
+++ b/cmd/platform/server.go
@@ -81,12 +81,12 @@ func runServer(configFileLocation string) {
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"))
utils.Cfg.SqlSettings.DataSourceReplicas = utils.Cfg.SqlSettings.DataSourceReplicas[:1]
}
- if !utils.IsLicensed {
+ if !utils.IsLicensed() {
utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
}
diff --git a/utils/authorization.go b/utils/authorization.go
index 6f01d7820..e0e587d71 100644
--- a/utils/authorization.go
+++ b/utils/authorization.go
@@ -11,7 +11,7 @@ func SetDefaultRolesBasedOnConfig() {
// Reset the roles to default to make this logic easier
model.InitalizeRoles()
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelCreation {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -33,7 +33,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelManagement {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -65,7 +65,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPublicChannelDeletion {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -97,7 +97,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelCreation {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -119,7 +119,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelManagement {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -151,7 +151,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelDeletion {
case model.PERMISSIONS_ALL:
model.ROLE_TEAM_USER.Permissions = append(
@@ -184,7 +184,7 @@ func SetDefaultRolesBasedOnConfig() {
}
// Restrict permissions for Private Channel Manage Members
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.TeamSettings.RestrictPrivateChannelManageMembers {
case model.PERMISSIONS_ALL:
model.ROLE_CHANNEL_USER.Permissions = append(
@@ -229,7 +229,7 @@ func SetDefaultRolesBasedOnConfig() {
}
// Grant permissions for inviting and adding users to a team.
- if IsLicensed {
+ if IsLicensed() {
if *Cfg.TeamSettings.RestrictTeamInvite == model.PERMISSIONS_TEAM_ADMIN {
model.ROLE_TEAM_ADMIN.Permissions = append(
model.ROLE_TEAM_ADMIN.Permissions,
@@ -251,7 +251,7 @@ func SetDefaultRolesBasedOnConfig() {
)
}
- if IsLicensed {
+ if IsLicensed() {
switch *Cfg.ServiceSettings.RestrictPostDelete {
case model.PERMISSIONS_DELETE_POST_ALL:
model.ROLE_CHANNEL_USER.Permissions = append(
diff --git a/utils/config.go b/utils/config.go
index c0c7ecc20..187af4125 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -489,7 +489,10 @@ func getClientConfig(c *model.Config) map[string]string {
props["DiagnosticId"] = CfgDiagnosticId
props["DiagnosticsEnabled"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
- if IsLicensed {
+ if IsLicensed() {
+
+ License := License()
+
if *License.Features.CustomBrand {
props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand)
props["CustomBrandText"] = *c.TeamSettings.CustomBrandText
diff --git a/utils/license.go b/utils/license.go
index e28a43e29..d0abc612d 100644
--- a/utils/license.go
+++ b/utils/license.go
@@ -16,17 +16,16 @@ import (
"os"
"strconv"
"strings"
+ "sync/atomic"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
)
-var IsLicensed bool = false
-var License *model.License = &model.License{
- Features: new(model.Features),
-}
-var ClientLicense map[string]string = map[string]string{"IsLicensed": "false"}
+var isLicensedInt32 int32
+var licenseValue atomic.Value
+var clientLicenseValue atomic.Value
var publicKey []byte = []byte(`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyZmShlU8Z8HdG0IWSZ8r
@@ -38,6 +37,34 @@ a0v85XL6i9ote2P+fLZ3wX9EoioHzgdgB7arOxY50QRJO7OyCqpKFKv6lRWTXuSt
hwIDAQAB
-----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) {
if success, licenseStr := ValidateLicense(licenseBytes); success {
license := model.LicenseFromJson(strings.NewReader(licenseStr))
@@ -49,23 +76,35 @@ func LoadLicense(licenseBytes []byte) {
}
func SetLicense(license *model.License) bool {
- license.Features.SetDefaults()
- if !license.IsExpired() {
- License = license
- IsLicensed = true
- ClientLicense = getClientLicense(license)
- ClientCfg = getClientConfig(Cfg)
- return true
- }
+ if license == nil {
+ SetIsLicensed(false)
+ license = &model.License{
+ Features: new(model.Features),
+ }
+ license.Features.SetDefaults()
+ licenseValue.Store(license)
- return false
+ 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
+ }
}
func RemoveLicense() {
- License = &model.License{}
- IsLicensed = false
- ClientLicense = getClientLicense(License)
+ SetLicense(nil)
ClientCfg = getClientConfig(Cfg)
}
@@ -162,9 +201,9 @@ func GetLicenseFileLocation(fileLocation string) string {
func getClientLicense(l *model.License) 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["Users"] = strconv.Itoa(*l.Features.Users)
props["LDAP"] = strconv.FormatBool(*l.Features.LDAP)
@@ -195,7 +234,7 @@ func getClientLicense(l *model.License) map[string]string {
func GetClientLicenseEtag(useSanitized bool) string {
value := ""
- lic := ClientLicense
+ lic := ClientLicense()
if useSanitized {
lic = GetSanitizedClientLicense()
@@ -211,11 +250,11 @@ func GetClientLicenseEtag(useSanitized bool) string {
func GetSanitizedClientLicense() map[string]string {
sanitizedLicense := make(map[string]string)
- for k, v := range ClientLicense {
+ for k, v := range ClientLicense() {
sanitizedLicense[k] = v
}
- if IsLicensed {
+ if IsLicensed() {
delete(sanitizedLicense, "Id")
delete(sanitizedLicense, "Name")
delete(sanitizedLicense, "Email")
diff --git a/utils/license_test.go b/utils/license_test.go
index 289262f4c..1d948b02f 100644
--- a/utils/license_test.go
+++ b/utils/license_test.go
@@ -54,14 +54,14 @@ func TestValidateLicense(t *testing.T) {
func TestClientLicenseEtag(t *testing.T) {
etag1 := GetClientLicenseEtag(false)
- ClientLicense["SomeFeature"] = "true"
+ SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "true"})
etag2 := GetClientLicenseEtag(false)
if etag1 == etag2 {
t.Fatal("etags should not match")
}
- ClientLicense["SomeFeature"] = "false"
+ SetClientLicense(map[string]string{"SomeFeature": "true", "IsLicensed": "false"})
etag3 := GetClientLicenseEtag(false)
if etag2 == etag3 {
diff --git a/utils/password.go b/utils/password.go
index 6aa785df8..7c2ca538b 100644
--- a/utils/password.go
+++ b/utils/password.go
@@ -15,7 +15,7 @@ func IsPasswordValid(password string) *model.AppError {
isError := false
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 {
isError = true
}