MM-10658 Change config fields to pointers (#9033)

* MM 10658 Change config fields to pointers (#8898)

* Change fields of config structs to pointers and set defaults

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix tests that go broken during switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Apply changes of current master while switching config structs to pointers

MM-10658 https://github.com/mattermost/mattermost-server/issues/8841

* Fix new config pointer uses

* Fix app tests

* Fix mail test

* remove debugging statement

* fix TestUpdateConfig

* assign config consistently

* initialize AmazonS3Region in TestS3TestConnection

* initialize fields for TestEmailTest

* fix TestCheckMandatoryS3Fields
Этот коммит содержится в:
Joram Wilander
2019-01-31 08:12:01 -05:00
коммит произвёл GitHub
родитель 0c981aa010
Коммит 2ca222033c
53 изменённых файлов: 729 добавлений и 516 удалений

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

@@ -96,7 +96,7 @@ func setupTestHelper(enterprise bool, updateConfig func(*model.Config)) *TestHel
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50 *cfg.TeamSettings.MaxUsersPerTeam = 50
*cfg.RateLimitSettings.Enable = false *cfg.RateLimitSettings.Enable = false
cfg.EmailSettings.SendEmailNotifications = true *cfg.EmailSettings.SendEmailNotifications = true
}) })
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
@@ -514,7 +514,7 @@ func (me *TestHelper) AddUserToChannel(user *model.User, channel *model.Channel)
} }
func (me *TestHelper) GenerateTestEmail() string { func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" { if *me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com") return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
} }
return strings.ToLower(model.NewId() + "@dockerhost") return strings.ToLower(model.NewId() + "@dockerhost")
@@ -674,17 +674,17 @@ func s3New(endpoint, accessKey, secretKey string, secure bool, signV2 bool, regi
func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error { func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
cfg := me.App.Config() cfg := me.App.Config()
if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
endpoint := cfg.FileSettings.AmazonS3Endpoint endpoint := *cfg.FileSettings.AmazonS3Endpoint
accessKey := cfg.FileSettings.AmazonS3AccessKeyId accessKey := *cfg.FileSettings.AmazonS3AccessKeyId
secretKey := cfg.FileSettings.AmazonS3SecretAccessKey secretKey := *cfg.FileSettings.AmazonS3SecretAccessKey
secure := *cfg.FileSettings.AmazonS3SSL secure := *cfg.FileSettings.AmazonS3SSL
signV2 := *cfg.FileSettings.AmazonS3SignV2 signV2 := *cfg.FileSettings.AmazonS3SignV2
region := cfg.FileSettings.AmazonS3Region region := *cfg.FileSettings.AmazonS3Region
s3Clnt, err := s3New(endpoint, accessKey, secretKey, secure, signV2, region) s3Clnt, err := s3New(endpoint, accessKey, secretKey, secure, signV2, region)
if err != nil { if err != nil {
return err return err
} }
bucket := cfg.FileSettings.AmazonS3Bucket bucket := *cfg.FileSettings.AmazonS3Bucket
if err := s3Clnt.RemoveObject(bucket, info.Path); err != nil { if err := s3Clnt.RemoveObject(bucket, info.Path); err != nil {
return err return err
} }
@@ -701,18 +701,18 @@ func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
} }
} }
} else if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { } else if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
if err := os.Remove(cfg.FileSettings.Directory + info.Path); err != nil { if err := os.Remove(*cfg.FileSettings.Directory + info.Path); err != nil {
return err return err
} }
if info.ThumbnailPath != "" { if info.ThumbnailPath != "" {
if err := os.Remove(cfg.FileSettings.Directory + info.ThumbnailPath); err != nil { if err := os.Remove(*cfg.FileSettings.Directory + info.ThumbnailPath); err != nil {
return err return err
} }
} }
if info.PreviewPath != "" { if info.PreviewPath != "" {
if err := os.Remove(cfg.FileSettings.Directory + info.PreviewPath); err != nil { if err := os.Remove(*cfg.FileSettings.Directory + info.PreviewPath); err != nil {
return err return err
} }
} }

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

@@ -163,12 +163,12 @@ func TestLoadTestHelpCommands(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
enableTesting := th.App.Config().ServiceSettings.EnableTesting enableTesting := *th.App.Config().ServiceSettings.EnableTesting
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test help")).(*model.CommandResponse) rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test help")).(*model.CommandResponse)
if !strings.Contains(rs.Text, "Mattermost testing commands to help") { if !strings.Contains(rs.Text, "Mattermost testing commands to help") {
@@ -185,12 +185,12 @@ func TestLoadTestSetupCommands(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
enableTesting := th.App.Config().ServiceSettings.EnableTesting enableTesting := *th.App.Config().ServiceSettings.EnableTesting
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test setup fuzz 1 1 1")).(*model.CommandResponse) rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test setup fuzz 1 1 1")).(*model.CommandResponse)
if rs.Text != "Created environment" { if rs.Text != "Created environment" {
@@ -207,12 +207,12 @@ func TestLoadTestUsersCommands(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
enableTesting := th.App.Config().ServiceSettings.EnableTesting enableTesting := *th.App.Config().ServiceSettings.EnableTesting
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test users fuzz 1 2")).(*model.CommandResponse) rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test users fuzz 1 2")).(*model.CommandResponse)
if rs.Text != "Added users" { if rs.Text != "Added users" {
@@ -229,12 +229,12 @@ func TestLoadTestChannelsCommands(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
enableTesting := th.App.Config().ServiceSettings.EnableTesting enableTesting := *th.App.Config().ServiceSettings.EnableTesting
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test channels fuzz 1 2")).(*model.CommandResponse) rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test channels fuzz 1 2")).(*model.CommandResponse)
if rs.Text != "Added channels" { if rs.Text != "Added channels" {
@@ -251,12 +251,12 @@ func TestLoadTestPostsCommands(t *testing.T) {
Client := th.Client Client := th.Client
channel := th.BasicChannel channel := th.BasicChannel
enableTesting := th.App.Config().ServiceSettings.EnableTesting enableTesting := *th.App.Config().ServiceSettings.EnableTesting
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = enableTesting }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = enableTesting })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableTesting = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test posts fuzz 2 3 2")).(*model.CommandResponse) rs := Client.Must(Client.ExecuteCommand(channel.Id, "/test posts fuzz 2 3 2")).(*model.CommandResponse)
if rs.Text != "Added posts" { if rs.Text != "Added posts" {

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

@@ -600,7 +600,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if !c.App.Config().FileSettings.EnablePublicLink { if !*c.App.Config().FileSettings.EnablePublicLink {
c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented) c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented)
return return
} }
@@ -696,7 +696,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if !c.App.Config().FileSettings.EnablePublicLink { if !*c.App.Config().FileSettings.EnablePublicLink {
c.Err = model.NewAppError("getPublicFile", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented) c.Err = model.NewAppError("getPublicFile", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented)
return return
} }

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

@@ -934,7 +934,7 @@ func TestGetFileLink(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink }) th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = model.NewId() })
fileId := "" fileId := ""
@@ -953,14 +953,14 @@ func TestGetFileLink(t *testing.T) {
// Hacky way to assign file to a post (usually would be done by CreatePost call) // Hacky way to assign file to a post (usually would be done by CreatePost call)
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)) store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id))
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
_, resp = Client.GetFileLink(fileId) _, resp = Client.GetFileLink(fileId)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
// Wait a bit for files to ready // Wait a bit for files to ready
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
link, resp := Client.GetFileLink(fileId) link, resp := Client.GetFileLink(fileId)
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -1129,7 +1129,7 @@ func TestGetPublicFile(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink }) th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = enablePublicLink })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = publicLinkSalt })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = GenerateTestId() }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = GenerateTestId() })
fileId := "" fileId := ""
@@ -1161,13 +1161,13 @@ func TestGetPublicFile(t *testing.T) {
t.Fatal("should've failed to get image with public link without hash", resp.Status) t.Fatal("should've failed to get image with public link without hash", resp.Status)
} }
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusNotImplemented { if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusNotImplemented {
t.Fatal("should've failed to get image with disabled public link") t.Fatal("should've failed to get image with disabled public link")
} }
// test after the salt has changed // test after the salt has changed
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FileSettings.EnablePublicLink = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = GenerateTestId() }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.PublicLinkSalt = GenerateTestId() })
if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusBadRequest { if resp, err := http.Get(link); err == nil && resp.StatusCode != http.StatusBadRequest {

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

@@ -325,7 +325,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) { func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.App.Config().ServiceSettings.EnableOAuthServiceProvider { if !*c.App.Config().ServiceSettings.EnableOAuthServiceProvider {
err := model.NewAppError("authorizeOAuth", "api.oauth.authorize_oauth.disabled.app_error", nil, "", http.StatusNotImplemented) err := model.NewAppError("authorizeOAuth", "api.oauth.authorize_oauth.disabled.app_error", nil, "", http.StatusNotImplemented)
utils.RenderWebAppError(c.App.Config(), w, r, err, c.App.AsymmetricSigningKey()) utils.RenderWebAppError(c.App.Config(), w, r, err, c.App.AsymmetricSigningKey())
return return

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

@@ -38,7 +38,7 @@ func TestCreateOAuthApp(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}, IsTrusted: true} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}, IsTrusted: true}
@@ -89,7 +89,7 @@ func TestCreateOAuthApp(t *testing.T) {
_, resp = Client.CreateOAuthApp(oapp) _, resp = Client.CreateOAuthApp(oapp)
CheckUnauthorizedStatus(t, resp) CheckUnauthorizedStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
oapp.Name = GenerateTestAppName() oapp.Name = GenerateTestAppName()
_, resp = AdminClient.CreateOAuthApp(oapp) _, resp = AdminClient.CreateOAuthApp(oapp)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
@@ -110,7 +110,7 @@ func TestUpdateOAuthApp(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{ oapp := &model.OAuthApp{
Name: "oapp", Name: "oapp",
@@ -198,7 +198,7 @@ func TestUpdateOAuthApp(t *testing.T) {
_, resp = AdminClient.UpdateOAuthApp(oapp) _, resp = AdminClient.UpdateOAuthApp(oapp)
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.UpdateOAuthApp(oapp) _, resp = AdminClient.UpdateOAuthApp(oapp)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
@@ -227,7 +227,7 @@ func TestGetOAuthApps(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -281,7 +281,7 @@ func TestGetOAuthApps(t *testing.T) {
_, resp = Client.GetOAuthApps(0, 1000) _, resp = Client.GetOAuthApps(0, 1000)
CheckUnauthorizedStatus(t, resp) CheckUnauthorizedStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.GetOAuthApps(0, 1000) _, resp = AdminClient.GetOAuthApps(0, 1000)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -301,7 +301,7 @@ func TestGetOAuthApp(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -357,7 +357,7 @@ func TestGetOAuthApp(t *testing.T) {
_, resp = AdminClient.GetOAuthApp(model.NewId()) _, resp = AdminClient.GetOAuthApp(model.NewId())
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.GetOAuthApp(rapp.Id) _, resp = AdminClient.GetOAuthApp(rapp.Id)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -377,7 +377,7 @@ func TestGetOAuthAppInfo(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -433,7 +433,7 @@ func TestGetOAuthAppInfo(t *testing.T) {
_, resp = AdminClient.GetOAuthAppInfo(model.NewId()) _, resp = AdminClient.GetOAuthAppInfo(model.NewId())
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.GetOAuthAppInfo(rapp.Id) _, resp = AdminClient.GetOAuthAppInfo(rapp.Id)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -453,7 +453,7 @@ func TestDeleteOAuthApp(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -503,7 +503,7 @@ func TestDeleteOAuthApp(t *testing.T) {
_, resp = AdminClient.DeleteOAuthApp(model.NewId()) _, resp = AdminClient.DeleteOAuthApp(model.NewId())
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.DeleteOAuthApp(rapp.Id) _, resp = AdminClient.DeleteOAuthApp(rapp.Id)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -523,7 +523,7 @@ func TestRegenerateOAuthAppSecret(t *testing.T) {
// Grant permission to regular users. // Grant permission to regular users.
th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID) th.AddPermissionToRole(model.PERMISSION_MANAGE_OAUTH.Id, model.SYSTEM_USER_ROLE_ID)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -577,7 +577,7 @@ func TestRegenerateOAuthAppSecret(t *testing.T) {
_, resp = AdminClient.RegenerateOAuthAppSecret(model.NewId()) _, resp = AdminClient.RegenerateOAuthAppSecret(model.NewId())
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
_, resp = AdminClient.RegenerateOAuthAppSecret(rapp.Id) _, resp = AdminClient.RegenerateOAuthAppSecret(rapp.Id)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -592,7 +592,7 @@ func TestGetAuthorizedOAuthAppsForUser(t *testing.T) {
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth }) th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -648,12 +648,12 @@ func TestAuthorizeOAuthApp(t *testing.T) {
Client := th.Client Client := th.Client
AdminClient := th.SystemAdminClient AdminClient := th.SystemAdminClient
enableOAuth := th.App.Config().ServiceSettings.EnableOAuthServiceProvider enableOAuth := *th.App.Config().ServiceSettings.EnableOAuthServiceProvider
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -741,7 +741,7 @@ func TestDeauthorizeOAuthApp(t *testing.T) {
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth }) th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
@@ -791,7 +791,7 @@ func TestOAuthAccessToken(t *testing.T) {
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth }) th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth })
}() }()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -803,14 +803,14 @@ func TestOAuthAccessToken(t *testing.T) {
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}} oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
oauthApp = Client.Must(Client.CreateOAuthApp(oauthApp)).(*model.OAuthApp) oauthApp = Client.Must(Client.CreateOAuthApp(oauthApp)).(*model.OAuthApp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
data := url.Values{"grant_type": []string{"junk"}, "client_id": []string{"12345678901234567890123456"}, "client_secret": []string{"12345678901234567890123456"}, "code": []string{"junk"}, "redirect_uri": []string{oauthApp.CallbackUrls[0]}} data := url.Values{"grant_type": []string{"junk"}, "client_id": []string{"12345678901234567890123456"}, "client_secret": []string{"12345678901234567890123456"}, "code": []string{"junk"}, "redirect_uri": []string{oauthApp.CallbackUrls[0]}}
if _, resp := Client.GetOAuthAccessToken(data); resp.Error == nil { if _, resp := Client.GetOAuthAccessToken(data); resp.Error == nil {
t.Log(resp.StatusCode) t.Log(resp.StatusCode)
t.Fatal("should have failed - oauth providing turned off") t.Fatal("should have failed - oauth providing turned off")
} }
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
authRequest := &model.AuthorizeRequest{ authRequest := &model.AuthorizeRequest{
ResponseType: model.AUTHCODE_RESPONSE_TYPE, ResponseType: model.AUTHCODE_RESPONSE_TYPE,
@@ -1022,32 +1022,32 @@ func TestOAuthComplete(t *testing.T) {
assert.NotNil(t, err) assert.NotNil(t, err)
closeBody(r) closeBody(r)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Enable = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Enable = true })
r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state=!#$#F@#Yˆ&~ñ", Client.HttpClient, "", true) r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state=!#$#F@#Yˆ&~ñ", Client.HttpClient, "", true)
assert.NotNil(t, err) assert.NotNil(t, err)
closeBody(r) closeBody(r)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Id = model.NewId() }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Id = model.NewId() })
stateProps := map[string]string{} stateProps := map[string]string{}
stateProps["action"] = model.OAUTH_ACTION_LOGIN stateProps["action"] = model.OAUTH_ACTION_LOGIN
stateProps["team_id"] = th.BasicTeam.Id stateProps["team_id"] = th.BasicTeam.Id
stateProps["redirect_to"] = th.App.Config().GitLabSettings.AuthEndpoint stateProps["redirect_to"] = *th.App.Config().GitLabSettings.AuthEndpoint
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps))) state := base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true) r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true)
assert.NotNil(t, err) assert.NotNil(t, err)
closeBody(r) closeBody(r)
stateProps["hash"] = utils.HashSha256(th.App.Config().GitLabSettings.Id) stateProps["hash"] = utils.HashSha256(*th.App.Config().GitLabSettings.Id)
state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps))) state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true) r, err = HttpGet(Client.Url+"/login/gitlab/complete?code=123&state="+url.QueryEscape(state), Client.HttpClient, "", true)
assert.NotNil(t, err) assert.NotNil(t, err)
closeBody(r) closeBody(r)
// We are going to use mattermost as the provider emulating gitlab // We are going to use mattermost as the provider emulating gitlab
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -1068,11 +1068,11 @@ func TestOAuthComplete(t *testing.T) {
} }
oauthApp = Client.Must(Client.CreateOAuthApp(oauthApp)).(*model.OAuthApp) oauthApp = Client.Must(Client.CreateOAuthApp(oauthApp)).(*model.OAuthApp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Id = oauthApp.Id }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Id = oauthApp.Id })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Secret = oauthApp.ClientSecret }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Secret = oauthApp.ClientSecret })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.AuthEndpoint = Client.Url + "/oauth/authorize" })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.TokenEndpoint = Client.Url + "/oauth/access_token" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.TokenEndpoint = Client.Url + "/oauth/access_token" })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.UserApiEndpoint = Client.ApiUrl + "/users/me" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.UserApiEndpoint = Client.ApiUrl + "/users/me" })
provider := &MattermostTestProvider{} provider := &MattermostTestProvider{}
@@ -1091,8 +1091,8 @@ func TestOAuthComplete(t *testing.T) {
code := rurl.Query().Get("code") code := rurl.Query().Get("code")
stateProps["action"] = model.OAUTH_ACTION_EMAIL_TO_SSO stateProps["action"] = model.OAUTH_ACTION_EMAIL_TO_SSO
delete(stateProps, "team_id") delete(stateProps, "team_id")
stateProps["redirect_to"] = th.App.Config().GitLabSettings.AuthEndpoint stateProps["redirect_to"] = *th.App.Config().GitLabSettings.AuthEndpoint
stateProps["hash"] = utils.HashSha256(th.App.Config().GitLabSettings.Id) stateProps["hash"] = utils.HashSha256(*th.App.Config().GitLabSettings.Id)
stateProps["redirect_to"] = "/oauth/authorize" stateProps["redirect_to"] = "/oauth/authorize"
state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps))) state = base64.StdEncoding.EncodeToString([]byte(model.MapToJson(stateProps)))
if r, err := HttpGet(Client.Url+"/login/"+model.SERVICE_GITLAB+"/complete?code="+url.QueryEscape(code)+"&state="+url.QueryEscape(state), Client.HttpClient, "", false); err == nil { if r, err := HttpGet(Client.Url+"/login/"+model.SERVICE_GITLAB+"/complete?code="+url.QueryEscape(code)+"&state="+url.QueryEscape(state), Client.HttpClient, "", false); err == nil {

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

@@ -174,16 +174,16 @@ func testCreatePostWithOutgoingHook(
team := th.BasicTeam team := th.BasicTeam
channel := th.BasicChannel channel := th.BasicChannel
enableOutgoingWebhooks := th.App.Config().ServiceSettings.EnableOutgoingWebhooks enableOutgoingWebhooks := *th.App.Config().ServiceSettings.EnableOutgoingWebhooks
allowedUntrustedInternalConnections := th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections allowedUntrustedInternalConnections := *th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections
defer func() { defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingWebhooks }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = enableOutgoingWebhooks })
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.AllowedUntrustedInternalConnections = allowedUntrustedInternalConnections *cfg.ServiceSettings.AllowedUntrustedInternalConnections = allowedUntrustedInternalConnections
}) })
}() }()
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) { th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1" *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
}) })

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

