Removing all FakeApp usages (#14174)
* Removing some other fake apps * More FakeApp removed * Removing entirely FakeApp * Fixing some tests * Fixing get Cluster id from get plugin status * Fixing failing tests * Fixing tests * Fixing test initialization for web * Fixing InitServer for server tests * Fixing InitServer for server tests * Reverting go.sum and go.mod * Removing unneded HTMLTemplates function in App layer * Moving back some functions to its old place to easy the review * Moving back some functions to its old place to easy the review * Using the last struct2interface version * Generating store layers * Fixing merge problems * Addressing PR comments * Small fix * Fixing app tests build * Fixing tests * fixing tests * Fix tests * Fixing tests * Fixing tests * Fixing tests * Moving license to server struct * Adding some fixes to the test compilation * Fixing cluster and some jobs initialization * Fixing some license tests compilation problems * Fixing recursive cache invalidation * Regenerating app layers * Fix test compilation Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f3ac33e6dc
Коммит
f5eab1271b
109
app/app.go
109
app/app.go
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/jobs"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/httpservice"
|
||||
@@ -63,6 +62,68 @@ func New(options ...AppOption) *App {
|
||||
return app
|
||||
}
|
||||
|
||||
func (a *App) InitServer() {
|
||||
a.srv.AppInitializedOnce.Do(func() {
|
||||
a.initEnterprise()
|
||||
a.accountMigration = a.srv.AccountMigration
|
||||
a.ldap = a.srv.Ldap
|
||||
a.notification = a.srv.Notification
|
||||
a.saml = a.srv.Saml
|
||||
|
||||
a.StartPushNotificationsHubWorkers()
|
||||
a.AddConfigListener(func(oldConfig *model.Config, newConfig *model.Config) {
|
||||
if *oldConfig.GuestAccountsSettings.Enable && !*newConfig.GuestAccountsSettings.Enable {
|
||||
if appErr := a.DeactivateGuests(); appErr != nil {
|
||||
mlog.Error("Unable to deactivate guest accounts", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Disable active guest accounts on first run if guest accounts are disabled
|
||||
if !*a.Config().GuestAccountsSettings.Enable {
|
||||
if appErr := a.DeactivateGuests(); appErr != nil {
|
||||
mlog.Error("Unable to deactivate guest accounts", mlog.Err(appErr))
|
||||
}
|
||||
}
|
||||
|
||||
pluginsRoute := a.srv.Router.PathPrefix("/plugins/{plugin_id:[A-Za-z0-9\\_\\-\\.]+}").Subrouter()
|
||||
pluginsRoute.HandleFunc("", a.ServePluginRequest)
|
||||
pluginsRoute.HandleFunc("/public/{public_file:.*}", a.ServePluginPublicRequest)
|
||||
pluginsRoute.HandleFunc("/{anything:.*}", a.ServePluginRequest)
|
||||
a.srv.Router.NotFoundHandler = http.HandlerFunc(a.Handle404)
|
||||
|
||||
// Scheduler must be started before cluster.
|
||||
a.initJobs()
|
||||
|
||||
if a.srv.joinCluster && a.srv.Cluster != nil {
|
||||
a.registerAllClusterMessageHandlers()
|
||||
}
|
||||
|
||||
a.DoAppMigrations()
|
||||
|
||||
a.InitPostMetadata()
|
||||
|
||||
a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
|
||||
a.AddConfigListener(func(prevCfg, cfg *model.Config) {
|
||||
if *cfg.PluginSettings.Enable {
|
||||
a.InitPlugins(*cfg.PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
|
||||
} else {
|
||||
a.srv.ShutDownPlugins()
|
||||
}
|
||||
})
|
||||
if a.Srv().runjobs {
|
||||
a.Srv().Go(func() {
|
||||
runLicenseExpirationCheckJob(a)
|
||||
})
|
||||
}
|
||||
a.srv.RunJobs()
|
||||
})
|
||||
a.accountMigration = a.srv.AccountMigration
|
||||
a.ldap = a.srv.Ldap
|
||||
a.notification = a.srv.Notification
|
||||
a.saml = a.srv.Saml
|
||||
}
|
||||
|
||||
// DO NOT CALL THIS.
|
||||
// This is to avoid having to change all the code in cmd/mattermost/commands/* for now
|
||||
// shutdown should be called directly on the server
|
||||
@@ -71,38 +132,18 @@ func (a *App) Shutdown() {
|
||||
a.srv = nil
|
||||
}
|
||||
|
||||
func (a *App) configOrLicenseListener() {
|
||||
a.regenerateClientConfig()
|
||||
}
|
||||
|
||||
func (s *Server) initJobs() {
|
||||
s.Jobs = jobs.NewJobServer(s, s.Store)
|
||||
if jobsDataRetentionJobInterface != nil {
|
||||
s.Jobs.DataRetentionJob = jobsDataRetentionJobInterface(s)
|
||||
}
|
||||
if jobsMessageExportJobInterface != nil {
|
||||
s.Jobs.MessageExportJob = jobsMessageExportJobInterface(s)
|
||||
}
|
||||
if jobsElasticsearchAggregatorInterface != nil {
|
||||
s.Jobs.ElasticsearchAggregator = jobsElasticsearchAggregatorInterface(s)
|
||||
}
|
||||
if jobsElasticsearchIndexerInterface != nil {
|
||||
s.Jobs.ElasticsearchIndexer = jobsElasticsearchIndexerInterface(s)
|
||||
}
|
||||
func (a *App) initJobs() {
|
||||
if jobsLdapSyncInterface != nil {
|
||||
s.Jobs.LdapSync = jobsLdapSyncInterface(s.FakeApp())
|
||||
a.srv.Jobs.LdapSync = jobsLdapSyncInterface(a)
|
||||
}
|
||||
if jobsMigrationsInterface != nil {
|
||||
s.Jobs.Migrations = jobsMigrationsInterface(s.FakeApp())
|
||||
a.srv.Jobs.Migrations = jobsMigrationsInterface(a)
|
||||
}
|
||||
if jobsPluginsInterface != nil {
|
||||
s.Jobs.Plugins = jobsPluginsInterface(s.FakeApp())
|
||||
a.srv.Jobs.Plugins = jobsPluginsInterface(a)
|
||||
}
|
||||
if jobsBleveIndexerInterface != nil {
|
||||
s.Jobs.BleveIndexer = jobsBleveIndexerInterface(s)
|
||||
}
|
||||
s.Jobs.Workers = s.Jobs.InitWorkers()
|
||||
s.Jobs.Schedulers = s.Jobs.InitSchedulers()
|
||||
a.srv.Jobs.Workers = a.srv.Jobs.InitWorkers()
|
||||
a.srv.Jobs.Schedulers = a.srv.Jobs.InitSchedulers()
|
||||
}
|
||||
|
||||
func (a *App) DiagnosticId() string {
|
||||
@@ -113,9 +154,9 @@ func (a *App) SetDiagnosticId(id string) {
|
||||
a.Srv().diagnosticId = id
|
||||
}
|
||||
|
||||
func (a *App) HTMLTemplates() *template.Template {
|
||||
if a.Srv().htmlTemplateWatcher != nil {
|
||||
return a.Srv().htmlTemplateWatcher.Templates()
|
||||
func (s *Server) HTMLTemplates() *template.Template {
|
||||
if s.htmlTemplateWatcher != nil {
|
||||
return s.htmlTemplateWatcher.Templates()
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -133,8 +174,8 @@ func (a *App) Handle404(w http.ResponseWriter, r *http.Request) {
|
||||
utils.RenderWebAppError(a.Config(), w, r, model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound), a.AsymmetricSigningKey())
|
||||
}
|
||||
|
||||
func (a *App) getSystemInstallDate() (int64, *model.AppError) {
|
||||
systemData, appErr := a.Srv().Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
func (s *Server) getSystemInstallDate() (int64, *model.AppError) {
|
||||
systemData, appErr := s.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
if appErr != nil {
|
||||
return 0, appErr
|
||||
}
|
||||
@@ -145,8 +186,8 @@ func (a *App) getSystemInstallDate() (int64, *model.AppError) {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (a *App) getFirstServerRunTimestamp() (int64, *model.AppError) {
|
||||
systemData, appErr := a.Srv().Store.System().GetByName(model.SYSTEM_FIRST_SERVER_RUN_TIMESTAMP_KEY)
|
||||
func (s *Server) getFirstServerRunTimestamp() (int64, *model.AppError) {
|
||||
systemData, appErr := s.Store.System().GetByName(model.SYSTEM_FIRST_SERVER_RUN_TIMESTAMP_KEY)
|
||||
if appErr != nil {
|
||||
return 0, appErr
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user