summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-31 09:39:31 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-10-31 10:39:31 -0400
commitce2b2be5de578bd9eb44b26e04db75ca61d67ca5 (patch)
tree54203a18ecfb167dcf1d7e0742cea0ed9aab220a /api4
parentb446d0aa0aa2bd3d87028b0543752eb539507481 (diff)
downloadchat-ce2b2be5de578bd9eb44b26e04db75ca61d67ca5.tar.gz
chat-ce2b2be5de578bd9eb44b26e04db75ca61d67ca5.tar.bz2
chat-ce2b2be5de578bd9eb44b26e04db75ca61d67ca5.zip
Refactoring cfg refs and load / save functions (#7749)
* refactoring cfg refs and load / save functions * improve error output
Diffstat (limited to 'api4')
-rw-r--r--api4/api_test.go7
-rw-r--r--api4/apitestlib.go14
-rw-r--r--api4/saml.go10
-rw-r--r--api4/user.go8
4 files changed, 15 insertions, 24 deletions
diff --git a/api4/api_test.go b/api4/api_test.go
index 8a8753a4f..fd804b70d 100644
--- a/api4/api_test.go
+++ b/api4/api_test.go
@@ -16,20 +16,15 @@ import (
func TestMain(m *testing.M) {
flag.Parse()
+ utils.TranslationsPreInit()
// In the case where a dev just wants to run a single test, it's faster to just use the default
// store.
if filter := flag.Lookup("test.run").Value.String(); filter != "" && filter != "." {
- utils.TranslationsPreInit()
- utils.LoadConfig("config.json")
l4g.Info("-test.run used, not creating temporary containers")
os.Exit(m.Run())
}
- utils.TranslationsPreInit()
- utils.LoadConfig("config.json")
- utils.InitTranslations(utils.Cfg.LocalizationSettings)
-
status := 0
container, settings, err := storetest.NewMySQLContainer()
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index 25d0ecc60..b7d07e89e 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -73,12 +73,6 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
- if utils.T == nil {
- utils.TranslationsPreInit()
- }
- utils.LoadConfig("config.json")
- utils.InitTranslations(utils.Cfg.LocalizationSettings)
-
var options []app.Option
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
@@ -89,9 +83,11 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th.originalConfig = th.App.Config().Clone()
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
- th.App.UpdateConfig(func(cfg *model.Config) { cfg.EmailSettings.SendEmailNotifications = true })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.TeamSettings.MaxUsersPerTeam = 50
+ *cfg.RateLimitSettings.Enable = false
+ cfg.EmailSettings.SendEmailNotifications = true
+ })
utils.DisableDebugLogForTest()
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
if testStore != nil {
diff --git a/api4/saml.go b/api4/saml.go
index b2f2b3eef..469576943 100644
--- a/api4/saml.go
+++ b/api4/saml.go
@@ -40,8 +40,8 @@ func getSamlMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte(metadata))
}
-func parseSamlCertificateRequest(r *http.Request) (*multipart.FileHeader, *model.AppError) {
- err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize)
+func parseSamlCertificateRequest(r *http.Request, maxFileSize int64) (*multipart.FileHeader, *model.AppError) {
+ err := r.ParseMultipartForm(maxFileSize)
if err != nil {
return nil, model.NewAppError("addSamlCertificate", "api.admin.add_certificate.no_file.app_error", nil, err.Error(), http.StatusBadRequest)
}
@@ -66,7 +66,7 @@ func addSamlPublicCertificate(c *Context, w http.ResponseWriter, r *http.Request
return
}
- fileData, err := parseSamlCertificateRequest(r)
+ fileData, err := parseSamlCertificateRequest(r, *c.App.Config().FileSettings.MaxFileSize)
if err != nil {
c.Err = err
return
@@ -85,7 +85,7 @@ func addSamlPrivateCertificate(c *Context, w http.ResponseWriter, r *http.Reques
return
}
- fileData, err := parseSamlCertificateRequest(r)
+ fileData, err := parseSamlCertificateRequest(r, *c.App.Config().FileSettings.MaxFileSize)
if err != nil {
c.Err = err
return
@@ -104,7 +104,7 @@ func addSamlIdpCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- fileData, err := parseSamlCertificateRequest(r)
+ fileData, err := parseSamlCertificateRequest(r, *c.App.Config().FileSettings.MaxFileSize)
if err != nil {
c.Err = err
return
diff --git a/api4/user.go b/api4/user.go
index 8d5c792d6..2f8e72ad9 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -122,7 +122,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
if c.Session.UserId == user.Id {
user.Sanitize(map[string]bool{})
} else {
- app.SanitizeProfile(user, c.IsSystemAdmin())
+ c.App.SanitizeProfile(user, c.IsSystemAdmin())
}
c.App.UpdateLastActivityAtIfNeeded(c.Session)
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
@@ -152,7 +152,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
if c.HandleEtag(etag, "Get User", w, r) {
return
} else {
- app.SanitizeProfile(user, c.IsSystemAdmin())
+ c.App.SanitizeProfile(user, c.IsSystemAdmin())
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(user.ToJson()))
return
@@ -180,7 +180,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
if c.HandleEtag(etag, "Get User", w, r) {
return
} else {
- app.SanitizeProfile(user, c.IsSystemAdmin())
+ c.App.SanitizeProfile(user, c.IsSystemAdmin())
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(user.ToJson()))
return
@@ -208,7 +208,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
var img []byte
- img, readFailed, err := app.GetProfileImage(user)
+ img, readFailed, err := c.App.GetProfileImage(user)
if err != nil {
c.Err = err
return