mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Eliminate utils.SetLicense calls (#8217)
* eliminate utils.SetLicense calls * test fix * another test fix * more test fixes
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store"
|
"github.com/mattermost/mattermost-server/store"
|
||||||
"github.com/mattermost/mattermost-server/store/sqlstore"
|
"github.com/mattermost/mattermost-server/store/sqlstore"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateChannel(t *testing.T) {
|
func TestCreateChannel(t *testing.T) {
|
||||||
@@ -97,23 +96,9 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
t.Fatal("Should have errored out on direct channel type")
|
t.Fatal("Should have errored out on direct channel type")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
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}
|
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||||
channel3 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel3 := &model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
@@ -130,7 +115,6 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic2()
|
th.LoginBasic2()
|
||||||
channel2.Name = "zz" + model.NewId() + "a"
|
channel2.Name = "zz" + model.NewId() + "a"
|
||||||
@@ -160,7 +144,6 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel2.Name = "zz" + model.NewId() + "a"
|
channel2.Name = "zz" + model.NewId() + "a"
|
||||||
channel3.Name = "zz" + model.NewId() + "a"
|
channel3.Name = "zz" + model.NewId() + "a"
|
||||||
@@ -181,9 +164,7 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel4 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
channel4 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||||
channel5 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel5 := model.Channel{DisplayName: "Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
@@ -196,7 +177,6 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateDirectChannel(t *testing.T) {
|
func TestCreateDirectChannel(t *testing.T) {
|
||||||
@@ -367,23 +347,9 @@ func TestUpdateChannel(t *testing.T) {
|
|||||||
t.Fatal("should have failed - channel deleted")
|
t.Fatal("should have failed - channel deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel2 := th.CreateChannel(Client, team)
|
channel2 := th.CreateChannel(Client, team)
|
||||||
channel3 := th.CreatePrivateChannel(Client, team)
|
channel3 := th.CreatePrivateChannel(Client, team)
|
||||||
@@ -404,14 +370,8 @@ func TestUpdateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel2)
|
th.MakeUserChannelUser(th.BasicUser, channel2)
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel3)
|
th.MakeUserChannelUser(th.BasicUser, channel3)
|
||||||
sqlstore.ClearChannelCaches()
|
sqlstore.ClearChannelCaches()
|
||||||
@@ -447,14 +407,9 @@ func TestUpdateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannel(channel2); err == nil {
|
if _, err := Client.UpdateChannel(channel2); err == nil {
|
||||||
t.Fatal("should have errored not team admin")
|
t.Fatal("should have errored not team admin")
|
||||||
@@ -477,14 +432,8 @@ func TestUpdateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannel(channel2); err == nil {
|
if _, err := Client.UpdateChannel(channel2); err == nil {
|
||||||
t.Fatal("should have errored not system admin")
|
t.Fatal("should have errored not system admin")
|
||||||
@@ -503,9 +452,7 @@ func TestUpdateChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannel(channel2); err != nil {
|
if _, err := Client.UpdateChannel(channel2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -618,23 +565,9 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
t.Fatal("should have errored non-channel member trying to update header")
|
t.Fatal("should have errored non-channel member trying to update header")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
channel2 := th.CreateChannel(Client, team)
|
channel2 := th.CreateChannel(Client, team)
|
||||||
@@ -659,11 +592,8 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel2)
|
th.MakeUserChannelUser(th.BasicUser, channel2)
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel3)
|
th.MakeUserChannelUser(th.BasicUser, channel3)
|
||||||
sqlstore.ClearChannelCaches()
|
sqlstore.ClearChannelCaches()
|
||||||
@@ -688,11 +618,8 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannelHeader(data2); err == nil {
|
if _, err := Client.UpdateChannelHeader(data2); err == nil {
|
||||||
t.Fatal("should have errored not team admin")
|
t.Fatal("should have errored not team admin")
|
||||||
@@ -715,11 +642,8 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannelHeader(data2); err == nil {
|
if _, err := Client.UpdateChannelHeader(data2); err == nil {
|
||||||
t.Fatal("should have errored not system admin")
|
t.Fatal("should have errored not system admin")
|
||||||
@@ -741,9 +665,7 @@ func TestUpdateChannelHeader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
|
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -814,23 +736,9 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
|||||||
t.Fatal("should have errored non-channel member trying to update purpose")
|
t.Fatal("should have errored non-channel member trying to update purpose")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
channel2 := th.CreateChannel(Client, team)
|
channel2 := th.CreateChannel(Client, team)
|
||||||
@@ -855,11 +763,8 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel2)
|
th.MakeUserChannelUser(th.BasicUser, channel2)
|
||||||
th.MakeUserChannelUser(th.BasicUser, channel3)
|
th.MakeUserChannelUser(th.BasicUser, channel3)
|
||||||
sqlstore.ClearChannelCaches()
|
sqlstore.ClearChannelCaches()
|
||||||
@@ -884,11 +789,8 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
|
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
|
||||||
t.Fatal("should have errored not team admin")
|
t.Fatal("should have errored not team admin")
|
||||||
@@ -911,11 +813,8 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
|
if _, err := Client.UpdateChannelPurpose(data2); err == nil {
|
||||||
t.Fatal("should have errored not system admin")
|
t.Fatal("should have errored not system admin")
|
||||||
@@ -937,9 +836,7 @@ func TestUpdateChannelPurpose(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
|
if _, err := SystemAdminClient.UpdateChannelHeader(data2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -1400,23 +1297,9 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
t.Fatal("should have failed - channel already deleted")
|
t.Fatal("should have failed - channel already deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginSystemAdmin()
|
th.LoginSystemAdmin()
|
||||||
th.LinkUserToTeam(th.BasicUser, team)
|
th.LinkUserToTeam(th.BasicUser, team)
|
||||||
@@ -1438,16 +1321,10 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginSystemAdmin()
|
th.LoginSystemAdmin()
|
||||||
|
|
||||||
@@ -1498,16 +1375,11 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
th.UpdateUserToNonTeamAdmin(th.BasicUser, team)
|
th.UpdateUserToNonTeamAdmin(th.BasicUser, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
|
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginSystemAdmin()
|
th.LoginSystemAdmin()
|
||||||
|
|
||||||
@@ -1537,16 +1409,10 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginSystemAdmin()
|
th.LoginSystemAdmin()
|
||||||
|
|
||||||
@@ -1578,9 +1444,7 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel2 = th.CreateChannel(Client, team)
|
channel2 = th.CreateChannel(Client, team)
|
||||||
channel3 = th.CreatePrivateChannel(Client, team)
|
channel3 = th.CreatePrivateChannel(Client, team)
|
||||||
@@ -1595,10 +1459,6 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
if _, err := Client.DeleteChannel(channel3.Id); err != nil {
|
if _, err := Client.DeleteChannel(channel3.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_ALL })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_ALL })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetChannelStats(t *testing.T) {
|
func TestGetChannelStats(t *testing.T) {
|
||||||
@@ -1675,16 +1535,9 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test policy does not apply to TE.
|
// Test policy does not apply to TE.
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel3 = Client.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel)
|
channel3 = Client.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel)
|
||||||
@@ -1694,18 +1547,8 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a license
|
// Add a license
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Check that a regular channel user can add other users.
|
// Check that a regular channel user can add other users.
|
||||||
channel4 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel4 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
@@ -1719,10 +1562,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel5 = Client.Must(th.SystemAdminClient.CreateChannel(channel5)).Data.(*model.Channel)
|
channel5 = Client.Must(th.SystemAdminClient.CreateChannel(channel5)).Data.(*model.Channel)
|
||||||
@@ -1733,10 +1572,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.MakeUserChannelAdmin(user1, channel5)
|
th.MakeUserChannelAdmin(user1, channel5)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.AddChannelMember(channel5.Id, user2.Id); err != nil {
|
if _, err := Client.AddChannelMember(channel5.Id, user2.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -1746,10 +1582,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel6 = Client.Must(th.SystemAdminClient.CreateChannel(channel6)).Data.(*model.Channel)
|
channel6 = Client.Must(th.SystemAdminClient.CreateChannel(channel6)).Data.(*model.Channel)
|
||||||
@@ -1760,10 +1592,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.UpdateUserToTeamAdmin(user1, team)
|
th.UpdateUserToTeamAdmin(user1, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.AddChannelMember(channel6.Id, user2.Id); err != nil {
|
if _, err := Client.AddChannelMember(channel6.Id, user2.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -1773,10 +1602,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel7 = Client.Must(th.SystemAdminClient.CreateChannel(channel7)).Data.(*model.Channel)
|
channel7 = Client.Must(th.SystemAdminClient.CreateChannel(channel7)).Data.(*model.Channel)
|
||||||
@@ -1860,16 +1685,9 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Test policy does not apply to TE.
|
// Test policy does not apply to TE.
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel3 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel3 = Client.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel)
|
channel3 = Client.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel)
|
||||||
@@ -1880,18 +1698,8 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a license
|
// Add a license
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Check that a regular channel user can remove other users.
|
// Check that a regular channel user can remove other users.
|
||||||
channel4 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel4 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
@@ -1906,10 +1714,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel5 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel5 = Client.Must(th.SystemAdminClient.CreateChannel(channel5)).Data.(*model.Channel)
|
channel5 = Client.Must(th.SystemAdminClient.CreateChannel(channel5)).Data.(*model.Channel)
|
||||||
@@ -1921,9 +1725,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.MakeUserChannelAdmin(user1, channel5)
|
th.MakeUserChannelAdmin(user1, channel5)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil {
|
if _, err := Client.RemoveChannelMember(channel5.Id, user2.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -1933,10 +1735,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel6 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel6 = Client.Must(th.SystemAdminClient.CreateChannel(channel6)).Data.(*model.Channel)
|
channel6 = Client.Must(th.SystemAdminClient.CreateChannel(channel6)).Data.(*model.Channel)
|
||||||
@@ -1948,10 +1746,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.UpdateUserToTeamAdmin(user1, team)
|
th.UpdateUserToTeamAdmin(user1, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.RemoveChannelMember(channel6.Id, user2.Id); err != nil {
|
if _, err := Client.RemoveChannelMember(channel6.Id, user2.Id); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -1961,10 +1756,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
channel7 := &model.Channel{DisplayName: "A Test API Name", Name: "zz" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
|
||||||
channel7 = Client.Must(th.SystemAdminClient.CreateChannel(channel7)).Data.(*model.Channel)
|
channel7 = Client.Must(th.SystemAdminClient.CreateChannel(channel7)).Data.(*model.Channel)
|
||||||
|
|||||||
@@ -160,20 +160,8 @@ func TestCreatePost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
disableTownSquareReadOnly := th.App.Config().TeamSettings.ExperimentalTownSquareIsReadOnly
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
defaultChannel := store.Must(th.App.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
defaultChannel := store.Must(th.App.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
||||||
defaultPost := &model.Post{
|
defaultPost := &model.Post{
|
||||||
@@ -466,16 +454,7 @@ func TestUpdatePost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test licensed policy controls for edit post
|
// Test licensed policy controls for edit post
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_NEVER })
|
||||||
|
|
||||||
post4 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
|
post4 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
|
||||||
@@ -966,7 +945,6 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
team1 := th.BasicTeam
|
team1 := th.BasicTeam
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_ALL })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a"}
|
post1 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a"}
|
||||||
@@ -1021,15 +999,7 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test licensed policy controls for delete post
|
// Test licensed policy controls for delete post
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
th.UpdateUserToTeamAdmin(th.BasicUser2, th.BasicTeam)
|
th.UpdateUserToTeamAdmin(th.BasicUser2, th.BasicTeam)
|
||||||
|
|
||||||
@@ -1044,7 +1014,6 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_TEAM_ADMIN
|
*cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
@@ -1069,7 +1038,6 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN
|
*cfg.ServiceSettings.RestrictPostDelete = model.PERMISSIONS_DELETE_POST_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
@@ -1088,9 +1056,7 @@ func TestDeletePosts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
post7 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a"}
|
post7 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a"}
|
||||||
|
|||||||
@@ -139,20 +139,8 @@ func TestAddUserToTeam(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore config/license at end of test case.
|
|
||||||
restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Set the config so that only team admins can add a user to a team.
|
// Set the config so that only team admins can add a user to a team.
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Test without the EE license to see that the permission restriction is ignored.
|
// Test without the EE license to see that the permission restriction is ignored.
|
||||||
user3 := th.CreateUser(th.BasicClient)
|
user3 := th.CreateUser(th.BasicClient)
|
||||||
@@ -161,10 +149,7 @@ func TestAddUserToTeam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add an EE license.
|
// Add an EE license.
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Check that a regular user can't add someone to the team.
|
// Check that a regular user can't add someone to the team.
|
||||||
user4 := th.CreateUser(th.BasicClient)
|
user4 := th.CreateUser(th.BasicClient)
|
||||||
@@ -175,11 +160,8 @@ func TestAddUserToTeam(t *testing.T) {
|
|||||||
// Should work as team admin.
|
// Should work as team admin.
|
||||||
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
user5 := th.CreateUser(th.BasicClient)
|
user5 := th.CreateUser(th.BasicClient)
|
||||||
if _, err := th.BasicClient.AddUserToTeam(th.BasicTeam.Id, user5.Id); err != nil {
|
if _, err := th.BasicClient.AddUserToTeam(th.BasicTeam.Id, user5.Id); err != nil {
|
||||||
@@ -188,7 +170,6 @@ func TestAddUserToTeam(t *testing.T) {
|
|||||||
|
|
||||||
// Change permission level to System Admin
|
// Change permission level to System Admin
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Should not work as team admin.
|
// Should not work as team admin.
|
||||||
user6 := th.CreateUser(th.BasicClient)
|
user6 := th.CreateUser(th.BasicClient)
|
||||||
@@ -565,13 +546,7 @@ func TestInviteMembers(t *testing.T) {
|
|||||||
t.Fatal("Should have errored out on no invites to send")
|
t.Fatal("Should have errored out on no invites to send")
|
||||||
}
|
}
|
||||||
|
|
||||||
restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic2()
|
th.LoginBasic2()
|
||||||
th.LinkUserToTeam(th.BasicUser2, team)
|
th.LinkUserToTeam(th.BasicUser2, team)
|
||||||
@@ -580,17 +555,7 @@ func TestInviteMembers(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.InviteMembers(invites); err == nil {
|
if _, err := Client.InviteMembers(invites); err == nil {
|
||||||
t.Fatal("should have errored not team admin and licensed")
|
t.Fatal("should have errored not team admin and licensed")
|
||||||
@@ -606,7 +571,6 @@ func TestInviteMembers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.InviteMembers(invites); err == nil {
|
if _, err := Client.InviteMembers(invites); err == nil {
|
||||||
t.Fatal("should have errored not system admin and licensed")
|
t.Fatal("should have errored not system admin and licensed")
|
||||||
|
|||||||
@@ -1889,17 +1889,7 @@ func TestUpdateMfa(t *testing.T) {
|
|||||||
|
|
||||||
Client := th.BasicClient
|
Client := th.BasicClient
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(nil)
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
}()
|
|
||||||
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}
|
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||||
rteam, _ := Client.CreateTeam(&team)
|
rteam, _ := Client.CreateTeam(&team)
|
||||||
@@ -1925,8 +1915,7 @@ func TestUpdateMfa(t *testing.T) {
|
|||||||
t.Fatal("should have failed - not licensed")
|
t.Fatal("should have failed - not licensed")
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense("mfa"))
|
||||||
*utils.License().Features.MFA = true
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
||||||
|
|
||||||
if _, err := Client.UpdateMfa(true, "123456"); err == nil {
|
if _, err := Client.UpdateMfa(true, "123456"); err == nil {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateIncomingHook(t *testing.T) {
|
func TestCreateIncomingHook(t *testing.T) {
|
||||||
@@ -93,7 +92,6 @@ func TestCreateIncomingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
|
if _, err := Client.CreateIncomingWebhook(hook); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -133,7 +131,6 @@ func TestUpdateIncomingHook(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := createIncomingWebhook(channel1.Id, Client, t)
|
hook := createIncomingWebhook(channel1.Id, Client, t)
|
||||||
|
|
||||||
@@ -217,7 +214,6 @@ func TestUpdateIncomingHook(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("OnlyAdminIntegrationsDisabled", func(t *testing.T) {
|
t.Run("OnlyAdminIntegrationsDisabled", func(t *testing.T) {
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
t.Run("UpdateHookOfSameUser", func(t *testing.T) {
|
t.Run("UpdateHookOfSameUser", func(t *testing.T) {
|
||||||
sameUserHook := &model.IncomingWebhook{ChannelId: channel1.Id, UserId: user2.Id}
|
sameUserHook := &model.IncomingWebhook{ChannelId: channel1.Id, UserId: user2.Id}
|
||||||
@@ -240,7 +236,6 @@ func TestUpdateIncomingHook(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
th.UpdateUserToTeamAdmin(user2, team)
|
th.UpdateUserToTeamAdmin(user2, team)
|
||||||
@@ -324,7 +319,6 @@ func TestListIncomingHooks(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook1 := &model.IncomingWebhook{ChannelId: channel1.Id}
|
hook1 := &model.IncomingWebhook{ChannelId: channel1.Id}
|
||||||
hook1 = Client.Must(Client.CreateIncomingWebhook(hook1)).Data.(*model.IncomingWebhook)
|
hook1 = Client.Must(Client.CreateIncomingWebhook(hook1)).Data.(*model.IncomingWebhook)
|
||||||
@@ -351,7 +345,6 @@ func TestListIncomingHooks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.ListIncomingWebhooks(); err != nil {
|
if _, err := Client.ListIncomingWebhooks(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -376,7 +369,6 @@ func TestDeleteIncomingHook(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
|
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
|
||||||
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
|
hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook)
|
||||||
@@ -410,7 +402,6 @@ func TestDeleteIncomingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
|
if _, err := Client.DeleteIncomingWebhook(hook.Id); err == nil {
|
||||||
t.Fatal("should have failed - not creator or team admin")
|
t.Fatal("should have failed - not creator or team admin")
|
||||||
@@ -447,7 +438,6 @@ func TestCreateOutgoingHook(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
||||||
|
|
||||||
@@ -518,7 +508,6 @@ func TestCreateOutgoingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.CreateOutgoingWebhook(hook); err != nil {
|
if _, err := Client.CreateOutgoingWebhook(hook); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -551,7 +540,6 @@ func TestListOutgoingHooks(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook1 := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
hook1 := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
||||||
hook1 = Client.Must(Client.CreateOutgoingWebhook(hook1)).Data.(*model.OutgoingWebhook)
|
hook1 = Client.Must(Client.CreateOutgoingWebhook(hook1)).Data.(*model.OutgoingWebhook)
|
||||||
@@ -578,7 +566,6 @@ func TestListOutgoingHooks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.ListOutgoingWebhooks(); err != nil {
|
if _, err := Client.ListOutgoingWebhooks(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -609,7 +596,6 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := createOutgoingWebhook(channel1.Id, []string{"http://nowhere.com"}, []string{"cats"}, Client, t)
|
hook := createOutgoingWebhook(channel1.Id, []string{"http://nowhere.com"}, []string{"cats"}, Client, t)
|
||||||
createOutgoingWebhook(channel1.Id, []string{"http://nowhere.com"}, []string{"dogs"}, Client, t)
|
createOutgoingWebhook(channel1.Id, []string{"http://nowhere.com"}, []string{"dogs"}, Client, t)
|
||||||
@@ -683,7 +669,6 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
hook2 := createOutgoingWebhook(channel1.Id, []string{"http://nowhereelse.com"}, []string{"dogs"}, Client, t)
|
hook2 := createOutgoingWebhook(channel1.Id, []string{"http://nowhereelse.com"}, []string{"dogs"}, Client, t)
|
||||||
|
|
||||||
if _, err := Client.UpdateOutgoingWebhook(hook2); err != nil {
|
if _, err := Client.UpdateOutgoingWebhook(hook2); err != nil {
|
||||||
@@ -691,7 +676,6 @@ func TestUpdateOutgoingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
th.LinkUserToTeam(user3, team)
|
th.LinkUserToTeam(user3, team)
|
||||||
@@ -779,7 +763,6 @@ func TestDeleteOutgoingHook(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
||||||
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
||||||
@@ -813,7 +796,6 @@ func TestDeleteOutgoingHook(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
if _, err := Client.DeleteOutgoingWebhook(hook.Id); err == nil {
|
if _, err := Client.DeleteOutgoingWebhook(hook.Id); err == nil {
|
||||||
t.Fatal("should have failed - not creator or team admin")
|
t.Fatal("should have failed - not creator or team admin")
|
||||||
@@ -848,7 +830,6 @@ func TestRegenOutgoingHookToken(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
hook := &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
||||||
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
||||||
@@ -883,7 +864,6 @@ func TestRegenOutgoingHookToken(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
hook = &model.OutgoingWebhook{ChannelId: channel1.Id, CallbackURLs: []string{"http://nowhere.com"}}
|
||||||
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
hook = Client.Must(Client.CreateOutgoingWebhook(hook)).Data.(*model.OutgoingWebhook)
|
||||||
@@ -917,10 +897,6 @@ func TestIncomingWebhooks(t *testing.T) {
|
|||||||
user2 := th.CreateUser(Client)
|
user2 := th.CreateUser(Client)
|
||||||
th.LinkUserToTeam(user2, team)
|
th.LinkUserToTeam(user2, team)
|
||||||
|
|
||||||
enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
|
||||||
|
|
||||||
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
|
hook := &model.IncomingWebhook{ChannelId: channel1.Id}
|
||||||
@@ -962,20 +938,8 @@ func TestIncomingWebhooks(t *testing.T) {
|
|||||||
t.Fatal("should not have failed -- ExperimentalTownSquareIsReadOnly is false and it's not a read only channel")
|
t.Fatal("should not have failed -- ExperimentalTownSquareIsReadOnly is false and it's not a read only channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
disableTownSquareReadOnly := th.App.Config().TeamSettings.ExperimentalTownSquareIsReadOnly
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = disableTownSquareReadOnly })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
if _, err := th.BasicClient.DoPost(url, fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", model.DEFAULT_CHANNEL), "application/json"); err == nil {
|
if _, err := th.BasicClient.DoPost(url, fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", model.DEFAULT_CHANNEL), "application/json"); err == nil {
|
||||||
t.Fatal("should have failed -- ExperimentalTownSquareIsReadOnly is true and it's a read only channel")
|
t.Fatal("should have failed -- ExperimentalTownSquareIsReadOnly is true and it's a read only channel")
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
|
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/store/sqlstore"
|
"github.com/mattermost/mattermost-server/store/sqlstore"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateChannel(t *testing.T) {
|
func TestCreateChannel(t *testing.T) {
|
||||||
@@ -82,23 +81,9 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Check permissions with policy config changes
|
// Check permissions with policy config changes
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelCreation
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelCreation
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel.Name = GenerateTestChannelName()
|
channel.Name = GenerateTestChannelName()
|
||||||
_, resp = Client.CreateChannel(channel)
|
_, resp = Client.CreateChannel(channel)
|
||||||
@@ -110,11 +95,8 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
_, resp = Client.CreateChannel(channel)
|
_, resp = Client.CreateChannel(channel)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
@@ -142,11 +124,8 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelCreation = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
@@ -173,9 +152,7 @@ func TestCreateChannel(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Check that if unlicensed the policy restriction is not enforced.
|
// Check that if unlicensed the policy restriction is not enforced.
|
||||||
utils.SetIsLicensed(false)
|
th.App.SetLicense(nil)
|
||||||
utils.SetLicense(nil)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
channel.Name = GenerateTestChannelName()
|
channel.Name = GenerateTestChannelName()
|
||||||
_, resp = Client.CreateChannel(channel)
|
_, resp = Client.CreateChannel(channel)
|
||||||
@@ -887,23 +864,9 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.InitBasic().InitSystemAdmin()
|
th.InitBasic().InitSystemAdmin()
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
restrictPublicChannel := *th.App.Config().TeamSettings.RestrictPublicChannelManagement
|
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManagement
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = restrictPublicChannel })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = restrictPrivateChannel })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPublicChannelManagement = model.PERMISSIONS_ALL })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManagement = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client = th.Client
|
Client = th.Client
|
||||||
team = th.BasicTeam
|
team = th.BasicTeam
|
||||||
@@ -926,11 +889,8 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// channels created by SystemAdmin
|
// channels created by SystemAdmin
|
||||||
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
||||||
@@ -967,9 +927,7 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
// successful delete by team admin
|
// successful delete by team admin
|
||||||
th.UpdateUserToTeamAdmin(user, team)
|
th.UpdateUserToTeamAdmin(user, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -979,16 +937,11 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.UpdateUserToNonTeamAdmin(user, team)
|
th.UpdateUserToNonTeamAdmin(user, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
// channels created by SystemAdmin
|
// channels created by SystemAdmin
|
||||||
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
||||||
@@ -1018,9 +971,7 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
// successful delete by team admin
|
// successful delete by team admin
|
||||||
th.UpdateUserToTeamAdmin(th.BasicUser, team)
|
th.UpdateUserToTeamAdmin(th.BasicUser, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -1030,11 +981,8 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPublicChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// channels created by SystemAdmin
|
// channels created by SystemAdmin
|
||||||
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
|
||||||
@@ -1064,9 +1012,7 @@ func TestDeleteChannel(t *testing.T) {
|
|||||||
// cannot delete by team admin
|
// cannot delete by team admin
|
||||||
th.UpdateUserToTeamAdmin(th.BasicUser, team)
|
th.UpdateUserToTeamAdmin(th.BasicUser, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
||||||
CheckForbiddenStatus(t, resp)
|
CheckForbiddenStatus(t, resp)
|
||||||
@@ -1823,16 +1769,9 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Test policy does not apply to TE.
|
// Test policy does not apply to TE.
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user2.Username, user2.Password)
|
Client.Login(user2.Username, user2.Password)
|
||||||
privateChannel = th.CreatePrivateChannel()
|
privateChannel = th.CreatePrivateChannel()
|
||||||
@@ -1846,18 +1785,8 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
Client.Logout()
|
Client.Logout()
|
||||||
|
|
||||||
// Add a license
|
// Add a license
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Check that a regular channel user can add other users.
|
// Check that a regular channel user can add other users.
|
||||||
Client.Login(user2.Username, user2.Password)
|
Client.Login(user2.Username, user2.Password)
|
||||||
@@ -1875,10 +1804,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user2.Username, user2.Password)
|
Client.Login(user2.Username, user2.Password)
|
||||||
privateChannel = th.CreatePrivateChannel()
|
privateChannel = th.CreatePrivateChannel()
|
||||||
@@ -1893,10 +1818,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.MakeUserChannelAdmin(user, privateChannel)
|
th.MakeUserChannelAdmin(user, privateChannel)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user.Username, user.Password)
|
Client.Login(user.Username, user.Password)
|
||||||
_, resp = Client.AddChannelMember(privateChannel.Id, user3.Id)
|
_, resp = Client.AddChannelMember(privateChannel.Id, user3.Id)
|
||||||
@@ -1907,10 +1829,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user2.Username, user2.Password)
|
Client.Login(user2.Username, user2.Password)
|
||||||
privateChannel = th.CreatePrivateChannel()
|
privateChannel = th.CreatePrivateChannel()
|
||||||
@@ -1925,10 +1843,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.UpdateUserToTeamAdmin(user, team)
|
th.UpdateUserToTeamAdmin(user, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user.Username, user.Password)
|
Client.Login(user.Username, user.Password)
|
||||||
_, resp = Client.AddChannelMember(privateChannel.Id, user3.Id)
|
_, resp = Client.AddChannelMember(privateChannel.Id, user3.Id)
|
||||||
@@ -1939,10 +1854,6 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
Client.Login(user2.Username, user2.Password)
|
Client.Login(user2.Username, user2.Password)
|
||||||
privateChannel = th.CreatePrivateChannel()
|
privateChannel = th.CreatePrivateChannel()
|
||||||
@@ -2019,16 +1930,9 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
|
|
||||||
// Test policy does not apply to TE.
|
// Test policy does not apply to TE.
|
||||||
restrictPrivateChannel := *th.App.Config().TeamSettings.RestrictPrivateChannelManageMembers
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = restrictPrivateChannel
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
privateChannel := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||||
@@ -2040,18 +1944,8 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Add a license
|
// Add a license
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Check that a regular channel user can remove other users.
|
// Check that a regular channel user can remove other users.
|
||||||
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||||
@@ -2067,10 +1961,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_CHANNEL_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||||
@@ -2083,9 +1973,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.MakeUserChannelAdmin(user1, privateChannel)
|
th.MakeUserChannelAdmin(user1, privateChannel)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -2094,10 +1982,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_TEAM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||||
@@ -2110,9 +1994,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
|
|
||||||
th.UpdateUserToTeamAdmin(user1, team)
|
th.UpdateUserToTeamAdmin(user1, team)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
_, resp = Client.RemoveUserFromChannel(privateChannel.Id, user2.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -2121,10 +2003,6 @@ func TestRemoveChannelMember(t *testing.T) {
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
*cfg.TeamSettings.RestrictPrivateChannelManageMembers = model.PERMISSIONS_SYSTEM_ADMIN
|
||||||
})
|
})
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
privateChannel = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
|
||||||
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
_, resp = th.SystemAdminClient.AddChannelMember(privateChannel.Id, user1.Id)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreatePost(t *testing.T) {
|
func TestCreatePost(t *testing.T) {
|
||||||
@@ -130,20 +129,8 @@ func testCreatePostWithOutgoingHook(
|
|||||||
team := th.BasicTeam
|
team := th.BasicTeam
|
||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
|
|
||||||
enableOutgoingHooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks
|
|
||||||
enableAdminOnlyHooks := th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
|
|
||||||
allowedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingHooks })
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
|
||||||
})
|
})
|
||||||
@@ -489,21 +476,8 @@ func TestUpdatePost(t *testing.T) {
|
|||||||
Client := th.Client
|
Client := th.Client
|
||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
allowEditPost := *th.App.Config().ServiceSettings.AllowEditPost
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = allowEditPost })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
post := &model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a"}
|
post := &model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a"}
|
||||||
rpost, resp := Client.CreatePost(post)
|
rpost, resp := Client.CreatePost(post)
|
||||||
@@ -574,21 +548,8 @@ func TestPatchPost(t *testing.T) {
|
|||||||
Client := th.Client
|
Client := th.Client
|
||||||
channel := th.BasicChannel
|
channel := th.BasicChannel
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
allowEditPost := *th.App.Config().ServiceSettings.AllowEditPost
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = allowEditPost })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowEditPost = model.ALLOW_EDIT_POST_ALWAYS })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
ChannelId: channel.Id,
|
ChannelId: channel.Id,
|
||||||
|
|||||||
@@ -68,13 +68,7 @@ func TestCreateTeam(t *testing.T) {
|
|||||||
CheckUnauthorizedStatus(t, resp)
|
CheckUnauthorizedStatus(t, resp)
|
||||||
|
|
||||||
// Update permission
|
// Update permission
|
||||||
enableTeamCreation := th.App.Config().TeamSettings.EnableTeamCreation
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableTeamCreation = enableTeamCreation })
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableTeamCreation = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableTeamCreation = false })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
_, resp = Client.CreateTeam(team)
|
_, resp = Client.CreateTeam(team)
|
||||||
@@ -1292,20 +1286,8 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
|
|
||||||
// Check effects of config and license changes.
|
|
||||||
restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Set the config so that only team admins can add a user to a team.
|
// Set the config so that only team admins can add a user to a team.
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Test without the EE license to see that the permission restriction is ignored.
|
// Test without the EE license to see that the permission restriction is ignored.
|
||||||
@@ -1313,10 +1295,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Add an EE license.
|
// Add an EE license.
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Check that a regular user can't add someone to the team.
|
// Check that a regular user can't add someone to the team.
|
||||||
@@ -1327,10 +1306,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Should work as a team admin.
|
// Should work as a team admin.
|
||||||
@@ -1339,7 +1315,6 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
|
|
||||||
// Change permission level to System Admin
|
// Change permission level to System Admin
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Should not work as team admin.
|
// Should not work as team admin.
|
||||||
_, resp = Client.AddTeamMember(team.Id, otherUser.Id)
|
_, resp = Client.AddTeamMember(team.Id, otherUser.Id)
|
||||||
@@ -1353,21 +1328,13 @@ func TestAddTeamMember(t *testing.T) {
|
|||||||
th.UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
|
th.UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Should work as a regular user.
|
// Should work as a regular user.
|
||||||
_, resp = Client.AddTeamMember(team.Id, otherUser.Id)
|
_, resp = Client.AddTeamMember(team.Id, otherUser.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Reset config and license.
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// by hash and data
|
// by hash and data
|
||||||
@@ -1506,20 +1473,8 @@ func TestAddTeamMembers(t *testing.T) {
|
|||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
|
|
||||||
// Check effects of config and license changes.
|
|
||||||
restrictTeamInvite := *th.App.Config().TeamSettings.RestrictTeamInvite
|
|
||||||
isLicensed := utils.IsLicensed()
|
|
||||||
license := utils.License()
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = restrictTeamInvite })
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Set the config so that only team admins can add a user to a team.
|
// Set the config so that only team admins can add a user to a team.
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Test without the EE license to see that the permission restriction is ignored.
|
// Test without the EE license to see that the permission restriction is ignored.
|
||||||
@@ -1527,10 +1482,7 @@ func TestAddTeamMembers(t *testing.T) {
|
|||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|
||||||
// Add an EE license.
|
// Add an EE license.
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Check that a regular user can't add someone to the team.
|
// Check that a regular user can't add someone to the team.
|
||||||
@@ -1541,10 +1493,7 @@ func TestAddTeamMembers(t *testing.T) {
|
|||||||
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
th.UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Should work as a team admin.
|
// Should work as a team admin.
|
||||||
@@ -1553,7 +1502,6 @@ func TestAddTeamMembers(t *testing.T) {
|
|||||||
|
|
||||||
// Change permission level to System Admin
|
// Change permission level to System Admin
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_SYSTEM_ADMIN })
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
|
|
||||||
// Should not work as team admin.
|
// Should not work as team admin.
|
||||||
_, resp = Client.AddTeamMembers(team.Id, userList)
|
_, resp = Client.AddTeamMembers(team.Id, userList)
|
||||||
@@ -1567,10 +1515,7 @@ func TestAddTeamMembers(t *testing.T) {
|
|||||||
th.UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
|
th.UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||||
th.App.InvalidateAllCaches()
|
th.App.InvalidateAllCaches()
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL })
|
||||||
utils.SetIsLicensed(true)
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.SetDefaultRolesBasedOnConfig()
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
|
|
||||||
// Should work as a regular user.
|
// Should work as a regular user.
|
||||||
@@ -1929,10 +1874,6 @@ func TestInviteUsersToTeam(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
restrictCreationToDomains := th.App.Config().TeamSettings.RestrictCreationToDomains
|
|
||||||
defer func() {
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = restrictCreationToDomains })
|
|
||||||
}()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = "@example.com" })
|
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = "@example.com" })
|
||||||
|
|
||||||
err := th.App.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id)
|
err := th.App.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id)
|
||||||
|
|||||||
@@ -1566,18 +1566,7 @@ func TestUpdateUserMfa(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
Client := th.Client
|
Client := th.Client
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense("mfa"))
|
||||||
license := utils.License()
|
|
||||||
enableMfa := *th.App.Config().ServiceSettings.EnableMultifactorAuthentication
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa })
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
*utils.License().Features.MFA = true
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
||||||
|
|
||||||
session, _ := th.App.GetSession(Client.AuthToken)
|
session, _ := th.App.GetSession(Client.AuthToken)
|
||||||
@@ -1612,18 +1601,7 @@ func TestCheckUserMfa(t *testing.T) {
|
|||||||
t.Fatal("should be false - mfa not active")
|
t.Fatal("should be false - mfa not active")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense("mfa"))
|
||||||
license := utils.License()
|
|
||||||
enableMfa := *th.App.Config().ServiceSettings.EnableMultifactorAuthentication
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa })
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
*utils.License().Features.MFA = true
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
||||||
|
|
||||||
th.LoginBasic()
|
th.LoginBasic()
|
||||||
@@ -1659,18 +1637,7 @@ func TestGenerateMfaSecret(t *testing.T) {
|
|||||||
_, resp = Client.GenerateMfaSecret("junk")
|
_, resp = Client.GenerateMfaSecret("junk")
|
||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense("mfa"))
|
||||||
license := utils.License()
|
|
||||||
enableMfa := *th.App.Config().ServiceSettings.EnableMultifactorAuthentication
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa })
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
*utils.License().Features.MFA = true
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableMultifactorAuthentication = true })
|
||||||
|
|
||||||
_, resp = Client.GenerateMfaSecret(model.NewId())
|
_, resp = Client.GenerateMfaSecret(model.NewId())
|
||||||
@@ -2187,19 +2154,7 @@ func TestSwitchAccount(t *testing.T) {
|
|||||||
t.Fatal("bad link")
|
t.Fatal("bad link")
|
||||||
}
|
}
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense())
|
||||||
license := utils.License()
|
|
||||||
enableAuthenticationTransfer := *th.App.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer = enableAuthenticationTransfer
|
|
||||||
})
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer = false })
|
||||||
|
|
||||||
sr = &model.SwitchRequest{
|
sr = &model.SwitchRequest{
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ func New(options ...Option) (*App, error) {
|
|||||||
panic("Only one App should exist at a time. Did you forget to call Shutdown()?")
|
panic("Only one App should exist at a time. Did you forget to call Shutdown()?")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove this once utils global license state is eliminated
|
||||||
|
utils.SetLicense(nil)
|
||||||
|
|
||||||
app := &App{
|
app := &App{
|
||||||
goroutineExitSignal: make(chan struct{}, 1),
|
goroutineExitSignal: make(chan struct{}, 1),
|
||||||
Srv: &Server{
|
Srv: &Server{
|
||||||
|
|||||||
@@ -254,11 +254,3 @@ func (a *App) Desanitize(cfg *model.Config) {
|
|||||||
cfg.SqlSettings.DataSourceSearchReplicas[i] = actual.SqlSettings.DataSourceSearchReplicas[i]
|
cfg.SqlSettings.DataSourceSearchReplicas[i] = actual.SqlSettings.DataSourceSearchReplicas[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// License returns the currently active license or nil if the application is unlicensed.
|
|
||||||
func (a *App) License() *model.License {
|
|
||||||
if utils.IsLicensed() {
|
|
||||||
return utils.License()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok := utils.SetLicense(license); !ok {
|
if ok := a.SetLicense(license); !ok {
|
||||||
return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +102,20 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
|||||||
return license, nil
|
return license, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// License returns the currently active license or nil if the application is unlicensed.
|
||||||
|
func (a *App) License() *model.License {
|
||||||
|
if utils.IsLicensed() {
|
||||||
|
return utils.License()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) SetLicense(license *model.License) bool {
|
||||||
|
ok := utils.SetLicense(license)
|
||||||
|
a.SetDefaultRolesBasedOnConfig()
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) RemoveLicense() *model.AppError {
|
func (a *App) RemoveLicense() *model.AppError {
|
||||||
utils.RemoveLicense()
|
utils.RemoveLicense()
|
||||||
|
|
||||||
|
|||||||
@@ -48,18 +48,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
|
|||||||
|
|
||||||
session, _ = th.App.CreateSession(session)
|
session, _ = th.App.CreateSession(session)
|
||||||
|
|
||||||
isLicensed := utils.IsLicensed()
|
th.App.SetLicense(model.NewTestLicense("compliance"))
|
||||||
license := utils.License()
|
|
||||||
timeout := *th.App.Config().ServiceSettings.SessionIdleTimeoutInMinutes
|
|
||||||
defer func() {
|
|
||||||
utils.SetIsLicensed(isLicensed)
|
|
||||||
utils.SetLicense(license)
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = timeout })
|
|
||||||
}()
|
|
||||||
utils.SetIsLicensed(true)
|
|
||||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
|
||||||
utils.License().Features.SetDefaults()
|
|
||||||
*utils.License().Features.Compliance = true
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 5 })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 5 })
|
||||||
|
|
||||||
rsession, err := th.App.GetSession(session.Token)
|
rsession, err := th.App.GetSession(session.Token)
|
||||||
|
|||||||
@@ -173,6 +173,25 @@ func (l *License) ToJson() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTestLicense returns a license that expires in the future and has the given features.
|
||||||
|
func NewTestLicense(features ...string) *License {
|
||||||
|
ret := &License{
|
||||||
|
ExpiresAt: GetMillis() + 90*24*60*60*1000,
|
||||||
|
Customer: &Customer{},
|
||||||
|
Features: &Features{},
|
||||||
|
}
|
||||||
|
ret.Features.SetDefaults()
|
||||||
|
|
||||||
|
featureMap := map[string]bool{}
|
||||||
|
for _, feature := range features {
|
||||||
|
featureMap[feature] = true
|
||||||
|
}
|
||||||
|
featureJson, _ := json.Marshal(featureMap)
|
||||||
|
json.Unmarshal(featureJson, &ret.Features)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func LicenseFromJson(data io.Reader) *License {
|
func LicenseFromJson(data io.Reader) *License {
|
||||||
var o *License
|
var o *License
|
||||||
json.NewDecoder(data).Decode(&o)
|
json.NewDecoder(data).Decode(&o)
|
||||||
|
|||||||
Reference in New Issue
Block a user