@@ -456,7 +456,7 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING { if *cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING {
cfg.FileSettings.AmazonS3SecretAccessKey = c.App.Config().FileSettings.AmazonS3SecretAccessKey cfg.FileSettings.AmazonS3SecretAccessKey = c.App.Config().FileSettings.AmazonS3SecretAccessKey
} }

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

@@ -57,22 +57,22 @@ func TestGetConfig(t *testing.T) {
if *cfg.FileSettings.PublicLinkSalt != model.FAKE_SETTING { if *cfg.FileSettings.PublicLinkSalt != model.FAKE_SETTING {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if cfg.FileSettings.AmazonS3SecretAccessKey != model.FAKE_SETTING && len(cfg.FileSettings.AmazonS3SecretAccessKey) != 0 { if *cfg.FileSettings.AmazonS3SecretAccessKey != model.FAKE_SETTING && len(*cfg.FileSettings.AmazonS3SecretAccessKey) != 0 {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if cfg.EmailSettings.InviteSalt != model.FAKE_SETTING { if *cfg.EmailSettings.InviteSalt != model.FAKE_SETTING {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if cfg.EmailSettings.SMTPPassword != model.FAKE_SETTING && len(cfg.EmailSettings.SMTPPassword) != 0 { if *cfg.EmailSettings.SMTPPassword != model.FAKE_SETTING && len(*cfg.EmailSettings.SMTPPassword) != 0 {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(cfg.GitLabSettings.Secret) != 0 { if *cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(*cfg.GitLabSettings.Secret) != 0 {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if *cfg.SqlSettings.DataSource != model.FAKE_SETTING { if *cfg.SqlSettings.DataSource != model.FAKE_SETTING {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if cfg.SqlSettings.AtRestEncryptKey != model.FAKE_SETTING { if *cfg.SqlSettings.AtRestEncryptKey != model.FAKE_SETTING {
t.Fatal("did not sanitize properly") t.Fatal("did not sanitize properly")
} }
if !strings.Contains(strings.Join(cfg.SqlSettings.DataSourceReplicas, " "), model.FAKE_SETTING) && len(cfg.SqlSettings.DataSourceReplicas) != 0 { if !strings.Contains(strings.Join(cfg.SqlSettings.DataSourceReplicas, " "), model.FAKE_SETTING) && len(cfg.SqlSettings.DataSourceReplicas) != 0 {
@@ -117,11 +117,11 @@ func TestUpdateConfig(t *testing.T) {
SiteName := th.App.Config().TeamSettings.SiteName SiteName := th.App.Config().TeamSettings.SiteName
cfg.TeamSettings.SiteName = "MyFancyName" *cfg.TeamSettings.SiteName = "MyFancyName"
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg) cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
CheckNoError(t, resp) CheckNoError(t, resp)
require.Equal(t, "MyFancyName", cfg.TeamSettings.SiteName, "It should update the SiteName") require.Equal(t, "MyFancyName", *cfg.TeamSettings.SiteName, "It should update the SiteName")
//Revert the change //Revert the change
cfg.TeamSettings.SiteName = SiteName cfg.TeamSettings.SiteName = SiteName
@@ -284,11 +284,11 @@ func TestGetOldClientConfig(t *testing.T) {
defer th.TearDown() defer th.TearDown()
testKey := "supersecretkey" testKey := "supersecretkey"
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.GoogleDeveloperKey = testKey }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoogleDeveloperKey = testKey })
t.Run("with session", func(t *testing.T) { t.Run("with session", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.GoogleDeveloperKey = testKey *cfg.ServiceSettings.GoogleDeveloperKey = testKey
}) })
Client := th.Client Client := th.Client
@@ -307,7 +307,7 @@ func TestGetOldClientConfig(t *testing.T) {
t.Run("without session", func(t *testing.T) { t.Run("without session", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.GoogleDeveloperKey = testKey *cfg.ServiceSettings.GoogleDeveloperKey = testKey
}) })
Client := th.CreateClient() Client := th.CreateClient()
@@ -417,9 +417,16 @@ func TestEmailTest(t *testing.T) {
Client := th.Client Client := th.Client
config := model.Config{ config := model.Config{
ServiceSettings: model.ServiceSettings{
SiteURL: model.NewString(""),
},
EmailSettings: model.EmailSettings{ EmailSettings: model.EmailSettings{
SMTPServer: "", SMTPServer: model.NewString(""),
SMTPPort: "", SMTPPort: model.NewString(""),
SMTPPassword: model.NewString(""),
FeedbackName: model.NewString(""),
FeedbackEmail: model.NewString(""),
SendEmailNotifications: model.NewBool(false),
}, },
} }
@@ -440,8 +447,8 @@ func TestEmailTest(t *testing.T) {
inbucket_port = "9000" inbucket_port = "9000"
} }
config.EmailSettings.SMTPServer = inbucket_host *config.EmailSettings.SMTPServer = inbucket_host
config.EmailSettings.SMTPPort = inbucket_port *config.EmailSettings.SMTPPort = inbucket_port
_, resp = th.SystemAdminClient.TestEmail(&config) _, resp = th.SystemAdminClient.TestEmail(&config)
CheckOKStatus(t, resp) CheckOKStatus(t, resp)
} }
@@ -679,10 +686,11 @@ func TestS3TestConnection(t *testing.T) {
config := model.Config{ config := model.Config{
FileSettings: model.FileSettings{ FileSettings: model.FileSettings{
DriverName: model.NewString(model.IMAGE_DRIVER_S3), DriverName: model.NewString(model.IMAGE_DRIVER_S3),
AmazonS3AccessKeyId: model.MINIO_ACCESS_KEY, AmazonS3AccessKeyId: model.NewString(model.MINIO_ACCESS_KEY),
AmazonS3SecretAccessKey: model.MINIO_SECRET_KEY, AmazonS3SecretAccessKey: model.NewString(model.MINIO_SECRET_KEY),
AmazonS3Bucket: "", AmazonS3Bucket: model.NewString(""),
AmazonS3Endpoint: s3Endpoint, AmazonS3Endpoint: model.NewString(s3Endpoint),
AmazonS3Region: model.NewString(""),
AmazonS3SSL: model.NewBool(false), AmazonS3SSL: model.NewBool(false),
}, },
} }
@@ -698,21 +706,21 @@ func TestS3TestConnection(t *testing.T) {
// If this fails, check the test configuration to ensure minio is setup with the // If this fails, check the test configuration to ensure minio is setup with the
// `mattermost-test` bucket defined by model.MINIO_BUCKET. // `mattermost-test` bucket defined by model.MINIO_BUCKET.
config.FileSettings.AmazonS3Bucket = model.MINIO_BUCKET *config.FileSettings.AmazonS3Bucket = model.MINIO_BUCKET
config.FileSettings.AmazonS3Region = "us-east-1" *config.FileSettings.AmazonS3Region = "us-east-1"
_, resp = th.SystemAdminClient.TestS3Connection(&config) _, resp = th.SystemAdminClient.TestS3Connection(&config)
CheckOKStatus(t, resp) CheckOKStatus(t, resp)
config.FileSettings.AmazonS3Region = "" config.FileSettings.AmazonS3Region = model.NewString("")
_, resp = th.SystemAdminClient.TestS3Connection(&config) _, resp = th.SystemAdminClient.TestS3Connection(&config)
CheckOKStatus(t, resp) CheckOKStatus(t, resp)
config.FileSettings.AmazonS3Bucket = "Wrong_bucket" config.FileSettings.AmazonS3Bucket = model.NewString("Wrong_bucket")
_, resp = th.SystemAdminClient.TestS3Connection(&config) _, resp = th.SystemAdminClient.TestS3Connection(&config)
CheckInternalErrorStatus(t, resp) CheckInternalErrorStatus(t, resp)
assert.Equal(t, "Unable to create bucket.", resp.Error.Message) assert.Equal(t, "Unable to create bucket.", resp.Error.Message)
config.FileSettings.AmazonS3Bucket = "shouldcreatenewbucket" *config.FileSettings.AmazonS3Bucket = "shouldcreatenewbucket"
_, resp = th.SystemAdminClient.TestS3Connection(&config) _, resp = th.SystemAdminClient.TestS3Connection(&config)
CheckOKStatus(t, resp) CheckOKStatus(t, resp)

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

@@ -1952,7 +1952,7 @@ func TestInviteUsersToTeam(t *testing.T) {
} }
} }
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.RestrictCreationToDomains = "@global.com,@common.com" }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.RestrictCreationToDomains = "@global.com,@common.com" })
t.Run("restricted domains", func(t *testing.T) { t.Run("restricted domains", func(t *testing.T) {
err := th.App.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id) err := th.App.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id)

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

@@ -119,7 +119,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
etag := user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress) etag := user.Etag(*c.App.Config().PrivacySettings.ShowFullName, *c.App.Config().PrivacySettings.ShowEmailAddress)
if c.HandleEtag(etag, "Get User", w, r) { if c.HandleEtag(etag, "Get User", w, r) {
return return
@@ -149,7 +149,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
etag := user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress) etag := user.Etag(*c.App.Config().PrivacySettings.ShowFullName, *c.App.Config().PrivacySettings.ShowEmailAddress)
if c.HandleEtag(etag, "Get User", w, r) { if c.HandleEtag(etag, "Get User", w, r) {
return return
@@ -184,7 +184,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
etag := user.Etag(c.App.Config().PrivacySettings.ShowFullName, c.App.Config().PrivacySettings.ShowEmailAddress) etag := user.Etag(*c.App.Config().PrivacySettings.ShowFullName, *c.App.Config().PrivacySettings.ShowEmailAddress)
if c.HandleEtag(etag, "Get User", w, r) { if c.HandleEtag(etag, "Get User", w, r) {
return return
@@ -577,8 +577,8 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
options.AllowEmails = true options.AllowEmails = true
options.AllowFullNames = true options.AllowFullNames = true
} else { } else {
options.AllowEmails = c.App.Config().PrivacySettings.ShowEmailAddress options.AllowEmails = *c.App.Config().PrivacySettings.ShowEmailAddress
options.AllowFullNames = c.App.Config().PrivacySettings.ShowFullName options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
} }
profiles, err := c.App.SearchUsers(props, options) profiles, err := c.App.SearchUsers(props, options)
@@ -610,7 +610,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) { if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
options.AllowFullNames = true options.AllowFullNames = true
} else { } else {
options.AllowFullNames = c.App.Config().PrivacySettings.ShowFullName options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
} }
if len(channelId) > 0 { if len(channelId) > 0 {

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

@@ -364,8 +364,8 @@ func TestGetUser(t *testing.T) {
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
// Check against privacy config settings // Check against privacy config settings
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowEmailAddress = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowFullName = false })
ruser, resp = th.Client.GetUser(user.Id, "") ruser, resp = th.Client.GetUser(user.Id, "")
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -418,8 +418,8 @@ func TestGetUserByUsername(t *testing.T) {
CheckNotFoundStatus(t, resp) CheckNotFoundStatus(t, resp)
// Check against privacy config settings // Check against privacy config settings
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowEmailAddress = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowFullName = false })
ruser, resp = th.Client.GetUserByUsername(th.BasicUser2.Username, "") ruser, resp = th.Client.GetUserByUsername(th.BasicUser2.Username, "")
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -464,8 +464,8 @@ func TestGetUserByEmail(t *testing.T) {
user := th.CreateUser() user := th.CreateUser()
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = true *cfg.PrivacySettings.ShowEmailAddress = true
cfg.PrivacySettings.ShowFullName = true *cfg.PrivacySettings.ShowFullName = true
}) })
t.Run("should be able to get another user by email", func(t *testing.T) { t.Run("should be able to get another user by email", func(t *testing.T) {
@@ -498,8 +498,8 @@ func TestGetUserByEmail(t *testing.T) {
t.Run("should sanitize full name for non-admin based on privacy settings", func(t *testing.T) { t.Run("should sanitize full name for non-admin based on privacy settings", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = true *cfg.PrivacySettings.ShowEmailAddress = true
cfg.PrivacySettings.ShowFullName = false *cfg.PrivacySettings.ShowFullName = false
}) })
ruser, resp := th.Client.GetUserByEmail(user.Email, "") ruser, resp := th.Client.GetUserByEmail(user.Email, "")
@@ -508,7 +508,7 @@ func TestGetUserByEmail(t *testing.T) {
assert.Equal(t, "", ruser.LastName, "last name should be blank") assert.Equal(t, "", ruser.LastName, "last name should be blank")
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowFullName = true *cfg.PrivacySettings.ShowFullName = true
}) })
ruser, resp = th.Client.GetUserByEmail(user.Email, "") ruser, resp = th.Client.GetUserByEmail(user.Email, "")
@@ -519,8 +519,8 @@ func TestGetUserByEmail(t *testing.T) {
t.Run("should not sanitize full name for admin, regardless of privacy settings", func(t *testing.T) { t.Run("should not sanitize full name for admin, regardless of privacy settings", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = true *cfg.PrivacySettings.ShowEmailAddress = true
cfg.PrivacySettings.ShowFullName = false *cfg.PrivacySettings.ShowFullName = false
}) })
ruser, resp := th.SystemAdminClient.GetUserByEmail(user.Email, "") ruser, resp := th.SystemAdminClient.GetUserByEmail(user.Email, "")
@@ -529,7 +529,7 @@ func TestGetUserByEmail(t *testing.T) {
assert.NotEqual(t, "", ruser.LastName, "last name should be set") assert.NotEqual(t, "", ruser.LastName, "last name should be set")
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowFullName = true *cfg.PrivacySettings.ShowFullName = true
}) })
ruser, resp = th.SystemAdminClient.GetUserByEmail(user.Email, "") ruser, resp = th.SystemAdminClient.GetUserByEmail(user.Email, "")
@@ -540,14 +540,14 @@ func TestGetUserByEmail(t *testing.T) {
t.Run("should return forbidden for non-admin when privacy settings hide email", func(t *testing.T) { t.Run("should return forbidden for non-admin when privacy settings hide email", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = false *cfg.PrivacySettings.ShowEmailAddress = false
}) })
_, resp := th.Client.GetUserByEmail(user.Email, "") _, resp := th.Client.GetUserByEmail(user.Email, "")
CheckForbiddenStatus(t, resp) CheckForbiddenStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = true *cfg.PrivacySettings.ShowEmailAddress = true
}) })
ruser, resp := th.Client.GetUserByEmail(user.Email, "") ruser, resp := th.Client.GetUserByEmail(user.Email, "")
@@ -557,7 +557,7 @@ func TestGetUserByEmail(t *testing.T) {
t.Run("should always return email for admin, regardless of privacy settings", func(t *testing.T) { t.Run("should always return email for admin, regardless of privacy settings", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = false *cfg.PrivacySettings.ShowEmailAddress = false
}) })
ruser, resp := th.SystemAdminClient.GetUserByEmail(user.Email, "") ruser, resp := th.SystemAdminClient.GetUserByEmail(user.Email, "")
@@ -565,7 +565,7 @@ func TestGetUserByEmail(t *testing.T) {
assert.Equal(t, user.Email, ruser.Email, "email should be set") assert.Equal(t, user.Email, ruser.Email, "email should be set")
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.PrivacySettings.ShowEmailAddress = true *cfg.PrivacySettings.ShowEmailAddress = true
}) })
ruser, resp = th.SystemAdminClient.GetUserByEmail(user.Email, "") ruser, resp = th.SystemAdminClient.GetUserByEmail(user.Email, "")
@@ -701,8 +701,8 @@ func TestSearchUsers(t *testing.T) {
search.Term = th.BasicUser.Username search.Term = th.BasicUser.Username
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowEmailAddress = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowFullName = false })
_, err = th.App.UpdateActive(th.BasicUser2, true) _, err = th.App.UpdateActive(th.BasicUser2, true)
if err != nil { if err != nil {
@@ -852,7 +852,7 @@ func TestAutocompleteUsers(t *testing.T) {
CheckNoError(t, resp) CheckNoError(t, resp)
// Check against privacy config settings // Check against privacy config settings
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowFullName = false })
th.LoginBasic() th.LoginBasic()
@@ -1389,7 +1389,7 @@ func TestUpdateUserActive(t *testing.T) {
} }
// Verify that both admins and regular users see the email when privacy settings allow same. // Verify that both admins and regular users see the email when privacy settings allow same.
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowEmailAddress = true })
_, resp := th.SystemAdminClient.UpdateUserActive(user.Id, false) _, resp := th.SystemAdminClient.UpdateUserActive(user.Id, false)
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -1397,7 +1397,7 @@ func TestUpdateUserActive(t *testing.T) {
assertWebsocketEventUserUpdatedWithEmail(t, adminWebSocketClient, user.Email) assertWebsocketEventUserUpdatedWithEmail(t, adminWebSocketClient, user.Email)
// Verify that only admins see the email when privacy settings hide emails. // Verify that only admins see the email when privacy settings hide emails.
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PrivacySettings.ShowEmailAddress = false })
_, resp = th.SystemAdminClient.UpdateUserActive(user.Id, true) _, resp = th.SystemAdminClient.UpdateUserActive(user.Id, true)
CheckNoError(t, resp) CheckNoError(t, resp)
@@ -2354,7 +2354,7 @@ func TestSwitchAccount(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.GitLabSettings.Enable = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Enable = true })
th.Client.Logout() th.Client.Logout()

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

