PLT-4938 Add app package and move logic over from api package (#4931)

* Add app package and move logic over from api package

* Change app package functions to return errors

* Move non-api tests into app package

* Fix merge
This commit is contained in:
Joram Wilander
2017-01-13 13:53:37 -05:00
committed by GitHub
parent 07bad4d6d5
commit 97558f6a6e
85 changed files with 3368 additions and 2997 deletions

View File

@@ -6,6 +6,7 @@ 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 +118,8 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
team := getTeamFromTeamArg(teamArg)
c := getMockContext()
channel := &model.Channel{
TeamId: team.Id,
Name: name,
@@ -124,10 +127,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
}
@@ -197,7 +200,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 +218,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 +243,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 +278,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] + "'")
}
}

View File

@@ -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)
}
}

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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 {
@@ -333,7 +333,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 +361,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 {
@@ -404,7 +404,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 +412,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 +431,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 +463,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 +471,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 +479,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 +524,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 +532,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,7 +540,7 @@ 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 {
@@ -570,14 +570,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 +615,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 +623,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 +637,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 +659,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 +667,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 +697,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,7 +705,7 @@ 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 {
@@ -741,14 +741,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 +766,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 {
@@ -798,7 +798,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 {
@@ -841,7 +841,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 {
@@ -927,7 +927,7 @@ func cmdResetDatabase() {
flushLogAndExit(1)
}
api.Srv.Store.DropAllTables()
app.Srv.Store.DropAllTables()
fmt.Print("SUCCESS: Database reset.")
flushLogAndExit(0)
}
@@ -1022,7 +1022,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 {
@@ -1054,7 +1054,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 {

View File

@@ -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"
@@ -63,8 +64,8 @@ func runServer(configFileLocation string) {
cmdUpdateDb30()
api.NewServer()
api.InitStores()
app.NewServer()
app.InitStores()
api.InitRouter()
api.InitApi()
web.InitWeb()
@@ -84,7 +85,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 {
@@ -120,7 +121,7 @@ func runServer(configFileLocation string) {
einterfaces.GetMetricsInterface().StopServer()
}
api.StopServer()
app.StopServer()
}
func runSecurityAndDiagnosticsJob() {
@@ -129,20 +130,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
@@ -151,7 +152,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()
@@ -176,20 +177,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))
}
@@ -206,7 +207,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 {
@@ -232,7 +233,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)
}
}
}
@@ -251,15 +252,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)
}

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/mattermost/platform/api"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/spf13/cobra"
)
@@ -92,10 +93,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
@@ -156,7 +155,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)
}
}

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -7,6 +7,7 @@ import (
"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"
@@ -220,7 +221,7 @@ 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())
}
@@ -277,7 +278,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
}
@@ -423,7 +424,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())
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}