From ac74066f0e4f3d62f2d4645c3fa34b88c13958d1 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 19 Sep 2017 18:31:35 -0500 Subject: remove einterface gets (#7455) --- app/admin.go | 41 ++++++++++++++++++++--------------------- app/analytics.go | 5 ++--- app/app.go | 28 +++++++++++++++++++++++++++- app/authentication.go | 28 ++++++++++++---------------- app/brand.go | 15 ++++++--------- app/channel.go | 2 +- app/cluster_discovery.go | 9 +++++++++ app/cluster_handlers.go | 30 ++++++++++++++---------------- app/compliance.go | 7 +++---- app/diagnostics.go | 2 +- app/elasticsearch.go | 9 ++++----- app/ldap.go | 15 +++++++-------- app/license.go | 4 ++-- app/login.go | 17 ++++++++--------- app/notification.go | 11 +++++------ app/oauth.go | 2 +- app/plugins.go | 6 ++---- app/post.go | 19 +++++++++---------- app/saml.go | 8 +++----- app/session.go | 13 ++++++------- app/session_test.go | 4 +++- app/status.go | 25 ++++++++++++------------- app/team.go | 6 +++--- app/user.go | 25 +++++++++++-------------- app/web_conn.go | 5 ++--- app/web_hub.go | 37 ++++++++++++++++++++----------------- app/webhook.go | 3 +-- 27 files changed, 194 insertions(+), 182 deletions(-) (limited to 'app') diff --git a/app/admin.go b/app/admin.go index bd48431c1..1bd33527b 100644 --- a/app/admin.go +++ b/app/admin.go @@ -14,35 +14,34 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/jobs" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" ) -func GetLogs(page, perPage int) ([]string, *model.AppError) { +func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) { perPage = 10000 var lines []string - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { lines = append(lines, "-----------------------------------------------------------------------------------------------------------") lines = append(lines, "-----------------------------------------------------------------------------------------------------------") - lines = append(lines, einterfaces.GetClusterInterface().GetMyClusterInfo().Hostname) + lines = append(lines, a.Cluster.GetMyClusterInfo().Hostname) lines = append(lines, "-----------------------------------------------------------------------------------------------------------") lines = append(lines, "-----------------------------------------------------------------------------------------------------------") } - melines, err := GetLogsSkipSend(page, perPage) + melines, err := a.GetLogsSkipSend(page, perPage) if err != nil { return nil, err } lines = append(lines, melines...) - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { - clines, err := einterfaces.GetClusterInterface().GetLogs(page, perPage) + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { + clines, err := a.Cluster.GetLogs(page, perPage) if err != nil { return nil, err } @@ -53,7 +52,7 @@ func GetLogs(page, perPage int) ([]string, *model.AppError) { return lines, nil } -func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { +func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { var lines []string if utils.Cfg.LogSettings.EnableFile { @@ -86,11 +85,11 @@ func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { return lines, nil } -func GetClusterStatus() []*model.ClusterInfo { +func (a *App) GetClusterStatus() []*model.ClusterInfo { infos := make([]*model.ClusterInfo, 0) - if einterfaces.GetClusterInterface() != nil { - infos = einterfaces.GetClusterInterface().GetClusterInfos() + if a.Cluster != nil { + infos = a.Cluster.GetClusterInfos() } return infos @@ -100,7 +99,7 @@ func (a *App) InvalidateAllCaches() *model.AppError { debug.FreeOSMemory() a.InvalidateAllCachesSkipSend() - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, @@ -108,7 +107,7 @@ func (a *App) InvalidateAllCaches() *model.AppError { WaitForAllToSend: true, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } return nil @@ -125,7 +124,7 @@ func (a *App) InvalidateAllCachesSkipSend() { a.LoadLicense() } -func GetConfig() *model.Config { +func (a *App) GetConfig() *model.Config { json := utils.Cfg.ToJson() cfg := model.ConfigFromJson(strings.NewReader(json)) cfg.Sanitize() @@ -133,7 +132,7 @@ func GetConfig() *model.Config { return cfg } -func ReloadConfig() { +func (a *App) ReloadConfig() { debug.FreeOSMemory() utils.LoadConfig(utils.CfgFileName) @@ -141,7 +140,7 @@ func ReloadConfig() { InitEmailBatching() } -func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError { +func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError { oldCfg := utils.Cfg cfg.SetDefaults() utils.Desanitize(cfg) @@ -163,16 +162,16 @@ func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.A utils.LoadConfig(utils.CfgFileName) utils.EnableConfigWatch() - if einterfaces.GetMetricsInterface() != nil { + if a.Metrics != nil { if *utils.Cfg.MetricsSettings.Enable { - einterfaces.GetMetricsInterface().StartServer() + a.Metrics.StartServer() } else { - einterfaces.GetMetricsInterface().StopServer() + a.Metrics.StopServer() } } - if einterfaces.GetClusterInterface() != nil { - err := einterfaces.GetClusterInterface().ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage) + if a.Cluster != nil { + err := a.Cluster.ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage) if err != nil { return err } diff --git a/app/analytics.go b/app/analytics.go index 562569fa2..70c049350 100644 --- a/app/analytics.go +++ b/app/analytics.go @@ -5,7 +5,6 @@ package app import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -98,8 +97,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo } // If in HA mode then aggregrate all the stats - if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable { - stats, err := einterfaces.GetClusterInterface().GetClusterStats() + if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable { + stats, err := a.Cluster.GetClusterStats() if err != nil { return nil, err } diff --git a/app/app.go b/app/app.go index 667c425bd..bf4a6b1b6 100644 --- a/app/app.go +++ b/app/app.go @@ -6,19 +6,45 @@ package app import ( "io/ioutil" "net/http" + "sync" + "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/plugin/pluginenv" ) type App struct { - Srv *Server + Srv *Server + PluginEnv *pluginenv.Environment PluginConfigListenerId string + + AccountMigration einterfaces.AccountMigrationInterface + Brand einterfaces.BrandInterface + Cluster einterfaces.ClusterInterface + Compliance einterfaces.ComplianceInterface + Elasticsearch einterfaces.ElasticsearchInterface + Ldap einterfaces.LdapInterface + Metrics einterfaces.MetricsInterface + Mfa einterfaces.MfaInterface + Saml einterfaces.SamlInterface } var globalApp App +var initEnterprise sync.Once + func Global() *App { + initEnterprise.Do(func() { + globalApp.AccountMigration = einterfaces.GetAccountMigrationInterface() + globalApp.Brand = einterfaces.GetBrandInterface() + globalApp.Cluster = einterfaces.GetClusterInterface() + globalApp.Compliance = einterfaces.GetComplianceInterface() + globalApp.Elasticsearch = einterfaces.GetElasticsearchInterface() + globalApp.Ldap = einterfaces.GetLdapInterface() + globalApp.Metrics = einterfaces.GetMetricsInterface() + globalApp.Mfa = einterfaces.GetMfaInterface() + globalApp.Saml = einterfaces.GetSamlInterface() + }) return &globalApp } diff --git a/app/authentication.go b/app/authentication.go index 5550589cf..01e1e0a48 100644 --- a/app/authentication.go +++ b/app/authentication.go @@ -7,13 +7,12 @@ import ( "net/http" "strings" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError { - if err := CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil { + if err := a.CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil { return err } @@ -53,23 +52,21 @@ func (a *App) checkUserPassword(user *model.User, password string) *model.AppErr } } -func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) { - ldapInterface := einterfaces.GetLdapInterface() - - if ldapInterface == nil || ldapId == nil { +func (a *App) checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) { + if a.Ldap == nil || ldapId == nil { err := model.NewAppError("doLdapAuthentication", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) return nil, err } var user *model.User - if ldapUser, err := ldapInterface.DoLogin(*ldapId, password); err != nil { + if ldapUser, err := a.Ldap.DoLogin(*ldapId, password); err != nil { err.StatusCode = http.StatusUnauthorized return nil, err } else { user = ldapUser } - if err := CheckUserMfa(user, mfaToken); err != nil { + if err := a.CheckUserMfa(user, mfaToken); err != nil { return nil, err } @@ -81,8 +78,8 @@ func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaTok return user, nil } -func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError { - if err := CheckUserMfa(user, mfaToken); err != nil { +func (a *App) CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError { + if err := a.CheckUserMfa(user, mfaToken); err != nil { return err } @@ -101,17 +98,16 @@ func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string return nil } -func CheckUserMfa(user *model.User, token string) *model.AppError { +func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError { if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication { return nil } - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) } - if ok, err := mfaInterface.ValidateToken(user.MfaSecret, token); err != nil { + if ok, err := a.Mfa.ValidateToken(user.MfaSecret, token); err != nil { return err } else if !ok { return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.bad_code.app_error", nil, "", http.StatusUnauthorized) @@ -143,13 +139,13 @@ 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 && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP + ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP if user.AuthService == model.USER_AUTH_SERVICE_LDAP { if !ldapAvailable { err := model.NewAppError("login", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) return user, err - } else if ldapUser, err := checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil { + } else if ldapUser, err := a.checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil { err.StatusCode = http.StatusUnauthorized return user, err } else { diff --git a/app/brand.go b/app/brand.go index dab69abd8..b108a7b32 100644 --- a/app/brand.go +++ b/app/brand.go @@ -7,39 +7,36 @@ import ( "mime/multipart" "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func SaveBrandImage(imageData *multipart.FileHeader) *model.AppError { +func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError { if len(*utils.Cfg.FileSettings.DriverName) == 0 { return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented) } - brandInterface := einterfaces.GetBrandInterface() - if brandInterface == nil { + if a.Brand == nil { return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented) } - if err := brandInterface.SaveBrandImage(imageData); err != nil { + if err := a.Brand.SaveBrandImage(imageData); err != nil { return err } return nil } -func GetBrandImage() ([]byte, *model.AppError) { +func (a *App) GetBrandImage() ([]byte, *model.AppError) { if len(*utils.Cfg.FileSettings.DriverName) == 0 { return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented) } - brandInterface := einterfaces.GetBrandInterface() - if brandInterface == nil { + if a.Brand == nil { return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented) } - if img, err := brandInterface.GetBrandImage(); err != nil { + if img, err := a.Brand.GetBrandImage(); err != nil { return nil, err } else { return img, nil diff --git a/app/channel.go b/app/channel.go index e7025633f..8ca3a563a 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1087,7 +1087,7 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError status.LastActivityAt = model.GetMillis() } - AddStatusCache(status) + a.AddStatusCache(status) if status.Status != oldStatus { BroadcastStatus(status) diff --git a/app/cluster_discovery.go b/app/cluster_discovery.go index c93684ccd..223b012dd 100644 --- a/app/cluster_discovery.go +++ b/app/cluster_discovery.go @@ -9,6 +9,7 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" ) const ( @@ -75,3 +76,11 @@ func (me *ClusterDiscoveryService) Start() { func (me *ClusterDiscoveryService) Stop() { me.stop <- true } + +func (a *App) IsLeader() bool { + if utils.IsLicensed() && *utils.Cfg.ClusterSettings.Enable && a.Cluster != nil { + return a.Cluster.IsLeader() + } else { + return true + } +} diff --git a/app/cluster_handlers.go b/app/cluster_handlers.go index daf87e886..5c4bd7026 100644 --- a/app/cluster_handlers.go +++ b/app/cluster_handlers.go @@ -6,33 +6,31 @@ package app import ( "strings" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" ) func (a *App) RegisterAllClusterMessageHandlers() { - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, ClusterPublishHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, ClusterUpdateStatusHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler) - einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler) - + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.ClusterPublishHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.ClusterUpdateStatusHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler) + a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler) } -func ClusterPublishHandler(msg *model.ClusterMessage) { +func (a *App) ClusterPublishHandler(msg *model.ClusterMessage) { event := model.WebSocketEventFromJson(strings.NewReader(msg.Data)) PublishSkipClusterSend(event) } -func ClusterUpdateStatusHandler(msg *model.ClusterMessage) { +func (a *App) ClusterUpdateStatusHandler(msg *model.ClusterMessage) { status := model.StatusFromJson(strings.NewReader(msg.Data)) - AddStatusCacheSkipClusterSend(status) + a.AddStatusCacheSkipClusterSend(status) } func (a *App) ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) { diff --git a/app/compliance.go b/app/compliance.go index fcfb35d41..cf942ca00 100644 --- a/app/compliance.go +++ b/app/compliance.go @@ -8,7 +8,6 @@ import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -26,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 || einterfaces.GetComplianceInterface() == nil { + if !*utils.Cfg.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) } @@ -36,14 +35,14 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m return nil, result.Err } else { job = result.Data.(*model.Compliance) - go einterfaces.GetComplianceInterface().RunComplianceJob(job) + go a.Compliance.RunComplianceJob(job) } return job, nil } func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) { - if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil { + if !*utils.Cfg.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 25f75ddad..1c0fab7ac 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -51,7 +51,7 @@ const ( var client *analytics.Client func (a *App) SendDailyDiagnostics() { - if *utils.Cfg.LogSettings.EnableDiagnostics && utils.IsLeader() { + if *utils.Cfg.LogSettings.EnableDiagnostics && a.IsLeader() { initDiagnostics("") a.trackActivity() trackConfig() diff --git a/app/elasticsearch.go b/app/elasticsearch.go index 96e271272..71fe6cedb 100644 --- a/app/elasticsearch.go +++ b/app/elasticsearch.go @@ -6,12 +6,11 @@ package app import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func TestElasticsearch(cfg *model.Config) *model.AppError { +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 @@ -20,7 +19,7 @@ func TestElasticsearch(cfg *model.Config) *model.AppError { } } - if esI := einterfaces.GetElasticsearchInterface(); esI != nil { + if esI := a.Elasticsearch; esI != nil { if err := esI.TestConfig(cfg); err != nil { return err } @@ -32,8 +31,8 @@ func TestElasticsearch(cfg *model.Config) *model.AppError { return nil } -func PurgeElasticsearchIndexes() *model.AppError { - if esI := einterfaces.GetElasticsearchInterface(); esI != nil { +func (a *App) PurgeElasticsearchIndexes() *model.AppError { + if esI := a.Elasticsearch; esI != nil { if err := esI.PurgeIndexes(); err != nil { return err } diff --git a/app/ldap.go b/app/ldap.go index b448850dd..279ea3708 100644 --- a/app/ldap.go +++ b/app/ldap.go @@ -7,15 +7,14 @@ import ( "net/http" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func SyncLdap() { +func (a *App) SyncLdap() { go func() { if utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { - if ldapI := einterfaces.GetLdapInterface(); ldapI != nil { + if ldapI := a.Ldap; ldapI != nil { ldapI.SyncNow() } else { l4g.Error("%v", model.NewAppError("SyncLdap", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented).Error()) @@ -24,8 +23,8 @@ func SyncLdap() { }() } -func TestLdap() *model.AppError { - if ldapI := einterfaces.GetLdapInterface(); ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { +func (a *App) TestLdap() *model.AppError { + if ldapI := a.Ldap; ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable { if err := ldapI.RunTest(); err != nil { err.StatusCode = 500 return err @@ -52,7 +51,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapId, ldapPassword stri return "", err } - ldapInterface := einterfaces.GetLdapInterface() + ldapInterface := a.Ldap if ldapInterface == nil { return "", model.NewAppError("SwitchEmailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -80,7 +79,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) ( return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_ldap_account.app_error", nil, "", http.StatusBadRequest) } - ldapInterface := einterfaces.GetLdapInterface() + ldapInterface := a.Ldap if ldapInterface == nil || user.AuthData == nil { return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -89,7 +88,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) ( return "", err } - if err := CheckUserMfa(user, code); err != nil { + if err := a.CheckUserMfa(user, code); err != nil { return "", err } diff --git a/app/license.go b/app/license.go index 5c3dbdd9f..18836c571 100644 --- a/app/license.go +++ b/app/license.go @@ -86,7 +86,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest) } - ReloadConfig() + a.ReloadConfig() a.InvalidateAllCaches() return license, nil @@ -104,7 +104,7 @@ func (a *App) RemoveLicense() *model.AppError { return result.Err } - ReloadConfig() + a.ReloadConfig() a.InvalidateAllCaches() diff --git a/app/login.go b/app/login.go index ad2412644..18b26c55c 100644 --- a/app/login.go +++ b/app/login.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/mssola/user_agent" @@ -27,15 +26,15 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId if len(id) != 0 { if user, err = a.GetUser(id); err != nil { err.StatusCode = http.StatusBadRequest - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } } else { if user, err = a.GetUserForLogin(loginId, ldapOnly); err != nil { - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } @@ -43,14 +42,14 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId // and then authenticate them if user, err = a.authenticateUser(user, password, mfaToken); err != nil { - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLoginFail() + if a.Metrics != nil { + a.Metrics.IncrementLoginFail() } return nil, err } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementLogin() + if a.Metrics != nil { + a.Metrics.IncrementLogin() } return user, nil diff --git a/app/notification.go b/app/notification.go index 511960f84..cc3db8b55 100644 --- a/app/notification.go +++ b/app/notification.go @@ -18,7 +18,6 @@ import ( "unicode" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -369,8 +368,8 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel } }() - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostSentEmail() + if a.Metrics != nil { + a.Metrics.IncrementPostSentEmail() } return nil @@ -641,8 +640,8 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel * go a.sendToPushProxy(tmpMessage, session) - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostSentPush() + if a.Metrics != nil { + a.Metrics.IncrementPostSentPush() } } @@ -701,7 +700,7 @@ func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE { l4g.Info("Device was reported as removed for UserId=%v SessionId=%v removing push for this session", session.UserId, session.Id) a.AttachDeviceId(session.Id, "", session.ExpiresAt) - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) } if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_FAIL { diff --git a/app/oauth.go b/app/oauth.go index 2b45409a6..cd45b0c10 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -426,7 +426,7 @@ func (a *App) RevokeAccessToken(token string) *model.AppError { } if session != nil { - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) } return nil diff --git a/app/plugins.go b/app/plugins.go index fb8182823..86c18ce22 100644 --- a/app/plugins.go +++ b/app/plugins.go @@ -16,7 +16,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -96,8 +95,7 @@ func (api *BuiltInPluginAPI) CreatePost(post *model.Post) (*model.Post, *model.A } func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) { - ldapInterface := einterfaces.GetLdapInterface() - if ldapInterface == nil { + if api.app.Ldap == nil { return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented) } @@ -106,7 +104,7 @@ func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []s return nil, err } - return ldapInterface.GetUserAttributes(*user.AuthData, attributes) + return api.app.Ldap.GetUserAttributes(*user.AuthData, attributes) } func (api *BuiltInPluginAPI) GetSessionFromRequest(r *http.Request) (*model.Session, *model.AppError) { diff --git a/app/post.go b/app/post.go index 80c66e530..feb024fb1 100644 --- a/app/post.go +++ b/app/post.go @@ -12,7 +12,6 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/dyatlov/go-opengraph/opengraph" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -151,13 +150,13 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo rpost = result.Data.(*model.Post) } - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go esInterface.IndexPost(rpost, channel.TeamId) } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostCreate() + if a.Metrics != nil { + a.Metrics.IncrementPostCreate() } if len(post.FileIds) > 0 { @@ -170,8 +169,8 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo } } - if einterfaces.GetMetricsInterface() != nil { - einterfaces.GetMetricsInterface().IncrementPostFileAttachment(len(post.FileIds)) + if a.Metrics != nil { + a.Metrics.IncrementPostFileAttachment(len(post.FileIds)) } } @@ -320,7 +319,7 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model } else { rpost := result.Data.(*model.Post) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go func() { if rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil { @@ -507,7 +506,7 @@ func (a *App) DeletePost(postId string) (*model.Post, *model.AppError) { go a.DeletePostFiles(post) go a.DeleteFlaggedPosts(post.Id) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing { go esInterface.DeletePost(post) } @@ -538,7 +537,7 @@ func (a *App) DeletePostFiles(post *model.Post) { func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) { paramsList := model.ParseSearchParams(terms) - esInterface := einterfaces.GetElasticsearchInterface() + esInterface := a.Elasticsearch if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch { finalParamsList := []*model.SearchParams{} @@ -580,7 +579,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr return nil, err } - postIds, err := einterfaces.GetElasticsearchInterface().SearchPosts(userChannels, finalParamsList) + postIds, err := a.Elasticsearch.SearchPosts(userChannels, finalParamsList) if err != nil { return nil, err } diff --git a/app/saml.go b/app/saml.go index f9e8dab3c..e6a688d8e 100644 --- a/app/saml.go +++ b/app/saml.go @@ -11,19 +11,17 @@ import ( "path/filepath" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) -func GetSamlMetadata() (string, *model.AppError) { - samlInterface := einterfaces.GetSamlInterface() - if samlInterface == nil { +func (a *App) GetSamlMetadata() (string, *model.AppError) { + if a.Saml == nil { err := model.NewAppError("GetSamlMetadata", "api.admin.saml.not_available.app_error", nil, "", http.StatusNotImplemented) return "", err } - if result, err := samlInterface.GetMetadata(); err != nil { + if result, err := a.Saml.GetMetadata(); err != nil { return "", model.NewAppError("GetSamlMetadata", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, err.StatusCode) } else { return result, nil diff --git a/app/session.go b/app/session.go index bf1a24c58..e5e5c939d 100644 --- a/app/session.go +++ b/app/session.go @@ -6,7 +6,6 @@ package app import ( "net/http" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -30,7 +29,7 @@ func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppE } func (a *App) GetSession(token string) (*model.Session, *model.AppError) { - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics var session *model.Session if ts, ok := sessionCache.Get(token); ok { @@ -102,22 +101,22 @@ func (a *App) RevokeAllSessions(userId string) *model.AppError { } } - ClearSessionCacheForUser(userId) + a.ClearSessionCacheForUser(userId) return nil } -func ClearSessionCacheForUser(userId string) { +func (a *App) ClearSessionCacheForUser(userId string) { ClearSessionCacheForUserSkipClusterSend(userId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: userId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -185,7 +184,7 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError { } RevokeWebrtcToken(session.Id) - ClearSessionCacheForUser(session.UserId) + a.ClearSessionCacheForUser(session.UserId) return nil } diff --git a/app/session_test.go b/app/session_test.go index b4fa42330..e91132a8a 100644 --- a/app/session_test.go +++ b/app/session_test.go @@ -10,6 +10,8 @@ import ( ) func TestCache(t *testing.T) { + th := Setup().InitBasic() + session := &model.Session{ Id: model.NewId(), Token: model.NewId(), @@ -23,7 +25,7 @@ func TestCache(t *testing.T) { t.Fatal("should have items") } - ClearSessionCacheForUser(session.UserId) + th.App.ClearSessionCacheForUser(session.UserId) rkeys := sessionCache.Keys() if len(rkeys) != len(keys)-1 { diff --git a/app/status.go b/app/status.go index e783e1d9d..fb93a9e39 100644 --- a/app/status.go +++ b/app/status.go @@ -6,7 +6,6 @@ package app import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -18,20 +17,20 @@ func ClearStatusCache() { statusCache.Purge() } -func AddStatusCacheSkipClusterSend(status *model.Status) { +func (a *App) AddStatusCacheSkipClusterSend(status *model.Status) { statusCache.Add(status.UserId, status) } -func AddStatusCache(status *model.Status) { - AddStatusCacheSkipClusterSend(status) +func (a *App) AddStatusCache(status *model.Status) { + a.AddStatusCacheSkipClusterSend(status) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_UPDATE_STATUS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: status.ToJson(), } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -63,7 +62,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model } statusMap := map[string]interface{}{} - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics missingUserIds := []string{} for _, userId := range userIds { @@ -87,7 +86,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model statuses := result.Data.([]*model.Status) for _, s := range statuses { - AddStatusCache(s) + a.AddStatusCache(s) statusMap[s.UserId] = s.Status } } @@ -110,7 +109,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap } var statusMap []*model.Status - metrics := einterfaces.GetMetricsInterface() + metrics := a.Metrics missingUserIds := []string{} for _, userId := range userIds { @@ -134,7 +133,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap statuses := result.Data.([]*model.Status) for _, s := range statuses { - AddStatusCache(s) + a.AddStatusCache(s) } statusMap = append(statusMap, statuses...) @@ -195,7 +194,7 @@ func (a *App) SetStatusOnline(userId string, sessionId string, manual bool) { status.LastActivityAt = model.GetMillis() } - AddStatusCache(status) + a.AddStatusCache(status) // Only update the database if the status has changed, the status has been manually set, // or enough time has passed since the previous action @@ -237,7 +236,7 @@ func (a *App) SetStatusOffline(userId string, manual bool) { status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: manual, LastActivityAt: model.GetMillis(), ActiveChannel: ""} - AddStatusCache(status) + a.AddStatusCache(status) if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) @@ -278,7 +277,7 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) { status.Manual = manual status.ActiveChannel = "" - AddStatusCache(status) + a.AddStatusCache(status) if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) diff --git a/app/team.go b/app/team.go index 1aa7abf87..fdf44a783 100644 --- a/app/team.go +++ b/app/team.go @@ -161,7 +161,7 @@ func (a *App) UpdateTeamMemberRoles(teamId string, userId string, newRoles strin return nil, result.Err } - ClearSessionCacheForUser(userId) + a.ClearSessionCacheForUser(userId) sendUpdatedMemberRoleEvent(userId, member) @@ -324,7 +324,7 @@ func (a *App) JoinUserToTeam(team *model.Team, user *model.User, userRequestorId l4g.Error(utils.T("api.user.create_user.joining.error"), user.Id, team.Id, err) } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) a.InvalidateCacheForUser(user.Id) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_ADDED_TO_TEAM, "", "", user.Id, nil) @@ -621,7 +621,7 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User) *model.AppError { return result.Err } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) a.InvalidateCacheForUser(user.Id) return nil diff --git a/app/user.go b/app/user.go index 9d3a52da3..c91b4cfb7 100644 --- a/app/user.go +++ b/app/user.go @@ -372,7 +372,7 @@ 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 && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP + ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP if result := <-a.Srv.Store.User().GetForLogin( loginId, @@ -391,7 +391,7 @@ func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *mode } // fall back to LDAP server to see if we can find a user - if ldapUser, ldapErr := einterfaces.GetLdapInterface().GetUser(loginId); ldapErr != nil { + if ldapUser, ldapErr := a.Ldap.GetUser(loginId); ldapErr != nil { ldapErr.StatusCode = http.StatusBadRequest return nil, ldapErr } else { @@ -607,8 +607,7 @@ func sanitizeProfiles(users []*model.User, asAdmin bool) []*model.User { } func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppError) { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { return nil, model.NewAppError("generateMfaSecret", "api.user.generate_mfa_qr.not_available.app_error", nil, "", http.StatusNotImplemented) } @@ -618,7 +617,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro return nil, err } - secret, img, err := mfaInterface.GenerateSecret(user) + secret, img, err := a.Mfa.GenerateSecret(user) if err != nil { return nil, err } @@ -628,8 +627,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro } func (a *App) ActivateMfa(userId, token string) *model.AppError { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { + if a.Mfa == nil { err := model.NewAppError("ActivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) return err } @@ -645,21 +643,20 @@ func (a *App) ActivateMfa(userId, token string) *model.AppError { return model.NewAppError("ActivateMfa", "api.user.activate_mfa.email_and_ldap_only.app_error", nil, "", http.StatusBadRequest) } - if err := mfaInterface.Activate(user, token); err != nil { + if err := a.Mfa.Activate(user, token); err != nil { return err } return nil } -func DeactivateMfa(userId string) *model.AppError { - mfaInterface := einterfaces.GetMfaInterface() - if mfaInterface == nil { +func (a *App) DeactivateMfa(userId string) *model.AppError { + if a.Mfa == nil { err := model.NewAppError("DeactivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented) return err } - if err := mfaInterface.Deactivate(userId); err != nil { + if err := a.Mfa.Deactivate(userId); err != nil { return err } @@ -1045,7 +1042,7 @@ func (a *App) UpdateMfa(activate bool, userId, token string) *model.AppError { return err } } else { - if err := DeactivateMfa(userId); err != nil { + if err := a.DeactivateMfa(userId); err != nil { return err } } @@ -1215,7 +1212,7 @@ func (a *App) UpdateUserRoles(userId string, newRoles string) (*model.User, *mod l4g.Error(result.Err) } - ClearSessionCacheForUser(user.Id) + a.ClearSessionCacheForUser(user.Id) return ruser, nil } diff --git a/app/web_conn.go b/app/web_conn.go index 556612e79..069d2c8f4 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -8,7 +8,6 @@ import ( "sync/atomic" "time" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" @@ -191,8 +190,8 @@ func (c *WebConn) WritePump() { return } - if einterfaces.GetMetricsInterface() != nil { - go einterfaces.GetMetricsInterface().IncrementWebSocketBroadcast(msg.EventType()) + if c.App.Metrics != nil { + go c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType()) } } diff --git a/app/web_hub.go b/app/web_hub.go index cd12202b5..b351de39e 100644 --- a/app/web_hub.go +++ b/app/web_hub.go @@ -15,7 +15,6 @@ import ( l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" ) @@ -145,13 +144,17 @@ func HubUnregister(webConn *WebConn) { } func Publish(message *model.WebSocketEvent) { - if metrics := einterfaces.GetMetricsInterface(); metrics != nil { + Global().Publish(message) +} + +func (a *App) Publish(message *model.WebSocketEvent) { + if metrics := a.Metrics; metrics != nil { metrics.IncrementWebsocketEvent(message.Event) } PublishSkipClusterSend(message) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { cm := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_PUBLISH, SendType: model.CLUSTER_SEND_BEST_EFFORT, @@ -166,7 +169,7 @@ func Publish(message *model.WebSocketEvent) { cm.SendType = model.CLUSTER_SEND_RELIABLE } - einterfaces.GetClusterInterface().SendClusterMessage(cm) + a.Cluster.SendClusterMessage(cm) } } @@ -180,14 +183,14 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) { a.InvalidateCacheForChannelSkipClusterSend(channel.Id) a.InvalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name) - if cluster := einterfaces.GetClusterInterface(); cluster != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channel.Id, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) nameMsg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, @@ -202,7 +205,7 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) { nameMsg.Props["id"] = channel.TeamId } - einterfaces.GetClusterInterface().SendClusterMessage(nameMsg) + a.Cluster.SendClusterMessage(nameMsg) } } @@ -213,13 +216,13 @@ func (a *App) InvalidateCacheForChannelSkipClusterSend(channelId string) { func (a *App) InvalidateCacheForChannelMembers(channelId string) { a.InvalidateCacheForChannelMembersSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -231,13 +234,13 @@ func (a *App) InvalidateCacheForChannelMembersSkipClusterSend(channelId string) func (a *App) InvalidateCacheForChannelMembersNotifyProps(channelId string) { a.InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -256,13 +259,13 @@ func (a *App) InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string func (a *App) InvalidateCacheForChannelPosts(channelId string) { a.InvalidateCacheForChannelPostsSkipClusterSend(channelId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: channelId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -273,13 +276,13 @@ func (a *App) InvalidateCacheForChannelPostsSkipClusterSend(channelId string) { func (a *App) InvalidateCacheForUser(userId string) { a.InvalidateCacheForUserSkipClusterSend(userId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: userId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } @@ -296,13 +299,13 @@ func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) { func (a *App) InvalidateCacheForWebhook(webhookId string) { a.InvalidateCacheForWebhookSkipClusterSend(webhookId) - if einterfaces.GetClusterInterface() != nil { + if a.Cluster != nil { msg := &model.ClusterMessage{ Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, SendType: model.CLUSTER_SEND_BEST_EFFORT, Data: webhookId, } - einterfaces.GetClusterInterface().SendClusterMessage(msg) + a.Cluster.SendClusterMessage(msg) } } diff --git a/app/webhook.go b/app/webhook.go index 61b8b4d1a..04887f203 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -11,7 +11,6 @@ import ( "unicode/utf8" l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/einterfaces" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/utils" @@ -126,7 +125,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove post := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType} post.AddProp("from_webhook", "true") - if metrics := einterfaces.GetMetricsInterface(); metrics != nil { + if metrics := a.Metrics; metrics != nil { metrics.IncrementWebhookPost() } -- cgit v1.2.3-1-g7c22