@@ -17,9 +17,9 @@ func TestCreateIncomingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
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.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -63,13 +63,13 @@ func TestCreateIncomingWebhook(t *testing.T) {
_, resp = Client.CreateIncomingWebhook(hook) _, resp = Client.CreateIncomingWebhook(hook)
CheckNoError(t, resp) CheckNoError(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = false })
_, resp = Client.CreateIncomingWebhook(hook) _, resp = Client.CreateIncomingWebhook(hook)
CheckNoError(t, resp) CheckNoError(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = false })
_, resp = Client.CreateIncomingWebhook(hook) _, resp = Client.CreateIncomingWebhook(hook)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -79,7 +79,7 @@ func TestGetIncomingWebhooks(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -158,7 +158,7 @@ func TestGetIncomingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.SystemAdminClient Client := th.SystemAdminClient
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
var resp *model.Response var resp *model.Response
var rhook *model.IncomingWebhook var rhook *model.IncomingWebhook
@@ -197,7 +197,7 @@ func TestDeleteIncomingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.SystemAdminClient Client := th.SystemAdminClient
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
var resp *model.Response var resp *model.Response
var rhook *model.IncomingWebhook var rhook *model.IncomingWebhook
@@ -248,7 +248,7 @@ func TestCreateOutgoingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -288,7 +288,7 @@ func TestCreateOutgoingWebhook(t *testing.T) {
_, resp = Client.CreateOutgoingWebhook(hook) _, resp = Client.CreateOutgoingWebhook(hook)
CheckNoError(t, resp) CheckNoError(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = false })
_, resp = Client.CreateOutgoingWebhook(hook) _, resp = Client.CreateOutgoingWebhook(hook)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -298,7 +298,7 @@ func TestGetOutgoingWebhooks(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions) th.RestoreDefaultRolePermissions(defaultRolePermissions)
@@ -399,7 +399,7 @@ func TestGetOutgoingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}} hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}}
@@ -429,7 +429,7 @@ func TestUpdateIncomingHook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -443,8 +443,8 @@ func TestUpdateIncomingHook(t *testing.T) {
createdHook, resp := th.SystemAdminClient.CreateIncomingWebhook(hook1) createdHook, resp := th.SystemAdminClient.CreateIncomingWebhook(hook1)
CheckNoError(t, resp) CheckNoError(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = false })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = false })
t.Run("UpdateIncomingHook, overrides disabled", func(t *testing.T) { t.Run("UpdateIncomingHook, overrides disabled", func(t *testing.T) {
createdHook.DisplayName = "hook2" createdHook.DisplayName = "hook2"
@@ -483,8 +483,8 @@ func TestUpdateIncomingHook(t *testing.T) {
assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId) assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId)
}) })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
t.Run("UpdateIncomingHook", func(t *testing.T) { t.Run("UpdateIncomingHook", func(t *testing.T) {
createdHook.DisplayName = "hook2" createdHook.DisplayName = "hook2"
@@ -604,13 +604,13 @@ func TestUpdateIncomingHook(t *testing.T) {
}) })
t.Run("IncomingHooksDisabled", func(t *testing.T) { t.Run("IncomingHooksDisabled", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = false })
_, resp := Client.UpdateIncomingWebhook(createdHook) _, resp := Client.UpdateIncomingWebhook(createdHook)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
CheckErrorMessage(t, resp, "api.incoming_webhook.disabled.app_error") CheckErrorMessage(t, resp, "api.incoming_webhook.disabled.app_error")
}) })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
t.Run("PrivateChannel", func(t *testing.T) { t.Run("PrivateChannel", func(t *testing.T) {
privateChannel := th.CreatePrivateChannel() privateChannel := th.CreatePrivateChannel()
@@ -644,7 +644,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}} hook := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}}
rhook, resp := th.SystemAdminClient.CreateOutgoingWebhook(hook) rhook, resp := th.SystemAdminClient.CreateOutgoingWebhook(hook)
@@ -666,7 +666,7 @@ func TestRegenOutgoingHookToken(t *testing.T) {
_, resp = Client.RegenOutgoingHookToken(rhook.Id) _, resp = Client.RegenOutgoingHookToken(rhook.Id)
CheckForbiddenStatus(t, resp) CheckForbiddenStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = false })
_, resp = th.SystemAdminClient.RegenOutgoingHookToken(rhook.Id) _, resp = th.SystemAdminClient.RegenOutgoingHookToken(rhook.Id)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
} }
@@ -676,7 +676,7 @@ func TestUpdateOutgoingHook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.Client Client := th.Client
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
th.RestoreDefaultRolePermissions(defaultRolePermissions) th.RestoreDefaultRolePermissions(defaultRolePermissions)
@@ -705,12 +705,12 @@ func TestUpdateOutgoingHook(t *testing.T) {
}) })
t.Run("OutgoingHooksDisabled", func(t *testing.T) { t.Run("OutgoingHooksDisabled", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = false })
_, resp := th.SystemAdminClient.UpdateOutgoingWebhook(createdHook) _, resp := th.SystemAdminClient.UpdateOutgoingWebhook(createdHook)
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
}) })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
t.Run("RetainCreateAt", func(t *testing.T) { t.Run("RetainCreateAt", func(t *testing.T) {
hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, hook2 := &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}} CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"rats"}}
@@ -839,7 +839,7 @@ func TestDeleteOutgoingHook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
Client := th.SystemAdminClient Client := th.SystemAdminClient
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
var resp *model.Response var resp *model.Response
var rhook *model.OutgoingWebhook var rhook *model.OutgoingWebhook

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

@@ -51,8 +51,8 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
var lines []string var lines []string
if a.Config().LogSettings.EnableFile { if *a.Config().LogSettings.EnableFile {
file, err := os.Open(utils.GetLogFileLocation(a.Config().LogSettings.FileLocation)) file, err := os.Open(utils.GetLogFileLocation(*a.Config().LogSettings.FileLocation))
if err != nil { if err != nil {
return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
} }
@@ -221,17 +221,17 @@ func (a *App) RecycleDatabaseConnection() {
} }
func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError { func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
if len(cfg.EmailSettings.SMTPServer) == 0 { if len(*cfg.EmailSettings.SMTPServer) == 0 {
return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest) return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest)
} }
// if the user hasn't changed their email settings, fill in the actual SMTP password so that // if the user hasn't changed their email settings, fill in the actual SMTP password so that
// the user can verify an existing SMTP connection // the user can verify an existing SMTP connection
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING { if *cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
if cfg.EmailSettings.SMTPServer == a.Config().EmailSettings.SMTPServer && if *cfg.EmailSettings.SMTPServer == *a.Config().EmailSettings.SMTPServer &&
cfg.EmailSettings.SMTPPort == a.Config().EmailSettings.SMTPPort && *cfg.EmailSettings.SMTPPort == *a.Config().EmailSettings.SMTPPort &&
cfg.EmailSettings.SMTPUsername == a.Config().EmailSettings.SMTPUsername { *cfg.EmailSettings.SMTPUsername == *a.Config().EmailSettings.SMTPUsername {
cfg.EmailSettings.SMTPPassword = a.Config().EmailSettings.SMTPPassword *cfg.EmailSettings.SMTPPassword = *a.Config().EmailSettings.SMTPPassword
} else { } else {
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest) return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
} }

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

@@ -138,7 +138,7 @@ func (a *App) CheckUserPreflightAuthenticationCriteria(user *model.User, mfaToke
} }
func (a *App) CheckUserPostflightAuthenticationCriteria(user *model.User) *model.AppError { func (a *App) CheckUserPostflightAuthenticationCriteria(user *model.User) *model.AppError {
if !user.EmailVerified && a.Config().EmailSettings.RequireEmailVerification { if !user.EmailVerified && *a.Config().EmailSettings.RequireEmailVerification {
return model.NewAppError("Login", "api.user.login.not_verified.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized) return model.NewAppError("Login", "api.user.login.not_verified.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized)
} }

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

@@ -21,8 +21,8 @@ func TestPermanentDeleteChannel(t *testing.T) {
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.EnableIncomingWebhooks = true *cfg.ServiceSettings.EnableIncomingWebhooks = true
cfg.ServiceSettings.EnableOutgoingWebhooks = true *cfg.ServiceSettings.EnableOutgoingWebhooks = true
}) })
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false) channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)

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

@@ -394,7 +394,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
isBotPost := !builtIn isBotPost := !builtIn
if a.Config().ServiceSettings.EnablePostUsernameOverride { if *a.Config().ServiceSettings.EnablePostUsernameOverride {
if len(command.Username) != 0 { if len(command.Username) != 0 {
post.AddProp("override_username", command.Username) post.AddProp("override_username", command.Username)
isBotPost = true isBotPost = true
@@ -404,7 +404,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
} }
} }
if a.Config().ServiceSettings.EnablePostIconOverride { if *a.Config().ServiceSettings.EnablePostIconOverride {
if len(command.IconURL) != 0 { if len(command.IconURL) != 0 {
post.AddProp("override_icon_url", command.IconURL) post.AddProp("override_icon_url", command.IconURL)
isBotPost = true isBotPost = true

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

@@ -28,7 +28,7 @@ func (me *InvitePeopleProvider) GetTrigger() string {
func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command { func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
autoComplete := true autoComplete := true
if !a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations { if !*a.Config().EmailSettings.SendEmailNotifications || !*a.Config().TeamSettings.EnableUserCreation || !*a.Config().ServiceSettings.EnableEmailInvitations {
autoComplete = false autoComplete = false
} }
return &model.Command{ return &model.Command{
@@ -49,7 +49,7 @@ func (me *InvitePeopleProvider) DoCommand(a *App, args *model.CommandArgs, messa
return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL} return &model.CommandResponse{Text: args.T("api.command_invite_people.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} }
if !a.Config().EmailSettings.SendEmailNotifications { if !*a.Config().EmailSettings.SendEmailNotifications {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.email_off")} return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.email_off")}
} }

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

@@ -74,7 +74,7 @@ func (me *LoadTestProvider) GetTrigger() string {
} }
func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command { func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
if !a.Config().ServiceSettings.EnableTesting { if !*a.Config().ServiceSettings.EnableTesting {
return nil return nil
} }
return &model.Command{ return &model.Command{
@@ -88,7 +88,7 @@ func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Co
func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse { func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
//This command is only available when EnableTesting is true //This command is only available when EnableTesting is true
if !a.Config().ServiceSettings.EnableTesting { if !*a.Config().ServiceSettings.EnableTesting {
return &model.CommandResponse{} return &model.CommandResponse{}
} }

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

@@ -127,7 +127,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
assert.NotEqual(t, args.ChannelId, post.ChannelId) assert.NotEqual(t, args.ChannelId, post.ChannelId)
// Override username config is turned off. No override should occur. // Override username config is turned off. No override should occur.
th.App.Config().ServiceSettings.EnablePostUsernameOverride = false *th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
resp.ChannelId = "" resp.ChannelId = ""
command.Username = "Command username" command.Username = "Command username"
resp.Username = "Response username" resp.Username = "Response username"
@@ -136,7 +136,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Nil(t, post.Props["override_username"]) assert.Nil(t, post.Props["override_username"])
th.App.Config().ServiceSettings.EnablePostUsernameOverride = true *th.App.Config().ServiceSettings.EnablePostUsernameOverride = true
// Override username config is turned on. Override username through command property. // Override username config is turned on. Override username through command property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn) post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)
@@ -152,10 +152,10 @@ func TestHandleCommandResponsePost(t *testing.T) {
assert.Equal(t, resp.Username, post.Props["override_username"]) assert.Equal(t, resp.Username, post.Props["override_username"])
assert.Equal(t, "true", post.Props["from_webhook"]) assert.Equal(t, "true", post.Props["from_webhook"])
th.App.Config().ServiceSettings.EnablePostUsernameOverride = false *th.App.Config().ServiceSettings.EnablePostUsernameOverride = false
// Override icon url config is turned off. No override should occur. // Override icon url config is turned off. No override should occur.
th.App.Config().ServiceSettings.EnablePostIconOverride = false *th.App.Config().ServiceSettings.EnablePostIconOverride = false
command.IconURL = "Command icon url" command.IconURL = "Command icon url"
resp.IconURL = "Response icon url" resp.IconURL = "Response icon url"
@@ -163,7 +163,7 @@ func TestHandleCommandResponsePost(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.Nil(t, post.Props["override_icon_url"]) assert.Nil(t, post.Props["override_icon_url"])
th.App.Config().ServiceSettings.EnablePostIconOverride = true *th.App.Config().ServiceSettings.EnablePostIconOverride = true
// Override icon url config is turned on. Override icon url through command property. // Override icon url config is turned on. Override icon url through command property.
post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn) post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn)

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

@@ -313,25 +313,25 @@ func (a *App) Desanitize(cfg *model.Config) {
if *cfg.FileSettings.PublicLinkSalt == model.FAKE_SETTING { if *cfg.FileSettings.PublicLinkSalt == model.FAKE_SETTING {
*cfg.FileSettings.PublicLinkSalt = *actual.FileSettings.PublicLinkSalt *cfg.FileSettings.PublicLinkSalt = *actual.FileSettings.PublicLinkSalt
} }
if cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING { if *cfg.FileSettings.AmazonS3SecretAccessKey == model.FAKE_SETTING {
cfg.FileSettings.AmazonS3SecretAccessKey = actual.FileSettings.AmazonS3SecretAccessKey cfg.FileSettings.AmazonS3SecretAccessKey = actual.FileSettings.AmazonS3SecretAccessKey
} }
if cfg.EmailSettings.InviteSalt == model.FAKE_SETTING { if *cfg.EmailSettings.InviteSalt == model.FAKE_SETTING {
cfg.EmailSettings.InviteSalt = actual.EmailSettings.InviteSalt cfg.EmailSettings.InviteSalt = actual.EmailSettings.InviteSalt
} }
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING { if *cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
cfg.EmailSettings.SMTPPassword = actual.EmailSettings.SMTPPassword cfg.EmailSettings.SMTPPassword = actual.EmailSettings.SMTPPassword
} }
if cfg.GitLabSettings.Secret == model.FAKE_SETTING { if *cfg.GitLabSettings.Secret == model.FAKE_SETTING {
cfg.GitLabSettings.Secret = actual.GitLabSettings.Secret *cfg.GitLabSettings.Secret = *actual.GitLabSettings.Secret
} }
if *cfg.SqlSettings.DataSource == model.FAKE_SETTING { if *cfg.SqlSettings.DataSource == model.FAKE_SETTING {
*cfg.SqlSettings.DataSource = *actual.SqlSettings.DataSource *cfg.SqlSettings.DataSource = *actual.SqlSettings.DataSource
} }
if cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING { if *cfg.SqlSettings.AtRestEncryptKey == model.FAKE_SETTING {
cfg.SqlSettings.AtRestEncryptKey = actual.SqlSettings.AtRestEncryptKey cfg.SqlSettings.AtRestEncryptKey = actual.SqlSettings.AtRestEncryptKey
} }

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

@@ -51,7 +51,7 @@ func TestConfigListener(t *testing.T) {
originalSiteName := th.App.Config().TeamSettings.SiteName originalSiteName := th.App.Config().TeamSettings.SiteName
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.TeamSettings.SiteName = "test123" *cfg.TeamSettings.SiteName = "test123"
}) })
listenerCalled := false listenerCalled := false
@@ -60,9 +60,9 @@ func TestConfigListener(t *testing.T) {
t.Fatal("listener called twice") t.Fatal("listener called twice")
} }
if oldConfig.TeamSettings.SiteName != "test123" { if *oldConfig.TeamSettings.SiteName != "test123" {
t.Fatal("old config contains incorrect site name") t.Fatal("old config contains incorrect site name")
} else if newConfig.TeamSettings.SiteName != originalSiteName { } else if *newConfig.TeamSettings.SiteName != *originalSiteName {
t.Fatal("new config contains incorrect site name") t.Fatal("new config contains incorrect site name")
} }

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

@@ -340,8 +340,8 @@ func (a *App) trackConfig() {
a.SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{ a.SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{
"enable_public_links": cfg.FileSettings.EnablePublicLink, "enable_public_links": cfg.FileSettings.EnablePublicLink,
"driver_name": *cfg.FileSettings.DriverName, "driver_name": *cfg.FileSettings.DriverName,
"isdefault_directory": isDefault(cfg.FileSettings.Directory, model.FILE_SETTINGS_DEFAULT_DIRECTORY), "isdefault_directory": isDefault(*cfg.FileSettings.Directory, model.FILE_SETTINGS_DEFAULT_DIRECTORY),
"isabsolute_directory": filepath.IsAbs(cfg.FileSettings.Directory), "isabsolute_directory": filepath.IsAbs(*cfg.FileSettings.Directory),
"amazon_s3_ssl": *cfg.FileSettings.AmazonS3SSL, "amazon_s3_ssl": *cfg.FileSettings.AmazonS3SSL,
"amazon_s3_sse": *cfg.FileSettings.AmazonS3SSE, "amazon_s3_sse": *cfg.FileSettings.AmazonS3SSE,
"amazon_s3_signv2": *cfg.FileSettings.AmazonS3SignV2, "amazon_s3_signv2": *cfg.FileSettings.AmazonS3SignV2,

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

@@ -341,7 +341,7 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
} }
bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&t=%s", siteURL, url.QueryEscape(data), url.QueryEscape(token.Token)) bodyPage.Props["Link"] = fmt.Sprintf("%s/signup_user_complete/?d=%s&t=%s", siteURL, url.QueryEscape(data), url.QueryEscape(token.Token))
if !a.Config().EmailSettings.SendEmailNotifications { if !*a.Config().EmailSettings.SendEmailNotifications {
mlog.Info(fmt.Sprintf("sending invitation to %v %v", invite, bodyPage.Props["Link"])) mlog.Info(fmt.Sprintf("sending invitation to %v %v", invite, bodyPage.Props["Link"]))
} }

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

@@ -158,7 +158,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
sender: sender, sender: sender,
} }
if a.Config().EmailSettings.SendEmailNotifications { if *a.Config().EmailSettings.SendEmailNotifications {
for _, id := range mentionedUsersList { for _, id := range mentionedUsersList {
if profileMap[id] == nil { if profileMap[id] == nil {
continue continue
@@ -180,7 +180,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
} }
//If email verification is required and user email is not verified don't send email. //If email verification is required and user email is not verified don't send email.
if a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified { if *a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
mlog.Error(fmt.Sprintf("Skipped sending notification email to %v, address not verified. [details: user_id=%v]", profileMap[id].Email, id)) mlog.Error(fmt.Sprintf("Skipped sending notification email to %v, address not verified. [details: user_id=%v]", profileMap[id].Email, id))
continue continue
} }
@@ -325,7 +325,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
message.Add("channel_type", channel.Type) message.Add("channel_type", channel.Type)
message.Add("channel_display_name", notification.GetChannelName(model.SHOW_USERNAME, "")) message.Add("channel_display_name", notification.GetChannelName(model.SHOW_USERNAME, ""))
message.Add("channel_name", channel.Name) message.Add("channel_name", channel.Name)
message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, a.Config().ServiceSettings.EnablePostUsernameOverride)) message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, *a.Config().ServiceSettings.EnablePostUsernameOverride))
message.Add("team_id", team.Id) message.Add("team_id", team.Id)
if len(post.FileIds) != 0 && fchan != nil { if len(post.FileIds) != 0 && fchan != nil {

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

@@ -42,7 +42,7 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
team = teams[0] team = teams[0]
} else { } else {
// in case the user hasn't joined any teams we send them to the select_team page // in case the user hasn't joined any teams we send them to the select_team page
team = &model.Team{Name: "select_team", DisplayName: a.Config().TeamSettings.SiteName} team = &model.Team{Name: "select_team", DisplayName: *a.Config().TeamSettings.SiteName}
} }
} }
@@ -82,7 +82,7 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
} }
channelName := notification.GetChannelName(nameFormat, "") channelName := notification.GetChannelName(nameFormat, "")
senderName := notification.GetSenderName(nameFormat, a.Config().ServiceSettings.EnablePostUsernameOverride) senderName := notification.GetSenderName(nameFormat, *a.Config().ServiceSettings.EnablePostUsernameOverride)
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if license := a.License(); license != nil && *license.Features.EmailNotificationContents { if license := a.License(); license != nil && *license.Features.EmailNotificationContents {
@@ -91,13 +91,13 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
var subjectText string var subjectText string
if channel.Type == model.CHANNEL_DIRECT { if channel.Type == model.CHANNEL_DIRECT {
subjectText = getDirectMessageNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, senderName, useMilitaryTime) subjectText = getDirectMessageNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, senderName, useMilitaryTime)
} else if channel.Type == model.CHANNEL_GROUP { } else if channel.Type == model.CHANNEL_GROUP {
subjectText = getGroupMessageNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType, useMilitaryTime) subjectText = getGroupMessageNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, channelName, emailNotificationContentsType, useMilitaryTime)
} else if *a.Config().EmailSettings.UseChannelInEmailNotifications { } else if *a.Config().EmailSettings.UseChannelInEmailNotifications {
subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channelName+")", useMilitaryTime) subjectText = getNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, team.DisplayName+" ("+channelName+")", useMilitaryTime)
} else { } else {
subjectText = getNotificationEmailSubject(user, post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime) subjectText = getNotificationEmailSubject(user, post, translateFunc, *a.Config().TeamSettings.SiteName, team.DisplayName, useMilitaryTime)
} }
teamURL := a.GetSiteURL() + "/" + team.Name teamURL := a.GetSiteURL() + "/" + team.Name

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

