Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
@@ -211,7 +212,7 @@ func createChannelCmdF(command *cobra.Command, args []string) error {
|
||||
CreatorId: "",
|
||||
}
|
||||
|
||||
createdChannel, errCreatedChannel := a.CreateChannel(channel, false)
|
||||
createdChannel, errCreatedChannel := a.CreateChannel(&request.Context{}, channel, false)
|
||||
if errCreatedChannel != nil {
|
||||
return errCreatedChannel
|
||||
}
|
||||
@@ -265,7 +266,7 @@ func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User,
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
if err := a.RemoveUserFromChannel(&request.Context{}, user.Id, "", channel); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
return
|
||||
}
|
||||
@@ -427,7 +428,7 @@ func moveChannel(a *app.App, team *model.Team, channel *model.Channel, user *mod
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.MoveChannel(team, channel, user); err != nil {
|
||||
if err := a.MoveChannel(&request.Context{}, team, channel, user); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -565,7 +566,7 @@ func modifyChannelCmdF(command *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("Unable to find user: '%v'", username)
|
||||
}
|
||||
|
||||
updatedChannel, errUpdate := a.UpdateChannelPrivacy(channel, user)
|
||||
updatedChannel, errUpdate := a.UpdateChannelPrivacy(&request.Context{}, channel, user)
|
||||
if errUpdate != nil {
|
||||
return errors.Wrapf(err, "Failed to update channel ('%s') privacy", args[0])
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
)
|
||||
|
||||
@@ -76,7 +77,7 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
||||
|
||||
importErr, log := a.SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||
importErr, log := a.SlackImport(&request.Context{}, fileReader, fileInfo.Size(), team.Id)
|
||||
|
||||
if importErr != nil {
|
||||
return err
|
||||
@@ -149,7 +150,7 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
if err, lineNumber := a.BulkImportWithPath(fileReader, !apply, workers, importPath); err != nil {
|
||||
if err, lineNumber := a.BulkImportWithPath(&request.Context{}, fileReader, !apply, workers, importPath); err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
if lineNumber != 0 {
|
||||
CommandPrintErrorln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/config"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/i18n"
|
||||
@@ -20,7 +21,7 @@ func initDBCommandContextCobra(command *cobra.Command, readOnlyConfigStore bool)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
a.InitPlugins(*a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
|
||||
a.InitPlugins(&request.Context{}, *a.Config().PluginSettings.Directory, *a.Config().PluginSettings.ClientDirectory)
|
||||
a.DoAppMigrations()
|
||||
|
||||
return a, nil
|
||||
@@ -53,7 +54,6 @@ func initDBCommandContext(configDSN string, readOnlyConfigStore bool) (*app.App,
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
a.Srv().LoadLicense()
|
||||
}
|
||||
a.InitServer()
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ func jobserverCmdF(command *cobra.Command, args []string) error {
|
||||
defer a.Srv().Shutdown()
|
||||
|
||||
a.Srv().LoadLicense()
|
||||
a.InitServer()
|
||||
|
||||
// Run jobs
|
||||
mlog.Info("Starting Mattermost job server")
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
@@ -373,7 +374,7 @@ func sampleDataCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
var importErr *model.AppError
|
||||
importErr, lineNumber := a.BulkImport(bulkFile, false, workers)
|
||||
importErr, lineNumber := a.BulkImport(&request.Context{}, bulkFile, false, workers)
|
||||
if importErr != nil {
|
||||
return fmt.Errorf("%s: %s, %s (line: %d)", importErr.Where, importErr.Message, importErr.DetailedError, lineNumber)
|
||||
}
|
||||
|
||||
@@ -100,10 +100,12 @@ func runServer(configStore *config.Store, usedPlatform bool, interruptChan chan
|
||||
mlog.Warn("The platform binary has been deprecated, please switch to using the mattermost binary.")
|
||||
}
|
||||
|
||||
api := api4.Init(server, server.AppOptions, server.Router)
|
||||
a := app.New(app.ServerConnector(server))
|
||||
api := api4.Init(a, server.Router)
|
||||
|
||||
wsapi.Init(server)
|
||||
web.New(server, server.AppOptions, server.Router)
|
||||
api4.InitLocal(server, server.AppOptions, server.LocalRouter)
|
||||
web.New(a, server.Router)
|
||||
api4.InitLocal(a, server.LocalRouter)
|
||||
|
||||
serverErr := server.Start()
|
||||
if serverErr != nil {
|
||||
@@ -111,13 +113,6 @@ func runServer(configStore *config.Store, usedPlatform bool, interruptChan chan
|
||||
return serverErr
|
||||
}
|
||||
|
||||
// TODO: remove this and handle all required initialization while creating
|
||||
// the server. In theory, we shouldn't depend on App to have a fully-featured
|
||||
// server. This initialization is added so that cluster handlers are registered
|
||||
// and job schedulers are initialized.
|
||||
fakeApp := app.New(app.ServerConnector(server))
|
||||
fakeApp.InitServer()
|
||||
|
||||
// If we allow testing then listen for manual testing URL hits
|
||||
if *server.Config().ServiceSettings.EnableTesting {
|
||||
manualtesting.Init(api)
|
||||
|
||||
@@ -58,7 +58,6 @@ func (th *ServerTestHelper) TearDownServerTest() {
|
||||
}
|
||||
|
||||
func TestRunServerSuccess(t *testing.T) {
|
||||
t.Skip("MM-34557")
|
||||
th := SetupServerTest(t)
|
||||
defer th.TearDownServerTest()
|
||||
|
||||
@@ -72,7 +71,6 @@ func TestRunServerSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunServerSystemdNotification(t *testing.T) {
|
||||
t.Skip("MM-34557")
|
||||
th := SetupServerTest(t)
|
||||
defer th.TearDownServerTest()
|
||||
|
||||
@@ -128,7 +126,6 @@ func TestRunServerSystemdNotification(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunServerNoSystemd(t *testing.T) {
|
||||
t.Skip("MM-34557")
|
||||
th := SetupServerTest(t)
|
||||
defer th.TearDownServerTest()
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
@@ -171,7 +172,7 @@ func createTeamCmdF(command *cobra.Command, args []string) error {
|
||||
Type: teamType,
|
||||
}
|
||||
|
||||
createdTeam, errCreate := a.CreateTeam(team)
|
||||
createdTeam, errCreate := a.CreateTeam(&request.Context{}, team)
|
||||
if errCreate != nil {
|
||||
return errors.New("Team creation failed: " + errCreate.Error())
|
||||
}
|
||||
@@ -208,7 +209,7 @@ func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := a.LeaveTeam(team, user, ""); err != nil {
|
||||
if err := a.LeaveTeam(&request.Context{}, team, user, ""); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
||||
return
|
||||
}
|
||||
@@ -243,7 +244,7 @@ func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg strin
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if _, err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||
if _, err := a.JoinUserToTeam(&request.Context{}, team, user, ""); err != nil {
|
||||
CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||
return serverErr
|
||||
}
|
||||
|
||||
api4.Init(a, a.Srv().AppOptions, a.Srv().Router)
|
||||
api4.Init(a, a.Srv().Router)
|
||||
wsapi.Init(a.Srv())
|
||||
a.UpdateConfig(setupClientTests)
|
||||
runWebClientTests()
|
||||
@@ -79,7 +79,7 @@ func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||
return serverErr
|
||||
}
|
||||
|
||||
api4.Init(a, a.Srv().AppOptions, a.Srv().Router)
|
||||
api4.Init(a, a.Srv().Router)
|
||||
wsapi.Init(a.Srv())
|
||||
a.UpdateConfig(setupClientTests)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
@@ -305,7 +306,7 @@ func changeUserActiveStatus(a *app.App, user *model.User, userArg string, activa
|
||||
if user.IsSSOUser() {
|
||||
fmt.Println("You must also deactivate this user in the SSO provider or they will be reactivated on next login or sync.")
|
||||
}
|
||||
updatedUser, err := a.UpdateActive(user, activate)
|
||||
updatedUser, err := a.UpdateActive(&request.Context{}, user, activate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to change activation status of user: %v", userArg)
|
||||
}
|
||||
@@ -371,7 +372,7 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
|
||||
Locale: locale,
|
||||
}
|
||||
|
||||
ruser, err := a.CreateUser(user)
|
||||
ruser, err := a.CreateUser(&request.Context{}, user)
|
||||
if ruser == nil {
|
||||
return errors.New("Unable to create user. Error: " + err.Error())
|
||||
}
|
||||
@@ -775,7 +776,7 @@ func deleteUserCmdF(command *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := a.PermanentDeleteUser(user); err != nil {
|
||||
if err := a.PermanentDeleteUser(&request.Context{}, user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -816,7 +817,7 @@ func deleteAllUsersCommandF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteAllUsers(); err != nil {
|
||||
if err := a.PermanentDeleteAllUsers(&request.Context{}); err != nil {
|
||||
return err
|
||||
}
|
||||
CommandPrettyPrintln("All user accounts successfully deleted.")
|
||||
|
||||
Ссылка в новой задаче
Block a user