Remove global app references (#7433)
* remove global app references * test fix * fix api4 test compilation
Этот коммит содержится в:
@@ -126,7 +126,8 @@ func init() {
|
||||
}
|
||||
|
||||
func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -170,7 +171,7 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
CreatorId: "",
|
||||
}
|
||||
|
||||
if _, err := app.Global().CreateChannel(channel, false); err != nil {
|
||||
if _, err := a.CreateChannel(channel, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -178,7 +179,8 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -197,24 +199,25 @@ func removeChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
removeUserFromChannel(channel, user, args[i+1])
|
||||
removeUserFromChannel(a, channel, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeUserFromChannel(channel *model.Channel, user *model.User, userArg string) {
|
||||
func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
if err := a.RemoveUserFromChannel(user.Id, "", channel); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -233,24 +236,25 @@ func addChannelUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
addUserToChannel(channel, user, args[i+1])
|
||||
addUserToChannel(a, channel, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addUserToChannel(channel *model.Channel, user *model.User, userArg string) {
|
||||
func addUserToChannel(a *app.App, channel *model.Channel, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if _, err := app.Global().AddUserToChannel(user, channel); err != nil {
|
||||
if _, err := a.AddUserToChannel(user, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -264,7 +268,7 @@ func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to archive channel '" + channel.Name + "' error: " + result.Err.Error())
|
||||
}
|
||||
}
|
||||
@@ -273,7 +277,8 @@ func archiveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -297,7 +302,7 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := deleteChannel(channel); err != nil {
|
||||
if err := deleteChannel(a, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Deleted channel '" + channel.Name + "'")
|
||||
@@ -307,12 +312,13 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteChannel(channel *model.Channel) *model.AppError {
|
||||
return app.Global().PermanentDeleteChannel(channel)
|
||||
func deleteChannel(a *app.App, channel *model.Channel) *model.AppError {
|
||||
return a.PermanentDeleteChannel(channel)
|
||||
}
|
||||
|
||||
func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -331,7 +337,7 @@ func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := moveChannel(team, channel); err != nil {
|
||||
if err := moveChannel(a, team, channel); err != nil {
|
||||
CommandPrintErrorln("Unable to move channel '" + channel.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Moved channel '" + channel.Name + "'")
|
||||
@@ -341,33 +347,33 @@ func moveChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func moveChannel(team *model.Team, channel *model.Channel) *model.AppError {
|
||||
func moveChannel(a *app.App, team *model.Team, channel *model.Channel) *model.AppError {
|
||||
oldTeamId := channel.TeamId
|
||||
|
||||
if err := app.Global().MoveChannel(team, channel); err != nil {
|
||||
if err := a.MoveChannel(team, channel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if incomingWebhooks, err := app.Global().GetIncomingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
if incomingWebhooks, err := a.GetIncomingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, webhook := range incomingWebhooks {
|
||||
if webhook.ChannelId == channel.Id {
|
||||
webhook.TeamId = team.Id
|
||||
if result := <-app.Global().Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(webhook); result.Err != nil {
|
||||
CommandPrintErrorln("Failed to move incoming webhook '" + webhook.Id + "' to new team.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if outgoingWebhooks, err := app.Global().GetOutgoingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
if outgoingWebhooks, err := a.GetOutgoingWebhooksForTeamPage(oldTeamId, 0, 10000000); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, webhook := range outgoingWebhooks {
|
||||
if webhook.ChannelId == channel.Id {
|
||||
webhook.TeamId = team.Id
|
||||
if result := <-app.Global().Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(webhook); result.Err != nil {
|
||||
CommandPrintErrorln("Failed to move outgoing webhook '" + webhook.Id + "' to new team.")
|
||||
}
|
||||
}
|
||||
@@ -378,7 +384,8 @@ func moveChannel(team *model.Team, channel *model.Channel) *model.AppError {
|
||||
}
|
||||
|
||||
func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -396,7 +403,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
|
||||
} else {
|
||||
channels := result.Data.([]*model.Channel)
|
||||
@@ -415,7 +422,8 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -433,7 +441,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if result := <-app.Global().Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
|
||||
CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
|
||||
}
|
||||
}
|
||||
@@ -442,7 +450,8 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func modifyChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -475,7 +484,7 @@ func modifyChannelCmdF(cmd *cobra.Command, args []string) error {
|
||||
channel.Type = model.CHANNEL_PRIVATE
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateChannel(channel); err != nil {
|
||||
if _, err := a.UpdateChannel(channel); err != nil {
|
||||
return errors.New("Failed to update channel '" + args[0] + "' - " + err.Error())
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -45,7 +44,8 @@ func init() {
|
||||
}
|
||||
|
||||
func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
||||
|
||||
app.Global().SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||
a.SlackImport(fileReader, fileInfo.Size(), team.Id)
|
||||
|
||||
CommandPrettyPrintln("Finished Slack Import.")
|
||||
|
||||
@@ -79,7 +79,8 @@ func slackImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func bulkImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ func bulkImportCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
if err, lineNumber := app.Global().BulkImport(fileReader, !apply, workers); err != nil {
|
||||
if err, lineNumber := a.BulkImport(fileReader, !apply, workers); err != nil {
|
||||
CommandPrettyPrintln(err.Error())
|
||||
if lineNumber != 0 {
|
||||
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
|
||||
@@ -7,32 +7,34 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func initDBCommandContextCobra(cmd *cobra.Command) error {
|
||||
func initDBCommandContextCobra(cmd *cobra.Command) (*app.App, error) {
|
||||
config, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := initDBCommandContext(config); err != nil {
|
||||
a, err := initDBCommandContext(config)
|
||||
if err != nil {
|
||||
// Returning an error just prints the usage message, so actually panic
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return a, nil
|
||||
}
|
||||
|
||||
func initDBCommandContext(configFileLocation string) error {
|
||||
func initDBCommandContext(configFileLocation string) (*app.App, error) {
|
||||
if err := utils.InitAndLoadConfig(configFileLocation); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
utils.ConfigureCmdLineLog()
|
||||
|
||||
app.Global().NewServer()
|
||||
app.Global().InitStores()
|
||||
a := app.Global()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
app.Global().LoadLicense()
|
||||
a.LoadLicense()
|
||||
}
|
||||
|
||||
return nil
|
||||
return a, nil
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
}
|
||||
|
||||
func ldapSyncCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
if _, err := initDBCommandContextCobra(cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,8 @@ func init() {
|
||||
}
|
||||
|
||||
func uploadLicenseCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -37,12 +37,11 @@ func uploadLicenseCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
var fileBytes []byte
|
||||
var err error
|
||||
if fileBytes, err = ioutil.ReadFile(args[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := app.Global().SaveLicense(fileBytes); err != nil {
|
||||
if _, err := a.SaveLicense(fileBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
// Plugins
|
||||
@@ -59,7 +58,8 @@ var resetCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func resetCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func resetCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
app.Global().Srv.Store.DropAllTables()
|
||||
a.Srv.Store.DropAllTables()
|
||||
CommandPrettyPrintln("Database sucessfully reset")
|
||||
|
||||
return nil
|
||||
|
||||
@@ -5,7 +5,6 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -38,7 +37,8 @@ func init() {
|
||||
}
|
||||
|
||||
func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateUserRoles(user.Id, "system_admin system_user"); err != nil {
|
||||
if _, err := a.UpdateUserRoles(user.Id, "system_admin system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,8 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ func makeMemberCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if _, err := app.Global().UpdateUserRoles(user.Id, "system_user"); err != nil {
|
||||
if _, err := a.UpdateUserRoles(user.Id, "system_user"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func runServer(configFileLocation string) {
|
||||
a := app.Global()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
|
||||
if model.BuildEnterpriseReady == "true" {
|
||||
a.LoadLicense()
|
||||
@@ -82,8 +82,8 @@ func runServer(configFileLocation string) {
|
||||
a.InitPlugins("plugins", "webapp/dist")
|
||||
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
web.InitWeb()
|
||||
|
||||
@@ -98,7 +98,7 @@ func runServer(configFileLocation string) {
|
||||
|
||||
app.ReloadConfig()
|
||||
|
||||
resetStatuses()
|
||||
resetStatuses(a)
|
||||
|
||||
a.StartServer()
|
||||
|
||||
@@ -107,13 +107,13 @@ func runServer(configFileLocation string) {
|
||||
manualtesting.InitManualTesting()
|
||||
}
|
||||
|
||||
setDiagnosticId()
|
||||
setDiagnosticId(a)
|
||||
utils.RegenerateClientConfig()
|
||||
go runSecurityJob()
|
||||
go runDiagnosticsJob()
|
||||
go runSecurityJob(a)
|
||||
go runDiagnosticsJob(a)
|
||||
|
||||
go runTokenCleanupJob()
|
||||
go runCommandWebhookCleanupJob()
|
||||
go runTokenCleanupJob(a)
|
||||
go runCommandWebhookCleanupJob(a)
|
||||
|
||||
if complianceI := einterfaces.GetComplianceInterface(); complianceI != nil {
|
||||
complianceI.StartComplianceDailyJob()
|
||||
@@ -162,61 +162,69 @@ func runServer(configFileLocation string) {
|
||||
a.StopServer()
|
||||
}
|
||||
|
||||
func runSecurityJob() {
|
||||
doSecurity()
|
||||
model.CreateRecurringTask("Security", doSecurity, time.Hour*4)
|
||||
func runSecurityJob(a *app.App) {
|
||||
doSecurity(a)
|
||||
model.CreateRecurringTask("Security", func() {
|
||||
doSecurity(a)
|
||||
}, time.Hour*4)
|
||||
}
|
||||
|
||||
func runDiagnosticsJob() {
|
||||
doDiagnostics()
|
||||
model.CreateRecurringTask("Diagnostics", doDiagnostics, time.Hour*24)
|
||||
func runDiagnosticsJob(a *app.App) {
|
||||
doDiagnostics(a)
|
||||
model.CreateRecurringTask("Diagnostics", func() {
|
||||
doDiagnostics(a)
|
||||
}, time.Hour*24)
|
||||
}
|
||||
|
||||
func runTokenCleanupJob() {
|
||||
doTokenCleanup()
|
||||
model.CreateRecurringTask("Token Cleanup", doTokenCleanup, time.Hour*1)
|
||||
func runTokenCleanupJob(a *app.App) {
|
||||
doTokenCleanup(a)
|
||||
model.CreateRecurringTask("Token Cleanup", func() {
|
||||
doTokenCleanup(a)
|
||||
}, time.Hour*1)
|
||||
}
|
||||
|
||||
func runCommandWebhookCleanupJob() {
|
||||
doCommandWebhookCleanup()
|
||||
model.CreateRecurringTask("Command Hook Cleanup", doCommandWebhookCleanup, time.Hour*1)
|
||||
func runCommandWebhookCleanupJob(a *app.App) {
|
||||
doCommandWebhookCleanup(a)
|
||||
model.CreateRecurringTask("Command Hook Cleanup", func() {
|
||||
doCommandWebhookCleanup(a)
|
||||
}, time.Hour*1)
|
||||
}
|
||||
|
||||
func resetStatuses() {
|
||||
if result := <-app.Global().Srv.Store.Status().ResetAll(); result.Err != nil {
|
||||
func resetStatuses(a *app.App) {
|
||||
if result := <-a.Srv.Store.Status().ResetAll(); result.Err != nil {
|
||||
l4g.Error(utils.T("mattermost.reset_status.error"), result.Err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func setDiagnosticId() {
|
||||
if result := <-app.Global().Srv.Store.System().Get(); result.Err == nil {
|
||||
func setDiagnosticId(a *app.App) {
|
||||
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
|
||||
id := props[model.SYSTEM_DIAGNOSTIC_ID]
|
||||
if len(id) == 0 {
|
||||
id = model.NewId()
|
||||
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
|
||||
<-app.Global().Srv.Store.System().Save(systemId)
|
||||
<-a.Srv.Store.System().Save(systemId)
|
||||
}
|
||||
|
||||
utils.CfgDiagnosticId = id
|
||||
}
|
||||
}
|
||||
|
||||
func doSecurity() {
|
||||
app.Global().DoSecurityUpdateCheck()
|
||||
func doSecurity(a *app.App) {
|
||||
a.DoSecurityUpdateCheck()
|
||||
}
|
||||
|
||||
func doDiagnostics() {
|
||||
func doDiagnostics(a *app.App) {
|
||||
if *utils.Cfg.LogSettings.EnableDiagnostics {
|
||||
app.Global().SendDailyDiagnostics()
|
||||
a.SendDailyDiagnostics()
|
||||
}
|
||||
}
|
||||
|
||||
func doTokenCleanup() {
|
||||
app.Global().Srv.Store.Token().Cleanup()
|
||||
func doTokenCleanup(a *app.App) {
|
||||
a.Srv.Store.Token().Cleanup()
|
||||
}
|
||||
|
||||
func doCommandWebhookCleanup() {
|
||||
app.Global().Srv.Store.CommandWebhook().Cleanup()
|
||||
func doCommandWebhookCleanup(a *app.App) {
|
||||
a.Srv.Store.CommandWebhook().Cleanup()
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ func init() {
|
||||
}
|
||||
|
||||
func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
Type: teamType,
|
||||
}
|
||||
|
||||
if _, err := app.Global().CreateTeam(team); err != nil {
|
||||
if _, err := a.CreateTeam(team); err != nil {
|
||||
return errors.New("Team creation failed: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -102,7 +103,8 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func removeUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,24 +119,25 @@ func removeUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
removeUserFromTeam(team, user, args[i+1])
|
||||
removeUserFromTeam(a, team, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeUserFromTeam(team *model.Team, user *model.User, userArg string) {
|
||||
func removeUserFromTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().LeaveTeam(team, user); err != nil {
|
||||
if err := a.LeaveTeam(team, user); err != nil {
|
||||
CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func addUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -149,24 +152,25 @@ func addUsersCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
users := getUsersFromUserArgs(args[1:])
|
||||
for i, user := range users {
|
||||
addUserToTeam(team, user, args[i+1])
|
||||
addUserToTeam(a, team, user, args[i+1])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addUserToTeam(team *model.Team, user *model.User, userArg string) {
|
||||
func addUserToTeam(a *app.App, team *model.Team, user *model.User, userArg string) {
|
||||
if user == nil {
|
||||
CommandPrintErrorln("Can't find user '" + userArg + "'")
|
||||
return
|
||||
}
|
||||
if err := app.Global().JoinUserToTeam(team, user, ""); err != nil {
|
||||
if err := a.JoinUserToTeam(team, user, ""); err != nil {
|
||||
CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -196,7 +200,7 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if err := deleteTeam(team); err != nil {
|
||||
if err := deleteTeam(a, team); err != nil {
|
||||
CommandPrintErrorln("Unable to delete team '" + team.Name + "' error: " + err.Error())
|
||||
} else {
|
||||
CommandPrettyPrintln("Deleted team '" + team.Name + "'")
|
||||
@@ -206,6 +210,6 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteTeam(team *model.Team) *model.AppError {
|
||||
return app.Global().PermanentDeleteTeam(team)
|
||||
func deleteTeam(a *app.App, team *model.Team) *model.AppError {
|
||||
return a.PermanentDeleteTeam(team)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/wsapi"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -46,43 +45,45 @@ func init() {
|
||||
}
|
||||
|
||||
func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
setupClientTests()
|
||||
app.Global().StartServer()
|
||||
a.StartServer()
|
||||
runWebClientTests()
|
||||
app.Global().StopServer()
|
||||
a.StopServer()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
api.InitRouter()
|
||||
a.Srv.Router = api.NewRouter()
|
||||
wsapi.InitRouter()
|
||||
api4.InitApi(false)
|
||||
api.InitApi()
|
||||
api4.InitApi(a.Srv.Router, false)
|
||||
api.InitApi(a.Srv.Router)
|
||||
wsapi.InitApi()
|
||||
setupClientTests()
|
||||
app.Global().StartServer()
|
||||
a.StartServer()
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-c
|
||||
|
||||
app.Global().StopServer()
|
||||
a.StopServer()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -158,7 +158,8 @@ func init() {
|
||||
}
|
||||
|
||||
func userActivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -166,14 +167,14 @@ func userActivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Expected at least one argument. See help text for details.")
|
||||
}
|
||||
|
||||
changeUsersActiveStatus(args, true)
|
||||
changeUsersActiveStatus(a, args, true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func changeUsersActiveStatus(userArgs []string, active bool) {
|
||||
func changeUsersActiveStatus(a *app.App, userArgs []string, active bool) {
|
||||
users := getUsersFromUserArgs(userArgs)
|
||||
for i, user := range users {
|
||||
err := changeUserActiveStatus(user, userArgs[i], active)
|
||||
err := changeUserActiveStatus(a, user, userArgs[i], active)
|
||||
|
||||
if err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
@@ -181,14 +182,14 @@ func changeUsersActiveStatus(userArgs []string, active bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func changeUserActiveStatus(user *model.User, userArg string, activate bool) error {
|
||||
func changeUserActiveStatus(a *app.App, user *model.User, userArg string, activate bool) error {
|
||||
if user == nil {
|
||||
return fmt.Errorf("Can't find user '%v'", userArg)
|
||||
}
|
||||
if user.IsLDAPUser() {
|
||||
return errors.New("You can not modify the activation status of AD/LDAP accounts. Please modify through the AD/LDAP server.")
|
||||
}
|
||||
if _, err := app.Global().UpdateActive(user, activate); err != nil {
|
||||
if _, err := a.UpdateActive(user, activate); err != nil {
|
||||
return fmt.Errorf("Unable to change activation status of user: %v", userArg)
|
||||
}
|
||||
|
||||
@@ -196,7 +197,8 @@ func changeUserActiveStatus(user *model.User, userArg string, activate bool) err
|
||||
}
|
||||
|
||||
func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -204,12 +206,13 @@ func userDeactivateCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Expected at least one argument. See help text for details.")
|
||||
}
|
||||
|
||||
changeUsersActiveStatus(args, false)
|
||||
changeUsersActiveStatus(a, args, false)
|
||||
return nil
|
||||
}
|
||||
|
||||
func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -241,13 +244,10 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
Locale: locale,
|
||||
}
|
||||
|
||||
ruser, err := app.Global().CreateUser(user)
|
||||
if err != nil {
|
||||
if ruser, err := a.CreateUser(user); err != nil {
|
||||
return errors.New("Unable to create user. Error: " + err.Error())
|
||||
}
|
||||
|
||||
if systemAdmin {
|
||||
app.Global().UpdateUserRoles(ruser.Id, "system_user system_admin")
|
||||
} else if systemAdmin {
|
||||
a.UpdateUserRoles(ruser.Id, "system_user system_admin")
|
||||
}
|
||||
|
||||
CommandPrettyPrintln("Created User")
|
||||
@@ -256,7 +256,8 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func userInviteCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -296,7 +297,8 @@ func inviteUser(email string, team *model.Team, teamArg string) error {
|
||||
}
|
||||
|
||||
func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -310,7 +312,7 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
password := args[1]
|
||||
|
||||
if result := <-app.Global().Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
@@ -318,7 +320,8 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -342,7 +345,8 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -373,7 +377,7 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if err := app.Global().PermanentDeleteUser(user); err != nil {
|
||||
if err := a.PermanentDeleteUser(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -382,7 +386,8 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -406,7 +411,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := app.Global().PermanentDeleteAllUsers(); err != nil {
|
||||
if err := a.PermanentDeleteAllUsers(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -415,7 +420,8 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -458,7 +464,8 @@ func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -473,7 +480,7 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find user '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
if cresult := <-app.Global().Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
||||
if cresult := <-a.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil {
|
||||
CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error())
|
||||
}
|
||||
}
|
||||
@@ -482,7 +489,8 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func searchUserCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -16,20 +16,21 @@ var versionCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func versionCmdF(cmd *cobra.Command, args []string) error {
|
||||
if err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printVersion()
|
||||
printVersion(a)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printVersion() {
|
||||
func printVersion(a *app.App) {
|
||||
CommandPrintln("Version: " + model.CurrentVersion)
|
||||
CommandPrintln("Build Number: " + model.BuildNumber)
|
||||
CommandPrintln("Build Date: " + model.BuildDate)
|
||||
CommandPrintln("Build Hash: " + model.BuildHash)
|
||||
CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
|
||||
CommandPrintln("DB Version: " + app.Global().Srv.Store.(*store.LayeredStore).DatabaseLayer.GetCurrentSchemaVersion())
|
||||
CommandPrintln("DB Version: " + a.Srv.Store.(*store.LayeredStore).DatabaseLayer.GetCurrentSchemaVersion())
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user