diff options
Diffstat (limited to 'cmd/platform')
-rw-r--r-- | cmd/platform/channel.go | 18 | ||||
-rw-r--r-- | cmd/platform/channelargs.go | 6 | ||||
-rw-r--r-- | cmd/platform/import.go | 4 | ||||
-rw-r--r-- | cmd/platform/init.go | 5 | ||||
-rw-r--r-- | cmd/platform/mattermost.go | 4 | ||||
-rw-r--r-- | cmd/platform/oldcommands.go | 107 | ||||
-rw-r--r-- | cmd/platform/roles.go | 6 | ||||
-rw-r--r-- | cmd/platform/server.go | 37 | ||||
-rw-r--r-- | cmd/platform/team.go | 14 | ||||
-rw-r--r-- | cmd/platform/teamargs.go | 6 | ||||
-rw-r--r-- | cmd/platform/test.go | 21 | ||||
-rw-r--r-- | cmd/platform/user.go | 20 | ||||
-rw-r--r-- | cmd/platform/userargs.go | 8 | ||||
-rw-r--r-- | cmd/platform/version.go | 4 |
14 files changed, 139 insertions, 121 deletions
diff --git a/cmd/platform/channel.go b/cmd/platform/channel.go index cf5ef61bc..fd2b097af 100644 --- a/cmd/platform/channel.go +++ b/cmd/platform/channel.go @@ -5,7 +5,7 @@ package main import ( "errors" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "github.com/spf13/cobra" @@ -117,6 +117,8 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error { team := getTeamFromTeamArg(teamArg) + c := getMockContext() + channel := &model.Channel{ TeamId: team.Id, Name: name, @@ -124,10 +126,10 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error { Header: header, Purpose: purpose, Type: channelType, + CreatorId: c.Session.UserId, } - c := getMockContext() - if _, err := api.CreateChannel(c, channel, false); err != nil { + if _, err := app.CreateChannel(channel, false); err != nil { return err } @@ -163,7 +165,7 @@ func removeUserFromChannel(channel *model.Channel, user *model.User, userArg str CommandPrintErrorln("Can't find user '" + userArg + "'") return } - if err := api.RemoveUserFromChannel(user.Id, "", channel); err != nil { + if err := app.RemoveUserFromChannel(user.Id, "", channel); err != nil { CommandPrintErrorln("Unable to remove '" + userArg + "' from " + channel.Name + ". Error: " + err.Error()) } } @@ -197,7 +199,7 @@ func addUserToChannel(channel *model.Channel, user *model.User, userArg string) CommandPrintErrorln("Can't find user '" + userArg + "'") return } - if _, err := api.AddUserToChannel(user, channel); err != nil { + if _, err := app.AddUserToChannel(user, channel); err != nil { CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error()) } } @@ -215,7 +217,7 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error { CommandPrintErrorln("Unable to find channel '" + args[i] + "'") continue } - if result := <-api.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil { + if result := <-app.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil { CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + result.Err.Error()) } } @@ -240,7 +242,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error { CommandPrintErrorln("Unable to find team '" + args[i] + "'") continue } - if result := <-api.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { + if result := <-app.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { CommandPrintErrorln("Unable to list channels for '" + args[i] + "'") } else { channels := result.Data.([]*model.Channel) @@ -275,7 +277,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error { CommandPrintErrorln("Unable to find channel '" + args[i] + "'") continue } - if result := <-api.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil { + if result := <-app.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil { CommandPrintErrorln("Unable to restore channel '" + args[i] + "'") } } diff --git a/cmd/platform/channelargs.go b/cmd/platform/channelargs.go index b94bb6b70..ec697d86b 100644 --- a/cmd/platform/channelargs.go +++ b/cmd/platform/channelargs.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" ) @@ -42,7 +42,7 @@ func getChannelFromChannelArg(channelArg string) *model.Channel { return nil } - if result := <-api.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, channelPart); result.Err == nil { + if result := <-app.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, channelPart); result.Err == nil { channel = result.Data.(*model.Channel) } else { fmt.Println(result.Err.Error()) @@ -50,7 +50,7 @@ func getChannelFromChannelArg(channelArg string) *model.Channel { } if channel == nil { - if result := <-api.Srv.Store.Channel().Get(channelPart, true); result.Err == nil { + if result := <-app.Srv.Store.Channel().Get(channelPart, true); result.Err == nil { channel = result.Data.(*model.Channel) } } diff --git a/cmd/platform/import.go b/cmd/platform/import.go index b482cda7e..09b135354 100644 --- a/cmd/platform/import.go +++ b/cmd/platform/import.go @@ -6,7 +6,7 @@ import ( "errors" "os" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/spf13/cobra" ) @@ -54,7 +54,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.") - api.SlackImport(fileReader, fileInfo.Size(), team.Id) + app.SlackImport(fileReader, fileInfo.Size(), team.Id) CommandPrettyPrintln("Finished Slack Import.") diff --git a/cmd/platform/init.go b/cmd/platform/init.go index 7cf941e9c..eb842d302 100644 --- a/cmd/platform/init.go +++ b/cmd/platform/init.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "github.com/spf13/cobra" @@ -37,8 +38,8 @@ func initDBCommandContext(configFileLocation string) { utils.ConfigureCmdLineLog() - api.NewServer() - api.InitStores() + app.NewServer() + app.InitStores() if model.BuildEnterpriseReady == "true" { api.LoadLicense() } diff --git a/cmd/platform/mattermost.go b/cmd/platform/mattermost.go index b5224c403..2ee539980 100644 --- a/cmd/platform/mattermost.go +++ b/cmd/platform/mattermost.go @@ -9,7 +9,7 @@ import ( "fmt" "os" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/spf13/cobra" // Plugins @@ -79,7 +79,7 @@ func resetCmdF(cmd *cobra.Command, args []string) error { } } - api.Srv.Store.DropAllTables() + app.Srv.Store.DropAllTables() CommandPrettyPrintln("Database sucessfully reset") return nil diff --git a/cmd/platform/oldcommands.go b/cmd/platform/oldcommands.go index a599fa47e..ee7f66567 100644 --- a/cmd/platform/oldcommands.go +++ b/cmd/platform/oldcommands.go @@ -13,6 +13,7 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" @@ -69,8 +70,8 @@ func doLegacyCommands() { doLoadConfig(flagConfigFile) utils.InitTranslations(utils.Cfg.LocalizationSettings) utils.ConfigureCmdLineLog() - api.NewServer() - api.InitStores() + app.NewServer() + app.InitStores() api.InitRouter() api.InitApi() web.InitWeb() @@ -187,9 +188,9 @@ func runCmds() { func cmdRunClientTests() { if flagCmdRunWebClientTests { setupClientTests() - api.StartServer() + app.StartServer() runWebClientTests() - api.StopServer() + app.StopServer() } } @@ -220,9 +221,8 @@ func cmdCreateTeam() { team.Email = flagEmail team.Type = model.TEAM_OPEN - api.CreateTeam(c, team) - if c.Err != nil { - if c.Err.Id != "store.sql_team.save.domain_exists.app_error" { + if _, err := app.CreateTeam(team); err != nil { + if err.Id != "store.sql_team.save.domain_exists.app_error" { l4g.Error("%v", c.Err) flushLogAndExit(1) } @@ -257,7 +257,7 @@ func cmdCreateUser() { } if len(flagTeamName) > 0 { - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -265,7 +265,7 @@ func cmdCreateUser() { } } - ruser, err := api.CreateUser(user) + ruser, err := app.CreateUser(user) if err != nil { if err.Id != "store.sql_user.save.email_exists.app_error" { l4g.Error("%v", err) @@ -274,7 +274,7 @@ func cmdCreateUser() { } if team != nil { - err = api.JoinUserToTeam(team, ruser) + err = app.JoinUserToTeam(team, ruser) if err != nil { l4g.Error("%v", err) flushLogAndExit(1) @@ -303,7 +303,7 @@ func cmdInviteUser() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -311,7 +311,7 @@ func cmdInviteUser() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(team.Email); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(team.Email); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -319,8 +319,7 @@ func cmdInviteUser() { } invites := []string{flagEmail} - c := getMockContext() - api.InviteMembers(team, user.GetDisplayName(), invites, c.GetSiteURL()) + app.SendInviteEmails(team, user.GetDisplayName(), invites, *utils.Cfg.ServiceSettings.SiteURL) os.Exit(0) } @@ -333,7 +332,7 @@ func cmdVersion() { fmt.Fprintln(os.Stderr, "Build Date: "+model.BuildDate) fmt.Fprintln(os.Stderr, "Build Hash: "+model.BuildHash) fmt.Fprintln(os.Stderr, "Build Enterprise Ready: "+model.BuildEnterpriseReady) - fmt.Fprintln(os.Stderr, "DB Version: "+api.Srv.Store.(*store.SqlStore).SchemaVersion) + fmt.Fprintln(os.Stderr, "DB Version: "+app.Srv.Store.(*store.SqlStore).SchemaVersion) os.Exit(0) } @@ -361,7 +360,7 @@ func cmdAssignRole() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -369,7 +368,7 @@ func cmdAssignRole() { } if !user.IsInRole(flagRole) { - api.UpdateUserRoles(user, flagRole) + app.UpdateUserRoles(user.Id, flagRole) } os.Exit(0) @@ -404,7 +403,7 @@ func cmdCreateChannel() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v %v", utils.T(result.Err.Message), result.Err.DetailedError) flushLogAndExit(1) } else { @@ -412,7 +411,7 @@ func cmdCreateChannel() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v %v", utils.T(result.Err.Message), result.Err.DetailedError) flushLogAndExit(1) } else { @@ -431,7 +430,7 @@ func cmdCreateChannel() { channel.Header = flagChannelHeader channel.Purpose = flagChannelPurpose - if _, err := api.CreateChannel(c, channel, true); err != nil { + if _, err := app.CreateChannel(channel, true); err != nil { l4g.Error("%v %v", utils.T(err.Message), err.DetailedError) flushLogAndExit(1) } @@ -463,7 +462,7 @@ func cmdJoinChannel() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -471,7 +470,7 @@ func cmdJoinChannel() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -479,14 +478,14 @@ func cmdJoinChannel() { } var channel *model.Channel - if result := <-api.Srv.Store.Channel().GetByName(team.Id, flagChannelName); result.Err != nil { + if result := <-app.Srv.Store.Channel().GetByName(team.Id, flagChannelName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { channel = result.Data.(*model.Channel) } - _, err := api.AddUserToChannel(user, channel) + _, err := app.AddUserToChannel(user, channel) if err != nil { l4g.Error("%v", err) flushLogAndExit(1) @@ -524,7 +523,7 @@ func cmdLeaveChannel() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -532,7 +531,7 @@ func cmdLeaveChannel() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -540,14 +539,14 @@ func cmdLeaveChannel() { } var channel *model.Channel - if result := <-api.Srv.Store.Channel().GetByName(team.Id, flagChannelName); result.Err != nil { + if result := <-app.Srv.Store.Channel().GetByName(team.Id, flagChannelName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { channel = result.Data.(*model.Channel) } - err := api.RemoveUserFromChannel(user.Id, user.Id, channel) + err := app.RemoveUserFromChannel(user.Id, user.Id, channel) if err != nil { l4g.Error("%v", err) flushLogAndExit(1) @@ -570,14 +569,14 @@ func cmdListChannels() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { team = result.Data.(*model.Team) } - if result := <-api.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { + if result := <-app.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -615,7 +614,7 @@ func cmdRestoreChannel() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -623,7 +622,7 @@ func cmdRestoreChannel() { } var channel *model.Channel - if result := <-api.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { + if result := <-app.Srv.Store.Channel().GetAll(team.Id); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -637,7 +636,7 @@ func cmdRestoreChannel() { } } - if result := <-api.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil { + if result := <-app.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } @@ -659,7 +658,7 @@ func cmdJoinTeam() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -667,14 +666,14 @@ func cmdJoinTeam() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { user = result.Data.(*model.User) } - err := api.JoinUserToTeam(team, user) + err := app.JoinUserToTeam(team, user) if err != nil { l4g.Error("%v", err) flushLogAndExit(1) @@ -697,7 +696,7 @@ func cmdLeaveTeam() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -705,14 +704,14 @@ func cmdLeaveTeam() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { user = result.Data.(*model.User) } - err := api.LeaveTeam(team, user) + err := app.LeaveTeam(team, user) if err != nil { l4g.Error("%v", err) @@ -741,14 +740,14 @@ func cmdResetPassword() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { user = result.Data.(*model.User) } - if result := <-api.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(flagPassword)); result.Err != nil { + if result := <-app.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(flagPassword)); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } @@ -766,14 +765,14 @@ func cmdResetMfa() { var user *model.User if len(flagEmail) > 0 { - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { user = result.Data.(*model.User) } } else { - if result := <-api.Srv.Store.User().GetByUsername(flagUsername); result.Err != nil { + if result := <-app.Srv.Store.User().GetByUsername(flagUsername); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -781,7 +780,7 @@ func cmdResetMfa() { } } - if err := api.DeactivateMfa(user.Id); err != nil { + if err := app.DeactivateMfa(user.Id); err != nil { l4g.Error("%v", err) flushLogAndExit(1) } @@ -798,7 +797,7 @@ func cmdPermDeleteUser() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -823,7 +822,7 @@ func cmdPermDeleteUser() { flushLogAndExit(1) } - if err := api.PermanentDeleteUser(user); err != nil { + if err := app.PermanentDeleteUser(user); err != nil { l4g.Error("%v", err) flushLogAndExit(1) } else { @@ -841,7 +840,7 @@ func cmdPermDeleteTeam() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -866,7 +865,7 @@ func cmdPermDeleteTeam() { flushLogAndExit(1) } - if err := api.PermanentDeleteTeam(team); err != nil { + if err := app.PermanentDeleteTeam(team); err != nil { l4g.Error("%v", err) flushLogAndExit(1) } else { @@ -896,7 +895,7 @@ func cmdPermDeleteAllUsers() { flushLogAndExit(1) } - if err := api.PermanentDeleteAllUsers(); err != nil { + if err := app.PermanentDeleteAllUsers(); err != nil { l4g.Error("%v", err) flushLogAndExit(1) } else { @@ -927,7 +926,7 @@ func cmdResetDatabase() { flushLogAndExit(1) } - api.Srv.Store.DropAllTables() + app.Srv.Store.DropAllTables() fmt.Print("SUCCESS: Database reset.") flushLogAndExit(0) } @@ -1022,7 +1021,7 @@ func cmdActivateUser() { } var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { + if result := <-app.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -1033,7 +1032,7 @@ func cmdActivateUser() { l4g.Error("%v", utils.T("api.user.update_active.no_deactivate_ldap.app_error")) } - if _, err := api.UpdateActive(user, !flagUserSetInactive); err != nil { + if _, err := app.UpdateActive(user, !flagUserSetInactive); err != nil { l4g.Error("%v", err) } @@ -1054,7 +1053,7 @@ func cmdSlackImport() { } var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { + if result := <-app.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil { l4g.Error("%v", result.Err) flushLogAndExit(1) } else { @@ -1076,7 +1075,7 @@ func cmdSlackImport() { fmt.Fprintln(os.Stdout, "Running Slack Import. This may take a long time for large teams or teams with many messages.") - api.SlackImport(fileReader, fileInfo.Size(), team.Id) + app.SlackImport(fileReader, fileInfo.Size(), team.Id) flushLogAndExit(0) } diff --git a/cmd/platform/roles.go b/cmd/platform/roles.go index 7b635c5a3..a65eb2bd6 100644 --- a/cmd/platform/roles.go +++ b/cmd/platform/roles.go @@ -5,7 +5,7 @@ package main import ( "errors" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/spf13/cobra" ) @@ -49,7 +49,7 @@ func makeSystemAdminCmdF(cmd *cobra.Command, args []string) error { return errors.New("Unable to find user '" + args[i] + "'") } - if _, err := api.UpdateUserRoles(user, "system_admin system_user"); err != nil { + if _, err := app.UpdateUserRoles(user.Id, "system_admin system_user"); err != nil { return err } } @@ -69,7 +69,7 @@ func makeMemberCmdF(cmd *cobra.Command, args []string) error { return errors.New("Unable to find user '" + args[i] + "'") } - if _, err := api.UpdateUserRoles(user, "system_user"); err != nil { + if _, err := app.UpdateUserRoles(user.Id, "system_user"); err != nil { return err } } diff --git a/cmd/platform/server.go b/cmd/platform/server.go index 83185a45f..560403a6b 100644 --- a/cmd/platform/server.go +++ b/cmd/platform/server.go @@ -16,6 +16,7 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/manualtesting" "github.com/mattermost/platform/model" @@ -69,8 +70,8 @@ func runServer(configFileLocation string) { cmdUpdateDb30() - api.NewServer() - api.InitStores() + app.NewServer() + app.InitStores() api.InitRouter() api.InitApi() web.InitWeb() @@ -90,7 +91,7 @@ func runServer(configFileLocation string) { resetStatuses() - api.StartServer() + app.StartServer() // If we allow testing then listen for manual testing URL hits if utils.Cfg.ServiceSettings.EnableTesting { @@ -126,7 +127,7 @@ func runServer(configFileLocation string) { einterfaces.GetMetricsInterface().StopServer() } - api.StopServer() + app.StopServer() } func runSecurityAndDiagnosticsJob() { @@ -135,20 +136,20 @@ func runSecurityAndDiagnosticsJob() { } func resetStatuses() { - if result := <-api.Srv.Store.Status().ResetAll(); result.Err != nil { + if result := <-app.Srv.Store.Status().ResetAll(); result.Err != nil { l4g.Error(utils.T("mattermost.reset_status.error"), result.Err.Error()) } } func setDiagnosticId() { - if result := <-api.Srv.Store.System().Get(); result.Err == nil { + if result := <-app.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} - <-api.Srv.Store.System().Save(systemId) + <-app.Srv.Store.System().Save(systemId) } utils.CfgDiagnosticId = id @@ -157,7 +158,7 @@ func setDiagnosticId() { func doSecurityAndDiagnostics() { if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert { - if result := <-api.Srv.Store.System().Get(); result.Err == nil { + if result := <-app.Srv.Store.System().Get(); result.Err == nil { props := result.Data.(model.StringMap) lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0) currentTime := model.GetMillis() @@ -182,20 +183,20 @@ func doSecurityAndDiagnostics() { systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)} if lastSecurityTime == 0 { - <-api.Srv.Store.System().Save(systemSecurityLastTime) + <-app.Srv.Store.System().Save(systemSecurityLastTime) } else { - <-api.Srv.Store.System().Update(systemSecurityLastTime) + <-app.Srv.Store.System().Update(systemSecurityLastTime) } - if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { + if ucr := <-app.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { v.Set(utils.PROP_DIAGNOSTIC_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10)) } - if ucr := <-api.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil { + if ucr := <-app.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil { v.Set(utils.PROP_DIAGNOSTIC_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10)) } - if tcr := <-api.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil { + if tcr := <-app.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil { v.Set(utils.PROP_DIAGNOSTIC_TEAM_COUNT, strconv.FormatInt(tcr.Data.(int64), 10)) } @@ -212,7 +213,7 @@ func doSecurityAndDiagnostics() { for _, bulletin := range bulletins { if bulletin.AppliesToVersion == model.CurrentVersion { if props["SecurityBulletin_"+bulletin.Id] == "" { - if results := <-api.Srv.Store.User().GetSystemAdminProfiles(); results.Err != nil { + if results := <-app.Srv.Store.User().GetSystemAdminProfiles(); results.Err != nil { l4g.Error(utils.T("mattermost.system_admins.error")) return } else { @@ -238,7 +239,7 @@ func doSecurityAndDiagnostics() { } bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id} - <-api.Srv.Store.System().Save(bulletinSeen) + <-app.Srv.Store.System().Save(bulletinSeen) } } } @@ -257,15 +258,15 @@ func sendServerDiagnostics() { var activeUserCount int64 var teamCount int64 - if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { + if ucr := <-app.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { userCount = ucr.Data.(int64) } - if ucr := <-api.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil { + if ucr := <-app.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil { activeUserCount = ucr.Data.(int64) } - if tcr := <-api.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil { + if tcr := <-app.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil { teamCount = tcr.Data.(int64) } diff --git a/cmd/platform/team.go b/cmd/platform/team.go index 8fecda6e1..1dc5d46eb 100644 --- a/cmd/platform/team.go +++ b/cmd/platform/team.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/spf13/cobra" ) @@ -92,10 +92,8 @@ func createTeamCmdF(cmd *cobra.Command, args []string) error { Type: teamType, } - c := getMockContext() - api.CreateTeam(c, team) - if c.Err != nil { - return errors.New("Team creation failed: " + c.Err.Error()) + if _, err := app.CreateTeam(team); err != nil { + return errors.New("Team creation failed: " + err.Error()) } return nil @@ -126,7 +124,7 @@ func removeUserFromTeam(team *model.Team, user *model.User, userArg string) { CommandPrintErrorln("Can't find user '" + userArg + "'") return } - if err := api.LeaveTeam(team, user); err != nil { + if err := app.LeaveTeam(team, user); err != nil { CommandPrintErrorln("Unable to remove '" + userArg + "' from " + team.Name + ". Error: " + err.Error()) } } @@ -156,7 +154,7 @@ func addUserToTeam(team *model.Team, user *model.User, userArg string) { CommandPrintErrorln("Can't find user '" + userArg + "'") return } - if err := api.JoinUserToTeam(team, user); err != nil { + if err := app.JoinUserToTeam(team, user); err != nil { CommandPrintErrorln("Unable to add '" + userArg + "' to " + team.Name) } } @@ -201,5 +199,5 @@ func deleteTeamsCmdF(cmd *cobra.Command, args []string) error { } func deleteTeam(team *model.Team) *model.AppError { - return api.PermanentDeleteTeam(team) + return app.PermanentDeleteTeam(team) } diff --git a/cmd/platform/teamargs.go b/cmd/platform/teamargs.go index 5ad56f5d9..506cc88ef 100644 --- a/cmd/platform/teamargs.go +++ b/cmd/platform/teamargs.go @@ -3,7 +3,7 @@ package main import ( - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" ) @@ -18,12 +18,12 @@ func getTeamsFromTeamArgs(teamArgs []string) []*model.Team { func getTeamFromTeamArg(teamArg string) *model.Team { var team *model.Team - if result := <-api.Srv.Store.Team().GetByName(teamArg); result.Err == nil { + if result := <-app.Srv.Store.Team().GetByName(teamArg); result.Err == nil { team = result.Data.(*model.Team) } if team == nil { - if result := <-api.Srv.Store.Team().Get(teamArg); result.Err == nil { + if result := <-app.Srv.Store.Team().Get(teamArg); result.Err == nil { team = result.Data.(*model.Team) } } diff --git a/cmd/platform/test.go b/cmd/platform/test.go index d82734c75..65a8528d0 100644 --- a/cmd/platform/test.go +++ b/cmd/platform/test.go @@ -10,6 +10,7 @@ import ( "os/exec" "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/utils" "github.com/spf13/cobra" ) @@ -38,9 +39,9 @@ func webClientTestsCmdF(cmd *cobra.Command, args []string) error { api.InitRouter() api.InitApi() setupClientTests() - api.StartServer() + app.StartServer() runWebClientTests() - api.StopServer() + app.StopServer() return nil } @@ -59,18 +60,34 @@ func executeTestCommand(cmd *exec.Cmd) { cmdOutPipe, err := cmd.StdoutPipe() if err != nil { CommandPrintErrorln("Failed to run tests") + os.Exit(1) + return + } + + cmdErrOutPipe, err := cmd.StderrPipe() + if err != nil { + CommandPrintErrorln("Failed to run tests") + os.Exit(1) return } cmdOutReader := bufio.NewScanner(cmdOutPipe) + cmdErrOutReader := bufio.NewScanner(cmdErrOutPipe) go func() { for cmdOutReader.Scan() { fmt.Println(cmdOutReader.Text()) } }() + go func() { + for cmdErrOutReader.Scan() { + fmt.Println(cmdErrOutReader.Text()) + } + }() + if err := cmd.Run(); err != nil { CommandPrintErrorln("Client Tests failed") + os.Exit(1) return } } diff --git a/cmd/platform/user.go b/cmd/platform/user.go index 373274241..fa93e418c 100644 --- a/cmd/platform/user.go +++ b/cmd/platform/user.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" @@ -174,7 +174,7 @@ func changeUserActiveStatus(user *model.User, userArg string, activate bool) { CommandPrintErrorln(utils.T("api.user.update_active.no_deactivate_ldap.app_error")) return } - if _, err := api.UpdateActive(user, activate); err != nil { + if _, err := app.UpdateActive(user, activate); err != nil { CommandPrintErrorln("Unable to change activation status of user: " + userArg) } } @@ -220,13 +220,13 @@ func userCreateCmdF(cmd *cobra.Command, args []string) error { Locale: locale, } - ruser, err := api.CreateUser(user) + ruser, err := app.CreateUser(user) if err != nil { return errors.New("Unable to create user. Error: " + err.Error()) } if system_admin { - api.UpdateUserRoles(ruser, "system_user system_admin") + app.UpdateUserRoles(ruser.Id, "system_user system_admin") } CommandPrettyPrintln("Created User") @@ -261,7 +261,7 @@ func inviteUser(email string, team *model.Team, teamArg string) { CommandPrintErrorln("Can't find team '" + teamArg + "'") return } - api.InviteMembers(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL) + app.SendInviteEmails(team, "Administrator", invites, *utils.Cfg.ServiceSettings.SiteURL) CommandPrettyPrintln("Invites may or may not have been sent.") } @@ -277,7 +277,7 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error { } password := args[1] - if result := <-api.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil { + if result := <-app.Srv.Store.User().UpdatePassword(user.Id, model.HashPassword(password)); result.Err != nil { return result.Err } @@ -297,7 +297,7 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error { return errors.New("Unable to find user '" + args[i] + "'") } - if err := api.DeactivateMfa(user.Id); err != nil { + if err := app.DeactivateMfa(user.Id); err != nil { return err } } @@ -334,7 +334,7 @@ func deleteUserCmdF(cmd *cobra.Command, args []string) error { return errors.New("Unable to find user '" + args[i] + "'") } - if err := api.PermanentDeleteUser(user); err != nil { + if err := app.PermanentDeleteUser(user); err != nil { return err } } @@ -364,7 +364,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error { } } - if err := api.PermanentDeleteAllUsers(); err != nil { + if err := app.PermanentDeleteAllUsers(); err != nil { return err } else { CommandPrettyPrintln("Sucsessfull. All users deleted.") @@ -423,7 +423,7 @@ func verifyUserCmdF(cmd *cobra.Command, args []string) error { if user == nil { CommandPrintErrorln("Unable to find user '" + args[i] + "'") } - if cresult := <-api.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil { + if cresult := <-app.Srv.Store.User().VerifyEmail(user.Id); cresult.Err != nil { CommandPrintErrorln("Unable to verify '" + args[i] + "' email. Error: " + cresult.Err.Error()) } } diff --git a/cmd/platform/userargs.go b/cmd/platform/userargs.go index 9ac00ae70..31ae3c251 100644 --- a/cmd/platform/userargs.go +++ b/cmd/platform/userargs.go @@ -3,7 +3,7 @@ package main import ( - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" ) @@ -18,18 +18,18 @@ func getUsersFromUserArgs(userArgs []string) []*model.User { func getUserFromUserArg(userArg string) *model.User { var user *model.User - if result := <-api.Srv.Store.User().GetByEmail(userArg); result.Err == nil { + if result := <-app.Srv.Store.User().GetByEmail(userArg); result.Err == nil { user = result.Data.(*model.User) } if user == nil { - if result := <-api.Srv.Store.User().GetByUsername(userArg); result.Err == nil { + if result := <-app.Srv.Store.User().GetByUsername(userArg); result.Err == nil { user = result.Data.(*model.User) } } if user == nil { - if result := <-api.Srv.Store.User().Get(userArg); result.Err == nil { + if result := <-app.Srv.Store.User().Get(userArg); result.Err == nil { user = result.Data.(*model.User) } } diff --git a/cmd/platform/version.go b/cmd/platform/version.go index 8da34e3a9..8978aa841 100644 --- a/cmd/platform/version.go +++ b/cmd/platform/version.go @@ -3,7 +3,7 @@ package main import ( - "github.com/mattermost/platform/api" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/spf13/cobra" @@ -26,5 +26,5 @@ func printVersion() { CommandPrintln("Build Date: " + model.BuildDate) CommandPrintln("Build Hash: " + model.BuildHash) CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady) - CommandPrintln("DB Version: " + api.Srv.Store.(*store.SqlStore).SchemaVersion) + CommandPrintln("DB Version: " + app.Srv.Store.(*store.SqlStore).SchemaVersion) } |