diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/admin.go | 20 | ||||
-rw-r--r-- | api/admin_test.go | 5 | ||||
-rw-r--r-- | api/api.go | 10 | ||||
-rw-r--r-- | api/apitestlib.go | 46 | ||||
-rw-r--r-- | api/channel.go | 120 | ||||
-rw-r--r-- | api/channel_test.go | 23 | ||||
-rw-r--r-- | api/cli_test.go | 6 | ||||
-rw-r--r-- | api/command.go | 22 | ||||
-rw-r--r-- | api/command_help_test.go | 3 | ||||
-rw-r--r-- | api/command_msg_test.go | 3 | ||||
-rw-r--r-- | api/context.go | 18 | ||||
-rw-r--r-- | api/emoji.go | 15 | ||||
-rw-r--r-- | api/emoji_test.go | 10 | ||||
-rw-r--r-- | api/file.go | 10 | ||||
-rw-r--r-- | api/file_test.go | 50 | ||||
-rw-r--r-- | api/license.go | 4 | ||||
-rw-r--r-- | api/license_test.go | 3 | ||||
-rw-r--r-- | api/oauth.go | 30 | ||||
-rw-r--r-- | api/oauth_test.go | 15 | ||||
-rw-r--r-- | api/post.go | 62 | ||||
-rw-r--r-- | api/post_test.go | 40 | ||||
-rw-r--r-- | api/preference.go | 14 | ||||
-rw-r--r-- | api/preference_test.go | 3 | ||||
-rw-r--r-- | api/reaction.go | 18 | ||||
-rw-r--r-- | api/status.go | 2 | ||||
-rw-r--r-- | api/status_test.go | 11 | ||||
-rw-r--r-- | api/team.go | 46 | ||||
-rw-r--r-- | api/team_test.go | 27 | ||||
-rw-r--r-- | api/user.go | 110 | ||||
-rw-r--r-- | api/user_test.go | 82 | ||||
-rw-r--r-- | api/webhook.go | 36 | ||||
-rw-r--r-- | api/websocket.go | 2 |
32 files changed, 436 insertions, 430 deletions
diff --git a/api/admin.go b/api/admin.go index 30dadc7ba..76a99764e 100644 --- a/api/admin.go +++ b/api/admin.go @@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) { } func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) { - if audits, err := app.GetAudits("", 200); err != nil { + if audits, err := c.App.GetAudits("", 200); err != nil { c.Err = err return } else if HandleEtag(audits.Etag(), "Get All Audits", w, r) { @@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) { } func invalidateAllCaches(c *Context, w http.ResponseWriter, r *http.Request) { - err := app.InvalidateAllCaches() + err := c.App.InvalidateAllCaches() if err != nil { c.Err = err return @@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) { } func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) { - app.RecycleDatabaseConnection() + c.App.RecycleDatabaseConnection() w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") ReturnStatusOK(w) } @@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := app.TestEmail(c.Session.UserId, cfg) + err := c.App.TestEmail(c.Session.UserId, cfg) if err != nil { c.Err = err return @@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { } func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) { - crs, err := app.GetComplianceReports(0, 10000) + crs, err := c.App.GetComplianceReports(0, 10000) if err != nil { c.Err = err return @@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) { job.UserId = c.Session.UserId - rjob, err := app.SaveComplianceReport(job) + rjob, err := c.App.SaveComplianceReport(job) if err != nil { c.Err = err return @@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request return } - job, err := app.GetComplianceReport(id) + job, err := c.App.GetComplianceReport(id) if err != nil { c.Err = err return @@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { teamId := params["id"] name := params["name"] - rows, err := app.GetAnalytics(name, teamId) + rows, err := c.App.GetAnalytics(name, teamId) if err != nil { c.Err = err return @@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil { + if err := c.App.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil { c.Err = err return } @@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) { } func getRecentlyActiveUsers(c *Context, w http.ResponseWriter, r *http.Request) { - if profiles, err := app.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil { + if profiles, err := c.App.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil { c.Err = err return } else { diff --git a/api/admin_test.go b/api/admin_test.go index 07504c4d1..74b6c1c80 100644 --- a/api/admin_test.go +++ b/api/admin_test.go @@ -8,7 +8,6 @@ import ( "strings" "testing" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" @@ -597,7 +596,7 @@ func TestAdminResetPassword(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) if _, err := Client.AdminResetPassword("", "newpwd1"); err == nil { t.Fatal("Should have errored - empty user id") @@ -619,7 +618,7 @@ func TestAdminResetPassword(t *testing.T) { user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) if _, err := Client.AdminResetPassword(user.Id, "newpwd1"); err != nil { t.Fatal(err) diff --git a/api/api.go b/api/api.go index 7e902c159..814341003 100644 --- a/api/api.go +++ b/api/api.go @@ -60,14 +60,14 @@ type Routes struct { var BaseRoutes *Routes func InitRouter() { - app.Srv.Router = mux.NewRouter() - app.Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404) + app.Global().Srv.Router = mux.NewRouter() + app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404) } func InitApi() { BaseRoutes = &Routes{} - BaseRoutes.Root = app.Srv.Router - BaseRoutes.ApiRoot = app.Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter() + BaseRoutes.Root = app.Global().Srv.Router + BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter() BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter() BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter() BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter() @@ -111,7 +111,7 @@ func InitApi() { InitDeprecated() // 404 on any api route before web.go has a chance to serve it - app.Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404)) + app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404)) utils.InitHTML() diff --git a/api/apitestlib.go b/api/apitestlib.go index 9aaf62e2b..de58221ab 100644 --- a/api/apitestlib.go +++ b/api/apitestlib.go @@ -17,6 +17,8 @@ import ( ) type TestHelper struct { + App *app.App + BasicClient *model.Client BasicTeam *model.Team BasicUser *model.User @@ -32,7 +34,7 @@ type TestHelper struct { } func SetupEnterprise() *TestHelper { - if app.Srv == nil { + if app.Global().Srv == nil { utils.TranslationsPreInit() utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) @@ -40,17 +42,17 @@ func SetupEnterprise() *TestHelper { *utils.Cfg.RateLimitSettings.Enable = false utils.DisableDebugLogForTest() utils.License().Features.SetDefaults() - app.NewServer() - app.InitStores() + app.Global().NewServer() + app.Global().InitStores() InitRouter() wsapi.InitRouter() - app.StartServer() + app.Global().StartServer() utils.InitHTML() api4.InitApi(false) InitApi() wsapi.InitApi() utils.EnableDebugLogForTest() - app.Srv.Store.MarkSystemRanUnitTests() + app.Global().Srv.Store.MarkSystemRanUnitTests() *utils.Cfg.TeamSettings.EnableOpenServer = true } @@ -59,7 +61,7 @@ func SetupEnterprise() *TestHelper { } func Setup() *TestHelper { - if app.Srv == nil { + if app.Global().Srv == nil { utils.TranslationsPreInit() utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) @@ -70,16 +72,16 @@ func Setup() *TestHelper { utils.Cfg.EmailSettings.SMTPPort = "2500" utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com" utils.DisableDebugLogForTest() - app.NewServer() - app.InitStores() + app.Global().NewServer() + app.Global().InitStores() InitRouter() wsapi.InitRouter() - app.StartServer() + app.Global().StartServer() api4.InitApi(false) InitApi() wsapi.InitApi() utils.EnableDebugLogForTest() - app.Srv.Store.MarkSystemRanUnitTests() + app.Global().Srv.Store.MarkSystemRanUnitTests() *utils.Cfg.TeamSettings.EnableOpenServer = true } @@ -100,6 +102,7 @@ func ReloadConfigForSetup() { } func (me *TestHelper) InitBasic() *TestHelper { + me.App = app.Global() me.BasicClient = me.CreateClient() me.BasicUser = me.CreateUser(me.BasicClient) me.LoginBasic() @@ -119,6 +122,7 @@ func (me *TestHelper) InitBasic() *TestHelper { } func (me *TestHelper) InitSystemAdmin() *TestHelper { + me.App = app.Global() me.SystemAdminClient = me.CreateClient() me.SystemAdminUser = me.CreateUser(me.SystemAdminClient) me.SystemAdminUser.Password = "Password1" @@ -126,7 +130,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { me.SystemAdminTeam = me.CreateTeam(me.SystemAdminClient) LinkUserToTeam(me.SystemAdminUser, me.SystemAdminTeam) me.SystemAdminClient.SetTeamId(me.SystemAdminTeam.Id) - app.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id) + me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id) me.SystemAdminChannel = me.CreateChannel(me.SystemAdminClient, me.SystemAdminTeam) return me @@ -168,7 +172,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User { utils.DisableDebugLogForTest() ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User) ruser.Password = "Password1" - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(app.Global().Srv.Store.User().VerifyEmail(ruser.Id)) utils.EnableDebugLogForTest() return ruser } @@ -176,7 +180,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User { func LinkUserToTeam(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() - err := app.JoinUserToTeam(team, user, "") + err := app.Global().JoinUserToTeam(team, user, "") if err != nil { l4g.Error(err.Error()) l4g.Close() @@ -191,7 +195,7 @@ func UpdateUserToTeamAdmin(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id + " " + model.ROLE_TEAM_ADMIN.Id} - if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil { + if tmr := <-app.Global().Srv.Store.Team().UpdateMember(tm); tmr.Err != nil { utils.EnableDebugLogForTest() l4g.Error(tmr.Err.Error()) l4g.Close() @@ -205,7 +209,7 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id} - if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil { + if tmr := <-app.Global().Srv.Store.Team().UpdateMember(tm); tmr.Err != nil { utils.EnableDebugLogForTest() l4g.Error(tmr.Err.Error()) l4g.Close() @@ -218,10 +222,10 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) { func MakeUserChannelAdmin(user *model.User, channel *model.Channel) { utils.DisableDebugLogForTest() - if cmr := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil { + if cmr := <-app.Global().Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil { cm := cmr.Data.(*model.ChannelMember) cm.Roles = "channel_admin channel_user" - if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil { + if sr := <-app.Global().Srv.Store.Channel().UpdateMember(cm); sr.Err != nil { utils.EnableDebugLogForTest() panic(sr.Err) } @@ -236,10 +240,10 @@ func MakeUserChannelAdmin(user *model.User, channel *model.Channel) { func MakeUserChannelUser(user *model.User, channel *model.Channel) { utils.DisableDebugLogForTest() - if cmr := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil { + if cmr := <-app.Global().Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil { cm := cmr.Data.(*model.ChannelMember) cm.Roles = "channel_user" - if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil { + if sr := <-app.Global().Srv.Store.Channel().UpdateMember(cm); sr.Err != nil { utils.EnableDebugLogForTest() panic(sr.Err) } @@ -323,7 +327,7 @@ func (me *TestHelper) LoginSystemAdmin() { } func TearDown() { - if app.Srv != nil { - app.StopServer() + if app.Global().Srv != nil { + app.Global().StopServer() } } diff --git a/api/channel.go b/api/channel.go index 360d69249..dc6124430 100644 --- a/api/channel.go +++ b/api/channel.go @@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if sc, err := app.CreateChannelWithUser(channel, c.Session.UserId); err != nil { + if sc, err := c.App.CreateChannelWithUser(channel, c.Session.UserId); err != nil { c.Err = err return } else { @@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if sc, err := app.CreateDirectChannel(c.Session.UserId, userId); err != nil { + if sc, err := c.App.CreateDirectChannel(c.Session.UserId, userId); err != nil { c.Err = err return } else { @@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) { userIds = append(userIds, c.Session.UserId) } - if sc, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil { + if sc, err := c.App.CreateGroupChannel(userIds, c.Session.UserId); err != nil { c.Err = err return } else { @@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) { } func CanManageChannel(c *Context, channel *model.Channel) bool { - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) { + if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) { c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) return false } - if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) { + if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) { c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) return false } @@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { var oldChannel *model.Channel var err *model.AppError - if oldChannel, err = app.GetChannel(channel.Id); err != nil { + if oldChannel, err = c.App.GetChannel(channel.Id); err != nil { c.Err = err return } - if _, err = app.GetChannelMember(channel.Id, c.Session.UserId); err != nil { + if _, err = c.App.GetChannelMember(channel.Id, c.Session.UserId); err != nil { c.Err = err return } @@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { oldChannel.Type = channel.Type } - if _, err := app.UpdateChannel(oldChannel); err != nil { + if _, err := c.App.UpdateChannel(oldChannel); err != nil { c.Err = err return } else { if oldChannelDisplayName != channel.DisplayName { - if err := app.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil { + if err := c.App.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil { l4g.Error(err.Error()) } } @@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(channelId); err != nil { + if channel, err = c.App.GetChannel(channelId); err != nil { c.Err = err return } - if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil { + if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil { c.Err = err return } @@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) { oldChannelHeader := channel.Header channel.Header = channelHeader - if _, err := app.UpdateChannel(channel); err != nil { + if _, err := c.App.UpdateChannel(channel); err != nil { c.Err = err return } else { - if err := app.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil { + if err := c.App.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil { l4g.Error(err.Error()) } c.LogAudit("name=" + channel.Name) @@ -278,12 +278,12 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(channelId); err != nil { + if channel, err = c.App.GetChannel(channelId); err != nil { c.Err = err return } - if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil { + if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil { c.Err = err return } @@ -295,11 +295,11 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) { oldChannelPurpose := channel.Purpose channel.Purpose = channelPurpose - if _, err := app.UpdateChannel(channel); err != nil { + if _, err := c.App.UpdateChannel(channel); err != nil { c.Err = err return } else { - if err := app.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil { + if err := c.App.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil { l4g.Error(err.Error()) } c.LogAudit("name=" + channel.Name) @@ -315,10 +315,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) { // user is already in the team // Get's all channels the user is a member of - if channels, err := app.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil { + if channels, err := c.App.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil { if err.Id == "store.sql_channel.get_channels.not_found.app_error" { // lets make sure the user is valid - if _, err := app.GetUser(c.Session.UserId); err != nil { + if _, err := c.App.GetUser(c.Session.UserId); err != nil { c.Err = err c.RemoveSessionCookie(w, r) l4g.Error(utils.T("api.channel.get_channels.error"), c.Session.UserId) @@ -356,7 +356,7 @@ func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if channels, err := app.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil { + if channels, err := c.App.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil { c.Err = err return } else { @@ -369,7 +369,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) { // user is already in the team - if counts, err := app.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil { + if counts, err := c.App.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil { c.Err = model.NewAppError("getChannelCounts", "api.channel.get_channel_counts.app_error", nil, err.Message, http.StatusInternalServerError) return } else if HandleEtag(counts.Etag(), "Get Channel Counts", w, r) { @@ -389,9 +389,9 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError if channelId != "" { - channel, err = app.GetChannel(channelId) + channel, err = c.App.GetChannel(channelId) } else if channelName != "" { - channel, err = app.GetChannelByName(channelName, c.TeamId) + channel, err = c.App.GetChannelByName(channelName, c.TeamId) } else { c.SetInvalidParam("join", "channel_id, channel_name") return @@ -409,7 +409,7 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) { } } - if err = app.JoinChannel(channel, c.Session.UserId); err != nil { + if err = c.App.JoinChannel(channel, c.Session.UserId); err != nil { c.Err = err return } @@ -422,7 +422,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["channel_id"] - err := app.LeaveChannel(id, c.Session.UserId) + err := c.App.LeaveChannel(id, c.Session.UserId) if err != nil { c.Err = err return @@ -440,22 +440,22 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(id); err != nil { + if channel, err = c.App.GetChannel(id); err != nil { c.Err = err return } - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) { + if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) { c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL) return } - if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) { + if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) { c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL) return } - err = app.DeleteChannel(channel, c.Session.UserId) + err = c.App.DeleteChannel(channel, c.Session.UserId) if err != nil { c.Err = err return @@ -474,7 +474,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(id); err != nil { + if channel, err = c.App.GetChannel(id); err != nil { c.Err = err return } @@ -485,7 +485,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) { } var member *model.ChannelMember - if member, err = app.GetChannelMember(id, c.Session.UserId); err != nil { + if member, err = c.App.GetChannelMember(id, c.Session.UserId); err != nil { c.Err = err return } @@ -506,11 +506,11 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelName := params["channel_name"] - if channel, err := app.GetChannelByName(channelName, c.TeamId); err != nil { + if channel, err := c.App.GetChannelByName(channelName, c.TeamId); err != nil { c.Err = err return } else { - if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -535,7 +535,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(id); err != nil { + if channel, err = c.App.GetChannel(id); err != nil { c.Err = err return } @@ -545,12 +545,12 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if memberCount, err := app.GetChannelMemberCount(id); err != nil { + if memberCount, err := c.App.GetChannelMemberCount(id); err != nil { c.Err = err return } else { @@ -564,12 +564,12 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) { channelId := params["channel_id"] userId := params["user_id"] - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if member, err := app.GetChannelMember(channelId, userId); err != nil { + if member, err := c.App.GetChannelMember(channelId, userId); err != nil { c.Err = err return } else { @@ -578,7 +578,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) { } func getMyChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) { - if members, err := app.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil { + if members, err := c.App.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil { c.Err = err return } else { @@ -590,7 +590,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) channelId := params["channel_id"] - if result := <-app.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil { + if result := <-c.App.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil { c.Err = result.Err return } else { @@ -614,28 +614,28 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(id); err != nil { + if channel, err = c.App.GetChannel(id); err != nil { c.Err = err return } - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) { + if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) { c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) return } - if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { + if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) return } var nUser *model.User - if nUser, err = app.GetUser(userId); err != nil { + if nUser, err = c.App.GetUser(userId); err != nil { c.Err = model.NewAppError("addMember", "api.channel.add_member.find_user.app_error", nil, err.Error(), http.StatusBadRequest) return } - cm, err := app.AddUserToChannel(nUser, channel) + cm, err := c.App.AddUserToChannel(nUser, channel) if err != nil { c.Err = err return @@ -644,14 +644,14 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("name=" + channel.Name + " user_id=" + userId) var oUser *model.User - if oUser, err = app.GetUser(c.Session.UserId); err != nil { + if oUser, err = c.App.GetUser(c.Session.UserId); err != nil { c.Err = model.NewAppError("addMember", "api.channel.add_member.user_adding.app_error", nil, err.Error(), http.StatusInternalServerError) return } - go app.PostAddToChannelMessage(oUser, nUser, channel) + go c.App.PostAddToChannelMessage(oUser, nUser, channel) - app.UpdateChannelLastViewedAt([]string{id}, oUser.Id) + c.App.UpdateChannelLastViewedAt([]string{id}, oUser.Id) w.Write([]byte(cm.ToJson())) } @@ -669,22 +669,22 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var err *model.AppError - if channel, err = app.GetChannel(channelId); err != nil { + if channel, err = c.App.GetChannel(channelId); err != nil { c.Err = err return } - if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) { + if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) { c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) return } - if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { + if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) { c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) return } - if err = app.RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil { + if err = c.App.RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil { c.Err = err return } @@ -717,7 +717,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) { return } - member, err := app.UpdateChannelMemberNotifyProps(data, channelId, userId) + member, err := c.App.UpdateChannelMemberNotifyProps(data, channelId, userId) if err != nil { c.Err = err return @@ -745,7 +745,7 @@ func searchMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) { return } - if channels, err := app.SearchChannelsUserNotIn(c.TeamId, c.Session.UserId, props.Term); err != nil { + if channels, err := c.App.SearchChannelsUserNotIn(c.TeamId, c.Session.UserId, props.Term); err != nil { c.Err = err return } else { @@ -763,7 +763,7 @@ func autocompleteChannels(c *Context, w http.ResponseWriter, r *http.Request) { } } - if channels, err := app.SearchChannels(c.TeamId, term); err != nil { + if channels, err := c.App.SearchChannels(c.TeamId, term); err != nil { c.Err = err return } else { @@ -779,7 +779,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.ViewChannel(view, c.Session.UserId, !c.Session.IsMobileApp()); err != nil { + if err := c.App.ViewChannel(view, c.Session.UserId, !c.Session.IsMobileApp()); err != nil { c.Err = err return } @@ -797,12 +797,12 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if members, err := app.GetChannelMembersByIds(channelId, userIds); err != nil { + if members, err := c.App.GetChannelMembersByIds(channelId, userIds); err != nil { c.Err = err return } else { @@ -822,7 +822,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) { c.SetPermissionError(model.PERMISSION_MANAGE_CHANNEL_ROLES) return } @@ -833,7 +833,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request return } - if _, err := app.UpdateChannelMemberRoles(channelId, userId, newRoles); err != nil { + if _, err := c.App.UpdateChannelMemberRoles(channelId, userId, newRoles); err != nil { c.Err = err return } diff --git a/api/channel_test.go b/api/channel_test.go index c6fa23282..8a0ec7c62 100644 --- a/api/channel_test.go +++ b/api/channel_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" @@ -404,7 +403,7 @@ func TestUpdateChannel(t *testing.T) { } UpdateUserToTeamAdmin(th.BasicUser, team) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() if _, err := Client.UpdateChannel(channel2); err != nil { t.Fatal(err) } @@ -412,7 +411,7 @@ func TestUpdateChannel(t *testing.T) { t.Fatal(err) } UpdateUserToNonTeamAdmin(th.BasicUser, team) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() MakeUserChannelAdmin(th.BasicUser, channel2) MakeUserChannelAdmin(th.BasicUser, channel3) @@ -1188,7 +1187,7 @@ func TestJoinChannelByNameDisabledUser(t *testing.T) { Client.Must(th.BasicClient.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser.Id)) - if _, err := app.AddUserToChannel(th.BasicUser, channel1); err == nil { + if _, err := th.App.AddUserToChannel(th.BasicUser, channel1); err == nil { t.Fatal("shoudn't be able to join channel") } else { if err.Id != "api.channel.add_user.to.channel.failed.deleted.app_error" { @@ -1406,7 +1405,7 @@ func TestDeleteChannel(t *testing.T) { UpdateUserToTeamAdmin(th.BasicUser, team) Client.Login(th.BasicUser.Email, th.BasicUser.Password) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() if _, err := Client.DeleteChannel(channel2.Id); err != nil { t.Fatal(err) @@ -1416,7 +1415,7 @@ func TestDeleteChannel(t *testing.T) { } UpdateUserToNonTeamAdmin(th.BasicUser, team) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) @@ -1634,7 +1633,7 @@ func TestAddChannelMember(t *testing.T) { } MakeUserChannelAdmin(user1, channel5) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) utils.License().Features.SetDefaults() @@ -1659,7 +1658,7 @@ func TestAddChannelMember(t *testing.T) { } UpdateUserToTeamAdmin(user1, team) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) utils.License().Features.SetDefaults() @@ -1810,7 +1809,7 @@ func TestRemoveChannelMember(t *testing.T) { } MakeUserChannelAdmin(user1, channel5) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) utils.License().Features.SetDefaults() @@ -1835,7 +1834,7 @@ func TestRemoveChannelMember(t *testing.T) { } UpdateUserToTeamAdmin(user1, team) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) utils.License().Features.SetDefaults() @@ -2255,7 +2254,7 @@ func TestGetChannelByName(t *testing.T) { user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) Client.SetTeamId(th.BasicTeam.Id) @@ -2314,7 +2313,7 @@ func TestViewChannel(t *testing.T) { func TestGetChannelMembersByIds(t *testing.T) { th := Setup().InitBasic() - if _, err := app.AddUserToChannel(th.BasicUser2, th.BasicChannel); err != nil { + if _, err := th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel); err != nil { t.Fatal("Could not add second user to channel") } diff --git a/api/cli_test.go b/api/cli_test.go index 671d1af11..971cfb017 100644 --- a/api/cli_test.go +++ b/api/cli_test.go @@ -107,7 +107,7 @@ func TestCliCreateUserWithoutTeam(t *testing.T) { t.Fatal(err) } - if result := <-app.Srv.Store.User().GetByEmail(email); result.Err != nil { + if result := <-app.Global().Srv.Store.User().GetByEmail(email); result.Err != nil { t.Fatal() } else { user := result.Data.(*model.User) @@ -131,7 +131,7 @@ func TestCliAssignRole(t *testing.T) { t.Fatal(err) } - if result := <-app.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { + if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil { t.Fatal() } else { user := result.Data.(*model.User) @@ -369,7 +369,7 @@ func TestCliLeaveTeam(t *testing.T) { t.Fatal("profile should not be on team") } - if result := <-app.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { + if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil { teamMembers := result.Data.([]*model.TeamMember) if len(teamMembers) > 0 { t.Fatal("Shouldn't be in team") diff --git a/api/command.go b/api/command.go index aaaa790c0..429b58836 100644 --- a/api/command.go +++ b/api/command.go @@ -34,7 +34,7 @@ func InitCommand() { } func listCommands(c *Context, w http.ResponseWriter, r *http.Request) { - commands, err := app.ListAutocompleteCommands(c.TeamId, c.T) + commands, err := c.App.ListAutocompleteCommands(c.TeamId, c.T) if err != nil { c.Err = err return @@ -56,7 +56,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) { } if len(commandArgs.ChannelId) > 0 { - if !app.SessionHasPermissionToChannel(c.Session, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) { + if !c.App.SessionHasPermissionToChannel(c.Session, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) { c.SetPermissionError(model.PERMISSION_USE_SLASH_COMMANDS) return } @@ -68,7 +68,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) { commandArgs.Session = c.Session commandArgs.SiteURL = c.GetSiteURLHeader() - response, err := app.ExecuteCommand(commandArgs) + response, err := c.App.ExecuteCommand(commandArgs) if err != nil { c.Err = err return @@ -95,7 +95,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) { cmd.CreatorId = c.Session.UserId cmd.TeamId = c.TeamId - rcmd, err := app.CreateCommand(cmd) + rcmd, err := c.App.CreateCommand(cmd) if err != nil { c.Err = err return @@ -115,7 +115,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - oldCmd, err := app.GetCommand(cmd.Id) + oldCmd, err := c.App.GetCommand(cmd.Id) if err != nil { c.Err = err return @@ -138,7 +138,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) { return } - rcmd, err := app.UpdateCommand(oldCmd, cmd) + rcmd, err := c.App.UpdateCommand(oldCmd, cmd) if err != nil { c.Err = err return @@ -155,7 +155,7 @@ func listTeamCommands(c *Context, w http.ResponseWriter, r *http.Request) { return } - cmds, err := app.ListTeamCommands(c.TeamId) + cmds, err := c.App.ListTeamCommands(c.TeamId) if err != nil { c.Err = err return @@ -175,7 +175,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - cmd, err := app.GetCommand(id) + cmd, err := c.App.GetCommand(id) if err != nil { c.Err = err return @@ -198,7 +198,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) { return } - rcmd, err := app.RegenCommandToken(cmd) + rcmd, err := c.App.RegenCommandToken(cmd) if err != nil { c.Err = err return @@ -218,7 +218,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - cmd, err := app.GetCommand(id) + cmd, err := c.App.GetCommand(id) if err != nil { c.Err = err return @@ -241,7 +241,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) { return } - err = app.DeleteCommand(cmd.Id) + err = c.App.DeleteCommand(cmd.Id) if err != nil { c.Err = err return diff --git a/api/command_help_test.go b/api/command_help_test.go index 20fa8c830..8ce9dec6c 100644 --- a/api/command_help_test.go +++ b/api/command_help_test.go @@ -4,9 +4,10 @@ package api import ( + "testing" + "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" - "testing" ) func TestHelpCommand(t *testing.T) { diff --git a/api/command_msg_test.go b/api/command_msg_test.go index 2e2d927e3..d1b15b7e7 100644 --- a/api/command_msg_test.go +++ b/api/command_msg_test.go @@ -4,9 +4,10 @@ package api import ( - "github.com/mattermost/platform/model" "strings" "testing" + + "github.com/mattermost/platform/model" ) func TestMsgCommands(t *testing.T) { diff --git a/api/context.go b/api/context.go index fc08b39f2..2778e68a4 100644 --- a/api/context.go +++ b/api/context.go @@ -21,6 +21,7 @@ import ( ) type Context struct { + App *app.App Session model.Session RequestId string IpAddress string @@ -107,6 +108,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } c := &Context{} + c.App = app.Global() c.T, c.Locale = utils.GetTranslationsAndLocale(w, r) c.RequestId = model.NewId() c.IpAddress = utils.GetIpAddress(r) @@ -165,7 +167,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if len(token) != 0 { - session, err := app.GetSession(token) + session, err := app.Global().GetSession(token) if err != nil { l4g.Error(utils.T("api.context.invalid_session.error"), err.Error()) @@ -206,8 +208,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 { - app.SetStatusOnline(c.Session.UserId, c.Session.Id, false) - app.UpdateLastActivityAtIfNeeded(c.Session) + app.Global().SetStatusOnline(c.Session.UserId, c.Session.Id, false) + app.Global().UpdateLastActivityAtIfNeeded(c.Session) } if c.Err == nil && (h.requireUser || h.requireSystemAdmin) { @@ -258,7 +260,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (c *Context) LogAudit(extraInfo string) { audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id} - if r := <-app.Srv.Store.Audit().Save(audit); r.Err != nil { + if r := <-app.Global().Srv.Store.Audit().Save(audit); r.Err != nil { c.LogError(r.Err) } } @@ -270,7 +272,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) { } audit := &model.Audit{UserId: userId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id} - if r := <-app.Srv.Store.Audit().Save(audit); r.Err != nil { + if r := <-app.Global().Srv.Store.Audit().Save(audit); r.Err != nil { c.LogError(r.Err) } } @@ -314,7 +316,7 @@ func (c *Context) MfaRequired() { return } - if result := <-app.Srv.Store.User().Get(c.Session.UserId); result.Err != nil { + if result := <-app.Global().Srv.Store.User().Get(c.Session.UserId); result.Err != nil { c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "MfaRequired", http.StatusUnauthorized) return } else { @@ -391,7 +393,7 @@ func (c *Context) setTeamURL(url string, valid bool) { } func (c *Context) SetTeamURLFromSession() { - if result := <-app.Srv.Store.Team().Get(c.TeamId); result.Err == nil { + if result := <-app.Global().Srv.Store.Team().Get(c.TeamId); result.Err == nil { c.setTeamURL(c.GetSiteURLHeader()+"/"+result.Data.(*model.Team).Name, true) } } @@ -445,7 +447,7 @@ func Handle404(w http.ResponseWriter, r *http.Request) { func (c *Context) CheckTeamId() { if c.TeamId != "" && c.Session.GetTeamByTeamId(c.TeamId) == nil { if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) { - if result := <-app.Srv.Store.Team().Get(c.TeamId); result.Err != nil { + if result := <-app.Global().Srv.Store.Team().Get(c.TeamId); result.Err != nil { c.Err = result.Err c.Err.StatusCode = http.StatusBadRequest return diff --git a/api/emoji.go b/api/emoji.go index 96a59cd84..ebecef276 100644 --- a/api/emoji.go +++ b/api/emoji.go @@ -10,6 +10,8 @@ import ( "net/http" "strings" + "image/color/palette" + l4g "github.com/alecthomas/log4go" "github.com/disintegration/imaging" "github.com/gorilla/mux" @@ -17,7 +19,6 @@ import ( "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" - "image/color/palette" ) func InitEmoji() { @@ -35,7 +36,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - listEmoji, err := app.GetEmojiList(0, 100000) + listEmoji, err := c.App.GetEmojiList(0, 100000) if err != nil { c.Err = err return @@ -97,7 +98,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-app.Srv.Store.Emoji().GetByName(emoji.Name); result.Err == nil && result.Data != nil { + if result := <-c.App.Srv.Store.Emoji().GetByName(emoji.Name); result.Err == nil && result.Data != nil { c.Err = model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest) return } @@ -110,7 +111,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-app.Srv.Store.Emoji().Save(emoji); result.Err != nil { + if result := <-c.App.Srv.Store.Emoji().Save(emoji); result.Err != nil { c.Err = result.Err return } else { @@ -141,7 +142,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - emoji, err := app.GetEmoji(id) + emoji, err := c.App.GetEmoji(id) if err != nil { c.Err = err return @@ -152,7 +153,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) { return } - err = app.DeleteEmoji(emoji) + err = c.App.DeleteEmoji(emoji) if err != nil { c.Err = err return @@ -180,7 +181,7 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - image, imageType, err := app.GetEmojiImage(id) + image, imageType, err := c.App.GetEmojiImage(id) if err != nil { c.Err = err return diff --git a/api/emoji_test.go b/api/emoji_test.go index 4de5f41dd..ee3bc0bf9 100644 --- a/api/emoji_test.go +++ b/api/emoji_test.go @@ -42,11 +42,11 @@ func TestGetEmoji(t *testing.T) { } for i, emoji := range emojis { - emojis[i] = store.Must(app.Srv.Store.Emoji().Save(emoji)).(*model.Emoji) + emojis[i] = store.Must(th.App.Srv.Store.Emoji().Save(emoji)).(*model.Emoji) } defer func() { for _, emoji := range emojis { - store.Must(app.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix())) + store.Must(th.App.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix())) } }() @@ -74,7 +74,7 @@ func TestGetEmoji(t *testing.T) { Name: model.NewId(), DeleteAt: 1, } - deleted = store.Must(app.Srv.Store.Emoji().Save(deleted)).(*model.Emoji) + deleted = store.Must(th.App.Srv.Store.Emoji().Save(deleted)).(*model.Emoji) if returnedEmojis, err := Client.ListEmoji(); err != nil { t.Fatal(err) @@ -264,10 +264,10 @@ func TestDeleteEmoji(t *testing.T) { } func createTestEmoji(t *testing.T, emoji *model.Emoji, imageData []byte) *model.Emoji { - emoji = store.Must(app.Srv.Store.Emoji().Save(emoji)).(*model.Emoji) + emoji = store.Must(app.Global().Srv.Store.Emoji().Save(emoji)).(*model.Emoji) if err := utils.WriteFile(imageData, "emoji/"+emoji.Id+"/image"); err != nil { - store.Must(app.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix())) + store.Must(app.Global().Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix())) t.Fatalf("failed to write image: %v", err.Error()) } diff --git a/api/file.go b/api/file.go index c7ed15a33..6fd963799 100644 --- a/api/file.go +++ b/api/file.go @@ -74,12 +74,12 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_UPLOAD_FILE) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_UPLOAD_FILE) { c.SetPermissionError(model.PERMISSION_UPLOAD_FILE) return } - resStruct, err := app.UploadFiles(c.TeamId, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"]) + resStruct, err := c.App.UploadFiles(c.TeamId, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"]) if err != nil { c.Err = err return @@ -205,7 +205,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool) return nil, NewInvalidParamError("getFileInfoForRequest", "file_id") } - info, err := app.GetFileInfo(fileId) + info, err := c.App.GetFileInfo(fileId) if err != nil { return nil, err } @@ -218,7 +218,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool) } if requireFileVisible { - if !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return nil, c.Err } @@ -261,7 +261,7 @@ func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) { path := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/" + filename var info *model.FileInfo - if result := <-app.Srv.Store.FileInfo().GetByPath(path); result.Err != nil { + if result := <-c.App.Srv.Store.FileInfo().GetByPath(path); result.Err != nil { c.Err = result.Err return } else { diff --git a/api/file_test.go b/api/file_test.go index 0d64608c3..367a414fb 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -61,7 +61,7 @@ func TestUploadFile(t *testing.T) { } var info *model.FileInfo - if result := <-app.Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil { + if result := <-th.App.Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil { t.Fatal(result.Err) } else { info = result.Data.(*model.FileInfo) @@ -170,7 +170,7 @@ func TestGetFileInfo(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // Other user shouldn't be able to get file info for this file if they're not in the channel for it if _, err := Client.GetFileInfo(fileId); err == nil { @@ -186,7 +186,7 @@ func TestGetFileInfo(t *testing.T) { t.Fatal("other user got incorrect file") } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -239,7 +239,7 @@ func TestGetFile(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // Other user shouldn't be able to get file for this file if they're not in the channel for it if _, err := Client.GetFile(fileId); err == nil { @@ -268,7 +268,7 @@ func TestGetFile(t *testing.T) { body.Close() } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -308,7 +308,7 @@ func TestGetFileThumbnail(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // Other user shouldn't be able to get thumbnail for this file if they're not in the channel for it if _, err := Client.GetFileThumbnail(fileId); err == nil { @@ -324,7 +324,7 @@ func TestGetFileThumbnail(t *testing.T) { body.Close() } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -364,7 +364,7 @@ func TestGetFilePreview(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // Other user shouldn't be able to get preview for this file if they're not in the channel for it if _, err := Client.GetFilePreview(fileId); err == nil { @@ -380,7 +380,7 @@ func TestGetFilePreview(t *testing.T) { body.Close() } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -413,7 +413,7 @@ func TestGetPublicFile(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) link := Client.MustGeneric(Client.GetPublicLink(fileId)).(string) @@ -447,7 +447,7 @@ func TestGetPublicFile(t *testing.T) { t.Fatal("should've failed to get image with public link after salt changed") } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -483,12 +483,12 @@ func TestGetPublicFileOld(t *testing.T) { CreatorId: th.BasicUser.Id, Path: fmt.Sprintf("teams/%s/channels/%s/users/%s/%s/%s", th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId, "test.png"), } - store.Must(app.Srv.Store.FileInfo().Save(&fileInfo)) + store.Must(th.App.Srv.Store.FileInfo().Save(&fileInfo)) uploadFileOld(t, data, fmt.Sprintf("data/teams/%s/channels/%s/users/%s/%s", th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId), "test.png") } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) // reconstruct old style of link siteURL := *utils.Cfg.ServiceSettings.SiteURL @@ -526,7 +526,7 @@ func TestGetPublicFileOld(t *testing.T) { t.Fatal("should've failed to get image with public link after salt changed") } - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -565,7 +565,7 @@ func TestGetPublicLink(t *testing.T) { } // Hacky way to assign file to a post (usually would be done by CreatePost call) - store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) + store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id)) utils.Cfg.FileSettings.EnablePublicLink = false @@ -600,7 +600,7 @@ func TestGetPublicLink(t *testing.T) { // Wait a bit for files to ready time.Sleep(2 * time.Second) - if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { + if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil { t.Fatal(err) } } @@ -635,7 +635,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) { } // Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post - post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{ + post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{ UserId: user1.Id, ChannelId: channel1.Id, Message: "test", @@ -757,20 +757,20 @@ func TestFindTeamIdForFilename(t *testing.T) { } // Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post - post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{ + post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{ UserId: user1.Id, ChannelId: channel1.Id, Message: "test", Filenames: []string{fmt.Sprintf("/%s/%s/%s/%s", channel1.Id, user1.Id, fileId1, "test.png")}, })).(*model.Post) - if teamId := app.FindTeamIdForFilename(post1, post1.Filenames[0]); teamId != team1.Id { + if teamId := th.App.FindTeamIdForFilename(post1, post1.Filenames[0]); teamId != team1.Id { t.Log(teamId) t.Fatal("file should've been found under team1") } Client.SetTeamId(team2.Id) - post2 := store.Must(app.Srv.Store.Post().Save(&model.Post{ + post2 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{ UserId: user1.Id, ChannelId: channel2.Id, Message: "test", @@ -778,7 +778,7 @@ func TestFindTeamIdForFilename(t *testing.T) { })).(*model.Post) Client.SetTeamId(team1.Id) - if teamId := app.FindTeamIdForFilename(post2, post2.Filenames[0]); teamId != team2.Id { + if teamId := th.App.FindTeamIdForFilename(post2, post2.Filenames[0]); teamId != team2.Id { t.Fatal("file should've been found under team2") } } @@ -808,13 +808,13 @@ func TestGetInfoForFilename(t *testing.T) { } else { fileId1 = Client.MustGeneric(Client.UploadPostAttachment(data, channel1.Id, "test.png")).(*model.FileUploadResponse).FileInfos[0].Id uploadFileOld(t, data, fmt.Sprintf("data/teams/%s/channels/%s/users/%s/%s", team1.Id, channel1.Id, user1.Id, fileId1), "test.png") - path = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path - thumbnailPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath - previewPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath + path = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path + thumbnailPath = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath + previewPath = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath } // Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post - post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{ + post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{ UserId: user1.Id, ChannelId: channel1.Id, Message: "test", diff --git a/api/license.go b/api/license.go index 081fa7ed9..84ee076e6 100644 --- a/api/license.go +++ b/api/license.go @@ -55,7 +55,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { buf := bytes.NewBuffer(nil) io.Copy(buf, file) - if license, err := app.SaveLicense(buf.Bytes()); err != nil { + if license, err := c.App.SaveLicense(buf.Bytes()); err != nil { if err.Id == model.EXPIRED_LICENSE_ERROR { c.LogAudit("failed - expired or non-started license") } else if err.Id == model.INVALID_LICENSE_ERROR { @@ -74,7 +74,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("") - if err := app.RemoveLicense(); err != nil { + if err := c.App.RemoveLicense(); err != nil { c.Err = err return } diff --git a/api/license_test.go b/api/license_test.go index 15d3b9eef..a8f36a2c7 100644 --- a/api/license_test.go +++ b/api/license_test.go @@ -4,8 +4,9 @@ package api import ( - "github.com/mattermost/platform/utils" "testing" + + "github.com/mattermost/platform/utils" ) func TestGetLicenceConfig(t *testing.T) { diff --git a/api/oauth.go b/api/oauth.go index bd52d05ed..007ec09d9 100644 --- a/api/oauth.go +++ b/api/oauth.go @@ -47,7 +47,7 @@ func registerOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { oauthApp.CreatorId = c.Session.UserId - rapp, err := app.CreateOAuthApp(oauthApp) + rapp, err := c.App.CreateOAuthApp(oauthApp) if err != nil { c.Err = err @@ -67,9 +67,9 @@ func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) { var apps []*model.OAuthApp var err *model.AppError if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) { - apps, err = app.GetOAuthApps(0, 100000) + apps, err = c.App.GetOAuthApps(0, 100000) } else { - apps, err = app.GetOAuthAppsByCreator(c.Session.UserId, 0, 100000) + apps, err = c.App.GetOAuthAppsByCreator(c.Session.UserId, 0, 100000) } if err != nil { @@ -84,7 +84,7 @@ func getOAuthAppInfo(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) clientId := params["client_id"] - oauthApp, err := app.GetOAuthApp(clientId) + oauthApp, err := c.App.GetOAuthApp(clientId) if err != nil { c.Err = err @@ -127,7 +127,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) { State: state, } - redirectUrl, err := app.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest) + redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest) if err != nil { c.Err = err @@ -140,7 +140,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) { } func getAuthorizedApps(c *Context, w http.ResponseWriter, r *http.Request) { - apps, err := app.GetAuthorizedAppsForUser(c.Session.UserId, 0, 10000) + apps, err := c.App.GetAuthorizedAppsForUser(c.Session.UserId, 0, 10000) if err != nil { c.Err = err return @@ -155,13 +155,13 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) { loginHint := r.URL.Query().Get("login_hint") redirectTo := r.URL.Query().Get("redirect_to") - teamId, err := app.GetTeamIdFromQuery(r.URL.Query()) + teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query()) if err != nil { c.Err = err return } - if authUrl, err := app.GetOAuthLoginEndpoint(w, r, service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil { + if authUrl, err := c.App.GetOAuthLoginEndpoint(w, r, service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil { c.Err = err return } else { @@ -178,13 +178,13 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) { return } - teamId, err := app.GetTeamIdFromQuery(r.URL.Query()) + teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query()) if err != nil { c.Err = err return } - if authUrl, err := app.GetOAuthSignupEndpoint(w, r, service, teamId); err != nil { + if authUrl, err := c.App.GetOAuthSignupEndpoint(w, r, service, teamId); err != nil { c.Err = err return } else { @@ -208,7 +208,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { return } - oauthApp, err := app.GetOAuthApp(id) + oauthApp, err := c.App.GetOAuthApp(id) if err != nil { c.Err = err return @@ -220,7 +220,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { return } - err = app.DeleteOAuthApp(id) + err = c.App.DeleteOAuthApp(id) if err != nil { c.Err = err return @@ -234,7 +234,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["id"] - err := app.DeauthorizeOAuthAppForUser(c.Session.UserId, id) + err := c.App.DeauthorizeOAuthAppForUser(c.Session.UserId, id) if err != nil { c.Err = err return @@ -248,7 +248,7 @@ func regenerateOAuthSecret(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["id"] - oauthApp, err := app.GetOAuthApp(id) + oauthApp, err := c.App.GetOAuthApp(id) if err != nil { c.Err = err return @@ -259,7 +259,7 @@ func regenerateOAuthSecret(c *Context, w http.ResponseWriter, r *http.Request) { return } - oauthApp, err = app.RegenerateOAuthAppSecret(oauthApp) + oauthApp, err = c.App.RegenerateOAuthAppSecret(oauthApp) if err != nil { c.Err = err return diff --git a/api/oauth_test.go b/api/oauth_test.go index 612563622..ffabf9414 100644 --- a/api/oauth_test.go +++ b/api/oauth_test.go @@ -12,7 +12,6 @@ import ( "strings" "testing" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" @@ -77,7 +76,7 @@ func TestOAuthRegisterApp(t *testing.T) { user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true} ruser := Client.Must(Client.CreateUser(user, "")).Data.(*model.User) - app.UpdateUserRoles(ruser.Id, "") + th.App.UpdateUserRoles(ruser.Id, "") Client.Logout() Client.Login(user.Email, user.Password) @@ -252,7 +251,7 @@ func TestOAuthGetAppsByUser(t *testing.T) { user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true} ruser := Client.Must(AdminClient.CreateUser(user, "")).Data.(*model.User) - app.UpdateUserRoles(ruser.Id, "") + th.App.UpdateUserRoles(ruser.Id, "") Client.Logout() Client.Login(user.Email, user.Password) @@ -357,7 +356,7 @@ func TestOAuthDeauthorizeApp(t *testing.T) { a1.RefreshToken = model.NewId() a1.ExpiresAt = model.GetMillis() a1.RedirectUri = "http://example.com" - <-app.Srv.Store.OAuth().SaveAccessData(&a1) + <-th.App.Srv.Store.OAuth().SaveAccessData(&a1) if err := Client.OAuthDeauthorizeApp(oauthApp.Id); err != nil { t.Fatal(err) @@ -465,7 +464,7 @@ func TestOAuthDeleteApp(t *testing.T) { user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true} ruser := Client.Must(AdminClient.CreateUser(user, "")).Data.(*model.User) - app.UpdateUserRoles(ruser.Id, "") + th.App.UpdateUserRoles(ruser.Id, "") Client.Logout() Client.Login(user.Email, user.Password) @@ -707,7 +706,7 @@ func TestOAuthAccessToken(t *testing.T) { } authData := &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: -1} - <-app.Srv.Store.OAuth().SaveAuthData(authData) + <-th.App.Srv.Store.OAuth().SaveAuthData(authData) data.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE) data.Set("client_id", oauthApp.Id) @@ -720,7 +719,7 @@ func TestOAuthAccessToken(t *testing.T) { } authData = &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: model.AUTHCODE_EXPIRE_TIME} - <-app.Srv.Store.OAuth().SaveAuthData(authData) + <-th.App.Srv.Store.OAuth().SaveAuthData(authData) data.Set("code", authData.Code) if _, err := Client.GetAccessToken(data); err == nil { @@ -819,7 +818,7 @@ func TestOAuthComplete(t *testing.T) { closeBody(r) } - if result := <-app.Srv.Store.User().UpdateAuthData( + if result := <-th.App.Srv.Store.User().UpdateAuthData( th.BasicUser.Id, model.SERVICE_GITLAB, &th.BasicUser.Email, th.BasicUser.Email, true); result.Err != nil { t.Fatal(result.Err) } diff --git a/api/post.go b/api/post.go index 89f85160f..0b5a5c612 100644 --- a/api/post.go +++ b/api/post.go @@ -52,9 +52,9 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { post.UserId = c.Session.UserId hasPermission := false - if app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) { + if c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) { hasPermission = true - } else if channel, err := app.GetChannel(post.ChannelId); err == nil { + } else if channel, err := c.App.GetChannel(post.ChannelId); err == nil { // Temporary permission check method until advanced permissions, please do not copy if channel.Type == model.CHANNEL_OPEN && app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_POST_PUBLIC) { hasPermission = true @@ -70,7 +70,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) { post.CreateAt = 0 } - rp, err := app.CreatePostAsUser(post) + rp, err := c.App.CreatePostAsUser(post) if err != nil { c.Err = err return @@ -87,14 +87,14 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_EDIT_POST) { + if !c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_EDIT_POST) { c.SetPermissionError(model.PERMISSION_EDIT_POST) return } post.UserId = c.Session.UserId - rpost, err := app.UpdatePost(post, true) + rpost, err := c.App.UpdatePost(post, true) if err != nil { c.Err = err return @@ -118,7 +118,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn return } - pchan := app.Srv.Store.Post().Get(postId) + pchan := c.App.Srv.Store.Post().Get(postId) var oldPost *model.Post if result := <-pchan; result.Err != nil { @@ -130,7 +130,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn *newPost = *oldPost newPost.IsPinned = isPinned - if result := <-app.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil { + if result := <-c.App.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil { c.Err = result.Err return } else { @@ -141,7 +141,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn go app.Publish(message) - app.InvalidateCacheForChannelPosts(rpost.ChannelId) + c.App.InvalidateCacheForChannelPosts(rpost.ChannelId) w.Write([]byte(rpost.ToJson())) } @@ -176,7 +176,7 @@ func getFlaggedPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } - if posts, err := app.GetFlaggedPostsForTeam(c.Session.UserId, c.TeamId, offset, limit); err != nil { + if posts, err := c.App.GetFlaggedPostsForTeam(c.Session.UserId, c.TeamId, offset, limit); err != nil { c.Err = err return } else { @@ -205,18 +205,18 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_CREATE_POST) { + if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_CREATE_POST) { c.SetPermissionError(model.PERMISSION_CREATE_POST) return } - etag := app.GetPostsEtag(id) + etag := c.App.GetPostsEtag(id) if HandleEtag(etag, "Get Posts", w, r) { return } - if list, err := app.GetPosts(id, offset, limit); err != nil { + if list, err := c.App.GetPosts(id, offset, limit); err != nil { c.Err = err return } else { @@ -241,12 +241,12 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if list, err := app.GetPostsSince(id, time); err != nil { + if list, err := c.App.GetPostsSince(id, time); err != nil { c.Err = err return } else { @@ -270,12 +270,12 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if list, err := app.GetPostThread(postId); err != nil { + if list, err := c.App.GetPostThread(postId); err != nil { c.Err = err return } else if HandleEtag(list.Etag(), "Get Post", w, r) { @@ -300,7 +300,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) { return } - if list, err := app.GetPostThread(postId); err != nil { + if list, err := c.App.GetPostThread(postId); err != nil { c.Err = err return } else { @@ -310,7 +310,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) { } post := list.Posts[list.Order[0]] - if !app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -334,7 +334,7 @@ func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) { } var channel *model.Channel - if result := <-app.Srv.Store.Channel().GetForPost(postId); result.Err == nil { + if result := <-c.App.Srv.Store.Channel().GetForPost(postId); result.Err == nil { channel = result.Data.(*model.Channel) } else { c.SetInvalidParam("getPermalinkTmp", "postId") @@ -342,18 +342,18 @@ func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) { } if channel.Type == model.CHANNEL_OPEN { - if !app.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { + if !c.App.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) { c.SetPermissionError(model.PERMISSION_JOIN_PUBLIC_CHANNELS) return } } else { - if !app.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_READ_CHANNEL) { + if !c.App.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } } - if list, err := app.GetPermalinkPost(postId, c.Session.UserId); err != nil { + if list, err := c.App.GetPermalinkPost(postId, c.Session.UserId); err != nil { c.Err = err return } else if HandleEtag(list.Etag(), "Get Permalink TMP", w, r) { @@ -379,17 +379,17 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_DELETE_POST) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_DELETE_POST) { c.SetPermissionError(model.PERMISSION_DELETE_POST) return } - if !app.SessionHasPermissionToPost(c.Session, postId, model.PERMISSION_DELETE_OTHERS_POSTS) { + if !c.App.SessionHasPermissionToPost(c.Session, postId, model.PERMISSION_DELETE_OTHERS_POSTS) { c.SetPermissionError(model.PERMISSION_DELETE_OTHERS_POSTS) return } - if post, err := app.DeletePost(postId); err != nil { + if post, err := c.App.DeletePost(postId); err != nil { c.Err = err return } else { @@ -439,19 +439,19 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b return } - if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } // We can do better than this etag in this situation - etag := app.GetPostsEtag(id) + etag := c.App.GetPostsEtag(id) if HandleEtag(etag, "Get Posts Before or After", w, r) { return } - if list, err := app.GetPostsAroundPost(postId, id, offset, numPosts, before); err != nil { + if list, err := c.App.GetPostsAroundPost(postId, id, offset, numPosts, before); err != nil { c.Err = err return } else { @@ -474,7 +474,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { isOrSearch = val.(bool) } - posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch) + posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch) if err != nil { c.Err = err return @@ -499,12 +499,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if infos, err := app.GetFileInfosForPost(postId, false); err != nil { + if infos, err := c.App.GetFileInfosForPost(postId, false); err != nil { c.Err = err return } else if HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) { diff --git a/api/post_test.go b/api/post_test.go index 18bf22f5c..23c7fa371 100644 --- a/api/post_test.go +++ b/api/post_test.go @@ -142,7 +142,7 @@ func TestCreatePost(t *testing.T) { } else if rpost9 := resp.Data.(*model.Post); len(rpost9.FileIds) != 3 { t.Fatal("post should have 3 files") } else { - infos := store.Must(app.Srv.Store.FileInfo().GetForPost(rpost9.Id, true, true)).([]*model.FileInfo) + infos := store.Must(adm.App.Srv.Store.FileInfo().GetForPost(rpost9.Id, true, true)).([]*model.FileInfo) if len(infos) != 3 { t.Fatal("should've attached all 3 files to post") @@ -164,7 +164,7 @@ func TestCreatePost(t *testing.T) { utils.SetLicense(&model.License{Features: &model.Features{}}) utils.License().Features.SetDefaults() - defaultChannel := store.Must(app.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel) + defaultChannel := store.Must(adm.App.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel) defaultPost := &model.Post{ ChannelId: defaultChannel.Id, Message: "Default Channel Post", @@ -173,7 +173,7 @@ func TestCreatePost(t *testing.T) { t.Fatal("should have failed -- ExperimentalTownSquareIsReadOnly is true and it's a read only channel") } - adminDefaultChannel := store.Must(app.Srv.Store.Channel().GetByName(adminTeam.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel) + adminDefaultChannel := store.Must(adm.App.Srv.Store.Channel().GetByName(adminTeam.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel) adminDefaultPost := &model.Post{ ChannelId: adminDefaultChannel.Id, Message: "Admin Default Channel Post", @@ -1085,7 +1085,7 @@ func TestEmailMention(t *testing.T) { data["comments"] = "any" Client.Must(Client.UpdateUserNotify(data)) - store.Must(app.Srv.Store.Preference().Save(&model.Preferences{{ + store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{ UserId: th.BasicUser2.Id, Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS, Name: model.PREFERENCE_NAME_EMAIL_INTERVAL, @@ -1189,28 +1189,28 @@ func TestGetFlaggedPosts(t *testing.T) { func TestGetMessageForNotification(t *testing.T) { Setup().InitBasic() - testPng := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{ + testPng := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{ CreatorId: model.NewId(), Path: "test1.png", Name: "test1.png", MimeType: "image/png", })).(*model.FileInfo) - testJpg1 := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{ + testJpg1 := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{ CreatorId: model.NewId(), Path: "test2.jpg", Name: "test2.jpg", MimeType: "image/jpeg", })).(*model.FileInfo) - testFile := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{ + testFile := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{ CreatorId: model.NewId(), Path: "test1.go", Name: "test1.go", MimeType: "text/plain", })).(*model.FileInfo) - testJpg2 := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{ + testJpg2 := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{ CreatorId: model.NewId(), Path: "test3.jpg", Name: "test3.jpg", @@ -1224,39 +1224,39 @@ func TestGetMessageForNotification(t *testing.T) { Message: "test", } - if app.GetMessageForNotification(post, translateFunc) != "test" { + if app.Global().GetMessageForNotification(post, translateFunc) != "test" { t.Fatal("should've returned message text") } post.FileIds = model.StringArray{testPng.Id} - store.Must(app.Srv.Store.FileInfo().AttachToPost(testPng.Id, post.Id)) - if app.GetMessageForNotification(post, translateFunc) != "test" { + store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testPng.Id, post.Id)) + if app.Global().GetMessageForNotification(post, translateFunc) != "test" { t.Fatal("should've returned message text, even with attachments") } post.Message = "" - if message := app.GetMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" { + if message := app.Global().GetMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" { t.Fatal("should've returned number of images:", message) } post.FileIds = model.StringArray{testPng.Id, testJpg1.Id} - store.Must(app.Srv.Store.FileInfo().AttachToPost(testJpg1.Id, post.Id)) - app.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id) - if message := app.GetMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" && message != "2 images sent: test2.jpg, test1.png" { + store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testJpg1.Id, post.Id)) + app.Global().Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id) + if message := app.Global().GetMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" && message != "2 images sent: test2.jpg, test1.png" { t.Fatal("should've returned number of images:", message) } post.Id = model.NewId() post.FileIds = model.StringArray{testFile.Id} - store.Must(app.Srv.Store.FileInfo().AttachToPost(testFile.Id, post.Id)) - if message := app.GetMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" { + store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testFile.Id, post.Id)) + if message := app.Global().GetMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" { t.Fatal("should've returned number of files:", message) } - store.Must(app.Srv.Store.FileInfo().AttachToPost(testJpg2.Id, post.Id)) - app.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id) + store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testJpg2.Id, post.Id)) + app.Global().Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id) post.FileIds = model.StringArray{testFile.Id, testJpg2.Id} - if message := app.GetMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test3.jpg" && message != "2 files sent: test3.jpg, test1.go" { + if message := app.Global().GetMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test3.jpg" && message != "2 files sent: test3.jpg, test1.go" { t.Fatal("should've returned number of mixed files:", message) } } diff --git a/api/preference.go b/api/preference.go index de8adf049..b8bdc6f94 100644 --- a/api/preference.go +++ b/api/preference.go @@ -4,12 +4,12 @@ package api import ( + "net/http" + l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" - "net/http" ) func InitPreference() { @@ -23,7 +23,7 @@ func InitPreference() { } func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) { - if result := <-app.Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil { + if result := <-c.App.Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil { c.Err = result.Err } else { data := result.Data.(model.Preferences) @@ -39,7 +39,7 @@ func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.UpdatePreferences(c.Session.UserId, preferences); err != nil { + if err := c.App.UpdatePreferences(c.Session.UserId, preferences); err != nil { c.Err = err return } @@ -51,7 +51,7 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) category := params["category"] - if result := <-app.Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil { + if result := <-c.App.Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil { c.Err = result.Err } else { data := result.Data.(model.Preferences) @@ -65,7 +65,7 @@ func getPreference(c *Context, w http.ResponseWriter, r *http.Request) { category := params["category"] name := params["name"] - if result := <-app.Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil { + if result := <-c.App.Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil { c.Err = result.Err } else { data := result.Data.(model.Preference) @@ -80,7 +80,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.DeletePreferences(c.Session.UserId, preferences); err != nil { + if err := c.App.DeletePreferences(c.Session.UserId, preferences); err != nil { c.Err = err return } diff --git a/api/preference_test.go b/api/preference_test.go index 8388138c1..bff6e4501 100644 --- a/api/preference_test.go +++ b/api/preference_test.go @@ -4,8 +4,9 @@ package api import ( - "github.com/mattermost/platform/model" "testing" + + "github.com/mattermost/platform/model" ) func TestGetAllPreferences(t *testing.T) { diff --git a/api/reaction.go b/api/reaction.go index df095b8b2..e3e207e2a 100644 --- a/api/reaction.go +++ b/api/reaction.go @@ -41,7 +41,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -54,7 +54,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) { var post *model.Post - if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil { + if result := <-c.App.Srv.Store.Post().Get(reaction.PostId); result.Err != nil { c.Err = result.Err return } else if post = result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId { @@ -63,7 +63,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - if reaction, err := app.SaveReactionForPost(reaction); err != nil { + if reaction, err := c.App.SaveReactionForPost(reaction); err != nil { c.Err = err return } else { @@ -92,7 +92,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -103,7 +103,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := app.DeleteReactionForPost(reaction) + err := c.App.DeleteReactionForPost(reaction) if err != nil { c.Err = err return @@ -120,7 +120,7 @@ func sendReactionEvent(event string, channelId string, reaction *model.Reaction, app.Publish(message) // THe post is always modified since the UpdateAt always changes - app.InvalidateCacheForChannelPosts(post.ChannelId) + app.Global().InvalidateCacheForChannelPosts(post.ChannelId) post.HasReactions = true post.UpdateAt = model.GetMillis() umessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil) @@ -144,9 +144,9 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) { return } - pchan := app.Srv.Store.Post().Get(postId) + pchan := c.App.Srv.Store.Post().Get(postId) - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -160,7 +160,7 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-app.Srv.Store.Reaction().GetForPost(postId, true); result.Err != nil { + if result := <-c.App.Srv.Store.Reaction().GetForPost(postId, true); result.Err != nil { c.Err = result.Err return } else { diff --git a/api/status.go b/api/status.go index b945d7e90..77454389e 100644 --- a/api/status.go +++ b/api/status.go @@ -33,7 +33,7 @@ func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) { return } - statusMap, err := app.GetStatusesByIds(userIds) + statusMap, err := c.App.GetStatusesByIds(userIds) if err != nil { c.Err = err return diff --git a/api/status_test.go b/api/status_test.go index ba276da06..1f936d286 100644 --- a/api/status_test.go +++ b/api/status_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" @@ -35,12 +34,12 @@ func TestStatuses(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) LinkUserToTeam(ruser, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id)) user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User) LinkUserToTeam(ruser2, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Id)) Client.Login(user.Email, user.Password) Client.SetTeamId(team.Id) @@ -138,7 +137,7 @@ func TestStatuses(t *testing.T) { WebSocketClient2.Close() - app.SetStatusAwayIfNeeded(th.BasicUser.Id, false) + th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, false) awayTimeout := *utils.Cfg.TeamSettings.UserStatusAwayTimeout defer func() { @@ -148,8 +147,8 @@ func TestStatuses(t *testing.T) { time.Sleep(1500 * time.Millisecond) - app.SetStatusAwayIfNeeded(th.BasicUser.Id, false) - app.SetStatusOnline(th.BasicUser.Id, "junk", false) + th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, false) + th.App.SetStatusOnline(th.BasicUser.Id, "junk", false) time.Sleep(1500 * time.Millisecond) diff --git a/api/team.go b/api/team.go index ec9a41993..31b38688e 100644 --- a/api/team.go +++ b/api/team.go @@ -61,7 +61,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - rteam, err := app.CreateTeamWithUser(team, c.Session.UserId) + rteam, err := c.App.CreateTeamWithUser(team, c.Session.UserId) if err != nil { c.Err = err return @@ -74,7 +74,7 @@ func GetAllTeamListings(c *Context, w http.ResponseWriter, r *http.Request) { var teams []*model.Team var err *model.AppError - if teams, err = app.GetAllOpenTeams(); err != nil { + if teams, err = c.App.GetAllOpenTeams(); err != nil { c.Err = err return } @@ -96,10 +96,10 @@ func getAll(c *Context, w http.ResponseWriter, r *http.Request) { var teams []*model.Team var err *model.AppError - if app.HasPermissionTo(c.Session.UserId, model.PERMISSION_MANAGE_SYSTEM) { - teams, err = app.GetAllTeams() + if c.App.HasPermissionTo(c.Session.UserId, model.PERMISSION_MANAGE_SYSTEM) { + teams, err = c.App.GetAllTeams() } else { - teams, err = app.GetTeamsForUser(c.Session.UserId) + teams, err = c.App.GetTeamsForUser(c.Session.UserId) } if err != nil { @@ -130,7 +130,7 @@ func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.InviteNewUsersToTeam(invites.ToEmailList(), c.TeamId, c.Session.UserId); err != nil { + if err := c.App.InviteNewUsersToTeam(invites.ToEmailList(), c.TeamId, c.Session.UserId); err != nil { c.Err = err return } @@ -152,7 +152,7 @@ func addUserToTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if _, err := app.AddUserToTeam(c.TeamId, userId, ""); err != nil { + if _, err := c.App.AddUserToTeam(c.TeamId, userId, ""); err != nil { c.Err = err return } @@ -176,7 +176,7 @@ func removeUserFromTeam(c *Context, w http.ResponseWriter, r *http.Request) { } } - if err := app.RemoveUserFromTeam(c.TeamId, userId); err != nil { + if err := c.App.RemoveUserFromTeam(c.TeamId, userId); err != nil { c.Err = err return } @@ -194,9 +194,9 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request) var err *model.AppError if len(hash) > 0 { - team, err = app.AddUserToTeamByHash(c.Session.UserId, hash, data) + team, err = c.App.AddUserToTeamByHash(c.Session.UserId, hash, data) } else if len(inviteId) > 0 { - team, err = app.AddUserToTeamByInviteId(inviteId, c.Session.UserId) + team, err = c.App.AddUserToTeamByInviteId(inviteId, c.Session.UserId) } else { c.Err = model.NewAppError("addUserToTeamFromInvite", "api.user.create_user.signup_link_invalid.app_error", nil, "", http.StatusBadRequest) return @@ -217,7 +217,7 @@ func findTeamByName(c *Context, w http.ResponseWriter, r *http.Request) { m := model.MapFromJson(r.Body) name := strings.ToLower(strings.TrimSpace(m["name"])) - found := app.FindTeamByName(name) + found := c.App.FindTeamByName(name) if found { w.Write([]byte("true")) @@ -230,7 +230,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) teamname := params["team_name"] - if team, err := app.GetTeamByName(teamname); err != nil { + if team, err := c.App.GetTeamByName(teamname); err != nil { c.Err = err return } else { @@ -250,7 +250,7 @@ func getMyTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) { if len(c.Session.TeamMembers) > 0 { w.Write([]byte(model.TeamMembersToJson(c.Session.TeamMembers))) } else { - if members, err := app.GetTeamMembersForUser(c.Session.UserId); err != nil { + if members, err := c.App.GetTeamMembersForUser(c.Session.UserId); err != nil { c.Err = err return } else { @@ -262,7 +262,7 @@ func getMyTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) { func getMyTeamsUnread(c *Context, w http.ResponseWriter, r *http.Request) { teamId := r.URL.Query().Get("id") - if unreads, err := app.GetTeamsUnreadForUser(teamId, c.Session.UserId); err != nil { + if unreads, err := c.App.GetTeamsUnreadForUser(teamId, c.Session.UserId); err != nil { c.Err = err return } else { @@ -288,7 +288,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) { var err *model.AppError var updatedTeam *model.Team - updatedTeam, err = app.UpdateTeam(team) + updatedTeam, err = c.App.UpdateTeam(team) if err != nil { c.Err = err return @@ -319,7 +319,7 @@ func updateMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) { return } - if _, err := app.UpdateTeamMemberRoles(teamId, userId, newRoles); err != nil { + if _, err := c.App.UpdateTeamMemberRoles(teamId, userId, newRoles); err != nil { c.Err = err return } @@ -335,7 +335,7 @@ func getMyTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - if team, err := app.GetTeam(c.TeamId); err != nil { + if team, err := c.App.GetTeam(c.TeamId); err != nil { c.Err = err return } else if HandleEtag(team.Etag(), "Get My Team", w, r) { @@ -355,7 +355,7 @@ func getTeamStats(c *Context, w http.ResponseWriter, r *http.Request) { } } - stats, err := app.GetTeamStats(c.TeamId) + stats, err := c.App.GetTeamStats(c.TeamId) if err != nil { c.Err = err return @@ -414,7 +414,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) { switch importFrom { case "slack": var err *model.AppError - if err, log = app.SlackImport(fileData, fileSize, c.TeamId); err != nil { + if err, log = c.App.SlackImport(fileData, fileSize, c.TeamId); err != nil { c.Err = err c.Err.StatusCode = http.StatusBadRequest } @@ -433,7 +433,7 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) { m := model.MapFromJson(r.Body) inviteId := m["invite_id"] - if team, err := app.GetTeamByInviteId(inviteId); err != nil { + if team, err := c.App.GetTeamByInviteId(inviteId); err != nil { c.Err = err return } else { @@ -473,7 +473,7 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) { } } - if members, err := app.GetTeamMembers(c.TeamId, offset, limit); err != nil { + if members, err := c.App.GetTeamMembers(c.TeamId, offset, limit); err != nil { c.Err = err return } else { @@ -498,7 +498,7 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) { } } - if member, err := app.GetTeamMember(c.TeamId, userId); err != nil { + if member, err := c.App.GetTeamMember(c.TeamId, userId); err != nil { c.Err = err return } else { @@ -521,7 +521,7 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) { } } - if members, err := app.GetTeamMembersByIds(c.TeamId, userIds); err != nil { + if members, err := c.App.GetTeamMembersByIds(c.TeamId, userIds); err != nil { c.Err = err return } else { diff --git a/api/team_test.go b/api/team_test.go index 99e54a904..58b471f72 100644 --- a/api/team_test.go +++ b/api/team_test.go @@ -6,7 +6,6 @@ package api import ( "testing" - "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" @@ -25,7 +24,7 @@ func TestCreateTeam(t *testing.T) { user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(rteam.Data.(*model.Team).Id) @@ -128,7 +127,7 @@ func TestAddUserToTeam(t *testing.T) { // Should work as team admin. UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam) - app.InvalidateAllCaches() + th.App.InvalidateAllCaches() *utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN utils.SetIsLicensed(true) utils.SetLicense(&model.License{Features: &model.Features{}}) @@ -219,7 +218,7 @@ func TestGetAllTeams(t *testing.T) { user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -258,7 +257,7 @@ func TestGetAllTeamListings(t *testing.T) { user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -275,7 +274,7 @@ func TestGetAllTeamListings(t *testing.T) { } } - app.UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id) + th.App.UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -305,7 +304,7 @@ func TestTeamPermDelete(t *testing.T) { user1 := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) LinkUserToTeam(user1, team) - store.Must(app.Srv.Store.User().VerifyEmail(user1.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user1.Id)) Client.Login(user1.Email, "passwd1") Client.SetTeamId(team.Id) @@ -329,7 +328,7 @@ func TestTeamPermDelete(t *testing.T) { c.RequestId = model.NewId() c.IpAddress = "test" - err := app.PermanentDeleteTeam(team) + err := th.App.PermanentDeleteTeam(team) if err != nil { t.Fatal(err) } @@ -350,7 +349,7 @@ func TestInviteMembers(t *testing.T) { user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -437,7 +436,7 @@ func TestUpdateTeamDisplayName(t *testing.T) { user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) Client.Login(user2.Email, "passwd1") Client.SetTeamId(team.Id) @@ -498,7 +497,7 @@ func TestGetMyTeam(t *testing.T) { user := model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.Login(user.Email, user.Password) Client.SetTeamId(team.Id) @@ -743,7 +742,7 @@ func TestGetTeamStats(t *testing.T) { user := model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.Login(user.Email, user.Password) @@ -764,7 +763,7 @@ func TestUpdateTeamDescription(t *testing.T) { user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) Client.Login(user2.Email, "passwd1") Client.SetTeamId(team.Id) @@ -817,7 +816,7 @@ func TestGetTeamByName(t *testing.T) { user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) Client.Login(user2.Email, "passwd1") diff --git a/api/user.go b/api/user.go index 551b751c1..8815f698f 100644 --- a/api/user.go +++ b/api/user.go @@ -85,11 +85,11 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) { var ruser *model.User var err *model.AppError if len(hash) > 0 { - ruser, err = app.CreateUserWithHash(user, hash, r.URL.Query().Get("d")) + ruser, err = c.App.CreateUserWithHash(user, hash, r.URL.Query().Get("d")) } else if len(inviteId) > 0 { - ruser, err = app.CreateUserWithInviteId(user, inviteId) + ruser, err = c.App.CreateUserWithInviteId(user, inviteId) } else { - ruser, err = app.CreateUserFromSignup(user) + ruser, err = c.App.CreateUserFromSignup(user) } if err != nil { @@ -111,7 +111,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) { ldapOnly := props["ldap_only"] == "true" c.LogAudit("attempt - user_id=" + id + " login_id=" + loginId) - user, err := app.AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId, ldapOnly) + user, err := c.App.AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId, ldapOnly) if err != nil { c.LogAudit("failure - user_id=" + id + " login_id=" + loginId) c.Err = err @@ -132,7 +132,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) { // User MUST be authenticated completely before calling Login func doLogin(c *Context, w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) { - session, err := app.DoLogin(w, r, user, deviceId) + session, err := c.App.DoLogin(w, r, user, deviceId) if err != nil { c.Err = err return @@ -145,7 +145,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) { props := model.MapFromJson(r.Body) id := props["id"] - if err := app.RevokeSessionById(id); err != nil { + if err := c.App.RevokeSessionById(id); err != nil { c.Err = err return } @@ -163,7 +163,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) { } // A special case where we logout of all other sessions with the same device id - if err := app.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil { + if err := c.App.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil { c.Err = err c.Err.StatusCode = http.StatusInternalServerError return @@ -192,7 +192,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) { http.SetCookie(w, sessionCookie) - if err := app.AttachDeviceId(c.Session.Id, deviceId, c.Session.ExpiresAt); err != nil { + if err := c.App.AttachDeviceId(c.Session.Id, deviceId, c.Session.ExpiresAt); err != nil { c.Err = err return } @@ -210,7 +210,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) { return } - if sessions, err := app.GetSessions(id); err != nil { + if sessions, err := c.App.GetSessions(id); err != nil { c.Err = err return } else { @@ -236,7 +236,7 @@ func Logout(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("") c.RemoveSessionCookie(w, r) if c.Session.Id != "" { - if err := app.RevokeSessionById(c.Session.Id); err != nil { + if err := c.App.RevokeSessionById(c.Session.Id); err != nil { c.Err = err return } @@ -245,7 +245,7 @@ func Logout(c *Context, w http.ResponseWriter, r *http.Request) { func getMe(c *Context, w http.ResponseWriter, r *http.Request) { - if user, err := app.GetUser(c.Session.UserId); err != nil { + if user, err := c.App.GetUser(c.Session.UserId); err != nil { c.Err = err c.RemoveSessionCookie(w, r) l4g.Error(utils.T("api.user.get_me.getting.error"), c.Session.UserId) @@ -267,20 +267,20 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) { if len(c.Session.UserId) != 0 { var err *model.AppError - il.User, err = app.GetUser(c.Session.UserId) + il.User, err = c.App.GetUser(c.Session.UserId) if err != nil { c.Err = err return } il.User.Sanitize(map[string]bool{}) - il.Preferences, err = app.GetPreferencesForUser(c.Session.UserId) + il.Preferences, err = c.App.GetPreferencesForUser(c.Session.UserId) if err != nil { c.Err = err return } - il.Teams, err = app.GetTeamsForUser(c.Session.UserId) + il.Teams, err = c.App.GetTeamsForUser(c.Session.UserId) if err != nil { c.Err = err return @@ -297,7 +297,7 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) { // Below is a special case when intializating a new server // Lets check to make sure the server is really empty - il.NoAccounts = app.IsFirstUserAccount() + il.NoAccounts = c.App.IsFirstUserAccount() } il.ClientCfg = utils.ClientCfg @@ -317,7 +317,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) { var user *model.User var err *model.AppError - if user, err = app.GetUser(id); err != nil { + if user, err = c.App.GetUser(id); err != nil { c.Err = err return } @@ -341,7 +341,7 @@ func getByUsername(c *Context, w http.ResponseWriter, r *http.Request) { var user *model.User var err *model.AppError - if user, err = app.GetUserByUsername(username); err != nil { + if user, err = c.App.GetUserByUsername(username); err != nil { c.Err = err return } else if HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Username", w, r) { @@ -359,7 +359,7 @@ func getByEmail(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) email := params["email"] - if user, err := app.GetUserByEmail(email); err != nil { + if user, err := c.App.GetUserByEmail(email); err != nil { c.Err = err return } else if HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Email", w, r) { @@ -388,12 +388,12 @@ func getProfiles(c *Context, w http.ResponseWriter, r *http.Request) { return } - etag := app.GetUsersEtag() + params["offset"] + "." + params["limit"] + etag := c.App.GetUsersEtag() + params["offset"] + "." + params["limit"] if HandleEtag(etag, "Get Profiles", w, r) { return } - if profiles, err := app.GetUsersMap(offset, limit, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.GetUsersMap(offset, limit, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -424,12 +424,12 @@ func getProfilesInTeam(c *Context, w http.ResponseWriter, r *http.Request) { return } - etag := app.GetUsersInTeamEtag(teamId) + etag := c.App.GetUsersInTeamEtag(teamId) if HandleEtag(etag, "Get Profiles In Team", w, r) { return } - if profiles, err := app.GetUsersInTeamMap(teamId, offset, limit, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.GetUsersInTeamMap(teamId, offset, limit, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -461,12 +461,12 @@ func getProfilesInChannel(c *Context, w http.ResponseWriter, r *http.Request) { } } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if profiles, err := app.GetUsersInChannelMap(channelId, offset, limit, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.GetUsersInChannelMap(channelId, offset, limit, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -485,7 +485,7 @@ func getProfilesNotInChannel(c *Context, w http.ResponseWriter, r *http.Request) } } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -502,7 +502,7 @@ func getProfilesNotInChannel(c *Context, w http.ResponseWriter, r *http.Request) return } - if profiles, err := app.GetUsersNotInChannelMap(c.TeamId, channelId, offset, limit, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.GetUsersNotInChannelMap(c.TeamId, channelId, offset, limit, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -519,7 +519,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) { return } - if audits, err := app.GetAudits(id, 20); err != nil { + if audits, err := c.App.GetAudits(id, 20); err != nil { c.Err = err return } else { @@ -545,7 +545,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { var etag string - if users, err := app.GetUsersByIds([]string{id}, false); err != nil { + if users, err := c.App.GetUsersByIds([]string{id}, false); err != nil { c.Err = err return } else { @@ -610,7 +610,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { imageData := imageArray[0] - if err := app.SetProfileImage(c.Session.UserId, imageData); err != nil { + if err := c.App.SetProfileImage(c.Session.UserId, imageData); err != nil { c.Err = err return } @@ -634,7 +634,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) { return } - if ruser, err := app.UpdateUserAsUser(user, c.IsSystemAdmin()); err != nil { + if ruser, err := c.App.UpdateUserAsUser(user, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -666,7 +666,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.UpdatePasswordAsUser(userId, currentPassword, newPassword); err != nil { + if err := c.App.UpdatePasswordAsUser(userId, currentPassword, newPassword); err != nil { c.LogAudit("failed") c.Err = err return @@ -700,7 +700,7 @@ func updateRoles(c *Context, w http.ResponseWriter, r *http.Request) { return } - if _, err := app.UpdateUserRoles(userId, newRoles); err != nil { + if _, err := c.App.UpdateUserRoles(userId, newRoles); err != nil { return } else { c.LogAuditWithUserId(userId, "roles="+newRoles) @@ -730,7 +730,7 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) { return } - if ruser, err := app.UpdateActiveNoLdap(userId, active); err != nil { + if ruser, err := c.App.UpdateActiveNoLdap(userId, active); err != nil { c.Err = err } else { c.LogAuditWithUserId(ruser.Id, fmt.Sprintf("active=%v", active)) @@ -747,7 +747,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) { return } - if sent, err := app.SendPasswordReset(email, utils.GetSiteURL()); err != nil { + if sent, err := c.App.SendPasswordReset(email, utils.GetSiteURL()); err != nil { c.Err = err return } else if sent { @@ -770,7 +770,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt - token=" + code) - if err := app.ResetPasswordFromToken(code, newPassword); err != nil { + if err := c.App.ResetPasswordFromToken(code, newPassword); err != nil { c.LogAudit("fail - token=" + code) c.Err = err return @@ -823,7 +823,7 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) { return } - ruser, err := app.UpdateUserNotifyProps(userId, props) + ruser, err := c.App.UpdateUserNotifyProps(userId, props) if err != nil { c.Err = err return @@ -860,7 +860,7 @@ func emailToOAuth(c *Context, w http.ResponseWriter, r *http.Request) { return } - link, err := app.SwitchEmailToOAuth(w, r, email, password, mfaToken, service) + link, err := c.App.SwitchEmailToOAuth(w, r, email, password, mfaToken, service) if err != nil { c.Err = err return @@ -885,7 +885,7 @@ func oauthToEmail(c *Context, w http.ResponseWriter, r *http.Request) { return } - link, err := app.SwitchOAuthToEmail(email, password, c.Session.UserId) + link, err := c.App.SwitchOAuthToEmail(email, password, c.Session.UserId) if err != nil { c.Err = err return @@ -931,7 +931,7 @@ func emailToLdap(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - link, err := app.SwitchEmailToLdap(email, emailPassword, token, ldapId, ldapPassword) + link, err := c.App.SwitchEmailToLdap(email, emailPassword, token, ldapId, ldapPassword) if err != nil { c.Err = err return @@ -971,7 +971,7 @@ func ldapToEmail(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - link, err := app.SwitchLdapToEmail(ldapPassword, token, email, emailPassword) + link, err := c.App.SwitchLdapToEmail(ldapPassword, token, email, emailPassword) if err != nil { c.Err = err return @@ -1036,7 +1036,7 @@ func resendVerification(c *Context, w http.ResponseWriter, r *http.Request) { }*/ func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) { - secret, err := app.GenerateMfaSecret(c.Session.UserId) + secret, err := c.App.GenerateMfaSecret(c.Session.UserId) if err != nil { c.Err = err return @@ -1069,7 +1069,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") if activate { - if err := app.ActivateMfa(c.Session.UserId, token); err != nil { + if err := c.App.ActivateMfa(c.Session.UserId, token); err != nil { c.Err = err return } @@ -1085,7 +1085,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) { go func() { var user *model.User var err *model.AppError - if user, err = app.GetUser(c.Session.UserId); err != nil { + if user, err = c.App.GetUser(c.Session.UserId); err != nil { l4g.Warn(err.Error()) return } @@ -1117,7 +1117,7 @@ func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) { } rdata := map[string]string{} - if user, err := app.GetUserForLogin(loginId, false); err != nil { + if user, err := c.App.GetUserForLogin(loginId, false); err != nil { rdata["mfa_required"] = "false" } else { rdata["mfa_required"] = strconv.FormatBool(user.MfaActive) @@ -1133,7 +1133,7 @@ func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) { return } - teamId, err := app.GetTeamIdFromQuery(r.URL.Query()) + teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query()) if err != nil { c.Err = err return @@ -1213,11 +1213,11 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) { case model.OAUTH_ACTION_SIGNUP: teamId := relayProps["team_id"] if len(teamId) > 0 { - go app.AddDirectChannels(teamId, user) + go c.App.AddDirectChannels(teamId, user) } break case model.OAUTH_ACTION_EMAIL_TO_SSO: - if err := app.RevokeAllSessions(user.Id); err != nil { + if err := c.App.RevokeAllSessions(user.Id); err != nil { c.Err = err return } @@ -1273,12 +1273,12 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) { return } - if props.InChannelId != "" && !app.SessionHasPermissionToChannel(c.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) { + if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(c.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if props.NotInChannelId != "" && !app.SessionHasPermissionToChannel(c.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) { + if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(c.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -1299,7 +1299,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) { } } - if profiles, err := app.SearchUsers(props, searchOptions, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.SearchUsers(props, searchOptions, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -1315,7 +1315,7 @@ func getProfilesByIds(c *Context, w http.ResponseWriter, r *http.Request) { return } - if profiles, err := app.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil { + if profiles, err := c.App.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil { c.Err = err return } else { @@ -1340,7 +1340,7 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque } } - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } @@ -1354,7 +1354,7 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true } - autocomplete, err := app.AutocompleteUsersInChannel(teamId, channelId, term, searchOptions, c.IsSystemAdmin()) + autocomplete, err := c.App.AutocompleteUsersInChannel(teamId, channelId, term, searchOptions, c.IsSystemAdmin()) if err != nil { c.Err = err return @@ -1384,7 +1384,7 @@ func autocompleteUsersInTeam(c *Context, w http.ResponseWriter, r *http.Request) searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true } - autocomplete, err := app.AutocompleteUsersInTeam(teamId, term, searchOptions, c.IsSystemAdmin()) + autocomplete, err := c.App.AutocompleteUsersInTeam(teamId, term, searchOptions, c.IsSystemAdmin()) if err != nil { c.Err = err return @@ -1408,7 +1408,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) { var profiles []*model.User var err *model.AppError - if profiles, err = app.SearchUsersInTeam("", term, searchOptions, c.IsSystemAdmin()); err != nil { + if profiles, err = c.App.SearchUsersInTeam("", term, searchOptions, c.IsSystemAdmin()); err != nil { c.Err = err return } diff --git a/api/user_test.go b/api/user_test.go index e11391434..72806bfd4 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -109,7 +109,7 @@ func TestLogin(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Username: "corey" + model.NewId(), Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) if result, err := Client.LoginById(ruser.Data.(*model.User).Id, user.Password); err != nil { t.Fatal(err) @@ -203,7 +203,7 @@ func TestLogin(t *testing.T) { AuthService: model.USER_AUTH_SERVICE_LDAP, } user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User) - store.Must(app.Srv.Store.User().VerifyEmail(user3.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id)) if _, err := Client.Login(user3.Id, user3.Password); err == nil { t.Fatal("AD/LDAP user should not be able to log in with AD/LDAP disabled") @@ -222,7 +222,7 @@ func TestLoginByLdap(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Username: "corey" + model.NewId(), Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) if _, err := Client.LoginByLdap(ruser.Data.(*model.User).Id, user.Password); err == nil { t.Fatal("should have failed to log in with non AD/LDAP user") @@ -249,7 +249,7 @@ func TestLoginWithDeviceId(t *testing.T) { t.Fatal(err) } - if sresult := <-app.Srv.Store.Session().Get(sessions[0].Id); sresult.Err == nil { + if sresult := <-th.App.Srv.Store.Session().Get(sessions[0].Id); sresult.Err == nil { t.Fatal("session should have been removed") } } @@ -355,17 +355,17 @@ func TestGetUser(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: "Corey", LastName: "Hulen"} ruser2, _ := Client.CreateUser(&user2, "") LinkUserToTeam(ruser2.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Data.(*model.User).Id)) user3 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser3, _ := Client.CreateUser(&user3, "") LinkUserToTeam(ruser3.Data.(*model.User), rteam2.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser3.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser3.Data.(*model.User).Id)) Client.Login(user.Email, user.Password) @@ -488,7 +488,7 @@ func TestGetUser(t *testing.T) { t.Fatal("shouldn't have accss") } - app.UpdateUserRoles(ruser.Data.(*model.User).Id, model.ROLE_SYSTEM_ADMIN.Id) + th.App.UpdateUserRoles(ruser.Data.(*model.User).Id, model.ROLE_SYSTEM_ADMIN.Id) Client.Login(user.Email, "passwd1") @@ -620,7 +620,7 @@ func TestGetAudits(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) time.Sleep(100 * time.Millisecond) @@ -675,7 +675,7 @@ func TestUserCreateImage(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") @@ -724,7 +724,7 @@ func TestUserUploadProfileImage(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) if *utils.Cfg.FileSettings.DriverName != "" { @@ -837,7 +837,7 @@ func TestUserUpdate(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", Roles: ""} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) if _, err := Client.UpdateUser(user); err == nil { t.Fatal("Should have errored") @@ -867,7 +867,7 @@ func TestUserUpdate(t *testing.T) { user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) Client.Login(user2.Email, "passwd1") Client.SetTeamId(team.Id) @@ -892,7 +892,7 @@ func TestUserUpdatePassword(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) if _, err := Client.UpdateUserPassword(user.Id, "passwd1", "newpasswd1"); err == nil { t.Fatal("Should have errored") @@ -976,12 +976,12 @@ func TestUserUpdateRoles(t *testing.T) { user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) if _, err := Client.UpdateUserRoles(user.Id, ""); err == nil { t.Fatal("Should have errored, not logged in") @@ -1000,7 +1000,7 @@ func TestUserUpdateRoles(t *testing.T) { user3 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User) LinkUserToTeam(user3, team2) - store.Must(app.Srv.Store.User().VerifyEmail(user3.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id)) Client.Login(user3.Email, "passwd1") Client.SetTeamId(team2.Id) @@ -1095,7 +1095,7 @@ func TestUserUpdateDeviceId(t *testing.T) { user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -1105,7 +1105,7 @@ func TestUserUpdateDeviceId(t *testing.T) { t.Fatal(err) } - if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil { + if result := <-th.App.Srv.Store.Session().GetSessions(user.Id); result.Err != nil { t.Fatal(result.Err) } else { sessions := result.Data.([]*model.Session) @@ -1126,7 +1126,7 @@ func TestUserUpdateDeviceId2(t *testing.T) { user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) @@ -1136,7 +1136,7 @@ func TestUserUpdateDeviceId2(t *testing.T) { t.Fatal(err) } - if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil { + if result := <-th.App.Srv.Store.Session().GetSessions(user.Id); result.Err != nil { t.Fatal(result.Err) } else { sessions := result.Data.([]*model.Session) @@ -1163,12 +1163,12 @@ func TestUserUpdateActive(t *testing.T) { user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) if _, err := Client.UpdateActive(user.Id, false); err == nil { t.Fatal("Should have errored, not logged in") @@ -1186,7 +1186,7 @@ func TestUserUpdateActive(t *testing.T) { user3 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User) LinkUserToTeam(user2, team2) - store.Must(app.Srv.Store.User().VerifyEmail(user3.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id)) Client.Login(user3.Email, "passwd1") Client.SetTeamId(team2.Id) @@ -1206,13 +1206,13 @@ func TestUserUpdateActive(t *testing.T) { t.Fatal("Should have errored, bad id") } - app.SetStatusOnline(user3.Id, "", false) + th.App.SetStatusOnline(user3.Id, "", false) if _, err := SystemAdminClient.UpdateActive(user3.Id, false); err != nil { t.Fatal(err) } - if status, err := app.GetStatus(user3.Id); err != nil { + if status, err := th.App.GetStatus(user3.Id); err != nil { t.Fatal(err) } else if status.Status != model.STATUS_OFFLINE { t.Fatal("status should have been set to offline") @@ -1229,7 +1229,7 @@ func TestUserPermDelete(t *testing.T) { user1 := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) LinkUserToTeam(user1, team) - store.Must(app.Srv.Store.User().VerifyEmail(user1.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user1.Id)) Client.Login(user1.Email, "passwd1") Client.SetTeamId(team.Id) @@ -1253,7 +1253,7 @@ func TestUserPermDelete(t *testing.T) { c.RequestId = model.NewId() c.IpAddress = "test" - err := app.PermanentDeleteUser(user1) + err := th.App.PermanentDeleteUser(user1) if err != nil { t.Fatal(err) } @@ -1271,7 +1271,7 @@ func TestSendPasswordReset(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) Client.Logout() @@ -1296,7 +1296,7 @@ func TestSendPasswordReset(t *testing.T) { user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) LinkUserToTeam(user2, team) - store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id)) if _, err := Client.SendPasswordReset(user2.Email); err == nil { t.Fatal("should have errored - SSO user can't send reset password link") @@ -1311,7 +1311,7 @@ func TestResetPassword(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) //Delete all the messages before check the reset password utils.DeleteMailBox(user.Email) @@ -1350,7 +1350,7 @@ func TestResetPassword(t *testing.T) { } var recoveryToken *model.Token - if result := <-app.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil { + if result := <-th.App.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil { t.Log(recoveryTokenString) t.Fatal(result.Err) } else { @@ -1412,7 +1412,7 @@ func TestUserUpdateNotify(t *testing.T) { user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", Roles: ""} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) - store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id)) data := make(map[string]string) data["user_id"] = user.Id @@ -1527,7 +1527,7 @@ func TestEmailToOAuth(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) LinkUserToTeam(ruser, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id)) m := map[string]string{} if _, err := Client.EmailToOAuth(m); err == nil { @@ -1580,12 +1580,12 @@ func TestOAuthToEmail(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) LinkUserToTeam(ruser, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id)) user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User) LinkUserToTeam(ruser2, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Id)) m := map[string]string{} if _, err := Client.OAuthToEmail(m); err == nil { @@ -1631,7 +1631,7 @@ func TestLDAPToEmail(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) LinkUserToTeam(ruser, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id)) Client.Login(user.Email, user.Password) @@ -1684,7 +1684,7 @@ func TestEmailToLDAP(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) LinkUserToTeam(ruser, rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id)) Client.Login(user.Email, user.Password) @@ -1815,7 +1815,7 @@ func TestGenerateMfaSecret(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.Logout() @@ -1856,7 +1856,7 @@ func TestUpdateMfa(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.Logout() @@ -1897,7 +1897,7 @@ func TestCheckMfa(t *testing.T) { user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) - store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) + store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) if result, err := Client.CheckMfa(user.Email); err != nil { t.Fatal(err) diff --git a/api/webhook.go b/api/webhook.go index 204df6b31..ce7084da9 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -34,7 +34,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - channel, err := app.GetChannel(hook.ChannelId) + channel, err := c.App.GetChannel(hook.ChannelId) if err != nil { c.Err = err return @@ -47,13 +47,13 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - if channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { c.LogAudit("fail - bad channel permissions") c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - if incomingHook, err := app.CreateIncomingWebhookForChannel(c.Session.UserId, channel, hook); err != nil { + if incomingHook, err := c.App.CreateIncomingWebhookForChannel(c.Session.UserId, channel, hook); err != nil { c.Err = err return } else { @@ -73,7 +73,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { c.LogAudit("attempt") - oldHook, err := app.GetIncomingWebhook(hook.Id) + oldHook, err := c.App.GetIncomingWebhook(hook.Id) if err != nil { c.Err = err return @@ -95,19 +95,19 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - channel, err := app.GetChannel(hook.ChannelId) + channel, err := c.App.GetChannel(hook.ChannelId) if err != nil { c.Err = err return } - if channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { + if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) { c.LogAudit("fail - bad channel permissions") c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - rhook, err := app.UpdateIncomingWebhook(oldHook, hook) + rhook, err := c.App.UpdateIncomingWebhook(oldHook, hook) if err != nil { c.Err = err return @@ -126,7 +126,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - hook, err := app.GetIncomingWebhook(id) + hook, err := c.App.GetIncomingWebhook(id) if err != nil { c.Err = err return @@ -145,7 +145,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.DeleteIncomingWebhook(id); err != nil { + if err := c.App.DeleteIncomingWebhook(id); err != nil { c.LogAudit("fail") c.Err = err return @@ -161,7 +161,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) { return } - if hooks, err := app.GetIncomingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil { + if hooks, err := c.App.GetIncomingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil { c.Err = err return } else { @@ -186,7 +186,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - if rhook, err := app.CreateOutgoingWebhook(hook); err != nil { + if rhook, err := c.App.CreateOutgoingWebhook(hook); err != nil { c.LogAudit("fail") c.Err = err return @@ -202,7 +202,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) { return } - if hooks, err := app.GetOutgoingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil { + if hooks, err := c.App.GetOutgoingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil { c.Err = err return } else { @@ -220,7 +220,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - oldHook, err := app.GetOutgoingWebhook(hook.Id) + oldHook, err := c.App.GetOutgoingWebhook(hook.Id) if err != nil { c.Err = err return @@ -243,7 +243,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - rhook, err := app.UpdateOutgoingWebhook(oldHook, hook) + rhook, err := c.App.UpdateOutgoingWebhook(oldHook, hook) if err != nil { c.Err = err return @@ -269,7 +269,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - hook, err := app.GetOutgoingWebhook(id) + hook, err := c.App.GetOutgoingWebhook(id) if err != nil { c.Err = err return @@ -281,7 +281,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := app.DeleteOutgoingWebhook(id); err != nil { + if err := c.App.DeleteOutgoingWebhook(id); err != nil { c.LogAudit("fail") c.Err = err return @@ -300,7 +300,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request) return } - hook, err := app.GetOutgoingWebhook(id) + hook, err := c.App.GetOutgoingWebhook(id) if err != nil { c.Err = err return @@ -324,7 +324,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request) return } - if rhook, err := app.RegenOutgoingWebhookToken(hook); err != nil { + if rhook, err := c.App.RegenOutgoingWebhookToken(hook); err != nil { c.Err = err return } else { diff --git a/api/websocket.go b/api/websocket.go index 6fd79a2dd..66a44013b 100644 --- a/api/websocket.go +++ b/api/websocket.go @@ -34,7 +34,7 @@ func connect(c *Context, w http.ResponseWriter, r *http.Request) { return } - wc := app.NewWebConn(ws, c.Session, c.T, c.Locale) + wc := c.App.NewWebConn(ws, c.Session, c.T, c.Locale) if len(c.Session.UserId) > 0 { app.HubRegister(wc) |