summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-18 15:36:43 -0700
committerGitHub <noreply@github.com>2017-10-18 15:36:43 -0700
commit8e19ba029f889519d93cf272960dce858971106c (patch)
treed8f38ac62661fb8578e2b5c3c619fe31ab29f480 /app
parent34a87fa8f47b1447b73e3ae56866b654801b3eee (diff)
downloadchat-8e19ba029f889519d93cf272960dce858971106c.tar.gz
chat-8e19ba029f889519d93cf272960dce858971106c.tar.bz2
chat-8e19ba029f889519d93cf272960dce858971106c.zip
Reduce utils.Cfg references (#7650)
* app.UpdateConfig method * test fix * another test fix * the config override option as-was is just error prone, remove it for now * derp
Diffstat (limited to 'app')
-rw-r--r--app/admin.go24
-rw-r--r--app/analytics.go7
-rw-r--r--app/app.go10
-rw-r--r--app/apptestlib.go9
-rw-r--r--app/authentication.go4
-rw-r--r--app/brand.go5
-rw-r--r--app/channel.go12
-rw-r--r--app/cluster_discovery.go2
-rw-r--r--app/command.go22
-rw-r--r--app/command_channel_rename_test.go2
-rw-r--r--app/command_help.go3
-rw-r--r--app/command_invite_people.go4
-rw-r--r--app/command_loadtest.go2
-rw-r--r--app/compliance.go6
-rw-r--r--app/diagnostics.go4
-rw-r--r--app/elasticsearch.go5
-rw-r--r--app/email.go4
-rw-r--r--app/email_batching.go16
-rw-r--r--app/emoji.go4
-rw-r--r--app/file.go2
-rw-r--r--app/import.go4
-rw-r--r--app/ldap.go4
-rw-r--r--app/login.go7
-rw-r--r--app/notification.go36
-rw-r--r--app/oauth.go32
-rw-r--r--app/options.go28
-rw-r--r--app/plugins.go8
-rw-r--r--app/post.go20
-rw-r--r--app/post_test.go4
-rw-r--r--app/security_update_check.go4
-rw-r--r--app/server.go24
-rw-r--r--app/session.go8
-rw-r--r--app/status.go12
-rw-r--r--app/team.go6
-rw-r--r--app/user.go28
-rw-r--r--app/webhook.go38
-rw-r--r--app/webhook_test.go2
37 files changed, 190 insertions, 222 deletions
diff --git a/app/admin.go b/app/admin.go
index 5994fc826..fc792a3f0 100644
--- a/app/admin.go
+++ b/app/admin.go
@@ -24,7 +24,7 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
perPage = 10000
var lines []string
- if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
+ if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
lines = append(lines, a.Cluster.GetMyClusterInfo().Hostname)
@@ -39,7 +39,7 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
lines = append(lines, melines...)
- if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
+ if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
clines, err := a.Cluster.GetLogs(page, perPage)
if err != nil {
return nil, err
@@ -54,8 +54,8 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
var lines []string
- if utils.Cfg.LogSettings.EnableFile {
- file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation))
+ if a.Config().LogSettings.EnableFile {
+ file, err := os.Open(utils.GetLogFileLocation(a.Config().LogSettings.FileLocation))
if err != nil {
return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -124,7 +124,7 @@ func (a *App) InvalidateAllCachesSkipSend() {
}
func (a *App) GetConfig() *model.Config {
- json := utils.Cfg.ToJson()
+ json := a.Config().ToJson()
cfg := model.ConfigFromJson(strings.NewReader(json))
cfg.Sanitize()
@@ -140,7 +140,7 @@ func (a *App) ReloadConfig() {
}
func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
- oldCfg := utils.Cfg
+ oldCfg := a.Config()
cfg.SetDefaults()
utils.Desanitize(cfg)
@@ -152,7 +152,7 @@ func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool)
return err
}
- if *utils.Cfg.ClusterSettings.Enable && *utils.Cfg.ClusterSettings.ReadOnlyConfig {
+ if *a.Config().ClusterSettings.Enable && *a.Config().ClusterSettings.ReadOnlyConfig {
return model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, "", http.StatusForbidden)
}
@@ -162,7 +162,7 @@ func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool)
utils.EnableConfigWatch()
if a.Metrics != nil {
- if *utils.Cfg.MetricsSettings.Enable {
+ if *a.Config().MetricsSettings.Enable {
a.Metrics.StartServer()
} else {
a.Metrics.StopServer()
@@ -205,10 +205,10 @@ func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
// 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
if cfg.EmailSettings.SMTPPassword == model.FAKE_SETTING {
- if cfg.EmailSettings.SMTPServer == utils.Cfg.EmailSettings.SMTPServer &&
- cfg.EmailSettings.SMTPPort == utils.Cfg.EmailSettings.SMTPPort &&
- cfg.EmailSettings.SMTPUsername == utils.Cfg.EmailSettings.SMTPUsername {
- cfg.EmailSettings.SMTPPassword = utils.Cfg.EmailSettings.SMTPPassword
+ if cfg.EmailSettings.SMTPServer == a.Config().EmailSettings.SMTPServer &&
+ cfg.EmailSettings.SMTPPort == a.Config().EmailSettings.SMTPPort &&
+ cfg.EmailSettings.SMTPUsername == a.Config().EmailSettings.SMTPUsername {
+ cfg.EmailSettings.SMTPPassword = a.Config().EmailSettings.SMTPPassword
} else {
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
}
diff --git a/app/analytics.go b/app/analytics.go
index 65a9e4129..5d30ad426 100644
--- a/app/analytics.go
+++ b/app/analytics.go
@@ -7,7 +7,6 @@ import (
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
- "github.com/mattermost/mattermost-server/utils"
)
const (
@@ -22,8 +21,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
return nil, r.Err
} else {
systemUserCount = r.Data.(int64)
- if systemUserCount > int64(*utils.Cfg.AnalyticsSettings.MaxUsersForStatistics) {
- l4g.Debug("More than %v users on the system, intensive queries skipped", *utils.Cfg.AnalyticsSettings.MaxUsersForStatistics)
+ if systemUserCount > int64(*a.Config().AnalyticsSettings.MaxUsersForStatistics) {
+ l4g.Debug("More than %v users on the system, intensive queries skipped", *a.Config().AnalyticsSettings.MaxUsersForStatistics)
skipIntensiveQueries = true
}
}
@@ -97,7 +96,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
}
// If in HA mode then aggregrate all the stats
- if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
+ if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
stats, err := a.Cluster.GetClusterStats()
if err != nil {
return nil, err
diff --git a/app/app.go b/app/app.go
index 34c0721a0..c82520cd9 100644
--- a/app/app.go
+++ b/app/app.go
@@ -47,8 +47,7 @@ type App struct {
Mfa einterfaces.MfaInterface
Saml einterfaces.SamlInterface
- newStore func() store.Store
- configOverride func(*model.Config) *model.Config
+ newStore func() store.Store
}
var appCount = 0
@@ -234,12 +233,13 @@ func (a *App) initEnterprise() {
}
func (a *App) Config() *model.Config {
- if a.configOverride != nil {
- return a.configOverride(utils.Cfg)
- }
return utils.Cfg
}
+func (a *App) UpdateConfig(f func(*model.Config)) {
+ f(utils.Cfg)
+}
+
// Go creates a goroutine, but maintains a record of it to ensure that execution completes before
// the app is destroyed.
func (a *App) Go(f func()) {
diff --git a/app/apptestlib.go b/app/apptestlib.go
index 9c26e0bbb..3557a8727 100644
--- a/app/apptestlib.go
+++ b/app/apptestlib.go
@@ -57,10 +57,6 @@ func setupTestHelper(enterprise bool) *TestHelper {
var options []Option
if testStore != nil {
options = append(options, StoreOverride(testStore))
- options = append(options, ConfigOverride(func(cfg *model.Config) {
- cfg.ServiceSettings.ListenAddress = new(string)
- *cfg.ServiceSettings.ListenAddress = ":0"
- }))
}
th := &TestHelper{
@@ -70,7 +66,12 @@ func setupTestHelper(enterprise bool) *TestHelper {
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
*utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest()
+ prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
+ if testStore != nil {
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
+ }
th.App.StartServer()
+ th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
utils.InitHTML()
utils.EnableDebugLogForTest()
th.App.Srv.Store.MarkSystemRanUnitTests()
diff --git a/app/authentication.go b/app/authentication.go
index 01e1e0a48..7aae48b97 100644
--- a/app/authentication.go
+++ b/app/authentication.go
@@ -99,7 +99,7 @@ func (a *App) CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaTok
}
func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError {
- if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
+ if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*a.Config().ServiceSettings.EnableMultifactorAuthentication {
return nil
}
@@ -139,7 +139,7 @@ func checkUserNotDisabled(user *model.User) *model.AppError {
}
func (a *App) authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
- ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
+ ldapAvailable := *a.Config().LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
if user.AuthService == model.USER_AUTH_SERVICE_LDAP {
if !ldapAvailable {
diff --git a/app/brand.go b/app/brand.go
index b108a7b32..ea04a59be 100644
--- a/app/brand.go
+++ b/app/brand.go
@@ -8,11 +8,10 @@ import (
"net/http"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*a.Config().FileSettings.DriverName) == 0 {
return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
}
@@ -28,7 +27,7 @@ func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
}
func (a *App) GetBrandImage() ([]byte, *model.AppError) {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*a.Config().FileSettings.DriverName) == 0 {
return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
}
diff --git a/app/channel.go b/app/channel.go
index 2ab591c42..29e2309cf 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -114,8 +114,8 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod
if count, err := a.GetNumberOfChannelsOnTeam(channel.TeamId); err != nil {
return nil, err
} else {
- if int64(count+1) > *utils.Cfg.TeamSettings.MaxChannelsPerTeam {
- return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *utils.Cfg.TeamSettings.MaxChannelsPerTeam}, "", http.StatusBadRequest)
+ if int64(count+1) > *a.Config().TeamSettings.MaxChannelsPerTeam {
+ return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *a.Config().TeamSettings.MaxChannelsPerTeam}, "", http.StatusBadRequest)
}
}
@@ -212,7 +212,7 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
}
func (a *App) WaitForChannelMembership(channelId string, userId string) {
- if len(utils.Cfg.SqlSettings.DataSourceReplicas) > 0 {
+ if len(a.Config().SqlSettings.DataSourceReplicas) > 0 {
now := model.GetMillis()
for model.GetMillis()-now < 12000 {
@@ -1119,7 +1119,7 @@ func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *mod
return result.Err
}
- if *utils.Cfg.ServiceSettings.EnableChannelViewedMessages {
+ if *a.Config().ServiceSettings.EnableChannelViewedMessages {
for _, channelId := range channelIds {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userId, nil)
message.Add("channel_id", channelId)
@@ -1163,7 +1163,7 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, clearPushNotif
if len(view.PrevChannelId) > 0 {
channelIds = append(channelIds, view.PrevChannelId)
- if *utils.Cfg.EmailSettings.SendPushNotifications && clearPushNotifications && len(view.ChannelId) > 0 {
+ if *a.Config().EmailSettings.SendPushNotifications && clearPushNotifications && len(view.ChannelId) > 0 {
pchan = a.Srv.Store.User().GetUnreadCountForChannel(userId, view.ChannelId)
}
}
@@ -1191,7 +1191,7 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, clearPushNotif
times = result.Data.(map[string]int64)
}
- if *utils.Cfg.ServiceSettings.EnableChannelViewedMessages && model.IsValidId(view.ChannelId) {
+ if *a.Config().ServiceSettings.EnableChannelViewedMessages && model.IsValidId(view.ChannelId) {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userId, nil)
message.Add("channel_id", view.ChannelId)
a.Go(func() {
diff --git a/app/cluster_discovery.go b/app/cluster_discovery.go
index 5278b339d..6418ab2be 100644
--- a/app/cluster_discovery.go
+++ b/app/cluster_discovery.go
@@ -80,7 +80,7 @@ func (me *ClusterDiscoveryService) Stop() {
}
func (a *App) IsLeader() bool {
- if utils.IsLicensed() && *utils.Cfg.ClusterSettings.Enable && a.Cluster != nil {
+ if utils.IsLicensed() && *a.Config().ClusterSettings.Enable && a.Cluster != nil {
return a.Cluster.IsLeader()
} else {
return true
diff --git a/app/command.go b/app/command.go
index 811294b6d..2d1a8ef71 100644
--- a/app/command.go
+++ b/app/command.go
@@ -73,7 +73,7 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
}
}
- if *utils.Cfg.ServiceSettings.EnableCommands {
+ if *a.Config().ServiceSettings.EnableCommands {
if result := <-a.Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
return nil, result.Err
} else {
@@ -92,7 +92,7 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
}
func (a *App) ListTeamCommands(teamId string) ([]*model.Command, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("ListTeamCommands", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -115,7 +115,7 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
}
}
- if *utils.Cfg.ServiceSettings.EnableCommands {
+ if *a.Config().ServiceSettings.EnableCommands {
if result := <-a.Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
return nil, result.Err
} else {
@@ -144,7 +144,7 @@ func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *
response := provider.DoCommand(a, args, message)
return a.HandleCommandResponse(provider.GetCommand(args.T), args, response, true)
} else {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -251,7 +251,7 @@ func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandA
post.AddProp("from_webhook", "true")
}
- if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
+ if a.Config().ServiceSettings.EnablePostUsernameOverride {
if len(command.Username) != 0 {
post.AddProp("override_username", command.Username)
} else if len(response.Username) != 0 {
@@ -259,7 +259,7 @@ func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandA
}
}
- if utils.Cfg.ServiceSettings.EnablePostIconOverride {
+ if a.Config().ServiceSettings.EnablePostIconOverride {
if len(command.IconURL) != 0 {
post.AddProp("override_icon_url", command.IconURL)
} else if len(response.IconURL) != 0 {
@@ -277,7 +277,7 @@ func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandA
}
func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("CreateCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -308,7 +308,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
}
func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -321,7 +321,7 @@ func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
}
func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("UpdateCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -352,7 +352,7 @@ func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppEr
}
func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return nil, model.NewAppError("RegenCommandToken", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -366,7 +366,7 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
}
func (a *App) DeleteCommand(commandId string) *model.AppError {
- if !*utils.Cfg.ServiceSettings.EnableCommands {
+ if !*a.Config().ServiceSettings.EnableCommands {
return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
}
diff --git a/app/command_channel_rename_test.go b/app/command_channel_rename_test.go
index 372e366b9..00b9eab0a 100644
--- a/app/command_channel_rename_test.go
+++ b/app/command_channel_rename_test.go
@@ -15,7 +15,7 @@ func TestRenameProviderDoCommand(t *testing.T) {
args := &model.CommandArgs{
T: func(s string, args ...interface{}) string { return s },
ChannelId: th.BasicChannel.Id,
- Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{&model.TeamMember{TeamId: th.BasicTeam.Id, Roles: model.ROLE_TEAM_USER.Id}}},
+ Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{{TeamId: th.BasicTeam.Id, Roles: model.ROLE_TEAM_USER.Id}}},
}
// Blank text is a success
diff --git a/app/command_help.go b/app/command_help.go
index 41f3a3cb4..d3b803d8b 100644
--- a/app/command_help.go
+++ b/app/command_help.go
@@ -5,7 +5,6 @@ package app
import (
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
goi18n "github.com/nicksnyder/go-i18n/i18n"
)
@@ -34,7 +33,7 @@ func (h *HelpProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
}
func (h *HelpProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
- helpLink := *utils.Cfg.SupportSettings.HelpLink
+ helpLink := *a.Config().SupportSettings.HelpLink
if helpLink == "" {
helpLink = model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK
diff --git a/app/command_invite_people.go b/app/command_invite_people.go
index d81eaa34a..03a4d0e36 100644
--- a/app/command_invite_people.go
+++ b/app/command_invite_people.go
@@ -42,11 +42,11 @@ func (me *InvitePeopleProvider) GetCommand(T goi18n.TranslateFunc) *model.Comman
}
func (me *InvitePeopleProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
- if !utils.Cfg.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")}
}
- if !utils.Cfg.TeamSettings.EnableUserCreation {
+ if !a.Config().TeamSettings.EnableUserCreation {
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.invite_off")}
}
diff --git a/app/command_loadtest.go b/app/command_loadtest.go
index 4bc371bdc..946f70919 100644
--- a/app/command_loadtest.go
+++ b/app/command_loadtest.go
@@ -87,7 +87,7 @@ func (me *LoadTestProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
func (me *LoadTestProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
//This command is only available when EnableTesting is true
- if !utils.Cfg.ServiceSettings.EnableTesting {
+ if !a.Config().ServiceSettings.EnableTesting {
return &model.CommandResponse{}
}
diff --git a/app/compliance.go b/app/compliance.go
index 77590af6c..44e0039d8 100644
--- a/app/compliance.go
+++ b/app/compliance.go
@@ -13,7 +13,7 @@ import (
)
func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
- if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance {
+ if !*a.Config().ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance {
return nil, model.NewAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
}
@@ -25,7 +25,7 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model
}
func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
- if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
+ if !*a.Config().ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
}
@@ -44,7 +44,7 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m
}
func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
- if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
+ if !*a.Config().ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
}
diff --git a/app/diagnostics.go b/app/diagnostics.go
index 5f5ef35b2..dda86eb35 100644
--- a/app/diagnostics.go
+++ b/app/diagnostics.go
@@ -52,7 +52,7 @@ const (
var client *analytics.Client
func (a *App) SendDailyDiagnostics() {
- if *utils.Cfg.LogSettings.EnableDiagnostics && a.IsLeader() {
+ if *a.Config().LogSettings.EnableDiagnostics && a.IsLeader() {
initDiagnostics("")
a.trackActivity()
trackConfig()
@@ -483,7 +483,7 @@ func (a *App) trackServer() {
data := map[string]interface{}{
"edition": model.BuildEnterpriseReady,
"version": model.CurrentVersion,
- "database_type": *utils.Cfg.SqlSettings.DriverName,
+ "database_type": *a.Config().SqlSettings.DriverName,
"operating_system": runtime.GOOS,
}
diff --git a/app/elasticsearch.go b/app/elasticsearch.go
index 71fe6cedb..c3b558bce 100644
--- a/app/elasticsearch.go
+++ b/app/elasticsearch.go
@@ -7,13 +7,12 @@ import (
"net/http"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
)
func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
if *cfg.ElasticsearchSettings.Password == model.FAKE_SETTING {
- if *cfg.ElasticsearchSettings.ConnectionUrl == *utils.Cfg.ElasticsearchSettings.ConnectionUrl && *cfg.ElasticsearchSettings.Username == *utils.Cfg.ElasticsearchSettings.Username {
- *cfg.ElasticsearchSettings.Password = *utils.Cfg.ElasticsearchSettings.Password
+ if *cfg.ElasticsearchSettings.ConnectionUrl == *a.Config().ElasticsearchSettings.ConnectionUrl && *cfg.ElasticsearchSettings.Username == *a.Config().ElasticsearchSettings.Username {
+ *cfg.ElasticsearchSettings.Password = *a.Config().ElasticsearchSettings.Password
} else {
return model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.reenter_password", nil, "", http.StatusBadRequest)
}
diff --git a/app/email.go b/app/email.go
index 76597dea0..a96c7005c 100644
--- a/app/email.go
+++ b/app/email.go
@@ -139,9 +139,9 @@ func (a *App) SendWelcomeEmail(userId string, email string, verified bool, local
bodyPage.Props["Info3"] = T("api.templates.welcome_body.info3")
bodyPage.Props["SiteURL"] = siteURL
- if *utils.Cfg.NativeAppSettings.AppDownloadLink != "" {
+ if *a.Config().NativeAppSettings.AppDownloadLink != "" {
bodyPage.Props["AppDownloadInfo"] = T("api.templates.welcome_body.app_download_info")
- bodyPage.Props["AppDownloadLink"] = *utils.Cfg.NativeAppSettings.AppDownloadLink
+ bodyPage.Props["AppDownloadLink"] = *a.Config().NativeAppSettings.AppDownloadLink
}
if !verified {
diff --git a/app/email_batching.go b/app/email_batching.go
index 4c546531f..75e09dd17 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -23,9 +23,9 @@ const (
)
func (a *App) InitEmailBatching() {
- if *utils.Cfg.EmailSettings.EnableEmailBatching {
+ if *a.Config().EmailSettings.EnableEmailBatching {
if a.EmailBatching == nil {
- a.EmailBatching = NewEmailBatchingJob(a, *utils.Cfg.EmailSettings.EmailBatchingBufferSize)
+ a.EmailBatching = NewEmailBatchingJob(a, *a.Config().EmailSettings.EmailBatchingBufferSize)
}
// note that we don't support changing EmailBatchingBufferSize without restarting the server
@@ -35,7 +35,7 @@ func (a *App) InitEmailBatching() {
}
func (a *App) AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError {
- if !*utils.Cfg.EmailSettings.EnableEmailBatching {
+ if !*a.Config().EmailSettings.EnableEmailBatching {
return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -197,7 +197,7 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch
}
translateFunc := utils.GetUserTranslations(user.Locale)
- displayNameFormat := *utils.Cfg.TeamSettings.TeammateNameDisplay
+ displayNameFormat := *a.Config().TeamSettings.TeammateNameDisplay
var contents string
for _, notification := range notifications {
@@ -221,23 +221,23 @@ func (a *App) sendBatchedEmailNotification(userId string, notifications []*batch
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed() && *utils.License().Features.EmailNotificationContents {
- emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
+ emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType
}
- contents += a.renderBatchedPost(notification, channel, sender, *utils.Cfg.ServiceSettings.SiteURL, displayNameFormat, translateFunc, user.Locale, emailNotificationContentsType)
+ contents += a.renderBatchedPost(notification, channel, sender, *a.Config().ServiceSettings.SiteURL, displayNameFormat, translateFunc, user.Locale, emailNotificationContentsType)
}
tm := time.Unix(notifications[0].post.CreateAt/1000, 0)
subject := translateFunc("api.email_batching.send_batched_email_notification.subject", len(notifications), map[string]interface{}{
- "SiteName": utils.Cfg.TeamSettings.SiteName,
+ "SiteName": a.Config().TeamSettings.SiteName,
"Year": tm.Year(),
"Month": translateFunc(tm.Month().String()),
"Day": tm.Day(),
})
body := utils.NewHTMLTemplate("post_batched_body", user.Locale)
- body.Props["SiteURL"] = *utils.Cfg.ServiceSettings.SiteURL
+ body.Props["SiteURL"] = *a.Config().ServiceSettings.SiteURL
body.Props["Posts"] = template.HTML(contents)
body.Props["BodyText"] = translateFunc("api.email_batching.send_batched_email_notification.body_text", len(notifications))
diff --git a/app/emoji.go b/app/emoji.go
index 308791aed..ba2bb4494 100644
--- a/app/emoji.go
+++ b/app/emoji.go
@@ -137,11 +137,11 @@ func (a *App) DeleteEmoji(emoji *model.Emoji) *model.AppError {
}
func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableCustomEmoji {
+ if !*a.Config().ServiceSettings.EnableCustomEmoji {
return nil, model.NewAppError("deleteEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
}
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*a.Config().FileSettings.DriverName) == 0 {
return nil, model.NewAppError("deleteImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
}
diff --git a/app/file.go b/app/file.go
index 2beb7231a..11e503c40 100644
--- a/app/file.go
+++ b/app/file.go
@@ -244,7 +244,7 @@ func GeneratePublicLinkHash(fileId, salt string) string {
}
func (a *App) UploadFiles(teamId string, channelId string, userId string, fileHeaders []*multipart.FileHeader, clientIds []string) (*model.FileUploadResponse, *model.AppError) {
- if len(*utils.Cfg.FileSettings.DriverName) == 0 {
+ if len(*a.Config().FileSettings.DriverName) == 0 {
return nil, model.NewAppError("uploadFile", "api.file.upload_file.storage.app_error", nil, "", http.StatusNotImplemented)
}
diff --git a/app/import.go b/app/import.go
index f7f9cf144..217e924b4 100644
--- a/app/import.go
+++ b/app/import.go
@@ -558,8 +558,8 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError {
hasUserChanged = true
}
} else {
- if user.Locale != *utils.Cfg.LocalizationSettings.DefaultClientLocale {
- user.Locale = *utils.Cfg.LocalizationSettings.DefaultClientLocale
+ if user.Locale != *a.Config().LocalizationSettings.DefaultClientLocale {
+ user.Locale = *a.Config().LocalizationSettings.DefaultClientLocale
hasUserChanged = true
}
}
diff --git a/app/ldap.go b/app/ldap.go
index 119587866..f1d46f824 100644
--- a/app/ldap.go
+++ b/app/ldap.go
@@ -13,7 +13,7 @@ import (
func (a *App) SyncLdap() {
a.Go(func() {
- if utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
+ if utils.IsLicensed() && *utils.License().Features.LDAP && *a.Config().LdapSettings.Enable {
if ldapI := a.Ldap; ldapI != nil {
ldapI.StartSynchronizeJob(false)
} else {
@@ -24,7 +24,7 @@ func (a *App) SyncLdap() {
}
func (a *App) TestLdap() *model.AppError {
- if ldapI := a.Ldap; ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
+ if ldapI := a.Ldap; ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *a.Config().LdapSettings.Enable {
if err := ldapI.RunTest(); err != nil {
err.StatusCode = 500
return err
diff --git a/app/login.go b/app/login.go
index 18b26c55c..ecc0f0163 100644
--- a/app/login.go
+++ b/app/login.go
@@ -10,7 +10,6 @@ import (
"time"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/utils"
"github.com/mssola/user_agent"
)
@@ -58,10 +57,10 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId
func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) (*model.Session, *model.AppError) {
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceId, IsOAuth: false}
- maxAge := *utils.Cfg.ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
+ maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
if len(deviceId) > 0 {
- session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
+ session.SetExpireInDays(*a.Config().ServiceSettings.SessionLengthMobileInDays)
// A special case where we logout of all other sessions with the same Id
if err := a.RevokeSessionsForDeviceId(user.Id, deviceId, ""); err != nil {
@@ -69,7 +68,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
return nil, err
}
} else {
- session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthWebInDays)
+ session.SetExpireInDays(*a.Config().ServiceSettings.SessionLengthWebInDays)
}
ua := user_agent.New(r.UserAgent())
diff --git a/app/notification.go b/app/notification.go
index 2a8f9ff2e..e11218faa 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -149,7 +149,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
senderUsername = sender.Username
}
- if utils.Cfg.EmailSettings.SendEmailNotifications {
+ if a.Config().EmailSettings.SendEmailNotifications {
for _, id := range mentionedUsersList {
userAllowsEmails := profileMap[id].NotifyProps[model.EMAIL_NOTIFY_PROP] != "false"
if channelEmail, ok := channelMemberNotifyPropsMap[id][model.EMAIL_NOTIFY_PROP]; ok {
@@ -159,7 +159,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 utils.Cfg.EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
+ if a.Config().EmailSettings.RequireEmailVerification && !profileMap[id].EmailVerified {
l4g.Error("Skipped sending notification email to %v, address not verified. [details: user_id=%v]", profileMap[id].Email, id)
continue
}
@@ -185,37 +185,37 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
T := utils.GetUserTranslations(sender.Locale)
// If the channel has more than 1K users then @here is disabled
- if hereNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
+ if hereNotification && int64(len(profileMap)) > *a.Config().TeamSettings.MaxNotificationsPerChannel {
hereNotification = false
a.SendEphemeralPost(
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
- Message: T("api.post.disabled_here", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
+ Message: T("api.post.disabled_here", map[string]interface{}{"Users": *a.Config().TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
}
// If the channel has more than 1K users then @channel is disabled
- if channelNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
+ if channelNotification && int64(len(profileMap)) > *a.Config().TeamSettings.MaxNotificationsPerChannel {
a.SendEphemeralPost(
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
- Message: T("api.post.disabled_channel", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
+ Message: T("api.post.disabled_channel", map[string]interface{}{"Users": *a.Config().TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
}
// If the channel has more than 1K users then @all is disabled
- if allNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
+ if allNotification && int64(len(profileMap)) > *a.Config().TeamSettings.MaxNotificationsPerChannel {
a.SendEphemeralPost(
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
- Message: T("api.post.disabled_all", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
+ Message: T("api.post.disabled_all", map[string]interface{}{"Users": *a.Config().TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
@@ -231,8 +231,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
sendPushNotifications := false
- if *utils.Cfg.EmailSettings.SendPushNotifications {
- pushServer := *utils.Cfg.EmailSettings.PushNotificationServer
+ if *a.Config().EmailSettings.SendPushNotifications {
+ pushServer := *a.Config().EmailSettings.PushNotificationServer
if pushServer == model.MHPNS && (!utils.IsLicensed() || !*utils.License().Features.MHPNS) {
l4g.Warn(utils.T("api.post.send_notifications_and_forget.push_notification.mhpnsWarn"))
sendPushNotifications = false
@@ -323,11 +323,11 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel
team = teams[0]
} else {
// in case the user hasn't joined any teams we send them to the select_team page
- team = &model.Team{Name: "select_team", DisplayName: utils.Cfg.TeamSettings.SiteName}
+ team = &model.Team{Name: "select_team", DisplayName: a.Config().TeamSettings.SiteName}
}
}
}
- if *utils.Cfg.EmailSettings.EnableEmailBatching {
+ if *a.Config().EmailSettings.EnableEmailBatching {
var sendBatched bool
if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); result.Err != nil {
// if the call fails, assume that the interval has not been explicitly set and batch the notifications
@@ -350,14 +350,14 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel
var subjectText string
if channel.Type == model.CHANNEL_DIRECT {
- subjectText = getDirectMessageNotificationEmailSubject(post, translateFunc, utils.Cfg.TeamSettings.SiteName, senderName)
+ subjectText = getDirectMessageNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, senderName)
} else {
- subjectText = getNotificationEmailSubject(post, translateFunc, utils.Cfg.TeamSettings.SiteName, team.DisplayName)
+ subjectText = getNotificationEmailSubject(post, translateFunc, a.Config().TeamSettings.SiteName, team.DisplayName)
}
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if utils.IsLicensed() && *utils.License().Features.EmailNotificationContents {
- emailNotificationContentsType = *utils.Cfg.EmailSettings.EmailNotificationContentsType
+ emailNotificationContentsType = *a.Config().EmailSettings.EmailNotificationContentsType
}
teamURL := utils.GetSiteURL() + "/" + team.Name
@@ -594,14 +594,14 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
msg.FromWebhook = fw.(string)
}
- if *utils.Cfg.EmailSettings.PushNotificationContents == model.FULL_NOTIFICATION {
+ if *a.Config().EmailSettings.PushNotificationContents == model.FULL_NOTIFICATION {
msg.Category = model.CATEGORY_CAN_REPLY
if channel.Type == model.CHANNEL_DIRECT {
msg.Message = senderName + ": " + model.ClearMentionTags(post.Message)
} else {
msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_in") + channelName + ": " + model.ClearMentionTags(post.Message)
}
- } else if *utils.Cfg.EmailSettings.PushNotificationContents == model.GENERIC_NO_CHANNEL_NOTIFICATION {
+ } else if *a.Config().EmailSettings.PushNotificationContents == model.GENERIC_NO_CHANNEL_NOTIFICATION {
if channel.Type == model.CHANNEL_DIRECT {
msg.Category = model.CATEGORY_CAN_REPLY
msg.Message = senderName + userLocale("api.post.send_notifications_and_forget.push_message")
@@ -693,7 +693,7 @@ func (a *App) ClearPushNotification(userId string, channelId string) {
func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session) {
msg.ServerId = utils.CfgDiagnosticId
- request, _ := http.NewRequest("POST", *utils.Cfg.EmailSettings.PushNotificationServer+model.API_URL_SUFFIX_V1+"/send_push", strings.NewReader(msg.ToJson()))
+ request, _ := http.NewRequest("POST", *a.Config().EmailSettings.PushNotificationServer+model.API_URL_SUFFIX_V1+"/send_push", strings.NewReader(msg.ToJson()))
if resp, err := utils.HttpClient(true).Do(request); err != nil {
l4g.Error("Device push reported as error for UserId=%v SessionId=%v message=%v", session.UserId, session.Id, err.Error())
diff --git a/app/oauth.go b/app/oauth.go
index 5a02f6238..83e9390c5 100644
--- a/app/oauth.go
+++ b/app/oauth.go
@@ -25,7 +25,7 @@ const (
)
func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("CreateOAuthApp", "api.oauth.register_oauth_app.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -40,7 +40,7 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr
}
func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -52,7 +52,7 @@ func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) {
}
func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("UpdateOauthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -69,7 +69,7 @@ func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp
}
func (a *App) DeleteOAuthApp(appId string) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return model.NewAppError("DeleteOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -83,7 +83,7 @@ func (a *App) DeleteOAuthApp(appId string) *model.AppError {
}
func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -95,7 +95,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) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -107,7 +107,7 @@ func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.
}
func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -153,7 +153,7 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author
}
func (a *App) GetOAuthAccessToken(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -234,7 +234,7 @@ func (a *App) GetOAuthAccessToken(clientId, grantType, redirectUri, code, secret
AccessToken: session.Token,
TokenType: model.ACCESS_TOKEN_TYPE,
RefreshToken: accessData.RefreshToken,
- ExpiresIn: int32(*utils.Cfg.ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24),
+ ExpiresIn: int32(*a.Config().ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24),
}
}
@@ -266,7 +266,7 @@ func (a *App) GetOAuthAccessToken(clientId, grantType, redirectUri, code, secret
func (a *App) newSession(appName string, user *model.User) (*model.Session, *model.AppError) {
// set new token an session
session := &model.Session{UserId: user.Id, Roles: user.Roles, IsOAuth: true}
- session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthSSOInDays)
+ session.SetExpireInDays(*a.Config().ServiceSettings.SessionLengthSSOInDays)
session.AddProp(model.SESSION_PROP_PLATFORM, appName)
session.AddProp(model.SESSION_PROP_OS, "OAuth2")
session.AddProp(model.SESSION_PROP_BROWSER, "OAuth2")
@@ -302,7 +302,7 @@ func (a *App) newSessionUpdateToken(appName string, accessData *model.AccessData
AccessToken: session.Token,
RefreshToken: accessData.RefreshToken,
TokenType: model.ACCESS_TOKEN_TYPE,
- ExpiresIn: int32(*utils.Cfg.ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24),
+ ExpiresIn: int32(*a.Config().ServiceSettings.SessionLengthSSOInDays * 60 * 60 * 24),
}
return accessRsp, nil
@@ -341,7 +341,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) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("GetAuthorizedAppsForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -359,7 +359,7 @@ func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*mod
}
func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -389,7 +389,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError {
}
func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
+ if !a.Config().ServiceSettings.EnableOAuthServiceProvider {
return nil, model.NewAppError("RegenerateOAuthAppSecret", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
}
@@ -563,7 +563,7 @@ func generateOAuthStateTokenExtra(email, action, cookie string) string {
}
func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
- sso := utils.Cfg.GetSSOService(service)
+ sso := a.Config().GetSSOService(service)
if sso != nil && !sso.Enable {
return "", model.NewAppError("GetAuthorizationCode", "api.user.get_authorization_code.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
}
@@ -616,7 +616,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) {
- sso := utils.Cfg.GetSSOService(service)
+ sso := a.Config().GetSSOService(service)
if sso == nil || !sso.Enable {
return nil, "", nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.unsupported.app_error", nil, "service="+service, http.StatusNotImplemented)
}
diff --git a/app/options.go b/app/options.go
index 121bbbf80..34fa92d93 100644
--- a/app/options.go
+++ b/app/options.go
@@ -4,39 +4,11 @@
package app
import (
- "github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
)
type Option func(a *App)
-// By default, the app will use a global configuration file. This allows you to override all or part
-// of that configuration.
-//
-// The override parameter must be a *model.Config, func(*model.Config), or func(*model.Config) *model.Config.
-//
-// XXX: Most code will not respect this at the moment. (We need to eliminate utils.Cfg first.)
-func ConfigOverride(override interface{}) Option {
- return func(a *App) {
- switch o := override.(type) {
- case *model.Config:
- a.configOverride = func(*model.Config) *model.Config {
- return o
- }
- case func(*model.Config):
- a.configOverride = func(cfg *model.Config) *model.Config {
- ret := *cfg
- o(&ret)
- return &ret
- }
- case func(*model.Config) *model.Config:
- a.configOverride = o
- default:
- panic("invalid ConfigOverride")
- }
- }
-}
-
// By default, the app will use the store specified by the configuration. This allows you to
// construct an app with a different store.
//
diff --git a/app/plugins.go b/app/plugins.go
index 9826674f1..ca3fe610c 100644
--- a/app/plugins.go
+++ b/app/plugins.go
@@ -295,7 +295,7 @@ func (a *App) ActivatePlugins() {
}
func (a *App) UnpackAndActivatePlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
- if a.PluginEnv == nil || !*utils.Cfg.PluginSettings.Enable {
+ if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -346,7 +346,7 @@ func (a *App) UnpackAndActivatePlugin(pluginFile io.Reader) (*model.Manifest, *m
}
func (a *App) GetActivePluginManifests() ([]*model.Manifest, *model.AppError) {
- if a.PluginEnv == nil || !*utils.Cfg.PluginSettings.Enable {
+ if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
return nil, model.NewAppError("GetActivePluginManifests", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -361,7 +361,7 @@ func (a *App) GetActivePluginManifests() ([]*model.Manifest, *model.AppError) {
}
func (a *App) RemovePlugin(id string) *model.AppError {
- if a.PluginEnv == nil || !*utils.Cfg.PluginSettings.Enable {
+ if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
return model.NewAppError("RemovePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -394,7 +394,7 @@ func (a *App) RemovePlugin(id string) *model.AppError {
}
func (a *App) InitPlugins(pluginPath, webappPath string) {
- if !utils.IsLicensed() || !*utils.License().Features.FutureFeatures || !*utils.Cfg.PluginSettings.Enable {
+ if !utils.IsLicensed() || !*utils.License().Features.FutureFeatures || !*a.Config().PluginSettings.Enable {
return
}
diff --git a/app/post.go b/app/post.go
index da5661ae2..f12866217 100644
--- a/app/post.go
+++ b/app/post.go
@@ -77,7 +77,7 @@ func (a *App) CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError)
l4g.Error(utils.T("api.post.create_post.last_viewed.error"), post.ChannelId, post.UserId, result.Err)
}
- if *utils.Cfg.ServiceSettings.EnableChannelViewedMessages {
+ if *a.Config().ServiceSettings.EnableChannelViewedMessages {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", post.UserId, nil)
message.Add("channel_id", post.ChannelId)
a.Go(func() {
@@ -117,7 +117,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
user = result.Data.(*model.User)
}
- if utils.IsLicensed() && *utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly &&
+ if utils.IsLicensed() && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
!post.IsSystemMessage() &&
channel.Name == model.DEFAULT_CHANNEL &&
!CheckIfRolesGrantPermission(user.GetRoles(), model.PERMISSION_MANAGE_SYSTEM.Id) {
@@ -158,7 +158,7 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
}
esInterface := a.Elasticsearch
- if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
+ if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() {
esInterface.IndexPost(rpost, channel.TeamId)
})
@@ -280,7 +280,7 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
oldPost = result.Data.(*model.PostList).Posts[post.Id]
if utils.IsLicensed() {
- if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_NEVER && post.Message != oldPost.Message {
+ if *a.Config().ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_NEVER && post.Message != oldPost.Message {
err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_denied.app_error", nil, "", http.StatusForbidden)
return nil, err
}
@@ -302,8 +302,8 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
}
if utils.IsLicensed() {
- if *utils.Cfg.ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_TIME_LIMIT && model.GetMillis() > oldPost.CreateAt+int64(*utils.Cfg.ServiceSettings.PostEditTimeLimit*1000) && post.Message != oldPost.Message {
- err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_time_limit.app_error", map[string]interface{}{"timeLimit": *utils.Cfg.ServiceSettings.PostEditTimeLimit}, "", http.StatusBadRequest)
+ if *a.Config().ServiceSettings.AllowEditPost == model.ALLOW_EDIT_POST_TIME_LIMIT && model.GetMillis() > oldPost.CreateAt+int64(*a.Config().ServiceSettings.PostEditTimeLimit*1000) && post.Message != oldPost.Message {
+ err := model.NewAppError("UpdatePost", "api.post.update_post.permissions_time_limit.app_error", map[string]interface{}{"timeLimit": *a.Config().ServiceSettings.PostEditTimeLimit}, "", http.StatusBadRequest)
return nil, err
}
}
@@ -331,7 +331,7 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
rpost := result.Data.(*model.Post)
esInterface := a.Elasticsearch
- if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
+ if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() {
if rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
l4g.Error("Couldn't get channel %v for post %v for Elasticsearch indexing.", rpost.ChannelId, rpost.Id)
@@ -523,7 +523,7 @@ func (a *App) DeletePost(postId string) (*model.Post, *model.AppError) {
})
esInterface := a.Elasticsearch
- if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
+ if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() {
esInterface.DeletePost(post)
})
@@ -556,7 +556,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
paramsList := model.ParseSearchParams(terms)
esInterface := a.Elasticsearch
- if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch {
+ if esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch {
finalParamsList := []*model.SearchParams{}
for _, params := range paramsList {
@@ -617,7 +617,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
return postList, nil
} else {
- if !*utils.Cfg.ServiceSettings.EnablePostSearch {
+ if !*a.Config().ServiceSettings.EnablePostSearch {
return nil, model.NewAppError("SearchPostsInTeam", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v", teamId, userId), http.StatusNotImplemented)
}
diff --git a/app/post_test.go b/app/post_test.go
index 5fa3d50d6..24910f964 100644
--- a/app/post_test.go
+++ b/app/post_test.go
@@ -106,10 +106,10 @@ func TestPostAction(t *testing.T) {
UserId: th.BasicUser.Id,
Props: model.StringInterface{
"attachments": []*model.SlackAttachment{
- &model.SlackAttachment{
+ {
Text: "hello",
Actions: []*model.PostAction{
- &model.PostAction{
+ {
Integration: &model.PostActionIntegration{
Context: model.StringInterface{
"s": "foo",
diff --git a/app/security_update_check.go b/app/security_update_check.go
index 32d1f4d31..bac558c8c 100644
--- a/app/security_update_check.go
+++ b/app/security_update_check.go
@@ -31,7 +31,7 @@ const (
)
func (a *App) DoSecurityUpdateCheck() {
- if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
+ if *a.Config().ServiceSettings.EnableSecurityFixAlert {
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
props := result.Data.(model.StringMap)
lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
@@ -45,7 +45,7 @@ func (a *App) DoSecurityUpdateCheck() {
v.Set(PROP_SECURITY_ID, utils.CfgDiagnosticId)
v.Set(PROP_SECURITY_BUILD, model.CurrentVersion+"."+model.BuildNumber)
v.Set(PROP_SECURITY_ENTERPRISE_READY, model.BuildEnterpriseReady)
- v.Set(PROP_SECURITY_DATABASE, *utils.Cfg.SqlSettings.DriverName)
+ v.Set(PROP_SECURITY_DATABASE, *a.Config().SqlSettings.DriverName)
v.Set(PROP_SECURITY_OS, runtime.GOOS)
if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
diff --git a/app/server.go b/app/server.go
index d686c1f24..f8dca6a4c 100644
--- a/app/server.go
+++ b/app/server.go
@@ -123,18 +123,18 @@ func (a *App) StartServer() {
var handler http.Handler = &CorsWrapper{a.Srv.Router}
- if *utils.Cfg.RateLimitSettings.Enable {
+ if *a.Config().RateLimitSettings.Enable {
l4g.Info(utils.T("api.server.start_server.rate.info"))
- store, err := memstore.New(*utils.Cfg.RateLimitSettings.MemoryStoreSize)
+ store, err := memstore.New(*a.Config().RateLimitSettings.MemoryStoreSize)
if err != nil {
l4g.Critical(utils.T("api.server.start_server.rate_limiting_memory_store"))
return
}
quota := throttled.RateQuota{
- MaxRate: throttled.PerSec(*utils.Cfg.RateLimitSettings.PerSec),
- MaxBurst: *utils.Cfg.RateLimitSettings.MaxBurst,
+ MaxRate: throttled.PerSec(*a.Config().RateLimitSettings.PerSec),
+ MaxBurst: *a.Config().RateLimitSettings.MaxBurst,
}
rateLimiter, err := throttled.NewGCRARateLimiter(store, quota)
@@ -157,13 +157,13 @@ func (a *App) StartServer() {
a.Srv.Server = &http.Server{
Handler: handlers.RecoveryHandler(handlers.RecoveryLogger(&RecoveryLogger{}), handlers.PrintRecoveryStack(true))(handler),
- ReadTimeout: time.Duration(*utils.Cfg.ServiceSettings.ReadTimeout) * time.Second,
- WriteTimeout: time.Duration(*utils.Cfg.ServiceSettings.WriteTimeout) * time.Second,
+ ReadTimeout: time.Duration(*a.Config().ServiceSettings.ReadTimeout) * time.Second,
+ WriteTimeout: time.Duration(*a.Config().ServiceSettings.WriteTimeout) * time.Second,
}
addr := *a.Config().ServiceSettings.ListenAddress
if addr == "" {
- if *utils.Cfg.ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
+ if *a.Config().ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
addr = ":https"
} else {
addr = ":http"
@@ -179,7 +179,7 @@ func (a *App) StartServer() {
l4g.Info(utils.T("api.server.start_server.listening.info"), listener.Addr().String())
- if *utils.Cfg.ServiceSettings.Forward80To443 {
+ if *a.Config().ServiceSettings.Forward80To443 {
go func() {
redirectListener, err := net.Listen("tcp", ":80")
if err != nil {
@@ -196,10 +196,10 @@ func (a *App) StartServer() {
a.Srv.didFinishListen = make(chan struct{})
go func() {
var err error
- if *utils.Cfg.ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
- if *utils.Cfg.ServiceSettings.UseLetsEncrypt {
+ if *a.Config().ServiceSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
+ if *a.Config().ServiceSettings.UseLetsEncrypt {
var m letsencrypt.Manager
- m.CacheFile(*utils.Cfg.ServiceSettings.LetsEncryptCertificateCacheFile)
+ m.CacheFile(*a.Config().ServiceSettings.LetsEncryptCertificateCacheFile)
tlsConfig := &tls.Config{
GetCertificate: m.GetCertificate,
@@ -210,7 +210,7 @@ func (a *App) StartServer() {
a.Srv.Server.TLSConfig = tlsConfig
err = a.Srv.Server.ServeTLS(listener, "", "")
} else {
- err = a.Srv.Server.ServeTLS(listener, *utils.Cfg.ServiceSettings.TLSCertFile, *utils.Cfg.ServiceSettings.TLSKeyFile)
+ err = a.Srv.Server.ServeTLS(listener, *a.Config().ServiceSettings.TLSCertFile, *a.Config().ServiceSettings.TLSKeyFile)
}
} else {
err = a.Srv.Server.Serve(listener)
diff --git a/app/session.go b/app/session.go
index be79b0266..f8b931043 100644
--- a/app/session.go
+++ b/app/session.go
@@ -71,12 +71,12 @@ func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
return nil, model.NewAppError("GetSession", "api.context.invalid_token.error", map[string]interface{}{"Token": token}, "", http.StatusUnauthorized)
}
- if *utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes > 0 &&
+ if *a.Config().ServiceSettings.SessionIdleTimeoutInMinutes > 0 &&
utils.IsLicensed() && *utils.License().Features.Compliance &&
session != nil && !session.IsOAuth && !session.IsMobileApp() &&
session.Props[model.SESSION_PROP_TYPE] != model.SESSION_TYPE_USER_ACCESS_TOKEN {
- timeout := int64(*utils.Cfg.ServiceSettings.SessionIdleTimeoutInMinutes) * 1000 * 60
+ timeout := int64(*a.Config().ServiceSettings.SessionIdleTimeoutInMinutes) * 1000 * 60
if model.GetMillis()-session.LastActivityAt > timeout {
a.RevokeSessionById(session.Id)
return nil, model.NewAppError("GetSession", "api.context.invalid_token.error", map[string]interface{}{"Token": token}, "idle timeout", http.StatusUnauthorized)
@@ -231,7 +231,7 @@ func (a *App) UpdateLastActivityAtIfNeeded(session model.Session) {
}
func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableUserAccessTokens {
+ if !*a.Config().ServiceSettings.EnableUserAccessTokens {
return nil, model.NewAppError("CreateUserAccessToken", "app.user_access_token.disabled", nil, "", http.StatusNotImplemented)
}
@@ -259,7 +259,7 @@ func (a *App) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAc
}
func (a *App) createSessionForUserAccessToken(tokenString string) (*model.Session, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableUserAccessTokens {
+ if !*a.Config().ServiceSettings.EnableUserAccessTokens {
return nil, model.NewAppError("createSessionForUserAccessToken", "app.user_access_token.invalid_or_missing", nil, "EnableUserAccessTokens=false", http.StatusUnauthorized)
}
diff --git a/app/status.go b/app/status.go
index 3d4837cb0..56bad2105 100644
--- a/app/status.go
+++ b/app/status.go
@@ -57,7 +57,7 @@ func GetAllStatuses() map[string]*model.Status {
}
func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return map[string]interface{}{}, nil
}
@@ -104,7 +104,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
//GetUserStatusesByIds used by apiV4
func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return []*model.Status{}, nil
}
@@ -161,7 +161,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
}
func (a *App) SetStatusOnline(userId string, sessionId string, manual bool) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return
}
@@ -227,7 +227,7 @@ func (a *App) BroadcastStatus(status *model.Status) {
}
func (a *App) SetStatusOffline(userId string, manual bool) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return
}
@@ -253,7 +253,7 @@ func (a *App) SetStatusOffline(userId string, manual bool) {
}
func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return
}
@@ -307,7 +307,7 @@ func GetStatusFromCache(userId string) *model.Status {
}
func (a *App) GetStatus(userId string) (*model.Status, *model.AppError) {
- if !*utils.Cfg.ServiceSettings.EnableUserStatuses {
+ if !*a.Config().ServiceSettings.EnableUserStatuses {
return &model.Status{}, nil
}
diff --git a/app/team.go b/app/team.go
index 1bc77c9f0..61d0f52b6 100644
--- a/app/team.go
+++ b/app/team.go
@@ -215,7 +215,7 @@ func (a *App) AddUserToTeamByTeamId(teamId string, user *model.User) *model.AppE
func (a *App) AddUserToTeamByHash(userId string, hash string, data string) (*model.Team, *model.AppError) {
props := model.MapFromJson(strings.NewReader(data))
- if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt)) {
+ if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, a.Config().EmailSettings.InviteSalt)) {
return nil, model.NewAppError("JoinUserToTeamByHash", "api.user.create_user.signup_link_invalid.app_error", nil, "", http.StatusBadRequest)
}
@@ -674,7 +674,7 @@ func (a *App) InviteNewUsersToTeam(emailList []string, teamId, senderId string)
user = result.Data.(*model.User)
}
- nameFormat := *utils.Cfg.TeamSettings.TeammateNameDisplay
+ nameFormat := *a.Config().TeamSettings.TeammateNameDisplay
SendInviteEmails(team, user.GetDisplayName(nameFormat), emailList, utils.GetSiteURL())
return nil
@@ -812,7 +812,7 @@ func (a *App) GetTeamIdFromQuery(query url.Values) (string, *model.AppError) {
data := query.Get("d")
props := model.MapFromJson(strings.NewReader(data))
- if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt)) {
+ if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, a.Config().EmailSettings.InviteSalt)) {
return "", model.NewAppError("GetTeamIdFromQuery", "api.oauth.singup_with_oauth.invalid_link.app_error", nil, "", http.StatusBadRequest)
}
diff --git a/app/user.go b/app/user.go
index edb4961fc..f27e4e06f 100644
--- a/app/user.go
+++ b/app/user.go
@@ -45,7 +45,7 @@ func (a *App) CreateUserWithHash(user *model.User, hash string, data string) (*m
props := model.MapFromJson(strings.NewReader(data))
- if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt)) {
+ if hash != utils.HashSha256(fmt.Sprintf("%v:%v", data, a.Config().EmailSettings.InviteSalt)) {
return nil, model.NewAppError("CreateUserWithHash", "api.user.create_user.signup_link_invalid.app_error", nil, "", http.StatusInternalServerError)
}
@@ -131,7 +131,7 @@ func (a *App) CreateUserFromSignup(user *model.User) (*model.User, *model.AppErr
return nil, err
}
- if !a.IsFirstUserAccount() && !*utils.Cfg.TeamSettings.EnableOpenServer {
+ if !a.IsFirstUserAccount() && !*a.Config().TeamSettings.EnableOpenServer {
err := model.NewAppError("CreateUserFromSignup", "api.user.create_user.no_open_server", nil, "email="+user.Email, http.StatusForbidden)
return nil, err
}
@@ -175,7 +175,7 @@ func (a *App) IsFirstUserAccount() bool {
}
func (a *App) CreateUser(user *model.User) (*model.User, *model.AppError) {
- if !user.IsLDAPUser() && !user.IsSAMLUser() && !CheckUserDomain(user, utils.Cfg.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)
}
@@ -193,7 +193,7 @@ func (a *App) CreateUser(user *model.User) (*model.User, *model.AppError) {
}
if _, ok := utils.GetSupportedLocales()[user.Locale]; !ok {
- user.Locale = *utils.Cfg.LocalizationSettings.DefaultClientLocale
+ user.Locale = *a.Config().LocalizationSettings.DefaultClientLocale
}
if ruser, err := a.createUser(user); err != nil {
@@ -241,7 +241,7 @@ func (a *App) createUser(user *model.User) (*model.User, *model.AppError) {
}
func (a *App) CreateOAuthUser(service string, userData io.Reader, teamId string) (*model.User, *model.AppError) {
- if !utils.Cfg.TeamSettings.EnableUserCreation {
+ if !a.Config().TeamSettings.EnableUserCreation {
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_user.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -374,12 +374,12 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User,
}
func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *model.AppError) {
- ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
+ ldapAvailable := *a.Config().LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
if result := <-a.Srv.Store.User().GetForLogin(
loginId,
- *utils.Cfg.EmailSettings.EnableSignInWithUsername && !onlyLdap,
- *utils.Cfg.EmailSettings.EnableSignInWithEmail && !onlyLdap,
+ *a.Config().EmailSettings.EnableSignInWithUsername && !onlyLdap,
+ *a.Config().EmailSettings.EnableSignInWithEmail && !onlyLdap,
ldapAvailable,
); result.Err != nil && result.Err.Id == "store.sql_user.get_for_login.multiple_users" {
// don't fall back to LDAP in this case since we already know there's an LDAP user, but that it shouldn't work
@@ -438,7 +438,7 @@ func (a *App) GetUsersPage(page int, perPage int, asAdmin bool) ([]*model.User,
}
func (a *App) GetUsersEtag() string {
- return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForAllProfiles()).Data.(string), utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress)
+ return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForAllProfiles()).Data.(string), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress)
}
func (a *App) GetUsersInTeam(teamId string, offset int, limit int) ([]*model.User, *model.AppError) {
@@ -492,11 +492,11 @@ func (a *App) GetUsersNotInTeamPage(teamId string, page int, perPage int, asAdmi
}
func (a *App) GetUsersInTeamEtag(teamId string) string {
- return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForProfiles(teamId)).Data.(string), utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress)
+ return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForProfiles(teamId)).Data.(string), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress)
}
func (a *App) GetUsersNotInTeamEtag(teamId string) string {
- return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForProfilesNotInTeam(teamId)).Data.(string), utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress)
+ return fmt.Sprintf("%v.%v.%v", (<-a.Srv.Store.User().GetEtagForProfilesNotInTeam(teamId)).Data.(string), a.Config().PrivacySettings.ShowFullName, a.Config().PrivacySettings.ShowEmailAddress)
}
func (a *App) GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError) {
@@ -823,7 +823,7 @@ func (a *App) SetProfileImage(userId string, imageData *multipart.FileHeader) *m
if user, err := a.GetUser(userId); err != nil {
l4g.Error(utils.T("api.user.get_me.getting.error"), userId)
} else {
- options := utils.Cfg.GetSanitizeOptions()
+ options := a.Config().GetSanitizeOptions()
user.SanitizeProfile(options)
omitUsers := make(map[string]bool, 1)
@@ -908,7 +908,7 @@ func (a *App) UpdateActive(user *model.User, active bool) (*model.User, *model.A
}
ruser := result.Data.([2]*model.User)[0]
- options := utils.Cfg.GetSanitizeOptions()
+ options := a.Config().GetSanitizeOptions()
options["passwordupdate"] = false
ruser.Sanitize(options)
@@ -1001,7 +1001,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
}
})
- if utils.Cfg.EmailSettings.RequireEmailVerification {
+ if a.Config().EmailSettings.RequireEmailVerification {
if err := a.SendEmailVerification(rusers[0]); err != nil {
l4g.Error(err.Error())
}
diff --git a/app/webhook.go b/app/webhook.go
index 231fe1529..e8f9936f8 100644
--- a/app/webhook.go
+++ b/app/webhook.go
@@ -22,7 +22,7 @@ const (
)
func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil
}
@@ -140,7 +140,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
metrics.IncrementWebhookPost()
}
- if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
+ if a.Config().ServiceSettings.EnablePostUsernameOverride {
if len(overrideUsername) != 0 {
post.AddProp("override_username", overrideUsername)
} else {
@@ -148,7 +148,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
}
}
- if utils.Cfg.ServiceSettings.EnablePostIconOverride {
+ if a.Config().ServiceSettings.EnablePostIconOverride {
if len(overrideIconUrl) != 0 {
post.AddProp("override_icon_url", overrideIconUrl)
}
@@ -200,7 +200,7 @@ 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) {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -215,7 +215,7 @@ func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.C
}
func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -235,7 +235,7 @@ func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook)
}
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -249,7 +249,7 @@ func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
}
func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -261,7 +261,7 @@ func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.
}
func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -273,7 +273,7 @@ func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) (
}
func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -285,7 +285,7 @@ func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebho
}
func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -333,7 +333,7 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
}
func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -384,7 +384,7 @@ func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook)
}
func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -396,7 +396,7 @@ func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.
}
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -408,7 +408,7 @@ func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebho
}
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -420,7 +420,7 @@ func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage
}
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("GetOutgoingWebhooksForTeamPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -432,7 +432,7 @@ func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) (
}
func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return model.NewAppError("DeleteOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -444,7 +444,7 @@ func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
}
func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
- if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
+ if !a.Config().ServiceSettings.EnableOutgoingWebhooks {
return nil, model.NewAppError("RegenOutgoingWebhookToken", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -458,7 +458,7 @@ func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.Out
}
func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError {
- if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
+ if !a.Config().ServiceSettings.EnableIncomingWebhooks {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -531,7 +531,7 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
}
}
- if utils.IsLicensed() && *utils.Cfg.TeamSettings.ExperimentalTownSquareIsReadOnly &&
+ if utils.IsLicensed() && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
channel.Name == model.DEFAULT_CHANNEL {
return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)
}
diff --git a/app/webhook_test.go b/app/webhook_test.go
index b9ba35f43..d6293e2b7 100644
--- a/app/webhook_test.go
+++ b/app/webhook_test.go
@@ -30,7 +30,7 @@ func TestCreateWebhookPost(t *testing.T) {
post, err := th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", model.StringInterface{
"attachments": []*model.SlackAttachment{
- &model.SlackAttachment{
+ {
Text: "text",
},
},