summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/apitestlib.go2
-rw-r--r--api/channel.go19
-rw-r--r--api/channel_test.go219
-rw-r--r--api/command_test.go3
-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.go38
-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
12 files changed, 176 insertions, 177 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.go b/api/channel.go
index 2a56e7c93..50dc840ff 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -448,23 +448,14 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- var memberCount int64
- if memberCount, err = app.GetChannelMemberCount(id); err != nil {
- c.Err = err
+ if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
+ c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
return
}
- // Allow delete if user is the only member left in channel
- if memberCount > 1 {
- if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
- c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
- return
- }
-
- if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
- c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
- return
- }
+ if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
+ c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
+ return
}
err = app.DeleteChannel(channel, c.Session.UserId)
diff --git a/api/channel_test.go b/api/channel_test.go
index 6ed4d55fa..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()
@@ -1476,9 +1476,8 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal("should have errored not system admin")
}
- // Only one left in channel, should be able to delete
- if _, err := Client.DeleteChannel(channel4.Id); err != nil {
- t.Fatal(err)
+ if _, err := Client.DeleteChannel(channel4.Id); err == nil {
+ t.Fatal("Should not be able to delete channel, even though only one user is left")
}
th.LoginSystemAdmin()
@@ -1491,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)
@@ -1599,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.
@@ -1622,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}
@@ -1636,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 {
@@ -1647,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}
@@ -1661,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 {
@@ -1672,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}
@@ -1773,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.
@@ -1797,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}
@@ -1812,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)
@@ -1822,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}
@@ -1837,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 {
@@ -1848,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/command_test.go b/api/command_test.go
index 9e6696d64..dd4180b16 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -233,10 +233,13 @@ func TestTestCommand(t *testing.T) {
channel1 := th.SystemAdminChannel
enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
+ *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost"
cmd1 := &model.Command{
URL: "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test",
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 c7bd7a04c..29c1f791a 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -188,10 +188,13 @@ func testCreatePostWithOutgoingHook(
channel := th.CreateChannel(Client, team)
enableOutgoingHooks := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
+ allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks
+ utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
}()
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = true
+ *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
var hook *model.OutgoingWebhook
var post *model.Post
@@ -406,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
@@ -948,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)
@@ -1011,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)
@@ -1359,10 +1362,13 @@ func TestGetOpenGraphMetadata(t *testing.T) {
Client := th.BasicClient
enableLinkPreviews := *utils.Cfg.ServiceSettings.EnableLinkPreviews
+ allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
defer func() {
*utils.Cfg.ServiceSettings.EnableLinkPreviews = enableLinkPreviews
+ utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
}()
*utils.Cfg.ServiceSettings.EnableLinkPreviews = true
+ *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
ogDataCacheMissCount := 0
diff --git a/api/team.go b/api/team.go
index b1fcdfd78..4010a0ac5 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 3c05588ce..99e54a904 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)
@@ -386,16 +386,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 {