@@ -79,11 +79,11 @@ func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, chann
msg.ChannelName = channelName msg.ChannelName = channelName
} }
if ou, ok := post.Props["override_username"].(string); ok && cfg.ServiceSettings.EnablePostUsernameOverride { if ou, ok := post.Props["override_username"].(string); ok && *cfg.ServiceSettings.EnablePostUsernameOverride {
msg.OverrideUsername = ou msg.OverrideUsername = ou
} }
if oi, ok := post.Props["override_icon_url"].(string); ok && cfg.ServiceSettings.EnablePostIconOverride { if oi, ok := post.Props["override_icon_url"].(string); ok && *cfg.ServiceSettings.EnablePostIconOverride {
msg.OverrideIconUrl = oi msg.OverrideIconUrl = oi
} }
@@ -130,7 +130,7 @@ func (a *App) sendPushNotification(notification *postNotification, user *model.U
} }
channelName := notification.GetChannelName(nameFormat, user.Id) channelName := notification.GetChannelName(nameFormat, user.Id)
senderName := notification.GetSenderName(nameFormat, cfg.ServiceSettings.EnablePostUsernameOverride) senderName := notification.GetSenderName(nameFormat, *cfg.ServiceSettings.EnablePostUsernameOverride)
c := a.Srv.PushNotificationsHub.GetGoChannelFromUserId(user.Id) c := a.Srv.PushNotificationsHub.GetGoChannelFromUserId(user.Id)
c <- PushNotification{ c <- PushNotification{

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

@@ -29,7 +29,7 @@ const (
) )
func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("CreateOAuthApp", "api.oauth.register_oauth_app.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("CreateOAuthApp", "api.oauth.register_oauth_app.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -44,7 +44,7 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr
} }
func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) { func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -57,7 +57,7 @@ func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
} }
func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) { func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("UpdateOauthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("UpdateOauthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -75,7 +75,7 @@ func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp
} }
func (a *App) DeleteOAuthApp(appId string) *model.AppError { func (a *App) DeleteOAuthApp(appId string) *model.AppError {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -91,7 +91,7 @@ func (a *App) DeleteOAuthApp(appId string) *model.AppError {
} }
func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError) { func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOAuthApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -104,7 +104,7 @@ func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppErro
} }
func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) { func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -144,7 +144,7 @@ func (a *App) GetOAuthCodeRedirect(userId string, authRequest *model.AuthorizeRe
} }
func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError) { func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -196,7 +196,7 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
} }
func (a *App) GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) { func (a *App) GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -226,7 +226,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *mod
} }
func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) { func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -417,7 +417,7 @@ func (a *App) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, ser
} }
func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) { func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetAuthorizedAppsForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetAuthorizedAppsForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -436,7 +436,7 @@ func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*mod
} }
func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError { func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -466,7 +466,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
} }
func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
if !a.Config().ServiceSettings.EnableOAuthServiceProvider { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("RegenerateOAuthAppSecret", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("RegenerateOAuthAppSecret", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -660,7 +660,7 @@ func (a *App) GetOAuthStateToken(token string) (*model.Token, *model.AppError) {
func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) { func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
sso := a.Config().GetSSOService(service) sso := a.Config().GetSSOService(service)
if sso == nil || !sso.Enable { if sso == nil || !*sso.Enable {
return "", model.NewAppError("GetAuthorizationCode", "api.user.get_authorization_code.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented) return "", model.NewAppError("GetAuthorizationCode", "api.user.get_authorization_code.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
} }
@@ -683,9 +683,9 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
http.SetCookie(w, oauthCookie) http.SetCookie(w, oauthCookie)
clientId := sso.Id clientId := *sso.Id
endpoint := sso.AuthEndpoint endpoint := *sso.AuthEndpoint
scope := sso.Scope scope := *sso.Scope
tokenExtra := generateOAuthStateTokenExtra(props["email"], props["action"], cookieValue) tokenExtra := generateOAuthStateTokenExtra(props["email"], props["action"], cookieValue)
stateToken, err := a.CreateOAuthStateToken(tokenExtra) stateToken, err := a.CreateOAuthStateToken(tokenExtra)
@@ -718,7 +718,7 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.AppError) { func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.AppError) {
sso := a.Config().GetSSOService(service) sso := a.Config().GetSSOService(service)
if sso == nil || !sso.Enable { if sso == nil || !*sso.Enable {
return nil, "", nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented) return nil, "", nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
} }
@@ -770,13 +770,13 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
teamId := stateProps["team_id"] teamId := stateProps["team_id"]
p := url.Values{} p := url.Values{}
p.Set("client_id", sso.Id) p.Set("client_id", *sso.Id)
p.Set("client_secret", sso.Secret) p.Set("client_secret", *sso.Secret)
p.Set("code", code) p.Set("code", code)
p.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE) p.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
p.Set("redirect_uri", redirectUri) p.Set("redirect_uri", redirectUri)
req, requestErr := http.NewRequest("POST", sso.TokenEndpoint, strings.NewReader(p.Encode())) req, requestErr := http.NewRequest("POST", *sso.TokenEndpoint, strings.NewReader(p.Encode()))
if requestErr != nil { if requestErr != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, requestErr.Error(), http.StatusInternalServerError) return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, requestErr.Error(), http.StatusInternalServerError)
} }
@@ -808,7 +808,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
p = url.Values{} p = url.Values{}
p.Set("access_token", ar.AccessToken) p.Set("access_token", ar.AccessToken)
req, requestErr = http.NewRequest("GET", sso.UserApiEndpoint, strings.NewReader("")) req, requestErr = http.NewRequest("GET", *sso.UserApiEndpoint, strings.NewReader(""))
if requestErr != nil { if requestErr != nil {
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]interface{}{"Service": service}, requestErr.Error(), http.StatusInternalServerError) return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.service.app_error", map[string]interface{}{"Service": service}, requestErr.Error(), http.StatusInternalServerError)
} }

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

@@ -20,7 +20,7 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
oapp := &model.OAuthApp{ oapp := &model.OAuthApp{
Name: "fakeoauthapp" + model.NewRandomString(10), Name: "fakeoauthapp" + model.NewRandomString(10),
@@ -45,13 +45,13 @@ func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
assert.NotNil(t, session) assert.NotNil(t, session)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest) session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
assert.NotNil(t, err, "should fail - oauth2 disabled") assert.NotNil(t, err, "should fail - oauth2 disabled")
assert.Nil(t, session) assert.Nil(t, session)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
authRequest.ClientId = "junk" authRequest.ClientId = "junk"
session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest) session, err = th.App.GetOAuthAccessTokenForImplicitFlow(th.BasicUser.Id, authRequest)
@@ -105,7 +105,7 @@ func TestOAuthDeleteApp(t *testing.T) {
th := Setup() th := Setup()
defer th.TearDown() defer th.TearDown()
th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true *th.App.Config().ServiceSettings.EnableOAuthServiceProvider = true
a1 := &model.OAuthApp{} a1 := &model.OAuthApp{}
a1.CreatorId = model.NewId() a1.CreatorId = model.NewId()
@@ -154,18 +154,18 @@ func TestAuthorizeOAuthUser(t *testing.T) {
th := Setup() th := Setup()
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.GitLabSettings.Enable = enable *cfg.GitLabSettings.Enable = enable
if tokenEndpoint { if tokenEndpoint {
cfg.GitLabSettings.TokenEndpoint = serverURL + "/token" *cfg.GitLabSettings.TokenEndpoint = serverURL + "/token"
} else { } else {
cfg.GitLabSettings.TokenEndpoint = "" *cfg.GitLabSettings.TokenEndpoint = ""
} }
if userEndpoint { if userEndpoint {
cfg.GitLabSettings.UserApiEndpoint = serverURL + "/user" *cfg.GitLabSettings.UserApiEndpoint = serverURL + "/user"
} else { } else {
cfg.GitLabSettings.UserApiEndpoint = "" *cfg.GitLabSettings.UserApiEndpoint = ""
} }
}) })

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

