summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-11-09 14:46:20 -0600
committerGitHub <noreply@github.com>2017-11-09 14:46:20 -0600
commit10c5a927cb619f1aa2a599cbe3667820f4766bda (patch)
treef415540ab66115e62928d304c99b533398d7f226
parentb0c18ece0988b1573b2286bb73b32e48a1d8c59a (diff)
downloadchat-10c5a927cb619f1aa2a599cbe3667820f4766bda.tar.gz
chat-10c5a927cb619f1aa2a599cbe3667820f4766bda.tar.bz2
chat-10c5a927cb619f1aa2a599cbe3667820f4766bda.zip
more global config ref cleanup (#7802)
-rw-r--r--api/admin.go2
-rw-r--r--api/file.go2
-rw-r--r--api/status.go3
-rw-r--r--api4/apitestlib.go27
-rw-r--r--api4/compliance.go3
-rw-r--r--api4/file.go2
-rw-r--r--api4/file_test.go11
-rw-r--r--api4/user_test.go20
-rw-r--r--app/command.go172
-rw-r--r--app/command_away.go2
-rw-r--r--app/command_channel_header.go2
-rw-r--r--app/command_channel_purpose.go2
-rw-r--r--app/command_channel_rename.go2
-rw-r--r--app/command_code.go2
-rw-r--r--app/command_dnd.go2
-rw-r--r--app/command_echo.go2
-rw-r--r--app/command_expand_collapse.go4
-rw-r--r--app/command_help.go2
-rw-r--r--app/command_invite_people.go5
-rw-r--r--app/command_join.go2
-rw-r--r--app/command_leave.go2
-rw-r--r--app/command_loadtest.go9
-rw-r--r--app/command_logout.go2
-rw-r--r--app/command_me.go2
-rw-r--r--app/command_msg.go2
-rw-r--r--app/command_offline.go2
-rw-r--r--app/command_online.go2
-rw-r--r--app/command_open.go4
-rw-r--r--app/command_remove.go7
-rw-r--r--app/command_search.go2
-rw-r--r--app/command_settings.go2
-rw-r--r--app/command_shortcuts.go2
-rw-r--r--app/command_shrug.go2
-rw-r--r--app/compliance.go5
-rw-r--r--app/diagnostics.go4
-rw-r--r--app/diagnostics_test.go8
-rw-r--r--app/email_batching.go4
-rw-r--r--app/file.go8
-rw-r--r--app/import_test.go3
-rw-r--r--app/notification.go6
-rw-r--r--app/notification_test.go12
-rw-r--r--app/session_test.go8
-rw-r--r--app/status.go10
-rw-r--r--app/team.go14
-rw-r--r--app/user.go2
-rw-r--r--app/webhook_test.go6
-rw-r--r--cmd/platform/server.go18
-rw-r--r--jobs/schedulers.go6
-rw-r--r--wsapi/status.go8
49 files changed, 215 insertions, 216 deletions
diff --git a/api/admin.go b/api/admin.go
index 1e343fdfa..c6c632c59 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -189,7 +189,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return
}
- reportBytes, err := app.GetComplianceFile(job)
+ reportBytes, err := c.App.GetComplianceFile(job)
if err != nil {
c.Err = err
return
diff --git a/api/file.go b/api/file.go
index bcb79bd5c..20b13fcb7 100644
--- a/api/file.go
+++ b/api/file.go
@@ -332,5 +332,5 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- w.Write([]byte(model.StringToJson(app.GeneratePublicLinkV3(c.GetSiteURLHeader(), info))))
+ w.Write([]byte(model.StringToJson(c.App.GeneratePublicLinkV3(c.GetSiteURLHeader(), info))))
}
diff --git a/api/status.go b/api/status.go
index 70106ad8c..a86d80f98 100644
--- a/api/status.go
+++ b/api/status.go
@@ -8,7 +8,6 @@ import (
l4g "github.com/alecthomas/log4go"
- "github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
)
@@ -21,7 +20,7 @@ func (api *API) InitStatus() {
}
func getStatusesHttp(c *Context, w http.ResponseWriter, r *http.Request) {
- statusMap := model.StatusMapToInterfaceMap(app.GetAllStatuses())
+ statusMap := model.StatusMapToInterfaceMap(c.App.GetAllStatuses())
w.Write([]byte(model.StringInterfaceToJson(statusMap)))
}
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index d777f8c19..6f066a140 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -689,19 +689,20 @@ func s3New(endpoint, accessKey, secretKey string, secure bool, signV2 bool, regi
return s3.NewWithCredentials(endpoint, creds, secure, region)
}
-func cleanupTestFile(info *model.FileInfo) error {
- if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
- endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint
- accessKey := utils.Cfg.FileSettings.AmazonS3AccessKeyId
- secretKey := utils.Cfg.FileSettings.AmazonS3SecretAccessKey
- secure := *utils.Cfg.FileSettings.AmazonS3SSL
- signV2 := *utils.Cfg.FileSettings.AmazonS3SignV2
- region := utils.Cfg.FileSettings.AmazonS3Region
+func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
+ cfg := me.App.Config()
+ if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
+ endpoint := cfg.FileSettings.AmazonS3Endpoint
+ accessKey := cfg.FileSettings.AmazonS3AccessKeyId
+ secretKey := cfg.FileSettings.AmazonS3SecretAccessKey
+ secure := *cfg.FileSettings.AmazonS3SSL
+ signV2 := *cfg.FileSettings.AmazonS3SignV2
+ region := cfg.FileSettings.AmazonS3Region
s3Clnt, err := s3New(endpoint, accessKey, secretKey, secure, signV2, region)
if err != nil {
return err
}
- bucket := utils.Cfg.FileSettings.AmazonS3Bucket
+ bucket := cfg.FileSettings.AmazonS3Bucket
if err := s3Clnt.RemoveObject(bucket, info.Path); err != nil {
return err
}
@@ -717,19 +718,19 @@ func cleanupTestFile(info *model.FileInfo) error {
return err
}
}
- } else if *utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
- if err := os.Remove(utils.Cfg.FileSettings.Directory + info.Path); err != nil {
+ } else if *cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
+ if err := os.Remove(cfg.FileSettings.Directory + info.Path); err != nil {
return err
}
if info.ThumbnailPath != "" {
- if err := os.Remove(utils.Cfg.FileSettings.Directory + info.ThumbnailPath); err != nil {
+ if err := os.Remove(cfg.FileSettings.Directory + info.ThumbnailPath); err != nil {
return err
}
}
if info.PreviewPath != "" {
- if err := os.Remove(utils.Cfg.FileSettings.Directory + info.PreviewPath); err != nil {
+ if err := os.Remove(cfg.FileSettings.Directory + info.PreviewPath); err != nil {
return err
}
}
diff --git a/api4/compliance.go b/api4/compliance.go
index 91d00fdf4..d58398595 100644
--- a/api4/compliance.go
+++ b/api4/compliance.go
@@ -8,7 +8,6 @@ import (
"strconv"
l4g "github.com/alecthomas/log4go"
- "github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
"github.com/mssola/user_agent"
@@ -100,7 +99,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return
}
- reportBytes, err := app.GetComplianceFile(job)
+ reportBytes, err := c.App.GetComplianceFile(job)
if err != nil {
c.Err = err
return
diff --git a/api4/file.go b/api4/file.go
index a8297df04..883d4f3c8 100644
--- a/api4/file.go
+++ b/api4/file.go
@@ -201,7 +201,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
}
resp := make(map[string]string)
- resp["link"] = app.GeneratePublicLink(c.GetSiteURLHeader(), info)
+ resp["link"] = c.App.GeneratePublicLink(c.GetSiteURLHeader(), info)
w.Write([]byte(model.MapToJson(resp)))
}
diff --git a/api4/file_test.go b/api4/file_test.go
index 394406d6e..7010b3039 100644
--- a/api4/file_test.go
+++ b/api4/file_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"time"
- "github.com/mattermost/mattermost-server/app"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
)
@@ -94,7 +93,7 @@ func TestUploadFile(t *testing.T) {
// Wait a bit for files to ready
time.Sleep(2 * time.Second)
- if err := cleanupTestFile(info); err != nil {
+ if err := th.cleanupTestFile(info); err != nil {
t.Fatal(err)
}
@@ -363,7 +362,7 @@ func TestGetFileLink(t *testing.T) {
if result := <-th.App.Srv.Store.FileInfo().Get(fileId); result.Err != nil {
t.Fatal(result.Err)
} else {
- cleanupTestFile(result.Data.(*model.FileInfo))
+ th.cleanupTestFile(result.Data.(*model.FileInfo))
}
}
@@ -520,7 +519,7 @@ func TestGetPublicFile(t *testing.T) {
result := <-th.App.Srv.Store.FileInfo().Get(fileId)
info := result.Data.(*model.FileInfo)
- link := app.GeneratePublicLink(Client.Url, info)
+ link := th.App.GeneratePublicLink(Client.Url, info)
// Wait a bit for files to ready
time.Sleep(2 * time.Second)
@@ -551,9 +550,9 @@ func TestGetPublicFile(t *testing.T) {
t.Fatal("should've failed to get image with public link after salt changed")
}
- if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
+ if err := th.cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
t.Fatal(err)
}
- cleanupTestFile(info)
+ th.cleanupTestFile(info)
}
diff --git a/api4/user_test.go b/api4/user_test.go
index d2bbdcd7b..12b808aa1 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -841,7 +841,7 @@ func TestGetProfileImage(t *testing.T) {
CheckNoError(t, resp)
info := &model.FileInfo{Path: "/users/" + user.Id + "/profile.png"}
- if err := cleanupTestFile(info); err != nil {
+ if err := th.cleanupTestFile(info); err != nil {
t.Fatal(err)
}
}
@@ -2089,7 +2089,7 @@ func TestSetProfileImage(t *testing.T) {
assert.True(t, buser.LastPictureUpdate < ruser.LastPictureUpdate, "Picture should have updated for user")
info := &model.FileInfo{Path: "users/" + user.Id + "/profile.png"}
- if err := cleanupTestFile(info); err != nil {
+ if err := th.cleanupTestFile(info); err != nil {
t.Fatal(err)
}
}
@@ -2381,11 +2381,9 @@ func TestDisableUserAccessToken(t *testing.T) {
testDescription := "test token"
- enableUserAccessTokens := *utils.Cfg.ServiceSettings.EnableUserAccessTokens
- defer func() {
- *utils.Cfg.ServiceSettings.EnableUserAccessTokens = enableUserAccessTokens
- }()
- *utils.Cfg.ServiceSettings.EnableUserAccessTokens = true
+ enableUserAccessTokens := *th.App.Config().ServiceSettings.EnableUserAccessTokens
+ defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = enableUserAccessTokens })
+ *th.App.Config().ServiceSettings.EnableUserAccessTokens = true
th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
@@ -2428,11 +2426,9 @@ func TestEnableUserAccessToken(t *testing.T) {
testDescription := "test token"
- enableUserAccessTokens := *utils.Cfg.ServiceSettings.EnableUserAccessTokens
- defer func() {
- *utils.Cfg.ServiceSettings.EnableUserAccessTokens = enableUserAccessTokens
- }()
- *utils.Cfg.ServiceSettings.EnableUserAccessTokens = true
+ enableUserAccessTokens := *th.App.Config().ServiceSettings.EnableUserAccessTokens
+ defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = enableUserAccessTokens })
+ *th.App.Config().ServiceSettings.EnableUserAccessTokens = true
th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id, false)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
diff --git a/app/command.go b/app/command.go
index 2d1a8ef71..96dd2656c 100644
--- a/app/command.go
+++ b/app/command.go
@@ -18,7 +18,7 @@ import (
type CommandProvider interface {
GetTrigger() string
- GetCommand(T goi18n.TranslateFunc) *model.Command
+ GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse
}
@@ -65,11 +65,13 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
commands := make([]*model.Command, 0, 32)
seen := make(map[string]bool)
for _, value := range commandProviders {
- cpy := *value.GetCommand(T)
- if cpy.AutoComplete && !seen[cpy.Id] {
- cpy.Sanitize()
- seen[cpy.Trigger] = true
- commands = append(commands, &cpy)
+ if cmd := value.GetCommand(a, T); cmd != nil {
+ cpy := *cmd
+ if cpy.AutoComplete && !seen[cpy.Id] {
+ cpy.Sanitize()
+ seen[cpy.Trigger] = true
+ commands = append(commands, &cpy)
+ }
}
}
@@ -107,11 +109,13 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
commands := make([]*model.Command, 0, 32)
seen := make(map[string]bool)
for _, value := range commandProviders {
- cpy := *value.GetCommand(T)
- if cpy.AutoComplete && !seen[cpy.Id] {
- cpy.Sanitize()
- seen[cpy.Trigger] = true
- commands = append(commands, &cpy)
+ if cmd := value.GetCommand(a, T); cmd != nil {
+ cpy := *cmd
+ if cpy.AutoComplete && !seen[cpy.Id] {
+ cpy.Sanitize()
+ seen[cpy.Trigger] = true
+ commands = append(commands, &cpy)
+ }
}
}
@@ -141,94 +145,96 @@ func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *
provider := GetCommandProvider(trigger)
if provider != nil {
- response := provider.DoCommand(a, args, message)
- return a.HandleCommandResponse(provider.GetCommand(args.T), args, response, true)
- } else {
- if !*a.Config().ServiceSettings.EnableCommands {
- return nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
+ if cmd := provider.GetCommand(a, args.T); cmd != nil {
+ response := provider.DoCommand(a, args, message)
+ return a.HandleCommandResponse(cmd, args, response, true)
}
+ }
- chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true)
- teamChan := a.Srv.Store.Team().Get(args.TeamId)
- userChan := a.Srv.Store.User().Get(args.UserId)
+ if !*a.Config().ServiceSettings.EnableCommands {
+ return nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
+ }
- if result := <-a.Srv.Store.Command().GetByTeam(args.TeamId); result.Err != nil {
- return nil, result.Err
- } else {
+ chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true)
+ teamChan := a.Srv.Store.Team().Get(args.TeamId)
+ userChan := a.Srv.Store.User().Get(args.UserId)
- var team *model.Team
- if tr := <-teamChan; tr.Err != nil {
- return nil, tr.Err
- } else {
- team = tr.Data.(*model.Team)
- }
+ if result := <-a.Srv.Store.Command().GetByTeam(args.TeamId); result.Err != nil {
+ return nil, result.Err
+ } else {
- var user *model.User
- if ur := <-userChan; ur.Err != nil {
- return nil, ur.Err
- } else {
- user = ur.Data.(*model.User)
- }
+ var team *model.Team
+ if tr := <-teamChan; tr.Err != nil {
+ return nil, tr.Err
+ } else {
+ team = tr.Data.(*model.Team)
+ }
- var channel *model.Channel
- if cr := <-chanChan; cr.Err != nil {
- return nil, cr.Err
- } else {
- channel = cr.Data.(*model.Channel)
- }
+ var user *model.User
+ if ur := <-userChan; ur.Err != nil {
+ return nil, ur.Err
+ } else {
+ user = ur.Data.(*model.User)
+ }
- teamCmds := result.Data.([]*model.Command)
- for _, cmd := range teamCmds {
- if trigger == cmd.Trigger {
- l4g.Debug(fmt.Sprintf(utils.T("api.command.execute_command.debug"), trigger, args.UserId))
+ var channel *model.Channel
+ if cr := <-chanChan; cr.Err != nil {
+ return nil, cr.Err
+ } else {
+ channel = cr.Data.(*model.Channel)
+ }
- p := url.Values{}
- p.Set("token", cmd.Token)
+ teamCmds := result.Data.([]*model.Command)
+ for _, cmd := range teamCmds {
+ if trigger == cmd.Trigger {
+ l4g.Debug(fmt.Sprintf(utils.T("api.command.execute_command.debug"), trigger, args.UserId))
- p.Set("team_id", cmd.TeamId)
- p.Set("team_domain", team.Name)
+ p := url.Values{}
+ p.Set("token", cmd.Token)
- p.Set("channel_id", args.ChannelId)
- p.Set("channel_name", channel.Name)
+ p.Set("team_id", cmd.TeamId)
+ p.Set("team_domain", team.Name)
- p.Set("user_id", args.UserId)
- p.Set("user_name", user.Username)
+ p.Set("channel_id", args.ChannelId)
+ p.Set("channel_name", channel.Name)
- p.Set("command", "/"+trigger)
- p.Set("text", message)
+ p.Set("user_id", args.UserId)
+ p.Set("user_name", user.Username)
- if hook, err := a.CreateCommandWebhook(cmd.Id, args); err != nil {
- return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError)
- } else {
- p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id)
- }
+ p.Set("command", "/"+trigger)
+ p.Set("text", message)
- method := "POST"
- if cmd.Method == model.COMMAND_METHOD_GET {
- method = "GET"
- }
+ if hook, err := a.CreateCommandWebhook(cmd.Id, args); err != nil {
+ return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError)
+ } else {
+ p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id)
+ }
- req, _ := http.NewRequest(method, cmd.URL, strings.NewReader(p.Encode()))
- req.Header.Set("Accept", "application/json")
- if cmd.Method == model.COMMAND_METHOD_POST {
- req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
- }
+ method := "POST"
+ if cmd.Method == model.COMMAND_METHOD_GET {
+ method = "GET"
+ }
- if resp, err := utils.HttpClient(false).Do(req); err != nil {
- return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError)
- } else {
- if resp.StatusCode == http.StatusOK {
- response := model.CommandResponseFromHTTPBody(resp.Header.Get("Content-Type"), resp.Body)
- if response == nil {
- return nil, model.NewAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusInternalServerError)
- } else {
- return a.HandleCommandResponse(cmd, args, response, false)
- }
+ req, _ := http.NewRequest(method, cmd.URL, strings.NewReader(p.Encode()))
+ req.Header.Set("Accept", "application/json")
+ if cmd.Method == model.COMMAND_METHOD_POST {
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ }
+
+ if resp, err := utils.HttpClient(false).Do(req); err != nil {
+ return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError)
+ } else {
+ if resp.StatusCode == http.StatusOK {
+ response := model.CommandResponseFromHTTPBody(resp.Header.Get("Content-Type"), resp.Body)
+ if response == nil {
+ return nil, model.NewAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusInternalServerError)
} else {
- defer resp.Body.Close()
- body, _ := ioutil.ReadAll(resp.Body)
- return nil, model.NewAppError("command", "api.command.execute_command.failed_resp.app_error", map[string]interface{}{"Trigger": trigger, "Status": resp.Status}, string(body), http.StatusInternalServerError)
+ return a.HandleCommandResponse(cmd, args, response, false)
}
+ } else {
+ defer resp.Body.Close()
+ body, _ := ioutil.ReadAll(resp.Body)
+ return nil, model.NewAppError("command", "api.command.execute_command.failed_resp.app_error", map[string]interface{}{"Trigger": trigger, "Status": resp.Status}, string(body), http.StatusInternalServerError)
}
}
}
@@ -293,8 +299,8 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
}
}
for _, builtInProvider := range commandProviders {
- builtInCommand := *builtInProvider.GetCommand(utils.T)
- if cmd.Trigger == builtInCommand.Trigger {
+ builtInCommand := builtInProvider.GetCommand(a, utils.T)
+ if builtInCommand != nil && cmd.Trigger == builtInCommand.Trigger {
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
}
}
diff --git a/app/command_away.go b/app/command_away.go
index 7505f0551..37f81d825 100644
--- a/app/command_away.go
+++ b/app/command_away.go
@@ -23,7 +23,7 @@ func (me *AwayProvider) GetTrigger() string {
return CMD_AWAY
}
-func (me *AwayProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *AwayProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_AWAY,
AutoComplete: true,
diff --git a/app/command_channel_header.go b/app/command_channel_header.go
index 51f40eb4f..63a9250a7 100644
--- a/app/command_channel_header.go
+++ b/app/command_channel_header.go
@@ -24,7 +24,7 @@ func (me *HeaderProvider) GetTrigger() string {
return CMD_HEADER
}
-func (me *HeaderProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *HeaderProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_HEADER,
AutoComplete: true,
diff --git a/app/command_channel_purpose.go b/app/command_channel_purpose.go
index d342991c7..547406692 100644
--- a/app/command_channel_purpose.go
+++ b/app/command_channel_purpose.go
@@ -23,7 +23,7 @@ func (me *PurposeProvider) GetTrigger() string {
return CMD_PURPOSE
}
-func (me *PurposeProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *PurposeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_PURPOSE,
AutoComplete: true,
diff --git a/app/command_channel_rename.go b/app/command_channel_rename.go
index b58a9e091..ddcfea67a 100644
--- a/app/command_channel_rename.go
+++ b/app/command_channel_rename.go
@@ -23,7 +23,7 @@ func (me *RenameProvider) GetTrigger() string {
return CMD_RENAME
}
-func (me *RenameProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *RenameProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_RENAME,
AutoComplete: true,
diff --git a/app/command_code.go b/app/command_code.go
index 6685144dd..276199807 100644
--- a/app/command_code.go
+++ b/app/command_code.go
@@ -25,7 +25,7 @@ func (me *CodeProvider) GetTrigger() string {
return CMD_CODE
}
-func (me *CodeProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *CodeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_CODE,
AutoComplete: true,
diff --git a/app/command_dnd.go b/app/command_dnd.go
index 7eff6039d..cd3764fdf 100644
--- a/app/command_dnd.go
+++ b/app/command_dnd.go
@@ -23,7 +23,7 @@ func (me *DndProvider) GetTrigger() string {
return CMD_DND
}
-func (me *DndProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *DndProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_DND,
AutoComplete: true,
diff --git a/app/command_echo.go b/app/command_echo.go
index ecf0d8d19..9fef8a0a9 100644
--- a/app/command_echo.go
+++ b/app/command_echo.go
@@ -30,7 +30,7 @@ func (me *EchoProvider) GetTrigger() string {
return CMD_ECHO
}
-func (me *EchoProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *EchoProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ECHO,
AutoComplete: true,
diff --git a/app/command_expand_collapse.go b/app/command_expand_collapse.go
index 093e53a38..a8eb3bc1f 100644
--- a/app/command_expand_collapse.go
+++ b/app/command_expand_collapse.go
@@ -34,7 +34,7 @@ func (me *CollapseProvider) GetTrigger() string {
return CMD_COLLAPSE
}
-func (me *ExpandProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *ExpandProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_EXPAND,
AutoComplete: true,
@@ -43,7 +43,7 @@ func (me *ExpandProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
}
}
-func (me *CollapseProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *CollapseProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_COLLAPSE,
AutoComplete: true,
diff --git a/app/command_help.go b/app/command_help.go
index d3b803d8b..22535b4cf 100644
--- a/app/command_help.go
+++ b/app/command_help.go
@@ -23,7 +23,7 @@ func (h *HelpProvider) GetTrigger() string {
return CMD_HELP
}
-func (h *HelpProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (h *HelpProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_HELP,
AutoComplete: true,
diff --git a/app/command_invite_people.go b/app/command_invite_people.go
index 03a4d0e36..e463bd37c 100644
--- a/app/command_invite_people.go
+++ b/app/command_invite_people.go
@@ -8,7 +8,6 @@ import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
@@ -27,9 +26,9 @@ func (me *InvitePeopleProvider) GetTrigger() string {
return CMD_INVITE_PEOPLE
}
-func (me *InvitePeopleProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *InvitePeopleProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
autoComplete := true
- if !utils.Cfg.EmailSettings.SendEmailNotifications || !utils.Cfg.TeamSettings.EnableUserCreation {
+ if !a.Config().EmailSettings.SendEmailNotifications || !a.Config().TeamSettings.EnableUserCreation {
autoComplete = false
}
return &model.Command{
diff --git a/app/command_join.go b/app/command_join.go
index 58b0170be..92084448e 100644
--- a/app/command_join.go
+++ b/app/command_join.go
@@ -23,7 +23,7 @@ func (me *JoinProvider) GetTrigger() string {
return CMD_JOIN
}
-func (me *JoinProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *JoinProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_JOIN,
AutoComplete: true,
diff --git a/app/command_leave.go b/app/command_leave.go
index 9d76f7ee5..f127947d5 100644
--- a/app/command_leave.go
+++ b/app/command_leave.go
@@ -23,7 +23,7 @@ func (me *LeaveProvider) GetTrigger() string {
return CMD_LEAVE
}
-func (me *LeaveProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *LeaveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LEAVE,
AutoComplete: true,
diff --git a/app/command_loadtest.go b/app/command_loadtest.go
index d5c201201..501263d04 100644
--- a/app/command_loadtest.go
+++ b/app/command_loadtest.go
@@ -66,16 +66,17 @@ type LoadTestProvider struct {
}
func init() {
- if !utils.Cfg.ServiceSettings.EnableTesting {
- RegisterCommandProvider(&LoadTestProvider{})
- }
+ RegisterCommandProvider(&LoadTestProvider{})
}
func (me *LoadTestProvider) GetTrigger() string {
return CMD_TEST
}
-func (me *LoadTestProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *LoadTestProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
+ if !a.Config().ServiceSettings.EnableTesting {
+ return nil
+ }
return &model.Command{
Trigger: CMD_TEST,
AutoComplete: false,
diff --git a/app/command_logout.go b/app/command_logout.go
index b21045b6a..ef81ede13 100644
--- a/app/command_logout.go
+++ b/app/command_logout.go
@@ -23,7 +23,7 @@ func (me *LogoutProvider) GetTrigger() string {
return CMD_LOGOUT
}
-func (me *LogoutProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *LogoutProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_LOGOUT,
AutoComplete: true,
diff --git a/app/command_me.go b/app/command_me.go
index 5683ff80d..e485d60ff 100644
--- a/app/command_me.go
+++ b/app/command_me.go
@@ -23,7 +23,7 @@ func (me *MeProvider) GetTrigger() string {
return CMD_ME
}
-func (me *MeProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *MeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ME,
AutoComplete: true,
diff --git a/app/command_msg.go b/app/command_msg.go
index 120619960..cf0e90c74 100644
--- a/app/command_msg.go
+++ b/app/command_msg.go
@@ -26,7 +26,7 @@ func (me *msgProvider) GetTrigger() string {
return CMD_MSG
}
-func (me *msgProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *msgProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_MSG,
AutoComplete: true,
diff --git a/app/command_offline.go b/app/command_offline.go
index ddc539c06..168961af1 100644
--- a/app/command_offline.go
+++ b/app/command_offline.go
@@ -23,7 +23,7 @@ func (me *OfflineProvider) GetTrigger() string {
return CMD_OFFLINE
}
-func (me *OfflineProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *OfflineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_OFFLINE,
AutoComplete: true,
diff --git a/app/command_online.go b/app/command_online.go
index b1319dd14..358bb8209 100644
--- a/app/command_online.go
+++ b/app/command_online.go
@@ -23,7 +23,7 @@ func (me *OnlineProvider) GetTrigger() string {
return CMD_ONLINE
}
-func (me *OnlineProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *OnlineProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_ONLINE,
AutoComplete: true,
diff --git a/app/command_open.go b/app/command_open.go
index ea7533663..9c608a8d3 100644
--- a/app/command_open.go
+++ b/app/command_open.go
@@ -24,8 +24,8 @@ func (open *OpenProvider) GetTrigger() string {
return CMD_OPEN
}
-func (open *OpenProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
- cmd := open.JoinProvider.GetCommand(T)
+func (open *OpenProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
+ cmd := open.JoinProvider.GetCommand(a, T)
cmd.Trigger = CMD_OPEN
cmd.DisplayName = T("api.command_open.name")
return cmd
diff --git a/app/command_remove.go b/app/command_remove.go
index 6047ff5be..a9c21e2d5 100644
--- a/app/command_remove.go
+++ b/app/command_remove.go
@@ -10,7 +10,6 @@ import (
goi18n "github.com/nicksnyder/go-i18n/i18n"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
type RemoveProvider struct {
@@ -37,7 +36,7 @@ func (me *KickProvider) GetTrigger() string {
return CMD_KICK
}
-func (me *RemoveProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *RemoveProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_REMOVE,
AutoComplete: true,
@@ -47,7 +46,7 @@ func (me *RemoveProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
}
}
-func (me *KickProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *KickProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_KICK,
AutoComplete: true,
@@ -102,7 +101,7 @@ func doCommand(a *App, args *model.CommandArgs, message string) *model.CommandRe
_, err = a.GetChannelMember(args.ChannelId, userProfile.Id)
if err != nil {
- nameFormat := *utils.Cfg.TeamSettings.TeammateNameDisplay
+ nameFormat := *a.Config().TeamSettings.TeammateNameDisplay
return &model.CommandResponse{Text: args.T("api.command_remove.user_not_in_channel", map[string]interface{}{"Username": userProfile.GetDisplayName(nameFormat)}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
diff --git a/app/command_search.go b/app/command_search.go
index e7fb7617c..546be2785 100644
--- a/app/command_search.go
+++ b/app/command_search.go
@@ -23,7 +23,7 @@ func (search *SearchProvider) GetTrigger() string {
return CMD_SEARCH
}
-func (search *SearchProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (search *SearchProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SEARCH,
AutoComplete: true,
diff --git a/app/command_settings.go b/app/command_settings.go
index c6fceb504..c3289bccf 100644
--- a/app/command_settings.go
+++ b/app/command_settings.go
@@ -23,7 +23,7 @@ func (settings *SettingsProvider) GetTrigger() string {
return CMD_SETTINGS
}
-func (settings *SettingsProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (settings *SettingsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SETTINGS,
AutoComplete: true,
diff --git a/app/command_shortcuts.go b/app/command_shortcuts.go
index 170911af8..5aab9658a 100644
--- a/app/command_shortcuts.go
+++ b/app/command_shortcuts.go
@@ -23,7 +23,7 @@ func (me *ShortcutsProvider) GetTrigger() string {
return CMD_SHORTCUTS
}
-func (me *ShortcutsProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *ShortcutsProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SHORTCUTS,
AutoComplete: true,
diff --git a/app/command_shrug.go b/app/command_shrug.go
index c476e6d88..21f492fe0 100644
--- a/app/command_shrug.go
+++ b/app/command_shrug.go
@@ -23,7 +23,7 @@ func (me *ShrugProvider) GetTrigger() string {
return CMD_SHRUG
}
-func (me *ShrugProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
+func (me *ShrugProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: CMD_SHRUG,
AutoComplete: true,
diff --git a/app/compliance.go b/app/compliance.go
index 44e0039d8..2a1b86a6b 100644
--- a/app/compliance.go
+++ b/app/compliance.go
@@ -55,10 +55,9 @@ func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.Ap
}
}
-func GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
- if f, err := ioutil.ReadFile(*utils.Cfg.ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip"); err != nil {
+func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
+ if f, err := ioutil.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip"); err != nil {
return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusNotImplemented)
-
} else {
return f, nil
}
diff --git a/app/diagnostics.go b/app/diagnostics.go
index 18a54e484..250b38646 100644
--- a/app/diagnostics.go
+++ b/app/diagnostics.go
@@ -458,8 +458,8 @@ func (a *App) trackConfig() {
SendDiagnostic(TRACK_CONFIG_PLUGIN, map[string]interface{}{
"enable_jira": pluginSetting(&cfg.PluginSettings, "jira", "enabled", false),
- "enable": *utils.Cfg.PluginSettings.Enable,
- "enable_uploads": *utils.Cfg.PluginSettings.EnableUploads,
+ "enable": *cfg.PluginSettings.Enable,
+ "enable_uploads": *cfg.PluginSettings.EnableUploads,
})
SendDiagnostic(TRACK_CONFIG_DATA_RETENTION, map[string]interface{}{
diff --git a/app/diagnostics_test.go b/app/diagnostics_test.go
index 47a5d8a27..25bc75265 100644
--- a/app/diagnostics_test.go
+++ b/app/diagnostics_test.go
@@ -144,11 +144,9 @@ func TestDiagnostics(t *testing.T) {
})
t.Run("SendDailyDiagnosticsDisabled", func(t *testing.T) {
- oldSetting := *utils.Cfg.LogSettings.EnableDiagnostics
- *utils.Cfg.LogSettings.EnableDiagnostics = false
- defer func() {
- *utils.Cfg.LogSettings.EnableDiagnostics = oldSetting
- }()
+ oldSetting := *th.App.Config().LogSettings.EnableDiagnostics
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = false })
+ defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.LogSettings.EnableDiagnostics = oldSetting })
th.App.SendDailyDiagnostics()
diff --git a/app/email_batching.go b/app/email_batching.go
index 75e09dd17..80e0966d5 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -72,8 +72,8 @@ func (job *EmailBatchingJob) Start() {
task.Cancel()
}
- l4g.Debug(utils.T("api.email_batching.start.starting"), *utils.Cfg.EmailSettings.EmailBatchingInterval)
- model.CreateRecurringTask(EMAIL_BATCHING_TASK_NAME, job.CheckPendingEmails, time.Duration(*utils.Cfg.EmailSettings.EmailBatchingInterval)*time.Second)
+ l4g.Debug(utils.T("api.email_batching.start.starting"), *job.app.Config().EmailSettings.EmailBatchingInterval)
+ model.CreateRecurringTask(EMAIL_BATCHING_TASK_NAME, job.CheckPendingEmails, time.Duration(*job.app.Config().EmailSettings.EmailBatchingInterval)*time.Second)
}
func (job *EmailBatchingJob) Add(user *model.User, post *model.Post, team *model.Team) bool {
diff --git a/app/file.go b/app/file.go
index 3b221d9e2..c1389ef37 100644
--- a/app/file.go
+++ b/app/file.go
@@ -225,13 +225,13 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
}
}
-func GeneratePublicLink(siteURL string, info *model.FileInfo) string {
- hash := GeneratePublicLinkHash(info.Id, *utils.Cfg.FileSettings.PublicLinkSalt)
+func (a *App) GeneratePublicLink(siteURL string, info *model.FileInfo) string {
+ hash := GeneratePublicLinkHash(info.Id, *a.Config().FileSettings.PublicLinkSalt)
return fmt.Sprintf("%s/files/%v/public?h=%s", siteURL, info.Id, hash)
}
-func GeneratePublicLinkV3(siteURL string, info *model.FileInfo) string {
- hash := GeneratePublicLinkHash(info.Id, *utils.Cfg.FileSettings.PublicLinkSalt)
+func (a *App) GeneratePublicLinkV3(siteURL string, info *model.FileInfo) string {
+ hash := GeneratePublicLinkHash(info.Id, *a.Config().FileSettings.PublicLinkSalt)
return fmt.Sprintf("%s%s/public/files/%v/get?h=%s", siteURL, model.API_URL_SUFFIX_V3, info.Id, hash)
}
diff --git a/app/import_test.go b/app/import_test.go
index ccd49608e..630077603 100644
--- a/app/import_test.go
+++ b/app/import_test.go
@@ -10,7 +10,6 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
- "github.com/mattermost/mattermost-server/utils"
)
func ptrStr(s string) *string {
@@ -1344,7 +1343,7 @@ func TestImportImportUser(t *testing.T) {
t.Fatalf("Expected EmailVerified to be true.")
}
- if user.Locale != *utils.Cfg.LocalizationSettings.DefaultClientLocale {
+ if user.Locale != *th.App.Config().LocalizationSettings.DefaultClientLocale {
t.Fatalf("Expected Locale to be the default.")
}
diff --git a/app/notification.go b/app/notification.go
index 01f76ab33..386016250 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -69,7 +69,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
mentionedUserIds[post.UserId] = true
}
} else {
- keywords := GetMentionKeywordsInChannel(profileMap, post.Type != model.POST_HEADER_CHANGE && post.Type != model.POST_PURPOSE_CHANGE)
+ keywords := a.GetMentionKeywordsInChannel(profileMap, post.Type != model.POST_HEADER_CHANGE && post.Type != model.POST_PURPOSE_CHANGE)
var potentialOtherMentions []string
mentionedUserIds, potentialOtherMentions, hereNotification, channelNotification, allNotification = GetExplicitMentions(post.Message, keywords)
@@ -909,7 +909,7 @@ func removeCodeFromMessage(message string) string {
// Given a map of user IDs to profiles, returns a list of mention
// keywords for all users in the channel.
-func GetMentionKeywordsInChannel(profiles map[string]*model.User, lookForSpecialMentions bool) map[string][]string {
+func (a *App) GetMentionKeywordsInChannel(profiles map[string]*model.User, lookForSpecialMentions bool) map[string][]string {
keywords := make(map[string][]string)
for id, profile := range profiles {
@@ -933,7 +933,7 @@ func GetMentionKeywordsInChannel(profiles map[string]*model.User, lookForSpecial
// Add @channel and @all to keywords if user has them turned on
if lookForSpecialMentions {
- if int64(len(profiles)) < *utils.Cfg.TeamSettings.MaxNotificationsPerChannel && profile.NotifyProps["channel"] == "true" {
+ if int64(len(profiles)) < *a.Config().TeamSettings.MaxNotificationsPerChannel && profile.NotifyProps["channel"] == "true" {
keywords["@channel"] = append(keywords["@channel"], profile.Id)
keywords["@all"] = append(keywords["@all"], profile.Id)
diff --git a/app/notification_test.go b/app/notification_test.go
index 83e725646..5ae765649 100644
--- a/app/notification_test.go
+++ b/app/notification_test.go
@@ -447,7 +447,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles := map[string]*model.User{user1.Id: user1}
- mentions := GetMentionKeywordsInChannel(profiles, true)
+ mentions := th.App.GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["user"]; !ok || ids[0] != user1.Id {
@@ -469,7 +469,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user2.Id: user2}
- mentions = GetMentionKeywordsInChannel(profiles, true)
+ mentions = th.App.GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 2 {
t.Fatal("should've returned two mention keyword")
} else if ids, ok := mentions["First"]; !ok || ids[0] != user2.Id {
@@ -487,7 +487,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user3.Id: user3}
- mentions = GetMentionKeywordsInChannel(profiles, true)
+ mentions = th.App.GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["@channel"]; !ok || ids[0] != user3.Id {
@@ -509,7 +509,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user4.Id: user4}
- mentions = GetMentionKeywordsInChannel(profiles, true)
+ mentions = th.App.GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 6 {
t.Fatal("should've returned six mention keywords")
} else if ids, ok := mentions["user"]; !ok || ids[0] != user4.Id {
@@ -551,7 +551,7 @@ func TestGetMentionKeywords(t *testing.T) {
user3.Id: user3,
user4.Id: user4,
}
- mentions = GetMentionKeywordsInChannel(profiles, true)
+ mentions = th.App.GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 6 {
t.Fatal("should've returned six mention keywords")
} else if ids, ok := mentions["user"]; !ok || len(ids) != 2 || (ids[0] != user1.Id && ids[1] != user1.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
@@ -572,7 +572,7 @@ func TestGetMentionKeywords(t *testing.T) {
profiles = map[string]*model.User{
user1.Id: user1,
}
- mentions = GetMentionKeywordsInChannel(profiles, false)
+ mentions = th.App.GetMentionKeywordsInChannel(profiles, false)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["user"]; !ok || len(ids) != 1 || ids[0] != user1.Id {
diff --git a/app/session_test.go b/app/session_test.go
index 97abb540a..bca3b59b7 100644
--- a/app/session_test.go
+++ b/app/session_test.go
@@ -50,17 +50,17 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
isLicensed := utils.IsLicensed()
license := utils.License()
- timeout := *utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes
+ timeout := *th.App.Config().ServiceSettings.SessionIdleTimeoutInMinutes
defer func() {
utils.SetIsLicensed(isLicensed)
utils.SetLicense(license)
- *utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes = timeout
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = timeout })
}()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
*utils.License().Features.Compliance = true
- *utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 5
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 5 })
rsession, err := th.App.GetSession(session.Token)
require.Nil(t, err)
@@ -139,7 +139,7 @@ func TestGetSessionIdleTimeoutInMinutes(t *testing.T) {
*utils.License().Features.Compliance = true
// Test regular session with timeout set to 0, should not timeout
- *utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 0
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SessionIdleTimeoutInMinutes = 0 })
session = &model.Session{
UserId: model.NewId(),
diff --git a/app/status.go b/app/status.go
index e5926a071..1ef7aef0f 100644
--- a/app/status.go
+++ b/app/status.go
@@ -34,8 +34,8 @@ func (a *App) AddStatusCache(status *model.Status) {
}
}
-func GetAllStatuses() map[string]*model.Status {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+func (a *App) GetAllStatuses() map[string]*model.Status {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return map[string]*model.Status{}
}
@@ -272,7 +272,7 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) {
return
}
- if !IsUserAway(status.LastActivityAt) {
+ if !a.IsUserAway(status.LastActivityAt) {
return
}
}
@@ -351,6 +351,6 @@ func (a *App) GetStatus(userId string) (*model.Status, *model.AppError) {
}
}
-func IsUserAway(lastActivityAt int64) bool {
- return model.GetMillis()-lastActivityAt >= *utils.Cfg.TeamSettings.UserStatusAwayTimeout*1000
+func (a *App) IsUserAway(lastActivityAt int64) bool {
+ return model.GetMillis()-lastActivityAt >= *a.Config().TeamSettings.UserStatusAwayTimeout*1000
}
diff --git a/app/team.go b/app/team.go
index 303fa9129..7b267f32a 100644
--- a/app/team.go
+++ b/app/team.go
@@ -39,7 +39,7 @@ func (a *App) CreateTeamWithUser(team *model.Team, userId string) (*model.Team,
team.Email = user.Email
}
- if !isTeamEmailAllowed(user) {
+ if !a.isTeamEmailAllowed(user) {
return nil, model.NewAppError("isTeamEmailAllowed", "api.team.is_team_creation_allowed.domain.app_error", nil, "", http.StatusBadRequest)
}
@@ -55,11 +55,11 @@ func (a *App) CreateTeamWithUser(team *model.Team, userId string) (*model.Team,
return rteam, nil
}
-func isTeamEmailAddressAllowed(email string) bool {
+func (a *App) isTeamEmailAddressAllowed(email string) bool {
email = strings.ToLower(email)
// commas and @ signs are optional
// can be in the form of "@corp.mattermost.com, mattermost.com mattermost.org" -> corp.mattermost.com mattermost.com mattermost.org
- domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(utils.Cfg.TeamSettings.RestrictCreationToDomains, "@", " ", -1), ",", " ", -1))))
+ domains := strings.Fields(strings.TrimSpace(strings.ToLower(strings.Replace(strings.Replace(a.Config().TeamSettings.RestrictCreationToDomains, "@", " ", -1), ",", " ", -1))))
matched := false
for _, d := range domains {
@@ -69,21 +69,21 @@ func isTeamEmailAddressAllowed(email string) bool {
}
}
- if len(utils.Cfg.TeamSettings.RestrictCreationToDomains) > 0 && !matched {
+ if len(a.Config().TeamSettings.RestrictCreationToDomains) > 0 && !matched {
return false
}
return true
}
-func isTeamEmailAllowed(user *model.User) bool {
+func (a *App) isTeamEmailAllowed(user *model.User) bool {
email := strings.ToLower(user.Email)
if len(user.AuthService) > 0 && len(*user.AuthData) > 0 {
return true
}
- return isTeamEmailAddressAllowed(email)
+ return a.isTeamEmailAddressAllowed(email)
}
func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
@@ -646,7 +646,7 @@ func (a *App) InviteNewUsersToTeam(emailList []string, teamId, senderId string)
var invalidEmailList []string
for _, email := range emailList {
- if !isTeamEmailAddressAllowed(email) {
+ if !a.isTeamEmailAddressAllowed(email) {
invalidEmailList = append(invalidEmailList, email)
}
}
diff --git a/app/user.go b/app/user.go
index 60a6c887b..d6ec9ddc1 100644
--- a/app/user.go
+++ b/app/user.go
@@ -743,7 +743,7 @@ func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
var img []byte
readFailed := false
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*a.Config().FileSettings.DriverName) == 0 {
var err *model.AppError
if img, err = CreateProfileImage(user.Username, user.Id, a.Config().FileSettings.InitialFont); err != nil {
return nil, false, err
diff --git a/app/webhook_test.go b/app/webhook_test.go
index 8dc90b49b..f0cc0610a 100644
--- a/app/webhook_test.go
+++ b/app/webhook_test.go
@@ -18,12 +18,12 @@ func TestCreateWebhookPost(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
- enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
+ enableIncomingHooks := th.App.Config().ServiceSettings.EnableIncomingWebhooks
defer func() {
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks })
utils.SetDefaultRolesBasedOnConfig()
}()
- utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
utils.SetDefaultRolesBasedOnConfig()
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
diff --git a/cmd/platform/server.go b/cmd/platform/server.go
index c64b607d8..01f5a0da1 100644
--- a/cmd/platform/server.go
+++ b/cmd/platform/server.go
@@ -90,26 +90,30 @@ func runServer(configFileLocation string) {
wsapi.Init(a, a.Srv.WebSocketRouter)
web.Init(api3)
- if !utils.IsLicensed() && len(utils.Cfg.SqlSettings.DataSourceReplicas) > 1 {
+ if !utils.IsLicensed() && len(a.Config().SqlSettings.DataSourceReplicas) > 1 {
l4g.Warn(utils.T("store.sql.read_replicas_not_licensed.critical"))
- utils.Cfg.SqlSettings.DataSourceReplicas = utils.Cfg.SqlSettings.DataSourceReplicas[:1]
+ a.UpdateConfig(func(cfg *model.Config) {
+ cfg.SqlSettings.DataSourceReplicas = cfg.SqlSettings.DataSourceReplicas[:1]
+ })
}
if !utils.IsLicensed() {
- utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
+ a.UpdateConfig(func(cfg *model.Config) {
+ cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
+ })
}
a.ReloadConfig()
// Enable developer settings if this is a "dev" build
if model.BuildNumber == "dev" {
- *utils.Cfg.ServiceSettings.EnableDeveloper = true
+ a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = true })
}
resetStatuses(a)
// If we allow testing then listen for manual testing URL hits
- if utils.Cfg.ServiceSettings.EnableTesting {
+ if a.Config().ServiceSettings.EnableTesting {
manualtesting.Init(api3)
}
@@ -142,10 +146,10 @@ func runServer(configFileLocation string) {
})
}
- if *utils.Cfg.JobSettings.RunJobs {
+ if *a.Config().JobSettings.RunJobs {
a.Jobs.StartWorkers()
}
- if *utils.Cfg.JobSettings.RunScheduler {
+ if *a.Config().JobSettings.RunScheduler {
a.Jobs.StartSchedulers()
}
diff --git a/jobs/schedulers.go b/jobs/schedulers.go
index 3d52c969a..cbe5f1749 100644
--- a/jobs/schedulers.go
+++ b/jobs/schedulers.go
@@ -65,10 +65,10 @@ func (schedulers *Schedulers) Start() *Schedulers {
now := time.Now()
for idx, scheduler := range schedulers.schedulers {
- if !scheduler.Enabled(utils.Cfg) {
+ if !scheduler.Enabled(schedulers.jobs.Config()) {
schedulers.nextRunTimes[idx] = nil
} else {
- schedulers.setNextRunTime(utils.Cfg, idx, now, false)
+ schedulers.setNextRunTime(schedulers.jobs.Config(), idx, now, false)
}
}
@@ -78,7 +78,7 @@ func (schedulers *Schedulers) Start() *Schedulers {
l4g.Debug("Schedulers received stop signal.")
return
case now = <-time.After(1 * time.Minute):
- cfg := utils.Cfg
+ cfg := schedulers.jobs.Config()
for idx, nextTime := range schedulers.nextRunTimes {
if nextTime == nil {
diff --git a/wsapi/status.go b/wsapi/status.go
index a20b6e284..f0b212c73 100644
--- a/wsapi/status.go
+++ b/wsapi/status.go
@@ -5,7 +5,7 @@ package wsapi
import (
l4g "github.com/alecthomas/log4go"
- "github.com/mattermost/mattermost-server/app"
+
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
)
@@ -13,12 +13,12 @@ import (
func (api *API) InitStatus() {
l4g.Debug(utils.T("wsapi.status.init.debug"))
- api.Router.Handle("get_statuses", api.ApiWebSocketHandler(getStatuses))
+ api.Router.Handle("get_statuses", api.ApiWebSocketHandler(api.getStatuses))
api.Router.Handle("get_statuses_by_ids", api.ApiWebSocketHandler(api.getStatusesByIds))
}
-func getStatuses(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
- statusMap := app.GetAllStatuses()
+func (api *API) getStatuses(req *model.WebSocketRequest) (map[string]interface{}, *model.AppError) {
+ statusMap := api.App.GetAllStatuses()
return model.StatusMapToInterfaceMap(statusMap), nil
}