From a2fc602bc263c382b5a1416ea63df4c490a36e32 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 7 Mar 2022 20:48:55 +0530 Subject: [PATCH] MM-40813: Use config service more extensively (#19679) https://mattermost.atlassian.net/browse/MM-40816 ```release-note NONE ``` Co-authored-by: Mattermod --- api4/user_test.go | 2 +- app/channels.go | 4 ++-- app/post_test.go | 2 +- app/product_notices.go | 10 +++++----- app/server.go | 8 ++++---- app/session.go | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/api4/user_test.go b/api4/user_test.go index 125d064c99..e15cfab084 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -3542,7 +3542,7 @@ func TestLoginWithLag(t *testing.T) { t.Skipf("requires test flag: -mysql-replica") } - if *th.App.Srv().Config().SqlSettings.DriverName != model.DatabaseDriverMysql { + if *th.App.Config().SqlSettings.DriverName != model.DatabaseDriverMysql { t.Skipf("requires %q database driver", model.DatabaseDriverMysql) } diff --git a/app/channels.go b/app/channels.go index fc7867e195..475762d615 100644 --- a/app/channels.go +++ b/app/channels.go @@ -247,9 +247,9 @@ func (ch *Channels) Stop() error { } func (ch *Channels) AddConfigListener(listener func(*model.Config, *model.Config)) string { - return ch.srv.AddConfigListener(listener) + return ch.cfgSvc.AddConfigListener(listener) } func (ch *Channels) RemoveConfigListener(id string) { - ch.srv.RemoveConfigListener(id) + ch.cfgSvc.RemoveConfigListener(id) } diff --git a/app/post_test.go b/app/post_test.go index 4a60735222..ebad76739f 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -2379,7 +2379,7 @@ func TestReplyToPostWithLag(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - if *th.App.Srv().Config().SqlSettings.DriverName != model.DatabaseDriverMysql { + if *th.App.Config().SqlSettings.DriverName != model.DatabaseDriverMysql { t.Skipf("requires %q database driver", model.DatabaseDriverMysql) } diff --git a/app/product_notices.go b/app/product_notices.go index 5e3ed8d816..515e1f6b79 100644 --- a/app/product_notices.go +++ b/app/product_notices.go @@ -235,12 +235,12 @@ func (a *App) GetProductNotices(c *request.Context, userID, teamID string, clien isTeamAdmin := a.SessionHasPermissionToTeam(*c.Session(), teamID, model.PermissionManageTeam) // check if notices for regular users are disabled - if !*a.Srv().Config().AnnouncementSettings.UserNoticesEnabled && !isSystemAdmin { + if !*a.Config().AnnouncementSettings.UserNoticesEnabled && !isSystemAdmin { return []model.NoticeMessage{}, nil } // check if notices for admins are disabled - if !*a.Srv().Config().AnnouncementSettings.AdminNoticesEnabled && (isTeamAdmin || isSystemAdmin) { + if !*a.Config().AnnouncementSettings.AdminNoticesEnabled && (isTeamAdmin || isSystemAdmin) { return []model.NoticeMessage{}, nil } @@ -251,7 +251,7 @@ func (a *App) GetProductNotices(c *request.Context, userID, teamID string, clien sku := a.Srv().ClientLicense()["SkuShortName"] isCloud := a.Srv().License() != nil && *a.Srv().License().Features.Cloud - dbName := *a.Srv().Config().SqlSettings.DriverName + dbName := *a.Config().SqlSettings.DriverName var searchEngineName, searchEngineVersion string if engine := a.Srv().SearchEngine; engine != nil && engine.ElasticsearchEngine != nil { @@ -339,8 +339,8 @@ func (a *App) UpdateViewedProductNoticesForNewUser(userID string) { // UpdateProductNotices is called periodically from a scheduled worker to fetch new notices and update the cache func (a *App) UpdateProductNotices() *model.AppError { - url := *a.Srv().Config().AnnouncementSettings.NoticesURL - skip := *a.Srv().Config().AnnouncementSettings.NoticesSkipCache + url := *a.Config().AnnouncementSettings.NoticesURL + skip := *a.Config().AnnouncementSettings.NoticesSkipCache mlog.Debug("Will fetch notices from", mlog.String("url", url), mlog.Bool("skip_cache", skip)) var err error a.ch.cachedPostCount, err = a.Srv().Store.Post().AnalyticsPostCount("", false, false) diff --git a/app/server.go b/app/server.go index 2bf1d11cb2..11a13e2cd7 100644 --- a/app/server.go +++ b/app/server.go @@ -2086,9 +2086,9 @@ func (a *App) getNotificationsLog() (*model.FileData, string) { var warning string // Getting notifications.log - if *a.Srv().Config().NotificationLogSettings.EnableFile { + if *a.Config().NotificationLogSettings.EnableFile { // notifications.log - notificationsLog := config.GetNotificationsLogFileLocation(*a.Srv().Config().LogSettings.FileLocation) + notificationsLog := config.GetNotificationsLogFileLocation(*a.Config().LogSettings.FileLocation) notificationsLogFileData, notificationsLogFileDataErr := ioutil.ReadFile(notificationsLog) @@ -2113,9 +2113,9 @@ func (a *App) getMattermostLog() (*model.FileData, string) { var warning string // Getting mattermost.log - if *a.Srv().Config().LogSettings.EnableFile { + if *a.Config().LogSettings.EnableFile { // mattermost.log - mattermostLog := config.GetLogFileLocation(*a.Srv().Config().LogSettings.FileLocation) + mattermostLog := config.GetLogFileLocation(*a.Config().LogSettings.FileLocation) mattermostLogFileData, mattermostLogFileDataErr := ioutil.ReadFile(mattermostLog) diff --git a/app/session.go b/app/session.go index 2029fd0414..fd7f70e12c 100644 --- a/app/session.go +++ b/app/session.go @@ -255,7 +255,7 @@ func (a *App) UpdateLastActivityAtIfNeeded(session model.Session) { // A new ExpiresAt is only written if enough time has elapsed since last update. // Returns true only if the session was extended. func (a *App) ExtendSessionExpiryIfNeeded(session *model.Session) bool { - if !*a.Srv().Config().ServiceSettings.ExtendSessionLengthWithActivity { + if !*a.Config().ServiceSettings.ExtendSessionLengthWithActivity { return false }