@@ -477,7 +477,7 @@ func (api *PluginAPI) GetFileInfo(fileId string) (*model.FileInfo, *model.AppErr
} }
func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) { func (api *PluginAPI) GetFileLink(fileId string) (string, *model.AppError) {
if !api.app.Config().FileSettings.EnablePublicLink { if !*api.app.Config().FileSettings.EnablePublicLink {
return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented) return "", model.NewAppError("GetFileLink", "plugin_api.get_file_link.disabled.app_error", nil, "", http.StatusNotImplemented)
} }

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

@@ -67,7 +67,7 @@ func (a *App) normalizeDomains(domains string) []string {
func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) bool { func (a *App) isTeamEmailAddressAllowed(email string, allowedDomains string) bool {
email = strings.ToLower(email) email = strings.ToLower(email)
// First check per team allowedDomains, then app wide restrictions // First check per team allowedDomains, then app wide restrictions
for _, restriction := range []string{allowedDomains, a.Config().TeamSettings.RestrictCreationToDomains} { for _, restriction := range []string{allowedDomains, *a.Config().TeamSettings.RestrictCreationToDomains} {
domains := a.normalizeDomains(restriction) domains := a.normalizeDomains(restriction)
if len(domains) <= 0 { if len(domains) <= 0 {
continue continue
@@ -103,7 +103,7 @@ func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
return nil, err return nil, err
} }
validDomains := a.normalizeDomains(a.Config().TeamSettings.RestrictCreationToDomains) validDomains := a.normalizeDomains(*a.Config().TeamSettings.RestrictCreationToDomains)
if len(validDomains) > 0 { if len(validDomains) > 0 {
for _, domain := range a.normalizeDomains(team.AllowedDomains) { for _, domain := range a.normalizeDomains(team.AllowedDomains) {
matched := false matched := false

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

@@ -161,7 +161,7 @@ func (a *App) CreateUserFromSignup(user *model.User) (*model.User, *model.AppErr
} }
func (a *App) IsUserSignUpAllowed() *model.AppError { func (a *App) IsUserSignUpAllowed() *model.AppError {
if !a.Config().EmailSettings.EnableSignUpWithEmail || !*a.Config().TeamSettings.EnableUserCreation { if !*a.Config().EmailSettings.EnableSignUpWithEmail || !*a.Config().TeamSettings.EnableUserCreation {
err := model.NewAppError("IsUserSignUpAllowed", "api.user.create_user.signup_email_disabled.app_error", nil, "", http.StatusNotImplemented) err := model.NewAppError("IsUserSignUpAllowed", "api.user.create_user.signup_email_disabled.app_error", nil, "", http.StatusNotImplemented)
return err return err
} }
@@ -184,7 +184,7 @@ func (a *App) IsFirstUserAccount() bool {
} }
func (a *App) CreateUser(user *model.User) (*model.User, *model.AppError) { func (a *App) CreateUser(user *model.User) (*model.User, *model.AppError) {
if !user.IsLDAPUser() && !user.IsSAMLUser() && !CheckUserDomain(user, a.Config().TeamSettings.RestrictCreationToDomains) { if !user.IsLDAPUser() && !user.IsSAMLUser() && !CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
return nil, model.NewAppError("CreateUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest) return nil, model.NewAppError("CreateUser", "api.user.create_user.accepted_domain.app_error", nil, "", http.StatusBadRequest)
} }
@@ -698,7 +698,7 @@ func getFont(initialFont string) (*truetype.Font, error) {
func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) { func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) {
if len(*a.Config().FileSettings.DriverName) == 0 { if len(*a.Config().FileSettings.DriverName) == 0 {
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont) img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
if appErr != nil { if appErr != nil {
return nil, false, appErr return nil, false, appErr
} }
@@ -709,7 +709,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
data, err := a.ReadFile(path) data, err := a.ReadFile(path)
if err != nil { if err != nil {
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont) img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
if appErr != nil { if appErr != nil {
return nil, false, appErr return nil, false, appErr
} }
@@ -726,7 +726,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
} }
func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError) { func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError) {
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont) img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
if appErr != nil { if appErr != nil {
return nil, appErr return nil, appErr
} }
@@ -734,7 +734,7 @@ func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError)
} }
func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError { func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
img, appErr := CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont) img, appErr := CreateProfileImage(user.Username, user.Id, *a.Config().FileSettings.InitialFont)
if appErr != nil { if appErr != nil {
return appErr return appErr
} }
@@ -994,7 +994,7 @@ func (a *App) sendUpdatedUserEvent(user model.User) {
} }
func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) { func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) {
if !CheckUserDomain(user, a.Config().TeamSettings.RestrictCreationToDomains) { if !CheckUserDomain(user, *a.Config().TeamSettings.RestrictCreationToDomains) {
result := <-a.Srv.Store.User().Get(user.Id) result := <-a.Srv.Store.User().Get(user.Id)
if result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
@@ -1019,7 +1019,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
} }
}) })
if a.Config().EmailSettings.RequireEmailVerification { if *a.Config().EmailSettings.RequireEmailVerification {
a.Srv.Go(func() { a.Srv.Go(func() {
if err := a.SendEmailVerification(rusers[0]); err != nil { if err := a.SendEmailVerification(rusers[0]); err != nil {
mlog.Error(err.Error()) mlog.Error(err.Error())

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

@@ -143,7 +143,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) {
defer th.App.PermanentDeleteUser(user) defer th.App.PermanentDeleteUser(user)
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.TeamSettings.RestrictCreationToDomains = "foo.com" *cfg.TeamSettings.RestrictCreationToDomains = "foo.com"
}) })
_, err := th.App.UpdateUser(user, false) _, err := th.App.UpdateUser(user, false)

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

@@ -25,7 +25,7 @@ const (
) )
func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError { func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil return nil
} }
@@ -133,11 +133,11 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
if len(webhookResp.Attachments) > 0 { if len(webhookResp.Attachments) > 0 {
webhookResp.Props["attachments"] = webhookResp.Attachments webhookResp.Props["attachments"] = webhookResp.Attachments
} }
if a.Config().ServiceSettings.EnablePostUsernameOverride && hook.Username != "" && webhookResp.Username == "" { if *a.Config().ServiceSettings.EnablePostUsernameOverride && hook.Username != "" && webhookResp.Username == "" {
webhookResp.Username = hook.Username webhookResp.Username = hook.Username
} }
if a.Config().ServiceSettings.EnablePostIconOverride && hook.IconURL != "" && webhookResp.IconURL == "" { if *a.Config().ServiceSettings.EnablePostIconOverride && hook.IconURL != "" && webhookResp.IconURL == "" {
webhookResp.IconURL = hook.IconURL webhookResp.IconURL = hook.IconURL
} }
if _, err := a.CreateWebhookPost(hook.CreatorId, channel, text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil { if _, err := a.CreateWebhookPost(hook.CreatorId, channel, text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type, postRootId); err != nil {
@@ -264,7 +264,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
metrics.IncrementWebhookPost() metrics.IncrementWebhookPost()
} }
if a.Config().ServiceSettings.EnablePostUsernameOverride { if *a.Config().ServiceSettings.EnablePostUsernameOverride {
if len(overrideUsername) != 0 { if len(overrideUsername) != 0 {
post.AddProp("override_username", overrideUsername) post.AddProp("override_username", overrideUsername)
} else { } else {
@@ -272,7 +272,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
} }
} }
if a.Config().ServiceSettings.EnablePostIconOverride { if *a.Config().ServiceSettings.EnablePostIconOverride {
if len(overrideIconUrl) != 0 { if len(overrideIconUrl) != 0 {
post.AddProp("override_icon_url", overrideIconUrl) post.AddProp("override_icon_url", overrideIconUrl)
} }
@@ -305,17 +305,17 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
} }
func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) { func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
hook.UserId = creatorId hook.UserId = creatorId
hook.TeamId = channel.TeamId hook.TeamId = channel.TeamId
if !a.Config().ServiceSettings.EnablePostUsernameOverride { if !*a.Config().ServiceSettings.EnablePostUsernameOverride {
hook.Username = "" hook.Username = ""
} }
if !a.Config().ServiceSettings.EnablePostIconOverride { if !*a.Config().ServiceSettings.EnablePostIconOverride {
hook.IconURL = "" hook.IconURL = ""
} }
@@ -331,14 +331,14 @@ func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.C
} }
func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) { func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
if !a.Config().ServiceSettings.EnablePostUsernameOverride { if !*a.Config().ServiceSettings.EnablePostUsernameOverride {
updatedHook.Username = oldHook.Username updatedHook.Username = oldHook.Username
} }
if !a.Config().ServiceSettings.EnablePostIconOverride { if !*a.Config().ServiceSettings.EnablePostIconOverride {
updatedHook.IconURL = oldHook.IconURL updatedHook.IconURL = oldHook.IconURL
} }
@@ -362,7 +362,7 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook)
} }
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError { func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -376,7 +376,7 @@ func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
} }
func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) { func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -388,7 +388,7 @@ func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.
} }
func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) { func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -400,7 +400,7 @@ func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) (
} }
func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) { func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -412,7 +412,7 @@ func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebho
} }
func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) { func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -460,7 +460,7 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
} }
func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) { func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -511,7 +511,7 @@ func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook)
} }
func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) { func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -523,7 +523,7 @@ func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.
} }
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) { func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -535,7 +535,7 @@ func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebho
} }
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) { func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -547,7 +547,7 @@ func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage
} }
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) { func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksForTeamPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetOutgoingWebhooksForTeamPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -559,7 +559,7 @@ func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) (
} }
func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError { func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return model.NewAppError("DeleteOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("DeleteOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -571,7 +571,7 @@ func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
} }
func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) { func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
if !a.Config().ServiceSettings.EnableOutgoingWebhooks { if !*a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("RegenOutgoingWebhookToken", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("RegenOutgoingWebhookToken", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
@@ -585,7 +585,7 @@ func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.Out
} }
func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError { func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError {
if !a.Config().ServiceSettings.EnableIncomingWebhooks { if !*a.Config().ServiceSettings.EnableIncomingWebhooks {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
} }

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

@@ -122,11 +122,11 @@ func TestCreateIncomingWebhookForChannel(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride *cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
}) })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
createdHook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &tc.IncomingWebhook) createdHook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &tc.IncomingWebhook)
if tc.ExpectedError && err == nil { if tc.ExpectedError && err == nil {
@@ -253,7 +253,7 @@ func TestUpdateIncomingWebhook(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
@@ -263,11 +263,11 @@ func TestUpdateIncomingWebhook(t *testing.T) {
} }
defer th.App.DeleteIncomingWebhook(hook.Id) defer th.App.DeleteIncomingWebhook(hook.Id)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = tc.EnableIncomingHooks })
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride *cfg.ServiceSettings.EnablePostUsernameOverride = tc.EnablePostUsernameOverride
}) })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = tc.EnablePostIconOverride })
updatedHook, err := th.App.UpdateIncomingWebhook(hook, &tc.IncomingWebhook) updatedHook, err := th.App.UpdateIncomingWebhook(hook, &tc.IncomingWebhook)
if tc.ExpectedError && err == nil { if tc.ExpectedError && err == nil {
@@ -292,7 +292,7 @@ func TestCreateWebhookPost(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
defer th.TearDown() defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = true })
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id}) hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
if err != nil { if err != nil {
@@ -492,7 +492,7 @@ func TestCreateOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
CreatorId: th.BasicUser.Id, CreatorId: th.BasicUser.Id,
} }
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
createdHook, err := th.App.CreateOutgoingWebhook(&outgoingWebhook) createdHook, err := th.App.CreateOutgoingWebhook(&outgoingWebhook)
@@ -609,9 +609,9 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.EnableOutgoingWebhooks = true *cfg.ServiceSettings.EnableOutgoingWebhooks = true
cfg.ServiceSettings.EnablePostUsernameOverride = testCase.EnablePostUsernameOverride *cfg.ServiceSettings.EnablePostUsernameOverride = testCase.EnablePostUsernameOverride
cfg.ServiceSettings.EnablePostIconOverride = testCase.EnablePostIconOverride *cfg.ServiceSettings.EnablePostIconOverride = testCase.EnablePostIconOverride
}) })
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -673,7 +673,7 @@ func TestDoOutgoingWebhookRequest(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { th.App.UpdateConfig(func(cfg *model.Config) {
cfg.ServiceSettings.AllowedUntrustedInternalConnections = model.NewString("127.0.0.1") cfg.ServiceSettings.AllowedUntrustedInternalConnections = model.NewString("127.0.0.1")
cfg.ServiceSettings.EnableOutgoingWebhooks = true *cfg.ServiceSettings.EnableOutgoingWebhooks = true
}) })
t.Run("with a valid response", func(t *testing.T) { t.Run("with a valid response", func(t *testing.T) {

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

@@ -76,7 +76,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
web.New(server, server.AppOptions, server.Router) web.New(server, server.AppOptions, server.Router)
// If we allow testing then listen for manual testing URL hits // If we allow testing then listen for manual testing URL hits
if server.Config().ServiceSettings.EnableTesting { if *server.Config().ServiceSettings.EnableTesting {
manualtesting.Init(api) manualtesting.Init(api)
} }

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

@@ -94,8 +94,8 @@ func setupClientTests(cfg *model.Config) {
*cfg.TeamSettings.EnableOpenServer = true *cfg.TeamSettings.EnableOpenServer = true
*cfg.ServiceSettings.EnableCommands = false *cfg.ServiceSettings.EnableCommands = false
*cfg.ServiceSettings.EnableCustomEmoji = true *cfg.ServiceSettings.EnableCustomEmoji = true
cfg.ServiceSettings.EnableIncomingWebhooks = false *cfg.ServiceSettings.EnableIncomingWebhooks = false
cfg.ServiceSettings.EnableOutgoingWebhooks = false *cfg.ServiceSettings.EnableOutgoingWebhooks = false
} }
func executeTestCommand(command *exec.Cmd) { func executeTestCommand(command *exec.Cmd) {

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

@@ -21,16 +21,16 @@ func TestListWebhooks(t *testing.T) {
config := th.Config() config := th.Config()
*config.ServiceSettings.EnableCommands = true *config.ServiceSettings.EnableCommands = true
config.ServiceSettings.EnableIncomingWebhooks = true *config.ServiceSettings.EnableIncomingWebhooks = true
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
config.ServiceSettings.EnablePostUsernameOverride = true *config.ServiceSettings.EnablePostUsernameOverride = true
config.ServiceSettings.EnablePostIconOverride = true *config.ServiceSettings.EnablePostIconOverride = true
th.SetConfig(config) th.SetConfig(config)
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.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -139,16 +139,16 @@ func TestCreateIncomingWebhook(t *testing.T) {
config := th.Config() config := th.Config()
*config.ServiceSettings.EnableCommands = true *config.ServiceSettings.EnableCommands = true
config.ServiceSettings.EnableIncomingWebhooks = true *config.ServiceSettings.EnableIncomingWebhooks = true
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
config.ServiceSettings.EnablePostUsernameOverride = true *config.ServiceSettings.EnablePostUsernameOverride = true
config.ServiceSettings.EnablePostIconOverride = true *config.ServiceSettings.EnablePostIconOverride = true
th.SetConfig(config) th.SetConfig(config)
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.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -191,16 +191,16 @@ func TestModifyIncomingWebhook(t *testing.T) {
config := th.Config() config := th.Config()
*config.ServiceSettings.EnableCommands = true *config.ServiceSettings.EnableCommands = true
config.ServiceSettings.EnableIncomingWebhooks = true *config.ServiceSettings.EnableIncomingWebhooks = true
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
config.ServiceSettings.EnablePostUsernameOverride = true *config.ServiceSettings.EnablePostUsernameOverride = true
config.ServiceSettings.EnablePostIconOverride = true *config.ServiceSettings.EnablePostIconOverride = true
th.SetConfig(config) th.SetConfig(config)
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.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -254,16 +254,16 @@ func TestCreateOutgoingWebhook(t *testing.T) {
config := th.Config() config := th.Config()
*config.ServiceSettings.EnableCommands = true *config.ServiceSettings.EnableCommands = true
config.ServiceSettings.EnableIncomingWebhooks = true *config.ServiceSettings.EnableIncomingWebhooks = true
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
config.ServiceSettings.EnablePostUsernameOverride = true *config.ServiceSettings.EnablePostUsernameOverride = true
config.ServiceSettings.EnablePostIconOverride = true *config.ServiceSettings.EnablePostIconOverride = true
th.SetConfig(config) th.SetConfig(config)
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.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {
@@ -322,7 +322,7 @@ func TestModifyOutgoingWebhook(t *testing.T) {
defer th.TearDown() defer th.TearDown()
config := th.Config() config := th.Config()
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
th.SetConfig(config) th.SetConfig(config)
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
@@ -423,16 +423,16 @@ func TestDeleteWebhooks(t *testing.T) {
config := th.Config() config := th.Config()
*config.ServiceSettings.EnableCommands = true *config.ServiceSettings.EnableCommands = true
config.ServiceSettings.EnableIncomingWebhooks = true *config.ServiceSettings.EnableIncomingWebhooks = true
config.ServiceSettings.EnableOutgoingWebhooks = true *config.ServiceSettings.EnableOutgoingWebhooks = true
config.ServiceSettings.EnablePostUsernameOverride = true *config.ServiceSettings.EnablePostUsernameOverride = true
config.ServiceSettings.EnablePostIconOverride = true *config.ServiceSettings.EnablePostIconOverride = true
th.SetConfig(config) th.SetConfig(config)
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.EnableOutgoingWebhooks = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOutgoingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostUsernameOverride = true })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnablePostIconOverride = true })
defaultRolePermissions := th.SaveDefaultRolePermissions() defaultRolePermissions := th.SaveDefaultRolePermissions()
defer func() { defer func() {

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

@@ -197,9 +197,9 @@
"EnablePreviewModeBanner": true, "EnablePreviewModeBanner": true,
"SkipServerCertificateVerification": false, "SkipServerCertificateVerification": false,
"EmailNotificationContentsType": "full", "EmailNotificationContentsType": "full",
"LoginButtonColor": "", "LoginButtonColor": "#0000",
"LoginButtonBorderColor": "", "LoginButtonBorderColor": "#2389D7",
"LoginButtonTextColor": "" "LoginButtonTextColor": "#2389D7"
}, },
"RateLimitSettings": { "RateLimitSettings": {
"Enable": false, "Enable": false,

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

@@ -84,7 +84,7 @@ const (
SITENAME_MAX_LENGTH = 30 SITENAME_MAX_LENGTH = 30
SERVICE_SETTINGS_DEFAULT_SITE_URL = "" SERVICE_SETTINGS_DEFAULT_SITE_URL = "http://localhost:8065"
SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE = "" SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE = ""
SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE = "" SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE = ""
SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT = 300 SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT = 300
@@ -95,6 +95,7 @@ const (
SERVICE_SETTINGS_DEFAULT_GFYCAT_API_KEY = "2_KtH_W5" SERVICE_SETTINGS_DEFAULT_GFYCAT_API_KEY = "2_KtH_W5"
SERVICE_SETTINGS_DEFAULT_GFYCAT_API_SECRET = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof" SERVICE_SETTINGS_DEFAULT_GFYCAT_API_SECRET = "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof"
TEAM_SETTINGS_DEFAULT_SITE_NAME = "Mattermost"
TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM = 50 TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM = 50
TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT = "" TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT = ""
TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT = "" TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT = ""
@@ -145,9 +146,9 @@ const (
TEAM_SETTINGS_DEFAULT_TEAM_TEXT = "default" TEAM_SETTINGS_DEFAULT_TEAM_TEXT = "default"
ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL = "" ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL = "http://dockerhost:9200"
ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME = "" ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME = "elastic"
ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD = "" ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD = "changeme"
ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS = 1 ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_REPLICAS = 1
ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS = 1 ELASTICSEARCH_SETTINGS_DEFAULT_POST_INDEX_SHARDS = 1
ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS = 365 ELASTICSEARCH_SETTINGS_DEFAULT_AGGREGATE_POSTS_AFTER_DAYS = 365
@@ -223,16 +224,16 @@ type ServiceSettings struct {
WriteTimeout *int WriteTimeout *int
MaximumLoginAttempts *int MaximumLoginAttempts *int
GoroutineHealthThreshold *int GoroutineHealthThreshold *int
GoogleDeveloperKey string GoogleDeveloperKey *string
EnableOAuthServiceProvider bool EnableOAuthServiceProvider *bool
EnableIncomingWebhooks bool EnableIncomingWebhooks *bool
EnableOutgoingWebhooks bool EnableOutgoingWebhooks *bool
EnableCommands *bool EnableCommands *bool
DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations *bool `json:"EnableOnlyAdminIntegrations"` // This field is deprecated and must not be used. DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations *bool `json:"EnableOnlyAdminIntegrations"` // This field is deprecated and must not be used.
EnablePostUsernameOverride bool EnablePostUsernameOverride *bool
EnablePostIconOverride bool EnablePostIconOverride *bool
EnableLinkPreviews *bool EnableLinkPreviews *bool
EnableTesting bool EnableTesting *bool
EnableDeveloper *bool EnableDeveloper *bool
EnableSecurityFixAlert *bool EnableSecurityFixAlert *bool
EnableInsecureOutgoingConnections *bool EnableInsecureOutgoingConnections *bool
@@ -314,6 +315,10 @@ func (s *ServiceSettings) SetDefaults() {
s.EnableLinkPreviews = NewBool(false) s.EnableLinkPreviews = NewBool(false)
} }
if s.EnableTesting == nil {
s.EnableTesting = NewBool(false)
}
if s.EnableDeveloper == nil { if s.EnableDeveloper == nil {
s.EnableDeveloper = NewBool(false) s.EnableDeveloper = NewBool(false)
} }
@@ -346,6 +351,26 @@ func (s *ServiceSettings) SetDefaults() {
s.GoroutineHealthThreshold = NewInt(-1) s.GoroutineHealthThreshold = NewInt(-1)
} }
if s.GoogleDeveloperKey == nil {
s.GoogleDeveloperKey = NewString("")
}
if s.EnableOAuthServiceProvider == nil {
s.EnableOAuthServiceProvider = NewBool(false)
}
if s.EnableIncomingWebhooks == nil {
s.EnableIncomingWebhooks = NewBool(true)
}
if s.EnableIncomingWebhooks == nil {
s.EnableIncomingWebhooks = NewBool(true)
}
if s.EnableOutgoingWebhooks == nil {
s.EnableOutgoingWebhooks = NewBool(true)
}
if s.ConnectionSecurity == nil { if s.ConnectionSecurity == nil {
s.ConnectionSecurity = NewString("") s.ConnectionSecurity = NewString("")
} }
@@ -451,13 +476,21 @@ func (s *ServiceSettings) SetDefaults() {
} }
if s.EnableCommands == nil { if s.EnableCommands == nil {
s.EnableCommands = NewBool(false) s.EnableCommands = NewBool(true)
} }
if s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations == nil { if s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations == nil {
s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations = NewBool(true) s.DEPRECATED_DO_NOT_USE_EnableOnlyAdminIntegrations = NewBool(true)
} }
if s.EnablePostUsernameOverride == nil {
s.EnablePostUsernameOverride = NewBool(false)
}
if s.EnablePostIconOverride == nil {
s.EnablePostIconOverride = NewBool(false)
}
if s.WebsocketPort == nil { if s.WebsocketPort == nil {
s.WebsocketPort = NewInt(80) s.WebsocketPort = NewInt(80)
} }
@@ -689,13 +722,43 @@ func (s *AnalyticsSettings) SetDefaults() {
} }
type SSOSettings struct { type SSOSettings struct {
Enable bool Enable *bool
Secret string Secret *string
Id string Id *string
Scope string Scope *string
AuthEndpoint string AuthEndpoint *string
TokenEndpoint string TokenEndpoint *string
UserApiEndpoint string UserApiEndpoint *string
}
func (s *SSOSettings) setDefaults() {
if s.Enable == nil {
s.Enable = NewBool(false)
}
if s.Secret == nil {
s.Secret = NewString("")
}
if s.Id == nil {
s.Id = NewString("")
}
if s.Scope == nil {
s.Scope = NewString("")
}
if s.AuthEndpoint == nil {
s.AuthEndpoint = NewString("")
}
if s.TokenEndpoint == nil {
s.TokenEndpoint = NewString("")
}
if s.UserApiEndpoint == nil {
s.UserApiEndpoint = NewString("")
}
} }
type SqlSettings struct { type SqlSettings struct {
@@ -706,8 +769,8 @@ type SqlSettings struct {
MaxIdleConns *int MaxIdleConns *int
ConnMaxLifetimeMilliseconds *int ConnMaxLifetimeMilliseconds *int
MaxOpenConns *int MaxOpenConns *int
Trace bool Trace *bool
AtRestEncryptKey string AtRestEncryptKey *string
QueryTimeout *int QueryTimeout *int
} }
@@ -720,8 +783,16 @@ func (s *SqlSettings) SetDefaults() {
s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE) s.DataSource = NewString(SQL_SETTINGS_DEFAULT_DATA_SOURCE)
} }
if len(s.AtRestEncryptKey) == 0 { if s.DataSourceReplicas == nil {
s.AtRestEncryptKey = NewRandomString(32) s.DataSourceReplicas = []string{}
}
if s.DataSourceSearchReplicas == nil {
s.DataSourceSearchReplicas = []string{}
}
if s.AtRestEncryptKey == nil || len(*s.AtRestEncryptKey) == 0 {
s.AtRestEncryptKey = NewString(NewRandomString(32))
} }
if s.MaxIdleConns == nil { if s.MaxIdleConns == nil {
@@ -736,24 +807,57 @@ func (s *SqlSettings) SetDefaults() {
s.ConnMaxLifetimeMilliseconds = NewInt(3600000) s.ConnMaxLifetimeMilliseconds = NewInt(3600000)
} }
if s.Trace == nil {
s.Trace = NewBool(false)
}
if s.QueryTimeout == nil { if s.QueryTimeout == nil {
s.QueryTimeout = NewInt(30) s.QueryTimeout = NewInt(30)
} }
} }
type LogSettings struct { type LogSettings struct {
EnableConsole bool EnableConsole *bool
ConsoleLevel string ConsoleLevel *string
ConsoleJson *bool ConsoleJson *bool
EnableFile bool EnableFile *bool
FileLevel string FileLevel *string
FileJson *bool FileJson *bool
FileLocation string FileFormat *string
EnableWebhookDebugging bool FileLocation *string
EnableWebhookDebugging *bool
EnableDiagnostics *bool EnableDiagnostics *bool
} }
func (s *LogSettings) SetDefaults() { func (s *LogSettings) SetDefaults() {
if s.EnableConsole == nil {
s.EnableConsole = NewBool(true)
}
if s.ConsoleLevel == nil {
s.ConsoleLevel = NewString("DEBUG")
}
if s.EnableFile == nil {
s.EnableFile = NewBool(true)
}
if s.FileLevel == nil {
s.FileLevel = NewString("INFO")
}
if s.FileFormat == nil {
s.FileFormat = NewString("")
}
if s.FileLocation == nil {
s.FileLocation = NewString("")
}
if s.EnableWebhookDebugging == nil {
s.EnableWebhookDebugging = NewBool(true)
}
if s.EnableDiagnostics == nil { if s.EnableDiagnostics == nil {
s.EnableDiagnostics = NewBool(true) s.EnableDiagnostics = NewBool(true)
} }
@@ -803,15 +907,15 @@ type FileSettings struct {
EnableMobileDownload *bool EnableMobileDownload *bool
MaxFileSize *int64 MaxFileSize *int64
DriverName *string DriverName *string
Directory string Directory *string
EnablePublicLink bool EnablePublicLink *bool
PublicLinkSalt *string PublicLinkSalt *string
InitialFont string InitialFont *string
AmazonS3AccessKeyId string AmazonS3AccessKeyId *string
AmazonS3SecretAccessKey string AmazonS3SecretAccessKey *string
AmazonS3Bucket string AmazonS3Bucket *string
AmazonS3Region string AmazonS3Region *string
AmazonS3Endpoint string AmazonS3Endpoint *string
AmazonS3SSL *bool AmazonS3SSL *bool
AmazonS3SignV2 *bool AmazonS3SignV2 *bool
AmazonS3SSE *bool AmazonS3SSE *bool
@@ -819,13 +923,62 @@ type FileSettings struct {
} }
func (s *FileSettings) SetDefaults() { func (s *FileSettings) SetDefaults() {
if s.EnableFileAttachments == nil {
s.EnableFileAttachments = NewBool(true)
}
if s.EnableMobileUpload == nil {
s.EnableMobileUpload = NewBool(true)
}
if s.EnableMobileDownload == nil {
s.EnableMobileDownload = NewBool(true)
}
if s.MaxFileSize == nil {
s.MaxFileSize = NewInt64(52428800) // 50 MB
}
if s.DriverName == nil { if s.DriverName == nil {
s.DriverName = NewString(IMAGE_DRIVER_LOCAL) s.DriverName = NewString(IMAGE_DRIVER_LOCAL)
} }
if s.AmazonS3Endpoint == "" { if s.Directory == nil {
s.Directory = NewString(FILE_SETTINGS_DEFAULT_DIRECTORY)
}
if s.EnablePublicLink == nil {
s.EnablePublicLink = NewBool(false)
}
if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 {
s.PublicLinkSalt = NewString(NewRandomString(32))
}
if s.InitialFont == nil {
// Defaults to "nunito-bold.ttf"
s.InitialFont = NewString("nunito-bold.ttf")
}
if s.AmazonS3AccessKeyId == nil {
s.AmazonS3AccessKeyId = NewString("")
}
if s.AmazonS3SecretAccessKey == nil {
s.AmazonS3SecretAccessKey = NewString("")
}
if s.AmazonS3Bucket == nil {
s.AmazonS3Bucket = NewString("")
}
if s.AmazonS3Region == nil {
s.AmazonS3Region = NewString("")
}
if s.AmazonS3Endpoint == nil || len(*s.AmazonS3Endpoint) == 0 {
// Defaults to "s3.amazonaws.com" // Defaults to "s3.amazonaws.com"
s.AmazonS3Endpoint = "s3.amazonaws.com" s.AmazonS3Endpoint = NewString("s3.amazonaws.com")
} }
if s.AmazonS3SSL == nil { if s.AmazonS3SSL == nil {
@@ -844,54 +997,25 @@ func (s *FileSettings) SetDefaults() {
if s.AmazonS3Trace == nil { if s.AmazonS3Trace == nil {
s.AmazonS3Trace = NewBool(false) s.AmazonS3Trace = NewBool(false)
} }
if s.EnableFileAttachments == nil {
s.EnableFileAttachments = NewBool(true)
}
if s.EnableMobileUpload == nil {
s.EnableMobileUpload = NewBool(true)
}
if s.EnableMobileDownload == nil {
s.EnableMobileDownload = NewBool(true)
}
if s.MaxFileSize == nil {
s.MaxFileSize = NewInt64(52428800) // 50 MB
}
if s.PublicLinkSalt == nil || len(*s.PublicLinkSalt) == 0 {
s.PublicLinkSalt = NewString(NewRandomString(32))
}
if s.InitialFont == "" {
// Defaults to "nunito-bold.ttf"
s.InitialFont = "nunito-bold.ttf"
}
if s.Directory == "" {
s.Directory = FILE_SETTINGS_DEFAULT_DIRECTORY
}
} }
type EmailSettings struct { type EmailSettings struct {
EnableSignUpWithEmail bool EnableSignUpWithEmail *bool
EnableSignInWithEmail *bool EnableSignInWithEmail *bool
EnableSignInWithUsername *bool EnableSignInWithUsername *bool
SendEmailNotifications bool SendEmailNotifications *bool
UseChannelInEmailNotifications *bool UseChannelInEmailNotifications *bool
RequireEmailVerification bool RequireEmailVerification *bool
FeedbackName string FeedbackName *string
FeedbackEmail string FeedbackEmail *string
FeedbackOrganization *string FeedbackOrganization *string
EnableSMTPAuth *bool EnableSMTPAuth *bool
SMTPUsername string SMTPUsername *string
SMTPPassword string SMTPPassword *string
SMTPServer string SMTPServer *string
SMTPPort string SMTPPort *string
ConnectionSecurity string ConnectionSecurity *string
InviteSalt string InviteSalt *string
SendPushNotifications *bool SendPushNotifications *bool
PushNotificationServer *string PushNotificationServer *string
PushNotificationContents *string PushNotificationContents *string
@@ -907,22 +1031,74 @@ type EmailSettings struct {
} }
func (s *EmailSettings) SetDefaults() { func (s *EmailSettings) SetDefaults() {
if len(s.InviteSalt) == 0 { if s.EnableSignUpWithEmail == nil {
s.InviteSalt = NewRandomString(32) s.EnableSignUpWithEmail = NewBool(true)
} }
if s.EnableSignInWithEmail == nil { if s.EnableSignInWithEmail == nil {
s.EnableSignInWithEmail = NewBool(s.EnableSignUpWithEmail) s.EnableSignInWithEmail = NewBool(*s.EnableSignUpWithEmail)
} }
if s.EnableSignInWithUsername == nil { if s.EnableSignInWithUsername == nil {
s.EnableSignInWithUsername = NewBool(false) s.EnableSignInWithUsername = NewBool(true)
}
if s.SendEmailNotifications == nil {
s.SendEmailNotifications = NewBool(true)
} }
if s.UseChannelInEmailNotifications == nil { if s.UseChannelInEmailNotifications == nil {
s.UseChannelInEmailNotifications = NewBool(false) s.UseChannelInEmailNotifications = NewBool(false)
} }
if s.RequireEmailVerification == nil {
s.RequireEmailVerification = NewBool(false)
}
if s.FeedbackName == nil {
s.FeedbackName = NewString("")
}
if s.FeedbackEmail == nil {
s.FeedbackEmail = NewString("test@example.com")
}
if s.FeedbackOrganization == nil {
s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION)
}
if s.EnableSMTPAuth == nil {
if s.ConnectionSecurity == nil || *s.ConnectionSecurity == CONN_SECURITY_NONE {
s.EnableSMTPAuth = NewBool(false)
} else {
s.EnableSMTPAuth = NewBool(true)
}
}
if s.SMTPUsername == nil {
s.SMTPUsername = NewString("")
}
if s.SMTPPassword == nil {
s.SMTPPassword = NewString("")
}
if s.SMTPServer == nil || len(*s.SMTPServer) == 0 {
s.SMTPServer = NewString("dockerhost")
}
if s.SMTPPort == nil || len(*s.SMTPPort) == 0 {
s.SMTPPort = NewString("2500")
}
if s.ConnectionSecurity == nil || *s.ConnectionSecurity == CONN_SECURITY_PLAIN {
s.ConnectionSecurity = NewString(CONN_SECURITY_NONE)
}
if s.InviteSalt == nil || len(*s.InviteSalt) == 0 {
s.InviteSalt = NewString(NewRandomString(32))
}
if s.SendPushNotifications == nil { if s.SendPushNotifications == nil {
s.SendPushNotifications = NewBool(false) s.SendPushNotifications = NewBool(false)
} }
@@ -935,10 +1111,6 @@ func (s *EmailSettings) SetDefaults() {
s.PushNotificationContents = NewString(GENERIC_NOTIFICATION) s.PushNotificationContents = NewString(GENERIC_NOTIFICATION)
} }
if s.FeedbackOrganization == nil {
s.FeedbackOrganization = NewString(EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION)
}
if s.EnableEmailBatching == nil { if s.EnableEmailBatching == nil {
s.EnableEmailBatching = NewBool(false) s.EnableEmailBatching = NewBool(false)
} }
@@ -956,16 +1128,15 @@ func (s *EmailSettings) SetDefaults() {
} }
if s.EnableSMTPAuth == nil { if s.EnableSMTPAuth == nil {
s.EnableSMTPAuth = new(bool) if *s.ConnectionSecurity == CONN_SECURITY_NONE {
if s.ConnectionSecurity == CONN_SECURITY_NONE { s.EnableSMTPAuth = NewBool(false)
*s.EnableSMTPAuth = false
} else { } else {
*s.EnableSMTPAuth = true s.EnableSMTPAuth = NewBool(true)
} }
} }
if s.ConnectionSecurity == CONN_SECURITY_PLAIN { if *s.ConnectionSecurity == CONN_SECURITY_PLAIN {
s.ConnectionSecurity = CONN_SECURITY_NONE *s.ConnectionSecurity = CONN_SECURITY_NONE
} }
if s.SkipServerCertificateVerification == nil { if s.SkipServerCertificateVerification == nil {
@@ -1026,8 +1197,18 @@ func (s *RateLimitSettings) SetDefaults() {
} }
type PrivacySettings struct { type PrivacySettings struct {
ShowEmailAddress bool ShowEmailAddress *bool
ShowFullName bool ShowFullName *bool
}
func (s *PrivacySettings) setDefaults() {
if s.ShowEmailAddress == nil {
s.ShowEmailAddress = NewBool(true)
}
if s.ShowFullName == nil {
s.ShowFullName = NewBool(true)
}
} }
type SupportSettings struct { type SupportSettings struct {
@@ -1151,13 +1332,13 @@ func (s *ThemeSettings) SetDefaults() {
} }
type TeamSettings struct { type TeamSettings struct {
SiteName string SiteName *string
MaxUsersPerTeam *int MaxUsersPerTeam *int
DEPRECATED_DO_NOT_USE_EnableTeamCreation *bool `json:"EnableTeamCreation"` // This field is deprecated and must not be used. DEPRECATED_DO_NOT_USE_EnableTeamCreation *bool `json:"EnableTeamCreation"` // This field is deprecated and must not be used.
EnableUserCreation *bool EnableUserCreation *bool
EnableOpenServer *bool EnableOpenServer *bool
EnableUserDeactivation *bool EnableUserDeactivation *bool
RestrictCreationToDomains string RestrictCreationToDomains *string
EnableCustomBrand *bool EnableCustomBrand *bool
CustomBrandText *string CustomBrandText *string
CustomDescriptionText *string CustomDescriptionText *string
@@ -1185,10 +1366,31 @@ type TeamSettings struct {
} }
func (s *TeamSettings) SetDefaults() { func (s *TeamSettings) SetDefaults() {
if s.SiteName == nil {
s.SiteName = NewString(TEAM_SETTINGS_DEFAULT_SITE_NAME)
}
if s.MaxUsersPerTeam == nil { if s.MaxUsersPerTeam == nil {
s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM) s.MaxUsersPerTeam = NewInt(TEAM_SETTINGS_DEFAULT_MAX_USERS_PER_TEAM)
} }
if s.DEPRECATED_DO_NOT_USE_EnableTeamCreation == nil {
s.DEPRECATED_DO_NOT_USE_EnableTeamCreation = NewBool(true)
}
if s.EnableUserCreation == nil {
s.EnableUserCreation = NewBool(true)
}
if s.EnableOpenServer == nil {
s.EnableOpenServer = NewBool(false)
}
if s.RestrictCreationToDomains == nil {
s.RestrictCreationToDomains = NewString("")
}
if s.EnableCustomBrand == nil { if s.EnableCustomBrand == nil {
s.EnableCustomBrand = NewBool(false) s.EnableCustomBrand = NewBool(false)
} }
@@ -1205,10 +1407,6 @@ func (s *TeamSettings) SetDefaults() {
s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT) s.CustomDescriptionText = NewString(TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT)
} }
if s.EnableOpenServer == nil {
s.EnableOpenServer = NewBool(false)
}
if s.RestrictDirectMessage == nil { if s.RestrictDirectMessage == nil {
s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY) s.RestrictDirectMessage = NewString(DIRECT_MESSAGE_ANY)
} }
@@ -2056,6 +2254,10 @@ func (o *Config) SetDefaults() {
o.SqlSettings.SetDefaults() o.SqlSettings.SetDefaults()
o.FileSettings.SetDefaults() o.FileSettings.SetDefaults()
o.EmailSettings.SetDefaults() o.EmailSettings.SetDefaults()
o.PrivacySettings.setDefaults()
o.Office365Settings.setDefaults()
o.GitLabSettings.setDefaults()
o.GoogleSettings.setDefaults()
o.ServiceSettings.SetDefaults() o.ServiceSettings.SetDefaults()
o.PasswordSettings.SetDefaults() o.PasswordSettings.SetDefaults()
o.TeamSettings.SetDefaults() o.TeamSettings.SetDefaults()
@@ -2178,7 +2380,7 @@ func (ts *TeamSettings) isValid() *AppError {
return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest) return NewAppError("Config.IsValid", "model.config.is_valid.teammate_name_display.app_error", nil, "", http.StatusBadRequest)
} }
if len(ts.SiteName) > SITENAME_MAX_LENGTH { if len(*ts.SiteName) > SITENAME_MAX_LENGTH {
return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest) return NewAppError("Config.IsValid", "model.config.is_valid.sitename_length.app_error", map[string]interface{}{"MaxLength": SITENAME_MAX_LENGTH}, "", http.StatusBadRequest)
} }
@@ -2186,7 +2388,7 @@ func (ts *TeamSettings) isValid() *AppError {
} }
func (ss *SqlSettings) isValid() *AppError { func (ss *SqlSettings) isValid() *AppError {
if len(ss.AtRestEncryptKey) < 32 { if len(*ss.AtRestEncryptKey) < 32 {
return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest) return NewAppError("Config.IsValid", "model.config.is_valid.encrypt_sql.app_error", nil, "", http.StatusBadRequest)
} }
@@ -2234,11 +2436,11 @@ func (fs *FileSettings) isValid() *AppError {
} }
func (es *EmailSettings) isValid() *AppError { func (es *EmailSettings) isValid() *AppError {
if !(es.ConnectionSecurity == CONN_SECURITY_NONE || es.ConnectionSecurity == CONN_SECURITY_TLS || es.ConnectionSecurity == CONN_SECURITY_STARTTLS || es.ConnectionSecurity == CONN_SECURITY_PLAIN) { if !(*es.ConnectionSecurity == CONN_SECURITY_NONE || *es.ConnectionSecurity == CONN_SECURITY_TLS || *es.ConnectionSecurity == CONN_SECURITY_STARTTLS || *es.ConnectionSecurity == CONN_SECURITY_PLAIN) {
return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest) return NewAppError("Config.IsValid", "model.config.is_valid.email_security.app_error", nil, "", http.StatusBadRequest)
} }
if len(es.InviteSalt) < 32 { if len(*es.InviteSalt) < 32 {
return NewAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "", http.StatusBadRequest) return NewAppError("Config.IsValid", "model.config.is_valid.email_salt.app_error", nil, "", http.StatusBadRequest)
} }
@@ -2580,8 +2782,8 @@ func (ips *ImageProxySettings) isValid() *AppError {
func (o *Config) GetSanitizeOptions() map[string]bool { func (o *Config) GetSanitizeOptions() map[string]bool {
options := map[string]bool{} options := map[string]bool{}
options["fullname"] = o.PrivacySettings.ShowFullName options["fullname"] = *o.PrivacySettings.ShowFullName
options["email"] = o.PrivacySettings.ShowEmailAddress options["email"] = *o.PrivacySettings.ShowEmailAddress
return options return options
} }
@@ -2592,21 +2794,21 @@ func (o *Config) Sanitize() {
} }
*o.FileSettings.PublicLinkSalt = FAKE_SETTING *o.FileSettings.PublicLinkSalt = FAKE_SETTING
if len(o.FileSettings.AmazonS3SecretAccessKey) > 0 { if len(*o.FileSettings.AmazonS3SecretAccessKey) > 0 {
o.FileSettings.AmazonS3SecretAccessKey = FAKE_SETTING *o.FileSettings.AmazonS3SecretAccessKey = FAKE_SETTING
} }
o.EmailSettings.InviteSalt = FAKE_SETTING *o.EmailSettings.InviteSalt = FAKE_SETTING
if len(o.EmailSettings.SMTPPassword) > 0 { if len(*o.EmailSettings.SMTPPassword) > 0 {
o.EmailSettings.SMTPPassword = FAKE_SETTING *o.EmailSettings.SMTPPassword = FAKE_SETTING
} }
if len(o.GitLabSettings.Secret) > 0 { if len(*o.GitLabSettings.Secret) > 0 {
o.GitLabSettings.Secret = FAKE_SETTING *o.GitLabSettings.Secret = FAKE_SETTING
} }
*o.SqlSettings.DataSource = FAKE_SETTING *o.SqlSettings.DataSource = FAKE_SETTING
o.SqlSettings.AtRestEncryptKey = FAKE_SETTING *o.SqlSettings.AtRestEncryptKey = FAKE_SETTING
for i := range o.SqlSettings.DataSourceReplicas { for i := range o.SqlSettings.DataSourceReplicas {
o.SqlSettings.DataSourceReplicas[i] = FAKE_SETTING o.SqlSettings.DataSourceReplicas[i] = FAKE_SETTING

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

@@ -59,7 +59,7 @@ func TestConfigDefaultFileSettingsDirectory(t *testing.T) {
c1 := Config{} c1 := Config{}
c1.SetDefaults() c1.SetDefaults()
if c1.FileSettings.Directory != "./data/" { if *c1.FileSettings.Directory != "./data/" {
t.Fatal("FileSettings.Directory should default to './data/'") t.Fatal("FileSettings.Directory should default to './data/'")
} }
} }

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

@@ -29,19 +29,19 @@ func NewFileBackend(settings *model.FileSettings, enableComplianceFeatures bool)
switch *settings.DriverName { switch *settings.DriverName {
case model.IMAGE_DRIVER_S3: case model.IMAGE_DRIVER_S3:
return &S3FileBackend{ return &S3FileBackend{
endpoint: settings.AmazonS3Endpoint, endpoint: *settings.AmazonS3Endpoint,
accessKey: settings.AmazonS3AccessKeyId, accessKey: *settings.AmazonS3AccessKeyId,
secretKey: settings.AmazonS3SecretAccessKey, secretKey: *settings.AmazonS3SecretAccessKey,
secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL, secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL,
signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2, signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2,
region: settings.AmazonS3Region, region: *settings.AmazonS3Region,
bucket: settings.AmazonS3Bucket, bucket: *settings.AmazonS3Bucket,
encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures, encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures,
trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace, trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace,
}, nil }, nil
case model.IMAGE_DRIVER_LOCAL: case model.IMAGE_DRIVER_LOCAL:
return &LocalFileBackend{ return &LocalFileBackend{
directory: settings.Directory, directory: *settings.Directory,
}, nil }, nil
} }
return nil, model.NewAppError("NewFileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError) return nil, model.NewAppError("NewFileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError)

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

@@ -42,7 +42,7 @@ func TestLocalFileBackendTestSuite(t *testing.T) {
suite.Run(t, &FileBackendTestSuite{ suite.Run(t, &FileBackendTestSuite{
settings: model.FileSettings{ settings: model.FileSettings{
DriverName: model.NewString(model.IMAGE_DRIVER_LOCAL), DriverName: model.NewString(model.IMAGE_DRIVER_LOCAL),
Directory: dir, Directory: &dir,
}, },
}) })
} }
@@ -71,10 +71,11 @@ func runBackendTest(t *testing.T, encrypt bool) {
suite.Run(t, &FileBackendTestSuite{ suite.Run(t, &FileBackendTestSuite{
settings: model.FileSettings{ settings: model.FileSettings{
DriverName: model.NewString(model.IMAGE_DRIVER_S3), DriverName: model.NewString(model.IMAGE_DRIVER_S3),
AmazonS3AccessKeyId: model.MINIO_ACCESS_KEY, AmazonS3AccessKeyId: model.NewString(model.MINIO_ACCESS_KEY),
AmazonS3SecretAccessKey: model.MINIO_SECRET_KEY, AmazonS3SecretAccessKey: model.NewString(model.MINIO_SECRET_KEY),
AmazonS3Bucket: model.MINIO_BUCKET, AmazonS3Bucket: model.NewString(model.MINIO_BUCKET),
AmazonS3Endpoint: s3Endpoint, AmazonS3Region: model.NewString(""),
AmazonS3Endpoint: model.NewString(s3Endpoint),
AmazonS3SSL: model.NewBool(false), AmazonS3SSL: model.NewBool(false),
AmazonS3SSE: model.NewBool(encrypt), AmazonS3SSE: model.NewBool(encrypt),
}, },

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

@@ -281,12 +281,12 @@ func s3PutOptions(encrypted bool, contentType string) s3.PutObjectOptions {
} }
func CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError { func CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError {
if len(settings.AmazonS3Bucket) == 0 { if settings.AmazonS3Bucket == nil || len(*settings.AmazonS3Bucket) == 0 {
return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_bucket", nil, "", http.StatusBadRequest) return model.NewAppError("S3File", "api.admin.test_s3.missing_s3_bucket", nil, "", http.StatusBadRequest)
} }
// if S3 endpoint is not set call the set defaults to set that // if S3 endpoint is not set call the set defaults to set that
if len(settings.AmazonS3Endpoint) == 0 { if settings.AmazonS3Endpoint == nil || len(*settings.AmazonS3Endpoint) == 0 {
settings.SetDefaults() settings.SetDefaults()
} }

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

@@ -17,15 +17,15 @@ func TestCheckMandatoryS3Fields(t *testing.T) {
t.Fatal("should've failed with missing s3 bucket") t.Fatal("should've failed with missing s3 bucket")
} }
cfg.AmazonS3Bucket = "test-mm" cfg.AmazonS3Bucket = model.NewString("test-mm")
err = CheckMandatoryS3Fields(&cfg) err = CheckMandatoryS3Fields(&cfg)
if err != nil { if err != nil {
t.Fatal("should've not failed") t.Fatal("should've not failed")
} }
cfg.AmazonS3Endpoint = "" cfg.AmazonS3Endpoint = model.NewString("")
err = CheckMandatoryS3Fields(&cfg) err = CheckMandatoryS3Fields(&cfg)
if err != nil || cfg.AmazonS3Endpoint != "s3.amazonaws.com" { if err != nil || *cfg.AmazonS3Endpoint != "s3.amazonaws.com" {
t.Fatal("should've not failed because it should set the endpoint to the default") t.Fatal("should've not failed because it should set the endpoint to the default")
} }

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

@@ -119,11 +119,11 @@ func ConnectToSMTPServerAdvanced(connectionInfo *SmtpConnectionInfo) (net.Conn,
func ConnectToSMTPServer(config *model.Config) (net.Conn, *model.AppError) { func ConnectToSMTPServer(config *model.Config) (net.Conn, *model.AppError) {
return ConnectToSMTPServerAdvanced( return ConnectToSMTPServerAdvanced(
&SmtpConnectionInfo{ &SmtpConnectionInfo{
ConnectionSecurity: config.EmailSettings.ConnectionSecurity, ConnectionSecurity: *config.EmailSettings.ConnectionSecurity,
SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification, SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification,
SmtpServerName: config.EmailSettings.SMTPServer, SmtpServerName: *config.EmailSettings.SMTPServer,
SmtpServerHost: config.EmailSettings.SMTPServer, SmtpServerHost: *config.EmailSettings.SMTPServer,
SmtpPort: config.EmailSettings.SMTPPort, SmtpPort: *config.EmailSettings.SMTPPort,
}, },
) )
} }
@@ -164,20 +164,20 @@ func NewSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
conn, conn,
utils.GetHostnameFromSiteURL(*config.ServiceSettings.SiteURL), utils.GetHostnameFromSiteURL(*config.ServiceSettings.SiteURL),
&SmtpConnectionInfo{ &SmtpConnectionInfo{
ConnectionSecurity: config.EmailSettings.ConnectionSecurity, ConnectionSecurity: *config.EmailSettings.ConnectionSecurity,
SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification, SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification,
SmtpServerName: config.EmailSettings.SMTPServer, SmtpServerName: *config.EmailSettings.SMTPServer,
SmtpServerHost: config.EmailSettings.SMTPServer, SmtpServerHost: *config.EmailSettings.SMTPServer,
SmtpPort: config.EmailSettings.SMTPPort, SmtpPort: *config.EmailSettings.SMTPPort,
Auth: *config.EmailSettings.EnableSMTPAuth, Auth: *config.EmailSettings.EnableSMTPAuth,
SmtpUsername: config.EmailSettings.SMTPUsername, SmtpUsername: *config.EmailSettings.SMTPUsername,
SmtpPassword: config.EmailSettings.SMTPPassword, SmtpPassword: *config.EmailSettings.SMTPPassword,
}, },
) )
} }
func TestConnection(config *model.Config) { func TestConnection(config *model.Config) {
if !config.EmailSettings.SendEmailNotifications { if !*config.EmailSettings.SendEmailNotifications {
return return
} }
@@ -198,14 +198,14 @@ func TestConnection(config *model.Config) {
} }
func SendMailUsingConfig(to, subject, htmlBody string, config *model.Config, enableComplianceFeatures bool) *model.AppError { func SendMailUsingConfig(to, subject, htmlBody string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
fromMail := mail.Address{Name: config.EmailSettings.FeedbackName, Address: config.EmailSettings.FeedbackEmail} fromMail := mail.Address{Name: *config.EmailSettings.FeedbackName, Address: *config.EmailSettings.FeedbackEmail}
return SendMailUsingConfigAdvanced(to, to, fromMail, subject, htmlBody, nil, nil, config, enableComplianceFeatures) return SendMailUsingConfigAdvanced(to, to, fromMail, subject, htmlBody, nil, nil, config, enableComplianceFeatures)
} }
// allows for sending an email with attachments and differing MIME/SMTP recipients // allows for sending an email with attachments and differing MIME/SMTP recipients
func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, config *model.Config, enableComplianceFeatures bool) *model.AppError { func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, config *model.Config, enableComplianceFeatures bool) *model.AppError {
if !config.EmailSettings.SendEmailNotifications || len(config.EmailSettings.SMTPServer) == 0 { if !*config.EmailSettings.SendEmailNotifications || len(*config.EmailSettings.SMTPServer) == 0 {
return nil return nil
} }

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

@@ -33,8 +33,8 @@ func TestMailConnectionFromConfig(t *testing.T) {
} }
} }
cfg.EmailSettings.SMTPServer = "wrongServer" *cfg.EmailSettings.SMTPServer = "wrongServer"
cfg.EmailSettings.SMTPPort = "553" *cfg.EmailSettings.SMTPPort = "553"
if _, err := ConnectToSMTPServer(cfg); err == nil { if _, err := ConnectToSMTPServer(cfg); err == nil {
t.Log(err) t.Log(err)
@@ -48,11 +48,11 @@ func TestMailConnectionAdvanced(t *testing.T) {
if conn, err := ConnectToSMTPServerAdvanced( if conn, err := ConnectToSMTPServerAdvanced(
&SmtpConnectionInfo{ &SmtpConnectionInfo{
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity, ConnectionSecurity: *cfg.EmailSettings.ConnectionSecurity,
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification, SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
SmtpServerName: cfg.EmailSettings.SMTPServer, SmtpServerName: *cfg.EmailSettings.SMTPServer,
SmtpServerHost: cfg.EmailSettings.SMTPServer, SmtpServerHost: *cfg.EmailSettings.SMTPServer,
SmtpPort: cfg.EmailSettings.SMTPPort, SmtpPort: *cfg.EmailSettings.SMTPPort,
}, },
); err != nil { ); err != nil {
t.Log(err) t.Log(err)
@@ -62,14 +62,14 @@ func TestMailConnectionAdvanced(t *testing.T) {
conn, conn,
utils.GetHostnameFromSiteURL(*cfg.ServiceSettings.SiteURL), utils.GetHostnameFromSiteURL(*cfg.ServiceSettings.SiteURL),
&SmtpConnectionInfo{ &SmtpConnectionInfo{
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity, ConnectionSecurity: *cfg.EmailSettings.ConnectionSecurity,
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification, SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
SmtpServerName: cfg.EmailSettings.SMTPServer, SmtpServerName: *cfg.EmailSettings.SMTPServer,
SmtpServerHost: cfg.EmailSettings.SMTPServer, SmtpServerHost: *cfg.EmailSettings.SMTPServer,
SmtpPort: cfg.EmailSettings.SMTPPort, SmtpPort: *cfg.EmailSettings.SMTPPort,
Auth: *cfg.EmailSettings.EnableSMTPAuth, Auth: *cfg.EmailSettings.EnableSMTPAuth,
SmtpUsername: cfg.EmailSettings.SMTPUsername, SmtpUsername: *cfg.EmailSettings.SMTPUsername,
SmtpPassword: cfg.EmailSettings.SMTPPassword, SmtpPassword: *cfg.EmailSettings.SMTPPassword,
}, },
); err1 != nil { ); err1 != nil {
t.Log(err) t.Log(err)
@@ -79,7 +79,7 @@ func TestMailConnectionAdvanced(t *testing.T) {
if _, err := ConnectToSMTPServerAdvanced( if _, err := ConnectToSMTPServerAdvanced(
&SmtpConnectionInfo{ &SmtpConnectionInfo{
ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity, ConnectionSecurity: *cfg.EmailSettings.ConnectionSecurity,
SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification, SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification,
SmtpServerName: "wrongServer", SmtpServerName: "wrongServer",
SmtpServerHost: "wrongServer", SmtpServerHost: "wrongServer",

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

@@ -250,7 +250,7 @@ func setupConnection(con_type string, dataSource string, settings *model.SqlSett
os.Exit(EXIT_NO_DRIVER) os.Exit(EXIT_NO_DRIVER)
} }
if settings.Trace { if settings.Trace != nil && *settings.Trace {
dbmap.TraceOn("", sqltrace.New(os.Stdout, "sql-trace:", sqltrace.Lmicroseconds)) dbmap.TraceOn("", sqltrace.New(os.Stdout, "sql-trace:", sqltrace.Lmicroseconds))
} }

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

@@ -136,8 +136,8 @@ func databaseSettings(driver, dataSource string) *model.SqlSettings {
MaxIdleConns: new(int), MaxIdleConns: new(int),
ConnMaxLifetimeMilliseconds: new(int), ConnMaxLifetimeMilliseconds: new(int),
MaxOpenConns: new(int), MaxOpenConns: new(int),
Trace: false, Trace: model.NewBool(false),
AtRestEncryptKey: model.NewRandomString(32), AtRestEncryptKey: model.NewString(model.NewRandomString(32)),
QueryTimeout: new(int), QueryTimeout: new(int),
} }
*settings.MaxIdleConns = 10 *settings.MaxIdleConns = 10

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

@@ -45,13 +45,13 @@ var (
func MloggerConfigFromLoggerConfig(s *model.LogSettings) *mlog.LoggerConfiguration { func MloggerConfigFromLoggerConfig(s *model.LogSettings) *mlog.LoggerConfiguration {
return &mlog.LoggerConfiguration{ return &mlog.LoggerConfiguration{
EnableConsole: s.EnableConsole, EnableConsole: *s.EnableConsole,
ConsoleJson: *s.ConsoleJson, ConsoleJson: *s.ConsoleJson,
ConsoleLevel: strings.ToLower(s.ConsoleLevel), ConsoleLevel: strings.ToLower(*s.ConsoleLevel),
EnableFile: s.EnableFile, EnableFile: *s.EnableFile,
FileJson: *s.FileJson, FileJson: *s.FileJson,
FileLevel: strings.ToLower(s.FileLevel), FileLevel: strings.ToLower(*s.FileLevel),
FileLocation: GetLogFileLocation(s.FileLocation), FileLocation: GetLogFileLocation(*s.FileLocation),
} }
} }
@@ -390,8 +390,9 @@ func LoadConfig(fileName string) (*model.Config, string, map[string]interface{},
return nil, "", nil, appErr return nil, "", nil, appErr
} }
needSave := len(config.SqlSettings.AtRestEncryptKey) == 0 || len(*config.FileSettings.PublicLinkSalt) == 0 || needSave := config.SqlSettings.AtRestEncryptKey == nil || len(*config.SqlSettings.AtRestEncryptKey) == 0 ||
len(config.EmailSettings.InviteSalt) == 0 config.FileSettings.PublicLinkSalt == nil || len(*config.FileSettings.PublicLinkSalt) == 0 ||
config.EmailSettings.InviteSalt == nil || len(*config.EmailSettings.InviteSalt) == 0
config.SetDefaults() config.SetDefaults()
@@ -416,8 +417,9 @@ func LoadConfig(fileName string) (*model.Config, string, map[string]interface{},
if *config.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if *config.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
dir := config.FileSettings.Directory dir := config.FileSettings.Directory
if len(dir) > 0 && dir[len(dir)-1:] != "/" { dirString := *dir
config.FileSettings.Directory += "/" if len(*dir) > 0 && dirString[len(dirString)-1:] != "/" {
*config.FileSettings.Directory += "/"
} }
} }
@@ -435,16 +437,16 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
props["ExperimentalPrimaryTeam"] = *c.TeamSettings.ExperimentalPrimaryTeam props["ExperimentalPrimaryTeam"] = *c.TeamSettings.ExperimentalPrimaryTeam
props["ExperimentalViewArchivedChannels"] = strconv.FormatBool(*c.TeamSettings.ExperimentalViewArchivedChannels) props["ExperimentalViewArchivedChannels"] = strconv.FormatBool(*c.TeamSettings.ExperimentalViewArchivedChannels)
props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider) props["EnableOAuthServiceProvider"] = strconv.FormatBool(*c.ServiceSettings.EnableOAuthServiceProvider)
props["GoogleDeveloperKey"] = c.ServiceSettings.GoogleDeveloperKey props["GoogleDeveloperKey"] = *c.ServiceSettings.GoogleDeveloperKey
props["EnableIncomingWebhooks"] = strconv.FormatBool(c.ServiceSettings.EnableIncomingWebhooks) props["EnableIncomingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableIncomingWebhooks)
props["EnableOutgoingWebhooks"] = strconv.FormatBool(c.ServiceSettings.EnableOutgoingWebhooks) props["EnableOutgoingWebhooks"] = strconv.FormatBool(*c.ServiceSettings.EnableOutgoingWebhooks)
props["EnableCommands"] = strconv.FormatBool(*c.ServiceSettings.EnableCommands) props["EnableCommands"] = strconv.FormatBool(*c.ServiceSettings.EnableCommands)
props["EnablePostUsernameOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostUsernameOverride) props["EnablePostUsernameOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostUsernameOverride)
props["EnablePostIconOverride"] = strconv.FormatBool(c.ServiceSettings.EnablePostIconOverride) props["EnablePostIconOverride"] = strconv.FormatBool(*c.ServiceSettings.EnablePostIconOverride)
props["EnableUserAccessTokens"] = strconv.FormatBool(*c.ServiceSettings.EnableUserAccessTokens) props["EnableUserAccessTokens"] = strconv.FormatBool(*c.ServiceSettings.EnableUserAccessTokens)
props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews) props["EnableLinkPreviews"] = strconv.FormatBool(*c.ServiceSettings.EnableLinkPreviews)
props["EnableTesting"] = strconv.FormatBool(c.ServiceSettings.EnableTesting) props["EnableTesting"] = strconv.FormatBool(*c.ServiceSettings.EnableTesting)
props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper) props["EnableDeveloper"] = strconv.FormatBool(*c.ServiceSettings.EnableDeveloper)
props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit) props["PostEditTimeLimit"] = fmt.Sprintf("%v", *c.ServiceSettings.PostEditTimeLimit)
props["CloseUnusedDirectMessages"] = strconv.FormatBool(*c.ServiceSettings.CloseUnusedDirectMessages) props["CloseUnusedDirectMessages"] = strconv.FormatBool(*c.ServiceSettings.CloseUnusedDirectMessages)
@@ -463,17 +465,17 @@ func GenerateClientConfig(c *model.Config, diagnosticId string, license *model.L
props["ExperimentalEnableAutomaticReplies"] = strconv.FormatBool(*c.TeamSettings.ExperimentalEnableAutomaticReplies) props["ExperimentalEnableAutomaticReplies"] = strconv.FormatBool(*c.TeamSettings.ExperimentalEnableAutomaticReplies)
props["ExperimentalTimezone"] = strconv.FormatBool(*c.DisplaySettings.ExperimentalTimezone) props["ExperimentalTimezone"] = strconv.FormatBool(*c.DisplaySettings.ExperimentalTimezone)
props["SendEmailNotifications"] = strconv.FormatBool(c.EmailSettings.SendEmailNotifications) props["SendEmailNotifications"] = strconv.FormatBool(*c.EmailSettings.SendEmailNotifications)
props["SendPushNotifications"] = strconv.FormatBool(*c.EmailSettings.SendPushNotifications) props["SendPushNotifications"] = strconv.FormatBool(*c.EmailSettings.SendPushNotifications)
props["RequireEmailVerification"] = strconv.FormatBool(c.EmailSettings.RequireEmailVerification) props["RequireEmailVerification"] = strconv.FormatBool(*c.EmailSettings.RequireEmailVerification)
props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching) props["EnableEmailBatching"] = strconv.FormatBool(*c.EmailSettings.EnableEmailBatching)
props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner) props["EnablePreviewModeBanner"] = strconv.FormatBool(*c.EmailSettings.EnablePreviewModeBanner)
props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType props["EmailNotificationContentsType"] = *c.EmailSettings.EmailNotificationContentsType
props["ShowEmailAddress"] = strconv.FormatBool(c.PrivacySettings.ShowEmailAddress) props["ShowEmailAddress"] = strconv.FormatBool(*c.PrivacySettings.ShowEmailAddress)
props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments) props["EnableFileAttachments"] = strconv.FormatBool(*c.FileSettings.EnableFileAttachments)
props["EnablePublicLink"] = strconv.FormatBool(c.FileSettings.EnablePublicLink) props["EnablePublicLink"] = strconv.FormatBool(*c.FileSettings.EnablePublicLink)
props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales
props["SQLDriverName"] = *c.SqlSettings.DriverName props["SQLDriverName"] = *c.SqlSettings.DriverName
@@ -605,7 +607,7 @@ func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *
props["BuildHashEnterprise"] = model.BuildHashEnterprise props["BuildHashEnterprise"] = model.BuildHashEnterprise
props["BuildEnterpriseReady"] = model.BuildEnterpriseReady props["BuildEnterpriseReady"] = model.BuildEnterpriseReady
props["SiteName"] = c.TeamSettings.SiteName props["SiteName"] = *c.TeamSettings.SiteName
props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/") props["WebsocketURL"] = strings.TrimRight(*c.ServiceSettings.WebsocketURL, "/")
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
@@ -621,7 +623,7 @@ func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *
props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics) props["EnableDiagnostics"] = strconv.FormatBool(*c.LogSettings.EnableDiagnostics)
props["EnableSignUpWithEmail"] = strconv.FormatBool(c.EmailSettings.EnableSignUpWithEmail) props["EnableSignUpWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignUpWithEmail)
props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail) props["EnableSignInWithEmail"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithEmail)
props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername) props["EnableSignInWithUsername"] = strconv.FormatBool(*c.EmailSettings.EnableSignInWithUsername)
@@ -629,7 +631,7 @@ func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *
props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor props["EmailLoginButtonBorderColor"] = *c.EmailSettings.LoginButtonBorderColor
props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor props["EmailLoginButtonTextColor"] = *c.EmailSettings.LoginButtonTextColor
props["EnableSignUpWithGitLab"] = strconv.FormatBool(c.GitLabSettings.Enable) props["EnableSignUpWithGitLab"] = strconv.FormatBool(*c.GitLabSettings.Enable)
props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink props["TermsOfServiceLink"] = *c.SupportSettings.TermsOfServiceLink
props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink props["PrivacyPolicyLink"] = *c.SupportSettings.PrivacyPolicyLink
@@ -692,11 +694,11 @@ func GenerateLimitedClientConfig(c *model.Config, diagnosticId string, license *
} }
if *license.Features.GoogleOAuth { if *license.Features.GoogleOAuth {
props["EnableSignUpWithGoogle"] = strconv.FormatBool(c.GoogleSettings.Enable) props["EnableSignUpWithGoogle"] = strconv.FormatBool(*c.GoogleSettings.Enable)
} }
if *license.Features.Office365OAuth { if *license.Features.Office365OAuth {
props["EnableSignUpWithOffice365"] = strconv.FormatBool(c.Office365Settings.Enable) props["EnableSignUpWithOffice365"] = strconv.FormatBool(*c.Office365Settings.Enable)
} }
if *license.Features.CustomTermsOfService { if *license.Features.CustomTermsOfService {

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

@@ -148,7 +148,7 @@ func TestConfigFromEnviroVars(t *testing.T) {
cfg, envCfg, err := ReadConfig(strings.NewReader(config), true) cfg, envCfg, err := ReadConfig(strings.NewReader(config), true)
require.Nil(t, err) require.Nil(t, err)
if cfg.TeamSettings.SiteName != "From Environment" { if *cfg.TeamSettings.SiteName != "From Environment" {
t.Fatal("Couldn't read config from environment var") t.Fatal("Couldn't read config from environment var")
} }
@@ -176,7 +176,7 @@ func TestConfigFromEnviroVars(t *testing.T) {
cfg, envCfg, err = ReadConfig(strings.NewReader(config), true) cfg, envCfg, err = ReadConfig(strings.NewReader(config), true)
require.Nil(t, err) require.Nil(t, err)
if cfg.TeamSettings.SiteName != "Mattermost" { if *cfg.TeamSettings.SiteName != "Mattermost" {
t.Fatal("should have been reset") t.Fatal("should have been reset")
} }

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

@@ -56,7 +56,7 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
} }
} }
if c.App.Config().LogSettings.EnableWebhookDebugging { if *c.App.Config().LogSettings.EnableWebhookDebugging {
mlog.Debug(fmt.Sprintf("Incoming webhook received. Id=%s Content=%s", id, incomingWebhookPayload.ToJson())) mlog.Debug(fmt.Sprintf("Incoming webhook received. Id=%s Content=%s", id, incomingWebhookPayload.ToJson()))
} }

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

@@ -20,7 +20,7 @@ func TestIncomingWebhook(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
defer th.TearDown() defer th.TearDown()
if !th.App.Config().ServiceSettings.EnableIncomingWebhooks { if !*th.App.Config().ServiceSettings.EnableIncomingWebhooks {
_, err := http.Post(ApiClient.Url+"/hooks/123", "", strings.NewReader("123")) _, err := http.Post(ApiClient.Url+"/hooks/123", "", strings.NewReader("123"))
assert.NotNil(t, err, "should have errored - webhooks turned off") assert.NotNil(t, err, "should have errored - webhooks turned off")
return return
@@ -224,7 +224,7 @@ func TestIncomingWebhook(t *testing.T) {
}) })
t.Run("DisableWebhooks", func(t *testing.T) { t.Run("DisableWebhooks", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false }) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableIncomingWebhooks = false })
resp, err := http.Post(url, "application/json", strings.NewReader("{\"text\":\"this is a test\"}")) resp, err := http.Post(url, "application/json", strings.NewReader("{\"text\":\"this is a test\"}"))
require.Nil(t, err) require.Nil(t, err)
assert.True(t, resp.StatusCode == http.StatusNotImplemented) assert.True(t, resp.StatusCode == http.StatusNotImplemented)