summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-09-06 17:12:54 -0500
committerGitHub <noreply@github.com>2017-09-06 17:12:54 -0500
commit1adfd0e9be69a93c7f63bb7afc742c9fafe31aa3 (patch)
tree2766bacc1f045fa685ca3d8310cd6174d0311d09 /api4
parentb84bd21089d305333fa4114b95be70f5ad94ad1b (diff)
downloadchat-1adfd0e9be69a93c7f63bb7afc742c9fafe31aa3.tar.gz
chat-1adfd0e9be69a93c7f63bb7afc742c9fafe31aa3.tar.bz2
chat-1adfd0e9be69a93c7f63bb7afc742c9fafe31aa3.zip
app type transition (#7167)
Diffstat (limited to 'api4')
-rw-r--r--api4/api.go10
-rw-r--r--api4/apitestlib.go74
-rw-r--r--api4/channel.go108
-rw-r--r--api4/channel_test.go69
-rw-r--r--api4/command.go28
-rw-r--r--api4/command_help_test.go3
-rw-r--r--api4/command_test.go17
-rw-r--r--api4/compliance.go8
-rw-r--r--api4/context.go10
-rw-r--r--api4/emoji.go12
-rw-r--r--api4/file.go26
-rw-r--r--api4/file_test.go12
-rw-r--r--api4/job.go6
-rw-r--r--api4/job_test.go19
-rw-r--r--api4/oauth.go50
-rw-r--r--api4/plugin.go6
-rw-r--r--api4/plugin_test.go5
-rw-r--r--api4/post.go72
-rw-r--r--api4/post_test.go34
-rw-r--r--api4/preference.go10
-rw-r--r--api4/reaction.go12
-rw-r--r--api4/reaction_test.go39
-rw-r--r--api4/status.go10
-rw-r--r--api4/status_test.go15
-rw-r--r--api4/system.go18
-rw-r--r--api4/team.go58
-rw-r--r--api4/team_test.go21
-rw-r--r--api4/user.go128
-rw-r--r--api4/user_test.go35
-rw-r--r--api4/webhook.go60
-rw-r--r--api4/webhook_test.go3
-rw-r--r--api4/websocket.go2
32 files changed, 489 insertions, 491 deletions
diff --git a/api4/api.go b/api4/api.go
index 3a4f2c412..ef96ec589 100644
--- a/api4/api.go
+++ b/api4/api.go
@@ -106,14 +106,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(full bool) {
BaseRoutes = &Routes{}
- BaseRoutes.Root = app.Srv.Router
- BaseRoutes.ApiRoot = app.Srv.Router.PathPrefix(model.API_URL_SUFFIX).Subrouter()
+ BaseRoutes.Root = app.Global().Srv.Router
+ BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX).Subrouter()
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
BaseRoutes.User = BaseRoutes.ApiRoot.PathPrefix("/users/{user_id:[A-Za-z0-9]+}").Subrouter()
@@ -213,7 +213,7 @@ func InitApi(full bool) {
InitOpenGraph()
InitPlugin()
- app.Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
+ app.Global().Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
// REMOVE CONDITION WHEN APIv3 REMOVED
if full {
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index b634de0d4..9d26342dc 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -29,6 +29,8 @@ import (
)
type TestHelper struct {
+ App *app.App
+
Client *model.Client4
BasicUser *model.User
BasicUser2 *model.User
@@ -44,7 +46,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)
@@ -56,32 +58,33 @@ func SetupEnterprise() *TestHelper {
utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
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()
InitApi(true)
wsapi.InitApi()
utils.EnableDebugLogForTest()
- app.Srv.Store.MarkSystemRanUnitTests()
+ app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
if jobs.Srv.Store == nil {
- jobs.Srv.Store = app.Srv.Store
+ jobs.Srv.Store = app.Global().Srv.Store
}
th := &TestHelper{}
+ th.App = app.Global()
th.Client = th.CreateClient()
th.SystemAdminClient = th.CreateClient()
return th
}
func Setup() *TestHelper {
- if app.Srv == nil {
+ if app.Global().Srv == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
@@ -92,32 +95,33 @@ 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()
InitApi(true)
wsapi.InitApi()
utils.EnableDebugLogForTest()
- app.Srv.Store.MarkSystemRanUnitTests()
+ app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
if jobs.Srv.Store == nil {
- jobs.Srv.Store = app.Srv.Store
+ jobs.Srv.Store = app.Global().Srv.Store
}
th := &TestHelper{}
+ th.App = app.Global()
th.Client = th.CreateClient()
th.SystemAdminClient = th.CreateClient()
return th
}
func StopServer() {
- if app.Srv != nil {
- app.StopServer()
+ if app.Global().Srv != nil {
+ app.Global().StopServer()
}
}
@@ -131,13 +135,13 @@ func TearDown() {
defer wg.Done()
options := map[string]bool{}
options[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
- if result := <-app.Srv.Store.User().Search("", "fakeuser", options); result.Err != nil {
+ if result := <-app.Global().Srv.Store.User().Search("", "fakeuser", options); result.Err != nil {
l4g.Error("Error tearing down test users")
} else {
users := result.Data.([]*model.User)
for _, u := range users {
- if err := app.PermanentDeleteUser(u); err != nil {
+ if err := app.Global().PermanentDeleteUser(u); err != nil {
l4g.Error(err.Error())
}
}
@@ -146,13 +150,13 @@ func TearDown() {
go func() {
defer wg.Done()
- if result := <-app.Srv.Store.Team().SearchByName("faketeam"); result.Err != nil {
+ if result := <-app.Global().Srv.Store.Team().SearchByName("faketeam"); result.Err != nil {
l4g.Error("Error tearing down test teams")
} else {
teams := result.Data.([]*model.Team)
for _, t := range teams {
- if err := app.PermanentDeleteTeam(t); err != nil {
+ if err := app.Global().PermanentDeleteTeam(t); err != nil {
l4g.Error(err.Error())
}
}
@@ -161,14 +165,14 @@ func TearDown() {
go func() {
defer wg.Done()
- if result := <-app.Srv.Store.OAuth().GetApps(0, 1000); result.Err != nil {
+ if result := <-app.Global().Srv.Store.OAuth().GetApps(0, 1000); result.Err != nil {
l4g.Error("Error tearing down test oauth apps")
} else {
apps := result.Data.([]*model.OAuthApp)
for _, a := range apps {
if strings.HasPrefix(a.Name, "fakeoauthapp") {
- <-app.Srv.Store.OAuth().DeleteApp(a.Id)
+ <-app.Global().Srv.Store.OAuth().DeleteApp(a.Id)
}
}
}
@@ -191,13 +195,13 @@ func (me *TestHelper) InitBasic() *TestHelper {
LinkUserToTeam(me.BasicUser, me.BasicTeam)
me.BasicUser2 = me.CreateUser()
LinkUserToTeam(me.BasicUser2, me.BasicTeam)
- app.AddUserToChannel(me.BasicUser, me.BasicChannel)
- app.AddUserToChannel(me.BasicUser2, me.BasicChannel)
- app.AddUserToChannel(me.BasicUser, me.BasicChannel2)
- app.AddUserToChannel(me.BasicUser2, me.BasicChannel2)
- app.AddUserToChannel(me.BasicUser, me.BasicPrivateChannel)
- app.AddUserToChannel(me.BasicUser2, me.BasicPrivateChannel)
- app.UpdateUserRoles(me.BasicUser.Id, model.ROLE_SYSTEM_USER.Id)
+ me.App.AddUserToChannel(me.BasicUser, me.BasicChannel)
+ me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel)
+ me.App.AddUserToChannel(me.BasicUser, me.BasicChannel2)
+ me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel2)
+ me.App.AddUserToChannel(me.BasicUser, me.BasicPrivateChannel)
+ me.App.AddUserToChannel(me.BasicUser2, me.BasicPrivateChannel)
+ me.App.UpdateUserRoles(me.BasicUser.Id, model.ROLE_SYSTEM_USER.Id)
me.LoginBasic()
return me
@@ -205,7 +209,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
func (me *TestHelper) InitSystemAdmin() *TestHelper {
me.SystemAdminUser = me.CreateUser()
- 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.LoginSystemAdmin()
return me
@@ -391,7 +395,7 @@ func (me *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
utils.DisableDebugLogForTest()
- _, err := app.UpdateActive(user, active)
+ _, err := app.Global().UpdateActive(user, active)
if err != nil {
l4g.Error(err.Error())
l4g.Close()
@@ -405,7 +409,7 @@ func (me *TestHelper) UpdateActiveUser(user *model.User, active bool) {
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()
@@ -441,7 +445,7 @@ func GenerateTestId() string {
}
func VerifyUserEmail(userId string) {
- store.Must(app.Srv.Store.User().VerifyEmail(userId))
+ store.Must(app.Global().Srv.Store.User().VerifyEmail(userId))
}
func CheckUserSanitization(t *testing.T, user *model.User) {
@@ -709,10 +713,10 @@ func cleanupTestFile(info *model.FileInfo) error {
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)
}
@@ -728,7 +732,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()
@@ -742,7 +746,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()
diff --git a/api4/channel.go b/api4/channel.go
index 8a14b85bb..98cbc4eff 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -66,7 +66,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 {
@@ -91,12 +91,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
}
@@ -134,12 +134,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())
}
}
@@ -160,7 +160,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oldChannel, err := app.GetChannel(c.Params.ChannelId)
+ oldChannel, err := c.App.GetChannel(c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -170,7 +170,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if rchannel, err := app.PatchChannel(oldChannel, patch, c.Session.UserId); err != nil {
+ if rchannel, err := c.App.PatchChannel(oldChannel, patch, c.Session.UserId); err != nil {
c.Err = err
return
} else {
@@ -187,7 +187,7 @@ func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannel(c.Params.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(c.Params.ChannelId); err != nil {
c.Err = err
return
}
@@ -198,7 +198,7 @@ func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- channel, err = app.RestoreChannel(channel)
+ channel, err = c.App.RestoreChannel(channel)
if err != nil {
c.Err = err
return
@@ -210,12 +210,12 @@ func restoreChannel(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
}
@@ -252,7 +252,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if sc, err := app.CreateDirectChannel(userIds[0], userIds[1]); err != nil {
+ if sc, err := c.App.CreateDirectChannel(userIds[0], userIds[1]); err != nil {
c.Err = err
return
} else {
@@ -289,7 +289,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if groupChannel, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
+ if groupChannel, err := c.App.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
c.Err = err
return
} else {
@@ -304,7 +304,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- channel, err := app.GetChannel(c.Params.ChannelId)
+ channel, err := c.App.GetChannel(c.Params.ChannelId)
if err != nil {
c.Err = err
return
@@ -316,7 +316,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
} else {
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -337,12 +337,12 @@ func getChannelUnread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- channelUnread, err := app.GetChannelUnread(c.Params.ChannelId, c.Params.UserId)
+ channelUnread, err := c.App.GetChannelUnread(c.Params.ChannelId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -357,12 +357,12 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- memberCount, err := app.GetChannelMemberCount(c.Params.ChannelId)
+ memberCount, err := c.App.GetChannelMemberCount(c.Params.ChannelId)
if err != nil {
c.Err = err
@@ -379,12 +379,12 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if posts, err := app.GetPinnedPosts(c.Params.ChannelId); err != nil {
+ if posts, err := c.App.GetPinnedPosts(c.Params.ChannelId); err != nil {
c.Err = err
return
} else if HandleEtag(posts.Etag(), "Get Pinned Posts", w, r) {
@@ -406,7 +406,7 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request
return
}
- if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil {
+ if channels, err := c.App.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -426,7 +426,7 @@ func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Reques
return
}
- if channels, err := app.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil {
+ if channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -459,7 +459,7 @@ func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Re
return
}
- if channels, err := app.GetPublicChannelsByIdsForTeam(c.Params.TeamId, channelIds); err != nil {
+ if channels, err := c.App.GetPublicChannelsByIdsForTeam(c.Params.TeamId, channelIds); err != nil {
c.Err = err
return
} else {
@@ -483,7 +483,7 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
return
}
- if channels, err := app.GetChannelsForUser(c.Params.TeamId, c.Params.UserId); err != nil {
+ if channels, err := c.App.GetChannelsForUser(c.Params.TeamId, c.Params.UserId); err != nil {
c.Err = err
return
} else if HandleEtag(channels.Etag(), "Get Channels", w, r) {
@@ -511,7 +511,7 @@ func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if channels, err := app.SearchChannels(c.Params.TeamId, props.Term); err != nil {
+ if channels, err := c.App.SearchChannels(c.Params.TeamId, props.Term); err != nil {
c.Err = err
return
} else {
@@ -527,22 +527,22 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannel(c.Params.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(c.Params.ChannelId); 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
@@ -562,7 +562,7 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannelByName(c.Params.ChannelName, c.Params.TeamId); err != nil {
+ if channel, err = c.App.GetChannelByName(c.Params.ChannelName, c.Params.TeamId); err != nil {
c.Err = err
return
}
@@ -573,7 +573,7 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
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
}
@@ -591,12 +591,12 @@ func getChannelByNameForTeamName(c *Context, w http.ResponseWriter, r *http.Requ
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannelByNameForTeamName(c.Params.ChannelName, c.Params.TeamName); err != nil {
+ if channel, err = c.App.GetChannelByNameForTeamName(c.Params.ChannelName, c.Params.TeamName); err != nil {
c.Err = err
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
}
@@ -611,12 +611,12 @@ func getChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if members, err := app.GetChannelMembersPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage); err != nil {
+ if members, err := c.App.GetChannelMembersPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -636,12 +636,12 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request)
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if members, err := app.GetChannelMembersByIds(c.Params.ChannelId, userIds); err != nil {
+ if members, err := c.App.GetChannelMembersByIds(c.Params.ChannelId, userIds); err != nil {
c.Err = err
return
} else {
@@ -655,12 +655,12 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if member, err := app.GetChannelMember(c.Params.ChannelId, c.Params.UserId); err != nil {
+ if member, err := c.App.GetChannelMember(c.Params.ChannelId, c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -684,7 +684,7 @@ func getChannelMembersForUser(c *Context, w http.ResponseWriter, r *http.Request
return
}
- if members, err := app.GetChannelMembersForUser(c.Params.TeamId, c.Params.UserId); err != nil {
+ if members, err := c.App.GetChannelMembersForUser(c.Params.TeamId, c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -709,7 +709,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.ViewChannel(view, c.Params.UserId, !c.Session.IsMobileApp()); err != nil {
+ if err := c.App.ViewChannel(view, c.Params.UserId, !c.Session.IsMobileApp()); err != nil {
c.Err = err
return
}
@@ -731,12 +731,12 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
return
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
c.SetPermissionError(model.PERMISSION_MANAGE_CHANNEL_ROLES)
return
}
- if _, err := app.UpdateChannelMemberRoles(c.Params.ChannelId, c.Params.UserId, newRoles); err != nil {
+ if _, err := c.App.UpdateChannelMemberRoles(c.Params.ChannelId, c.Params.UserId, newRoles); err != nil {
c.Err = err
return
}
@@ -761,7 +761,7 @@ func updateChannelMemberNotifyProps(c *Context, w http.ResponseWriter, r *http.R
return
}
- _, err := app.UpdateChannelMemberNotifyProps(props, c.Params.ChannelId, c.Params.UserId)
+ _, err := c.App.UpdateChannelMemberNotifyProps(props, c.Params.ChannelId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -791,7 +791,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannel(member.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(member.ChannelId); err != nil {
c.Err = err
return
}
@@ -799,24 +799,24 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
// Check join permission if adding yourself, otherwise check manage permission
if channel.Type == model.CHANNEL_OPEN {
if member.UserId == c.Session.UserId {
- if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
c.SetPermissionError(model.PERMISSION_JOIN_PUBLIC_CHANNELS)
return
}
} else {
- if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
+ if !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 cm, err := app.AddChannelMember(member.UserId, channel, c.Session.UserId); err != nil {
+ if cm, err := c.App.AddChannelMember(member.UserId, channel, c.Session.UserId); err != nil {
c.Err = err
return
} else {
@@ -834,24 +834,24 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
- if channel, err = app.GetChannel(c.Params.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(c.Params.ChannelId); err != nil {
c.Err = err
return
}
if c.Params.UserId != c.Session.UserId {
- 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(c.Params.UserId, c.Session.UserId, channel); err != nil {
+ if err = c.App.RemoveUserFromChannel(c.Params.UserId, c.Session.UserId, channel); err != nil {
c.Err = err
return
}
diff --git a/api4/channel_test.go b/api4/channel_test.go
index e4da4f4d2..4a200571f 100644
--- a/api4/channel_test.go
+++ b/api4/channel_test.go
@@ -11,7 +11,6 @@ import (
"strconv"
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
@@ -390,7 +389,7 @@ func TestCreateGroupChannel(t *testing.T) {
t.Fatal("should have created a channel of group type")
}
- m, _ := app.GetChannelMembersPage(rgc.Id, 0, 10)
+ m, _ := th.App.GetChannelMembersPage(rgc.Id, 0, 10)
if len(*m) != 3 {
t.Fatal("should have 3 channel members")
}
@@ -403,7 +402,7 @@ func TestCreateGroupChannel(t *testing.T) {
t.Fatal("should have returned existing channel")
}
- m2, _ := app.GetChannelMembersPage(rgc2.Id, 0, 10)
+ m2, _ := th.App.GetChannelMembersPage(rgc2.Id, 0, 10)
if !reflect.DeepEqual(*m, *m2) {
t.Fatal("should be equal")
}
@@ -798,9 +797,9 @@ func TestDeleteChannel(t *testing.T) {
t.Fatal("should have passed")
}
- if ch, err := app.GetChannel(publicChannel1.Id); err == nil && ch.DeleteAt == 0 {
+ if ch, err := th.App.GetChannel(publicChannel1.Id); err == nil && ch.DeleteAt == 0 {
t.Fatal("should have failed to get deleted channel")
- } else if err := app.JoinChannel(ch, user2.Id); err == nil {
+ } else if err := th.App.JoinChannel(ch, user2.Id); err == nil {
t.Fatal("should have failed to join deleted channel")
}
@@ -816,7 +815,7 @@ func TestDeleteChannel(t *testing.T) {
// successful delete of channel with multiple members
publicChannel3 := th.CreatePublicChannel()
- app.AddUserToChannel(user2, publicChannel3)
+ th.App.AddUserToChannel(user2, publicChannel3)
_, resp = Client.DeleteChannel(publicChannel3.Id)
CheckNoError(t, resp)
@@ -827,7 +826,7 @@ func TestDeleteChannel(t *testing.T) {
CheckNoError(t, resp)
// default channel cannot be deleted.
- defaultChannel, _ := app.GetChannelByName(model.DEFAULT_CHANNEL, team.Id)
+ defaultChannel, _ := th.App.GetChannelByName(model.DEFAULT_CHANNEL, team.Id)
pass, resp = Client.DeleteChannel(defaultChannel.Id)
CheckBadRequestStatus(t, resp)
@@ -904,9 +903,9 @@ func TestDeleteChannel(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
privateChannel7 := th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
- app.AddUserToChannel(user, publicChannel6)
- app.AddUserToChannel(user, privateChannel7)
- app.AddUserToChannel(user2, privateChannel7)
+ th.App.AddUserToChannel(user, publicChannel6)
+ th.App.AddUserToChannel(user, privateChannel7)
+ th.App.AddUserToChannel(user2, privateChannel7)
// successful delete by user
_, resp = Client.DeleteChannel(publicChannel6.Id)
@@ -922,9 +921,9 @@ func TestDeleteChannel(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
- app.AddUserToChannel(user, publicChannel6)
- app.AddUserToChannel(user, privateChannel7)
- app.AddUserToChannel(user2, privateChannel7)
+ th.App.AddUserToChannel(user, publicChannel6)
+ th.App.AddUserToChannel(user, privateChannel7)
+ th.App.AddUserToChannel(user2, privateChannel7)
// cannot delete by user
_, resp = Client.DeleteChannel(publicChannel6.Id)
@@ -947,13 +946,13 @@ func TestDeleteChannel(t *testing.T) {
// // channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
- app.AddUserToChannel(user, publicChannel6)
- app.AddUserToChannel(user, privateChannel7)
- app.AddUserToChannel(user2, privateChannel7)
+ th.App.AddUserToChannel(user, publicChannel6)
+ th.App.AddUserToChannel(user, privateChannel7)
+ th.App.AddUserToChannel(user2, privateChannel7)
// successful delete by team admin
UpdateUserToTeamAdmin(user, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -968,7 +967,7 @@ func TestDeleteChannel(t *testing.T) {
*utils.Cfg.TeamSettings.RestrictPrivateChannelDeletion = model.PERMISSIONS_TEAM_ADMIN
utils.SetDefaultRolesBasedOnConfig()
UpdateUserToNonTeamAdmin(user, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -976,9 +975,9 @@ func TestDeleteChannel(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
- app.AddUserToChannel(user, publicChannel6)
- app.AddUserToChannel(user, privateChannel7)
- app.AddUserToChannel(user2, privateChannel7)
+ th.App.AddUserToChannel(user, publicChannel6)
+ th.App.AddUserToChannel(user, privateChannel7)
+ th.App.AddUserToChannel(user2, privateChannel7)
// cannot delete by user
_, resp = Client.DeleteChannel(publicChannel6.Id)
@@ -1000,7 +999,7 @@ func TestDeleteChannel(t *testing.T) {
// successful delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1018,9 +1017,9 @@ func TestDeleteChannel(t *testing.T) {
// channels created by SystemAdmin
publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_OPEN)
privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.CHANNEL_PRIVATE)
- app.AddUserToChannel(user, publicChannel6)
- app.AddUserToChannel(user, privateChannel7)
- app.AddUserToChannel(user2, privateChannel7)
+ th.App.AddUserToChannel(user, publicChannel6)
+ th.App.AddUserToChannel(user, privateChannel7)
+ th.App.AddUserToChannel(user2, privateChannel7)
// cannot delete by user
_, resp = Client.DeleteChannel(publicChannel6.Id)
@@ -1042,7 +1041,7 @@ func TestDeleteChannel(t *testing.T) {
// cannot delete by team admin
UpdateUserToTeamAdmin(th.BasicUser, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1560,7 +1559,7 @@ func TestUpdateChannelRoles(t *testing.T) {
channel := th.CreatePublicChannel()
// Adds User 2 to the channel, making them a channel member by default.
- app.AddUserToChannel(th.BasicUser2, channel)
+ th.App.AddUserToChannel(th.BasicUser2, channel)
// User 1 promotes User 2
pass, resp := Client.UpdateChannelRoles(channel.Id, th.BasicUser2.Id, CHANNEL_ADMIN)
@@ -1643,7 +1642,7 @@ func TestUpdateChannelNotifyProps(t *testing.T) {
t.Fatal("should have passed")
}
- member, err := app.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id)
+ member, err := th.App.GetChannelMember(th.BasicChannel.Id, th.BasicUser.Id)
if err != nil {
t.Fatal(err)
}
@@ -1838,7 +1837,7 @@ func TestAddChannelMember(t *testing.T) {
Client.Logout()
MakeUserChannelAdmin(user, privateChannel)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1868,7 +1867,7 @@ func TestAddChannelMember(t *testing.T) {
Client.Logout()
UpdateUserToTeamAdmin(user, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -1932,7 +1931,7 @@ func TestRemoveChannelMember(t *testing.T) {
_, resp = Client.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser.Id)
CheckForbiddenStatus(t, resp)
- app.AddUserToChannel(th.BasicUser2, th.BasicChannel)
+ th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
_, resp = Client.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser2.Id)
CheckNoError(t, resp)
@@ -1944,7 +1943,7 @@ func TestRemoveChannelMember(t *testing.T) {
th.LoginBasic()
private := th.CreatePrivateChannel()
- app.AddUserToChannel(th.BasicUser2, private)
+ th.App.AddUserToChannel(th.BasicUser2, private)
_, resp = Client.RemoveUserFromChannel(private.Id, th.BasicUser2.Id)
CheckNoError(t, resp)
@@ -1958,7 +1957,7 @@ func TestRemoveChannelMember(t *testing.T) {
th.LoginBasic()
UpdateUserToNonTeamAdmin(user1, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
// Test policy does not apply to TE.
restrictPrivateChannel := *utils.Cfg.TeamSettings.RestrictPrivateChannelManageMembers
@@ -2018,7 +2017,7 @@ func TestRemoveChannelMember(t *testing.T) {
CheckForbiddenStatus(t, resp)
MakeUserChannelAdmin(user1, privateChannel)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
@@ -2043,7 +2042,7 @@ func TestRemoveChannelMember(t *testing.T) {
CheckForbiddenStatus(t, resp)
UpdateUserToTeamAdmin(user1, team)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
utils.License().Features.SetDefaults()
diff --git a/api4/command.go b/api4/command.go
index 31361b00a..ebcc34a72 100644
--- a/api4/command.go
+++ b/api4/command.go
@@ -48,7 +48,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
cmd.CreatorId = c.Session.UserId
- rcmd, err := app.CreateCommand(cmd)
+ rcmd, err := c.App.CreateCommand(cmd)
if err != nil {
c.Err = err
return
@@ -73,7 +73,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- oldCmd, err := app.GetCommand(c.Params.CommandId)
+ oldCmd, err := c.App.GetCommand(c.Params.CommandId)
if err != nil {
c.Err = err
return
@@ -96,7 +96,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
@@ -115,7 +115,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- cmd, err := app.GetCommand(c.Params.CommandId)
+ cmd, err := c.App.GetCommand(c.Params.CommandId)
if err != nil {
c.Err = err
return
@@ -133,7 +133,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
@@ -164,7 +164,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS)
return
}
- commands, err = app.ListTeamCommands(teamId)
+ commands, err = c.App.ListTeamCommands(teamId)
if err != nil {
c.Err = err
return
@@ -172,13 +172,13 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
} else {
//User with no permission should see only system commands
if !app.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
- commands, err = app.ListAutocompleteCommands(teamId, c.T)
+ commands, err = c.App.ListAutocompleteCommands(teamId, c.T)
if err != nil {
c.Err = err
return
}
} else {
- commands, err = app.ListAllCommands(teamId, c.T)
+ commands, err = c.App.ListAllCommands(teamId, c.T)
if err != nil {
c.Err = err
return
@@ -201,12 +201,12 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- 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
}
- channel, err := app.GetChannel(commandArgs.ChannelId)
+ channel, err := c.App.GetChannel(commandArgs.ChannelId)
if err != nil {
c.Err = err
return
@@ -224,7 +224,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
@@ -244,7 +244,7 @@ func listAutocompleteCommands(c *Context, w http.ResponseWriter, r *http.Request
return
}
- commands, err := app.ListAutocompleteCommands(c.Params.TeamId, c.T)
+ commands, err := c.App.ListAutocompleteCommands(c.Params.TeamId, c.T)
if err != nil {
c.Err = err
return
@@ -260,7 +260,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
}
c.LogAudit("attempt")
- cmd, err := app.GetCommand(c.Params.CommandId)
+ cmd, err := c.App.GetCommand(c.Params.CommandId)
if err != nil {
c.Err = err
return
@@ -278,7 +278,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
diff --git a/api4/command_help_test.go b/api4/command_help_test.go
index cb0f1b634..5178370e5 100644
--- a/api4/command_help_test.go
+++ b/api4/command_help_test.go
@@ -4,9 +4,10 @@
package api4
import (
+ "testing"
+
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
- "testing"
)
func TestHelpCommand(t *testing.T) {
diff --git a/api4/command_test.go b/api4/command_test.go
index 3c61f82b1..71db0456a 100644
--- a/api4/command_test.go
+++ b/api4/command_test.go
@@ -7,7 +7,6 @@ import (
"strings"
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
@@ -82,7 +81,7 @@ func TestUpdateCommand(t *testing.T) {
Trigger: "trigger1",
}
- cmd1, _ = app.CreateCommand(cmd1)
+ cmd1, _ = th.App.CreateCommand(cmd1)
cmd2 := &model.Command{
CreatorId: GenerateTestId(),
@@ -168,7 +167,7 @@ func TestDeleteCommand(t *testing.T) {
Trigger: "trigger1",
}
- rcmd1, _ := app.CreateCommand(cmd1)
+ rcmd1, _ := th.App.CreateCommand(cmd1)
ok, resp := Client.DeleteCommand(rcmd1.Id)
CheckNoError(t, resp)
@@ -177,7 +176,7 @@ func TestDeleteCommand(t *testing.T) {
t.Fatal("should have returned true")
}
- rcmd1, _ = app.GetCommand(rcmd1.Id)
+ rcmd1, _ = th.App.GetCommand(rcmd1.Id)
if rcmd1 != nil {
t.Fatal("should be nil")
}
@@ -200,7 +199,7 @@ func TestDeleteCommand(t *testing.T) {
Trigger: "trigger2",
}
- rcmd2, _ := app.CreateCommand(cmd2)
+ rcmd2, _ := th.App.CreateCommand(cmd2)
_, resp = th.Client.DeleteCommand(rcmd2.Id)
CheckForbiddenStatus(t, resp)
@@ -405,7 +404,7 @@ func TestExecuteCommand(t *testing.T) {
Trigger: "postcommand",
}
- if _, err := app.CreateCommand(postCmd); err != nil {
+ if _, err := th.App.CreateCommand(postCmd); err != nil {
t.Fatal("failed to create post command")
}
@@ -416,7 +415,7 @@ func TestExecuteCommand(t *testing.T) {
t.Fatal("command response should have returned")
}
- posts, err := app.GetPostsPage(channel.Id, 0, 10)
+ posts, err := th.App.GetPostsPage(channel.Id, 0, 10)
if err != nil || posts == nil || len(posts.Order) != 3 {
t.Fatal("Test command failed to send")
}
@@ -441,7 +440,7 @@ func TestExecuteCommand(t *testing.T) {
Trigger: "getcommand",
}
- if _, err := app.CreateCommand(getCmd); err != nil {
+ if _, err := th.App.CreateCommand(getCmd); err != nil {
t.Fatal("failed to create get command")
}
@@ -452,7 +451,7 @@ func TestExecuteCommand(t *testing.T) {
t.Fatal("command response should have returned")
}
- posts, err = app.GetPostsPage(channel.Id, 0, 10)
+ posts, err = th.App.GetPostsPage(channel.Id, 0, 10)
if err != nil || posts == nil || len(posts.Order) != 4 {
t.Fatal("Test command failed to send")
}
diff --git a/api4/compliance.go b/api4/compliance.go
index 733abeecf..45f6460c8 100644
--- a/api4/compliance.go
+++ b/api4/compliance.go
@@ -37,7 +37,7 @@ func createComplianceReport(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
@@ -54,7 +54,7 @@ func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- crs, err := app.GetComplianceReports(c.Params.Page, c.Params.PerPage)
+ crs, err := c.App.GetComplianceReports(c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
return
@@ -74,7 +74,7 @@ func getComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- job, err := app.GetComplianceReport(c.Params.ReportId)
+ job, err := c.App.GetComplianceReport(c.Params.ReportId)
if err != nil {
c.Err = err
return
@@ -94,7 +94,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return
}
- job, err := app.GetComplianceReport(c.Params.ReportId)
+ job, err := c.App.GetComplianceReport(c.Params.ReportId)
if err != nil {
c.Err = err
return
diff --git a/api4/context.go b/api4/context.go
index 2c0e54ea0..f8768b11e 100644
--- a/api4/context.go
+++ b/api4/context.go
@@ -20,6 +20,7 @@ import (
)
type Context struct {
+ App *app.App
Session model.Session
Params *ApiParams
Err *model.AppError
@@ -87,6 +88,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
l4g.Debug("%v - %v", r.Method, r.URL.Path)
c := &Context{}
+ c.App = app.Global()
c.T, _ = utils.GetTranslationsAndLocale(w, r)
c.RequestId = model.NewId()
c.IpAddress = utils.GetIpAddress(r)
@@ -138,7 +140,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())
@@ -199,7 +201,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)
}
}
@@ -211,7 +213,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)
}
}
@@ -259,7 +261,7 @@ func (c *Context) MfaRequired() {
return
}
- if user, err := app.GetUser(c.Session.UserId); err != nil {
+ if user, err := app.Global().GetUser(c.Session.UserId); err != nil {
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "MfaRequired", http.StatusUnauthorized)
return
} else {
diff --git a/api4/emoji.go b/api4/emoji.go
index 11801169d..35aea5b0d 100644
--- a/api4/emoji.go
+++ b/api4/emoji.go
@@ -66,7 +66,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- newEmoji, err := app.CreateEmoji(c.Session.UserId, emoji, m)
+ newEmoji, err := c.App.CreateEmoji(c.Session.UserId, emoji, m)
if err != nil {
c.Err = err
return
@@ -81,7 +81,7 @@ func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- listEmoji, err := app.GetEmojiList(c.Params.Page, c.Params.PerPage)
+ listEmoji, err := c.App.GetEmojiList(c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
return
@@ -96,7 +96,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- emoji, err := app.GetEmoji(c.Params.EmojiId)
+ emoji, err := c.App.GetEmoji(c.Params.EmojiId)
if err != nil {
c.Err = err
return
@@ -107,7 +107,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
@@ -127,7 +127,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- emoji, err := app.GetEmoji(c.Params.EmojiId)
+ emoji, err := c.App.GetEmoji(c.Params.EmojiId)
if err != nil {
c.Err = err
return
@@ -152,7 +152,7 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- image, imageType, err := app.GetEmojiImage(c.Params.EmojiId)
+ image, imageType, err := c.App.GetEmojiImage(c.Params.EmojiId)
if err != nil {
c.Err = err
return
diff --git a/api4/file.go b/api4/file.go
index ab71b998b..b1a77b567 100644
--- a/api4/file.go
+++ b/api4/file.go
@@ -86,12 +86,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(FILE_TEAM_ID, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"])
+ resStruct, err := c.App.UploadFiles(FILE_TEAM_ID, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"])
if err != nil {
c.Err = err
return
@@ -112,13 +112,13 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
forceDownload = false
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
}
- if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
+ if info.CreatorId != c.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -148,13 +148,13 @@ func getFileThumbnail(c *Context, w http.ResponseWriter, r *http.Request) {
forceDownload = false
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
}
- if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
+ if info.CreatorId != c.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -184,13 +184,13 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
}
- if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
+ if info.CreatorId != c.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -217,13 +217,13 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
forceDownload = false
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
}
- if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
+ if info.CreatorId != c.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -248,13 +248,13 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
}
- if info.CreatorId != c.Session.UserId && !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
+ if info.CreatorId != c.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -274,7 +274,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- info, err := app.GetFileInfo(c.Params.FileId)
+ info, err := c.App.GetFileInfo(c.Params.FileId)
if err != nil {
c.Err = err
return
diff --git a/api4/file_test.go b/api4/file_test.go
index 04c0a8569..f08597047 100644
--- a/api4/file_test.go
+++ b/api4/file_test.go
@@ -51,7 +51,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)
@@ -317,7 +317,7 @@ func TestGetFileLink(t *testing.T) {
CheckBadRequestStatus(t, resp)
// 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
_, resp = Client.GetFileLink(fileId)
@@ -352,7 +352,7 @@ func TestGetFileLink(t *testing.T) {
_, resp = th.SystemAdminClient.GetFileLink(fileId)
CheckNoError(t, resp)
- if result := <-app.Srv.Store.FileInfo().Get(fileId); result.Err != nil {
+ if result := <-th.App.Srv.Store.FileInfo().Get(fileId); result.Err != nil {
t.Fatal(result.Err)
} else {
cleanupTestFile(result.Data.(*model.FileInfo))
@@ -508,9 +508,9 @@ 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))
- result := <-app.Srv.Store.FileInfo().Get(fileId)
+ result := <-th.App.Srv.Store.FileInfo().Get(fileId)
info := result.Data.(*model.FileInfo)
link := app.GeneratePublicLink(Client.Url, info)
@@ -543,7 +543,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)
}
diff --git a/api4/job.go b/api4/job.go
index 941e5d543..9c4b64ab1 100644
--- a/api4/job.go
+++ b/api4/job.go
@@ -32,7 +32,7 @@ func getJob(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if job, err := app.GetJob(c.Params.JobId); err != nil {
+ if job, err := c.App.GetJob(c.Params.JobId); err != nil {
c.Err = err
return
} else {
@@ -71,7 +71,7 @@ func getJobs(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if jobs, err := app.GetJobsPage(c.Params.Page, c.Params.PerPage); err != nil {
+ if jobs, err := c.App.GetJobsPage(c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -90,7 +90,7 @@ func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if jobs, err := app.GetJobsByTypePage(c.Params.JobType, c.Params.Page, c.Params.PerPage); err != nil {
+ if jobs, err := c.App.GetJobsByTypePage(c.Params.JobType, c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
diff --git a/api4/job_test.go b/api4/job_test.go
index 511386810..50ce0bef6 100644
--- a/api4/job_test.go
+++ b/api4/job_test.go
@@ -7,7 +7,6 @@ import (
"strings"
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
)
@@ -26,7 +25,7 @@ func TestCreateJob(t *testing.T) {
received, resp := th.SystemAdminClient.CreateJob(job)
CheckNoError(t, resp)
- defer app.Srv.Store.Job().Delete(received.Id)
+ defer th.App.Srv.Store.Job().Delete(received.Id)
job = &model.Job{
Type: model.NewId(),
@@ -47,11 +46,11 @@ func TestGetJob(t *testing.T) {
Id: model.NewId(),
Status: model.JOB_STATUS_PENDING,
}
- if result := <-app.Srv.Store.Job().Save(job); result.Err != nil {
+ if result := <-th.App.Srv.Store.Job().Save(job); result.Err != nil {
t.Fatal(result.Err)
}
- defer app.Srv.Store.Job().Delete(job.Id)
+ defer th.App.Srv.Store.Job().Delete(job.Id)
received, resp := th.SystemAdminClient.GetJob(job.Id)
CheckNoError(t, resp)
@@ -95,8 +94,8 @@ func TestGetJobs(t *testing.T) {
}
for _, job := range jobs {
- store.Must(app.Srv.Store.Job().Save(job))
- defer app.Srv.Store.Job().Delete(job.Id)
+ store.Must(th.App.Srv.Store.Job().Save(job))
+ defer th.App.Srv.Store.Job().Delete(job.Id)
}
received, resp := th.SystemAdminClient.GetJobs(0, 2)
@@ -151,8 +150,8 @@ func TestGetJobsByType(t *testing.T) {
}
for _, job := range jobs {
- store.Must(app.Srv.Store.Job().Save(job))
- defer app.Srv.Store.Job().Delete(job.Id)
+ store.Must(th.App.Srv.Store.Job().Save(job))
+ defer th.App.Srv.Store.Job().Delete(job.Id)
}
received, resp := th.SystemAdminClient.GetJobsByType(jobType, 0, 2)
@@ -208,8 +207,8 @@ func TestCancelJob(t *testing.T) {
}
for _, job := range jobs {
- store.Must(app.Srv.Store.Job().Save(job))
- defer app.Srv.Store.Job().Delete(job.Id)
+ store.Must(th.App.Srv.Store.Job().Save(job))
+ defer th.App.Srv.Store.Job().Delete(job.Id)
}
_, resp := th.Client.CancelJob(jobs[0].Id)
diff --git a/api4/oauth.go b/api4/oauth.go
index ae5035fdc..0cd0f5ab9 100644
--- a/api4/oauth.go
+++ b/api4/oauth.go
@@ -59,7 +59,7 @@ func createOAuthApp(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
return
@@ -79,9 +79,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(c.Params.Page, c.Params.PerPage)
+ apps, err = c.App.GetOAuthApps(c.Params.Page, c.Params.PerPage)
} else if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_OAUTH) {
- apps, err = app.GetOAuthAppsByCreator(c.Session.UserId, c.Params.Page, c.Params.PerPage)
+ apps, err = c.App.GetOAuthAppsByCreator(c.Session.UserId, c.Params.Page, c.Params.PerPage)
} else {
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
return
@@ -106,7 +106,7 @@ func getOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oauthApp, err := app.GetOAuthApp(c.Params.AppId)
+ oauthApp, err := c.App.GetOAuthApp(c.Params.AppId)
if err != nil {
c.Err = err
return
@@ -126,7 +126,7 @@ func getOAuthAppInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oauthApp, err := app.GetOAuthApp(c.Params.AppId)
+ oauthApp, err := c.App.GetOAuthApp(c.Params.AppId)
if err != nil {
c.Err = err
return
@@ -149,7 +149,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oauthApp, err := app.GetOAuthApp(c.Params.AppId)
+ oauthApp, err := c.App.GetOAuthApp(c.Params.AppId)
if err != nil {
c.Err = err
return
@@ -160,7 +160,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err = app.DeleteOAuthApp(oauthApp.Id)
+ err = c.App.DeleteOAuthApp(oauthApp.Id)
if err != nil {
c.Err = err
return
@@ -181,7 +181,7 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
return
}
- oauthApp, err := app.GetOAuthApp(c.Params.AppId)
+ oauthApp, err := c.App.GetOAuthApp(c.Params.AppId)
if err != nil {
c.Err = err
return
@@ -192,7 +192,7 @@ func regenerateOAuthAppSecret(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
@@ -213,7 +213,7 @@ func getAuthorizedOAuthApps(c *Context, w http.ResponseWriter, r *http.Request)
return
}
- apps, err := app.GetAuthorizedAppsForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
+ apps, err := c.App.GetAuthorizedAppsForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
return
@@ -235,7 +235,7 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- redirectUrl, err := app.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
+ redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
if err != nil {
c.Err = err
@@ -256,7 +256,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err := app.DeauthorizeOAuthAppForUser(c.Session.UserId, clientId)
+ err := c.App.DeauthorizeOAuthAppForUser(c.Session.UserId, clientId)
if err != nil {
c.Err = err
return
@@ -286,7 +286,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oauthApp, err := app.GetOAuthApp(authRequest.ClientId)
+ oauthApp, err := c.App.GetOAuthApp(authRequest.ClientId)
if err != nil {
utils.RenderWebError(err, w, r)
return
@@ -300,7 +300,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
isAuthorized := false
- if _, err := app.GetPreferenceByCategoryAndNameForUser(c.Session.UserId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, authRequest.ClientId); err == nil {
+ if _, err := c.App.GetPreferenceByCategoryAndNameForUser(c.Session.UserId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, authRequest.ClientId); err == nil {
// when we support scopes we should check if the scopes match
isAuthorized = true
}
@@ -308,7 +308,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
// Automatically allow if the app is trusted
if oauthApp.IsTrusted || isAuthorized {
authRequest.ResponseType = model.AUTHCODE_RESPONSE_TYPE
- redirectUrl, err := app.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
+ redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
if err != nil {
utils.RenderWebError(err, w, r)
@@ -367,7 +367,7 @@ func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- accessRsp, err := app.GetOAuthAccessToken(clientId, grantType, redirectUri, code, secret, refreshToken)
+ accessRsp, err := c.App.GetOAuthAccessToken(clientId, grantType, redirectUri, code, secret, refreshToken)
if err != nil {
c.Err = err
return
@@ -400,7 +400,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
uri := c.GetSiteURLHeader() + "/signup/" + service + "/complete"
- body, teamId, props, err := app.AuthorizeOAuthUser(w, r, service, code, state, uri)
+ body, teamId, props, err := c.App.AuthorizeOAuthUser(w, r, service, code, state, uri)
action := ""
if props != nil {
@@ -418,7 +418,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- user, err := app.CompleteOAuth(service, body, teamId, props)
+ user, err := c.App.CompleteOAuth(service, body, teamId, props)
if err != nil {
err.Translate(c.T)
l4g.Error(err.Error())
@@ -437,7 +437,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
redirectUrl = app.GetProtocol(r) + "://" + r.Host + "/claim?email=" + url.QueryEscape(props["email"])
} else {
- session, err := app.DoLogin(w, r, user, "")
+ session, err := c.App.DoLogin(w, r, user, "")
if err != nil {
err.Translate(c.T)
c.Err = err
@@ -469,13 +469,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, c.Params.Service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
+ if authUrl, err := c.App.GetOAuthLoginEndpoint(w, r, c.Params.Service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
c.Err = err
return
} else {
@@ -489,13 +489,13 @@ func mobileLoginWithOAuth(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.GetOAuthLoginEndpoint(w, r, c.Params.Service, teamId, model.OAUTH_ACTION_MOBILE, "", ""); err != nil {
+ if authUrl, err := c.App.GetOAuthLoginEndpoint(w, r, c.Params.Service, teamId, model.OAUTH_ACTION_MOBILE, "", ""); err != nil {
c.Err = err
return
} else {
@@ -514,13 +514,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, c.Params.Service, teamId); err != nil {
+ if authUrl, err := c.App.GetOAuthSignupEndpoint(w, r, c.Params.Service, teamId); err != nil {
c.Err = err
return
} else {
diff --git a/api4/plugin.go b/api4/plugin.go
index 109695174..7c7b595ed 100644
--- a/api4/plugin.go
+++ b/api4/plugin.go
@@ -63,7 +63,7 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
- manifest, unpackErr := app.UnpackAndActivatePlugin(file)
+ manifest, unpackErr := c.App.UnpackAndActivatePlugin(file)
if unpackErr != nil {
c.Err = unpackErr
@@ -85,7 +85,7 @@ func getPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- manifests, err := app.GetActivePluginManifests()
+ manifests, err := c.App.GetActivePluginManifests()
if err != nil {
c.Err = err
return
@@ -110,7 +110,7 @@ func removePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err := app.RemovePlugin(c.Params.PluginId)
+ err := c.App.RemovePlugin(c.Params.PluginId)
if err != nil {
c.Err = err
return
diff --git a/api4/plugin_test.go b/api4/plugin_test.go
index c1d6c987c..caaeeef6b 100644
--- a/api4/plugin_test.go
+++ b/api4/plugin_test.go
@@ -9,7 +9,6 @@ import (
"os"
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -30,7 +29,7 @@ func TestPlugin(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
- app.StartupPlugins(pluginDir, webappDir)
+ th.App.StartupPlugins(pluginDir, webappDir)
enablePlugins := *utils.Cfg.PluginSettings.Enable
defer func() {
@@ -111,5 +110,5 @@ func TestPlugin(t *testing.T) {
_, resp = th.SystemAdminClient.RemovePlugin("bad.id")
CheckNotFoundStatus(t, resp)
- app.Srv.PluginEnv = nil
+ th.App.Srv.PluginEnv = nil
}
diff --git a/api4/post.go b/api4/post.go
index ea23e098b..eaa910502 100644
--- a/api4/post.go
+++ b/api4/post.go
@@ -42,9 +42,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
@@ -60,13 +60,13 @@ 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
}
- app.SetStatusOnline(c.Session.UserId, c.Session.Id, false)
+ c.App.SetStatusOnline(c.Session.UserId, c.Session.Id, false)
w.WriteHeader(http.StatusCreated)
w.Write([]byte(rp.ToJson()))
@@ -93,7 +93,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -103,31 +103,31 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
etag := ""
if since > 0 {
- list, err = app.GetPostsSince(c.Params.ChannelId, since)
+ list, err = c.App.GetPostsSince(c.Params.ChannelId, since)
} else if len(afterPost) > 0 {
- etag = app.GetPostsEtag(c.Params.ChannelId)
+ etag = c.App.GetPostsEtag(c.Params.ChannelId)
if HandleEtag(etag, "Get Posts After", w, r) {
return
}
- list, err = app.GetPostsAfterPost(c.Params.ChannelId, afterPost, c.Params.Page, c.Params.PerPage)
+ list, err = c.App.GetPostsAfterPost(c.Params.ChannelId, afterPost, c.Params.Page, c.Params.PerPage)
} else if len(beforePost) > 0 {
- etag = app.GetPostsEtag(c.Params.ChannelId)
+ etag = c.App.GetPostsEtag(c.Params.ChannelId)
if HandleEtag(etag, "Get Posts Before", w, r) {
return
}
- list, err = app.GetPostsBeforePost(c.Params.ChannelId, beforePost, c.Params.Page, c.Params.PerPage)
+ list, err = c.App.GetPostsBeforePost(c.Params.ChannelId, beforePost, c.Params.Page, c.Params.PerPage)
} else {
- etag = app.GetPostsEtag(c.Params.ChannelId)
+ etag = c.App.GetPostsEtag(c.Params.ChannelId)
if HandleEtag(etag, "Get Posts", w, r) {
return
}
- list, err = app.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage)
+ list, err = c.App.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage)
}
if err != nil {
@@ -159,11 +159,11 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
var err *model.AppError
if len(channelId) > 0 {
- posts, err = app.GetFlaggedPostsForChannel(c.Params.UserId, channelId, c.Params.Page, c.Params.PerPage)
+ posts, err = c.App.GetFlaggedPostsForChannel(c.Params.UserId, channelId, c.Params.Page, c.Params.PerPage)
} else if len(teamId) > 0 {
- posts, err = app.GetFlaggedPostsForTeam(c.Params.UserId, teamId, c.Params.Page, c.Params.PerPage)
+ posts, err = c.App.GetFlaggedPostsForTeam(c.Params.UserId, teamId, c.Params.Page, c.Params.PerPage)
} else {
- posts, err = app.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage)
+ posts, err = c.App.GetFlaggedPosts(c.Params.UserId, c.Params.Page, c.Params.PerPage)
}
if err != nil {
@@ -182,18 +182,18 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
var post *model.Post
var err *model.AppError
- if post, err = app.GetSinglePost(c.Params.PostId); err != nil {
+ if post, err = c.App.GetSinglePost(c.Params.PostId); err != nil {
c.Err = err
return
}
var channel *model.Channel
- if channel, err = app.GetChannel(post.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(post.ChannelId); err != nil {
c.Err = err
return
}
- if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
if channel.Type == model.CHANNEL_OPEN {
if !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
@@ -219,12 +219,12 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_DELETE_OTHERS_POSTS) {
+ if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_DELETE_OTHERS_POSTS) {
c.SetPermissionError(model.PERMISSION_DELETE_OTHERS_POSTS)
return
}
- if _, err := app.DeletePost(c.Params.PostId); err != nil {
+ if _, err := c.App.DeletePost(c.Params.PostId); err != nil {
c.Err = err
return
}
@@ -240,7 +240,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
var list *model.PostList
var err *model.AppError
- if list, err = app.GetPostThread(c.Params.PostId); err != nil {
+ if list, err = c.App.GetPostThread(c.Params.PostId); err != nil {
c.Err = err
return
}
@@ -254,12 +254,12 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
}
var channel *model.Channel
- if channel, err = app.GetChannel(post.ChannelId); err != nil {
+ if channel, err = c.App.GetChannel(post.ChannelId); err != nil {
c.Err = err
return
}
- if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
if channel.Type == model.CHANNEL_OPEN {
if !app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
@@ -299,7 +299,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
isOrSearch, _ := props["is_or_search"].(bool)
- posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
+ posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
if err != nil {
c.Err = err
return
@@ -322,19 +322,19 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
c.SetPermissionError(model.PERMISSION_EDIT_POST)
return
}
- if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
+ if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
return
}
post.Id = c.Params.PostId
- rpost, err := app.UpdatePost(post, false)
+ rpost, err := c.App.UpdatePost(post, false)
if err != nil {
c.Err = err
return
@@ -356,17 +356,17 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
c.SetPermissionError(model.PERMISSION_EDIT_POST)
return
}
- if !app.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
+ if !c.App.SessionHasPermissionToPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
return
}
- patchedPost, err := app.PatchPost(c.Params.PostId, post)
+ patchedPost, err := c.App.PatchPost(c.Params.PostId, post)
if err != nil {
c.Err = err
return
@@ -381,7 +381,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -390,7 +390,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
patch.IsPinned = new(bool)
*patch.IsPinned = isPinned
- _, err := app.PatchPost(c.Params.PostId, patch)
+ _, err := c.App.PatchPost(c.Params.PostId, patch)
if err != nil {
c.Err = err
return
@@ -413,12 +413,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if infos, err := app.GetFileInfosForPost(c.Params.PostId, false); err != nil {
+ if infos, err := c.App.GetFileInfosForPost(c.Params.PostId, false); err != nil {
c.Err = err
return
} else if HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) {
@@ -436,12 +436,12 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if err := app.DoPostAction(c.Params.PostId, c.Params.ActionId, c.Session.UserId); err != nil {
+ if err := c.App.DoPostAction(c.Params.PostId, c.Params.ActionId, c.Session.UserId); err != nil {
c.Err = err
return
}
diff --git a/api4/post_test.go b/api4/post_test.go
index c09cb77d1..36ebf26ab 100644
--- a/api4/post_test.go
+++ b/api4/post_test.go
@@ -277,8 +277,8 @@ func TestCreatePostPublic(t *testing.T) {
_, resp = Client.CreatePost(post)
CheckForbiddenStatus(t, resp)
- app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL_PUBLIC.Id)
- app.InvalidateAllCaches()
+ th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL_PUBLIC.Id)
+ th.App.InvalidateAllCaches()
Client.Login(user.Email, user.Password)
@@ -289,10 +289,10 @@ func TestCreatePostPublic(t *testing.T) {
_, resp = Client.CreatePost(post)
CheckForbiddenStatus(t, resp)
- app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id)
- app.JoinUserToTeam(th.BasicTeam, ruser, "")
- app.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL_PUBLIC.Id)
- app.InvalidateAllCaches()
+ th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id)
+ th.App.JoinUserToTeam(th.BasicTeam, ruser, "")
+ th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL_PUBLIC.Id)
+ th.App.InvalidateAllCaches()
Client.Login(user.Email, user.Password)
@@ -314,7 +314,7 @@ func TestCreatePostAll(t *testing.T) {
user := model.User{Email: GenerateTestEmail(), Nickname: "Joram Wilander", Password: "hello1", Username: GenerateTestUsername(), Roles: model.ROLE_SYSTEM_USER.Id}
- directChannel, _ := app.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
+ directChannel, _ := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
ruser, resp := Client.CreateUser(&user)
CheckNoError(t, resp)
@@ -324,8 +324,8 @@ func TestCreatePostAll(t *testing.T) {
_, resp = Client.CreatePost(post)
CheckForbiddenStatus(t, resp)
- app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL.Id)
- app.InvalidateAllCaches()
+ th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_POST_ALL.Id)
+ th.App.InvalidateAllCaches()
Client.Login(user.Email, user.Password)
@@ -340,10 +340,10 @@ func TestCreatePostAll(t *testing.T) {
_, resp = Client.CreatePost(post)
CheckNoError(t, resp)
- app.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id)
- app.JoinUserToTeam(th.BasicTeam, ruser, "")
- app.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL.Id)
- app.InvalidateAllCaches()
+ th.App.UpdateUserRoles(ruser.Id, model.ROLE_SYSTEM_USER.Id)
+ th.App.JoinUserToTeam(th.BasicTeam, ruser, "")
+ th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.ROLE_TEAM_USER.Id+" "+model.ROLE_TEAM_POST_ALL.Id)
+ th.App.InvalidateAllCaches()
Client.Login(user.Email, user.Password)
@@ -557,7 +557,7 @@ func TestPinPost(t *testing.T) {
t.Fatal("should have passed")
}
- if rpost, err := app.GetSinglePost(post.Id); err != nil && rpost.IsPinned != true {
+ if rpost, err := th.App.GetSinglePost(post.Id); err != nil && rpost.IsPinned != true {
t.Fatal("failed to pin post")
}
@@ -592,7 +592,7 @@ func TestUnpinPost(t *testing.T) {
t.Fatal("should have passed")
}
- if rpost, err := app.GetSinglePost(pinnedPost.Id); err != nil && rpost.IsPinned != false {
+ if rpost, err := th.App.GetSinglePost(pinnedPost.Id); err != nil && rpost.IsPinned != false {
t.Fatal("failed to pin post")
}
@@ -1297,8 +1297,8 @@ func TestSearchPostsFromUser(t *testing.T) {
th.LoginTeamAdmin()
user := th.CreateUser()
LinkUserToTeam(user, th.BasicTeam)
- app.AddUserToChannel(user, th.BasicChannel)
- app.AddUserToChannel(user, th.BasicChannel2)
+ th.App.AddUserToChannel(user, th.BasicChannel)
+ th.App.AddUserToChannel(user, th.BasicChannel2)
message := "sgtitlereview with space"
_ = th.CreateMessagePost(message)
diff --git a/api4/preference.go b/api4/preference.go
index 371f8054b..355c06ec5 100644
--- a/api4/preference.go
+++ b/api4/preference.go
@@ -33,7 +33,7 @@ func getPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if preferences, err := app.GetPreferencesForUser(c.Params.UserId); err != nil {
+ if preferences, err := c.App.GetPreferencesForUser(c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -53,7 +53,7 @@ func getPreferencesByCategory(c *Context, w http.ResponseWriter, r *http.Request
return
}
- if preferences, err := app.GetPreferenceByCategoryForUser(c.Params.UserId, c.Params.Category); err != nil {
+ if preferences, err := c.App.GetPreferenceByCategoryForUser(c.Params.UserId, c.Params.Category); err != nil {
c.Err = err
return
} else {
@@ -73,7 +73,7 @@ func getPreferenceByCategoryAndName(c *Context, w http.ResponseWriter, r *http.R
return
}
- if preferences, err := app.GetPreferenceByCategoryAndNameForUser(c.Params.UserId, c.Params.Category, c.Params.PreferenceName); err != nil {
+ if preferences, err := c.App.GetPreferenceByCategoryAndNameForUser(c.Params.UserId, c.Params.Category, c.Params.PreferenceName); err != nil {
c.Err = err
return
} else {
@@ -99,7 +99,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.UpdatePreferences(c.Params.UserId, preferences); err != nil {
+ if err := c.App.UpdatePreferences(c.Params.UserId, preferences); err != nil {
c.Err = err
return
}
@@ -124,7 +124,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.DeletePreferences(c.Params.UserId, preferences); err != nil {
+ if err := c.App.DeletePreferences(c.Params.UserId, preferences); err != nil {
c.Err = err
return
}
diff --git a/api4/reaction.go b/api4/reaction.go
index 7f161d7fe..41f794639 100644
--- a/api4/reaction.go
+++ b/api4/reaction.go
@@ -37,12 +37,12 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, reaction.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, reaction.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if reaction, err := app.SaveReactionForPost(reaction); err != nil {
+ if reaction, err := c.App.SaveReactionForPost(reaction); err != nil {
c.Err = err
return
} else {
@@ -57,12 +57,12 @@ func getReactions(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- if reactions, err := app.GetReactionsForPost(c.Params.PostId); err != nil {
+ if reactions, err := c.App.GetReactionsForPost(c.Params.PostId); err != nil {
c.Err = err
return
} else {
@@ -87,7 +87,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, 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) {
EmojiName: c.Params.EmojiName,
}
- err := app.DeleteReactionForPost(reaction)
+ err := c.App.DeleteReactionForPost(reaction)
if err != nil {
c.Err = err
return
diff --git a/api4/reaction_test.go b/api4/reaction_test.go
index c973c9a13..ca8335206 100644
--- a/api4/reaction_test.go
+++ b/api4/reaction_test.go
@@ -9,7 +9,6 @@ import (
"reflect"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
)
@@ -45,7 +44,7 @@ func TestSaveReaction(t *testing.T) {
t.Fatal("CreateAt should exist")
}
- if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
t.Fatal("didn't save reaction correctly")
}
@@ -53,7 +52,7 @@ func TestSaveReaction(t *testing.T) {
rr, resp = Client.SaveReaction(reaction)
CheckNoError(t, resp)
- if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
t.Fatal("should have not save duplicated reaction")
}
@@ -66,7 +65,7 @@ func TestSaveReaction(t *testing.T) {
t.Fatal("EmojiName did not match")
}
- if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 2 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil && len(reactions) != 2 {
t.Fatal("should have save multiple reactions")
}
@@ -80,7 +79,7 @@ func TestSaveReaction(t *testing.T) {
t.Fatal("EmojiName did not match")
}
- if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 3 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil && len(reactions) != 3 {
t.Fatal("should have save multiple reactions")
}
@@ -171,7 +170,7 @@ func TestGetReactions(t *testing.T) {
var reactions []*model.Reaction
for _, userReaction := range userReactions {
- if result := <-app.Srv.Store.Reaction().Save(userReaction); result.Err != nil {
+ if result := <-th.App.Srv.Store.Reaction().Save(userReaction); result.Err != nil {
t.Fatal(result.Err)
} else {
reactions = append(reactions, result.Data.(*model.Reaction))
@@ -222,8 +221,8 @@ func TestDeleteReaction(t *testing.T) {
EmojiName: "smile",
}
- app.SaveReactionForPost(r1)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 1 {
+ th.App.SaveReactionForPost(r1)
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 1 {
t.Fatal("didn't save reaction correctly")
}
@@ -234,7 +233,7 @@ func TestDeleteReaction(t *testing.T) {
t.Fatal("should have returned true")
}
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
t.Fatal("should have deleted reaction")
}
@@ -245,16 +244,16 @@ func TestDeleteReaction(t *testing.T) {
EmojiName: "smile-",
}
- app.SaveReactionForPost(r1)
- app.SaveReactionForPost(r2)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
+ th.App.SaveReactionForPost(r1)
+ th.App.SaveReactionForPost(r2)
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
t.Fatal("didn't save reactions correctly")
}
_, resp = Client.DeleteReaction(r2)
CheckNoError(t, resp)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 1 || *reactions[0] != *r1 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 1 || *reactions[0] != *r1 {
t.Fatal("should have deleted 1 reaction only")
}
@@ -265,15 +264,15 @@ func TestDeleteReaction(t *testing.T) {
EmojiName: "+1",
}
- app.SaveReactionForPost(r3)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
+ th.App.SaveReactionForPost(r3)
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
t.Fatal("didn't save reactions correctly")
}
_, resp = Client.DeleteReaction(r3)
CheckNoError(t, resp)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 1 || *reactions[0] != *r1 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 1 || *reactions[0] != *r1 {
t.Fatal("should have deleted 1 reaction only")
}
@@ -285,8 +284,8 @@ func TestDeleteReaction(t *testing.T) {
}
th.LoginBasic2()
- app.SaveReactionForPost(r4)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
+ th.App.SaveReactionForPost(r4)
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
t.Fatal("didn't save reaction correctly")
}
@@ -299,7 +298,7 @@ func TestDeleteReaction(t *testing.T) {
t.Fatal("should have returned false")
}
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 2 {
t.Fatal("should have not deleted a reaction")
}
@@ -346,7 +345,7 @@ func TestDeleteReaction(t *testing.T) {
_, resp = th.SystemAdminClient.DeleteReaction(r4)
CheckNoError(t, resp)
- if reactions, err := app.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
+ if reactions, err := th.App.GetReactionsForPost(postId); err != nil || len(reactions) != 0 {
t.Fatal("should have deleted both reactions")
}
}
diff --git a/api4/status.go b/api4/status.go
index 3a2c5c762..4e8b1852e 100644
--- a/api4/status.go
+++ b/api4/status.go
@@ -29,7 +29,7 @@ func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
// No permission check required
- if statusMap, err := app.GetUserStatusesByIds([]string{c.Params.UserId}); err != nil {
+ if statusMap, err := c.App.GetUserStatusesByIds([]string{c.Params.UserId}); err != nil {
c.Err = err
return
} else {
@@ -52,7 +52,7 @@ func getUserStatusesByIds(c *Context, w http.ResponseWriter, r *http.Request) {
// No permission check required
- if statusMap, err := app.GetUserStatusesByIds(userIds); err != nil {
+ if statusMap, err := c.App.GetUserStatusesByIds(userIds); err != nil {
c.Err = err
return
} else {
@@ -79,11 +79,11 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
switch status.Status {
case "online":
- app.SetStatusOnline(c.Params.UserId, "", true)
+ c.App.SetStatusOnline(c.Params.UserId, "", true)
case "offline":
- app.SetStatusOffline(c.Params.UserId, true)
+ c.App.SetStatusOffline(c.Params.UserId, true)
case "away":
- app.SetStatusAwayIfNeeded(c.Params.UserId, true)
+ c.App.SetStatusAwayIfNeeded(c.Params.UserId, true)
default:
c.SetInvalidParam("status")
return
diff --git a/api4/status_test.go b/api4/status_test.go
index c8277b3de..6d9b6c98e 100644
--- a/api4/status_test.go
+++ b/api4/status_test.go
@@ -3,7 +3,6 @@ package api4
import (
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
)
@@ -18,21 +17,21 @@ func TestGetUserStatus(t *testing.T) {
t.Fatal("Should return offline status")
}
- app.SetStatusOnline(th.BasicUser.Id, "", true)
+ th.App.SetStatusOnline(th.BasicUser.Id, "", true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "online" {
t.Fatal("Should return online status")
}
- app.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
+ th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "away" {
t.Fatal("Should return away status")
}
- app.SetStatusOffline(th.BasicUser.Id, true)
+ th.App.SetStatusOffline(th.BasicUser.Id, true)
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
CheckNoError(t, resp)
if userStatus.Status != "offline" {
@@ -70,8 +69,8 @@ func TestGetUsersStatusesByIds(t *testing.T) {
}
}
- app.SetStatusOnline(th.BasicUser.Id, "", true)
- app.SetStatusOnline(th.BasicUser2.Id, "", true)
+ th.App.SetStatusOnline(th.BasicUser.Id, "", true)
+ th.App.SetStatusOnline(th.BasicUser2.Id, "", true)
usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds)
CheckNoError(t, resp)
for _, userStatus := range usersStatuses {
@@ -80,8 +79,8 @@ func TestGetUsersStatusesByIds(t *testing.T) {
}
}
- app.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
- app.SetStatusAwayIfNeeded(th.BasicUser2.Id, true)
+ th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
+ th.App.SetStatusAwayIfNeeded(th.BasicUser2.Id, true)
usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds)
CheckNoError(t, resp)
for _, userStatus := range usersStatuses {
diff --git a/api4/system.go b/api4/system.go
index 8f98afedb..f92dd22f8 100644
--- a/api4/system.go
+++ b/api4/system.go
@@ -79,7 +79,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
@@ -144,7 +144,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- audits, err := app.GetAuditsPage("", c.Params.Page, c.Params.PerPage)
+ audits, err := c.App.GetAuditsPage("", c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
@@ -161,7 +161,7 @@ func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- app.RecycleDatabaseConnection()
+ c.App.RecycleDatabaseConnection()
ReturnStatusOK(w)
}
@@ -172,7 +172,7 @@ func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err := app.InvalidateAllCaches()
+ err := c.App.InvalidateAllCaches()
if err != nil {
c.Err = err
return
@@ -243,8 +243,8 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
respCfg[k] = v
}
- respCfg["NoAccounts"] = strconv.FormatBool(app.IsFirstUserAccount())
- respCfg["Plugins"] = app.GetPluginsForClientConfig()
+ respCfg["NoAccounts"] = strconv.FormatBool(c.App.IsFirstUserAccount())
+ respCfg["Plugins"] = c.App.GetPluginsForClientConfig()
w.Write([]byte(model.MapToJson(respCfg)))
}
@@ -318,7 +318,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 {
@@ -342,7 +342,7 @@ func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.RemoveLicense(); err != nil {
+ if err := c.App.RemoveLicense(); err != nil {
c.Err = err
return
}
@@ -364,7 +364,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- rows, err := app.GetAnalytics(name, teamId)
+ rows, err := c.App.GetAnalytics(name, teamId)
if err != nil {
c.Err = err
return
diff --git a/api4/team.go b/api4/team.go
index 656c4dbbc..5b0054bb8 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -65,7 +65,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
@@ -81,7 +81,7 @@ func getTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if team, err := app.GetTeam(c.Params.TeamId); err != nil {
+ if team, err := c.App.GetTeam(c.Params.TeamId); err != nil {
c.Err = err
return
} else {
@@ -101,7 +101,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if team, err := app.GetTeamByName(c.Params.TeamName); err != nil {
+ if team, err := c.App.GetTeamByName(c.Params.TeamName); err != nil {
c.Err = err
return
} else {
@@ -135,7 +135,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- updatedTeam, err := app.UpdateTeam(team)
+ updatedTeam, err := c.App.UpdateTeam(team)
if err != nil {
c.Err = err
@@ -163,7 +163,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- patchedTeam, err := app.PatchTeam(c.Params.TeamId, team)
+ patchedTeam, err := c.App.PatchTeam(c.Params.TeamId, team)
if err != nil {
c.Err = err
@@ -187,9 +187,9 @@ func deleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if c.Params.Permanent {
- err = app.PermanentDeleteTeamId(c.Params.TeamId)
+ err = c.App.PermanentDeleteTeamId(c.Params.TeamId)
} else {
- err = app.SoftDeleteTeam(c.Params.TeamId)
+ err = c.App.SoftDeleteTeam(c.Params.TeamId)
}
if err != nil {
@@ -211,7 +211,7 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if teams, err := app.GetTeamsForUser(c.Params.UserId); err != nil {
+ if teams, err := c.App.GetTeamsForUser(c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -233,7 +233,7 @@ func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
// optional team id to be excluded from the result
teamId := r.URL.Query().Get("exclude_team")
- unreadTeamsList, err := app.GetTeamsUnreadForUser(teamId, c.Params.UserId)
+ unreadTeamsList, err := c.App.GetTeamsUnreadForUser(teamId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -253,7 +253,7 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if team, err := app.GetTeamMember(c.Params.TeamId, c.Params.UserId); err != nil {
+ if team, err := c.App.GetTeamMember(c.Params.TeamId, c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -273,7 +273,7 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if members, err := app.GetTeamMembers(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
+ if members, err := c.App.GetTeamMembers(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -293,7 +293,7 @@ func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- members, err := app.GetTeamMembersForUser(c.Params.UserId)
+ members, err := c.App.GetTeamMembersForUser(c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -320,7 +320,7 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- members, err := app.GetTeamMembersByIds(c.Params.TeamId, userIds)
+ members, err := c.App.GetTeamMembersByIds(c.Params.TeamId, userIds)
if err != nil {
c.Err = err
return
@@ -352,7 +352,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- member, err = app.AddTeamMember(member.TeamId, member.UserId)
+ member, err = c.App.AddTeamMember(member.TeamId, member.UserId)
if err != nil {
c.Err = err
@@ -372,9 +372,9 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request)
var err *model.AppError
if len(hash) > 0 && len(data) > 0 {
- member, err = app.AddTeamMemberByHash(c.Session.UserId, hash, data)
+ member, err = c.App.AddTeamMemberByHash(c.Session.UserId, hash, data)
} else if len(inviteId) > 0 {
- member, err = app.AddTeamMemberByInviteId(inviteId, c.Session.UserId)
+ member, err = c.App.AddTeamMemberByInviteId(inviteId, c.Session.UserId)
} else {
err = model.NewAppError("addTeamMember", "api.team.add_user_to_team.missing_parameter.app_error", nil, "", http.StatusBadRequest)
}
@@ -422,7 +422,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- members, err = app.AddTeamMembers(c.Params.TeamId, userIds, c.Session.UserId)
+ members, err = c.App.AddTeamMembers(c.Params.TeamId, userIds, c.Session.UserId)
if err != nil {
c.Err = err
@@ -446,7 +446,7 @@ func removeTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if err := app.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId); err != nil {
+ if err := c.App.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId); err != nil {
c.Err = err
return
}
@@ -470,7 +470,7 @@ func getTeamUnread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- unreadTeam, err := app.GetTeamUnread(c.Params.TeamId, c.Params.UserId)
+ unreadTeam, err := c.App.GetTeamUnread(c.Params.TeamId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -490,7 +490,7 @@ func getTeamStats(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if stats, err := app.GetTeamStats(c.Params.TeamId); err != nil {
+ if stats, err := c.App.GetTeamStats(c.Params.TeamId); err != nil {
c.Err = err
return
} else {
@@ -518,7 +518,7 @@ func updateTeamMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if _, err := app.UpdateTeamMemberRoles(c.Params.TeamId, c.Params.UserId, newRoles); err != nil {
+ if _, err := c.App.UpdateTeamMemberRoles(c.Params.TeamId, c.Params.UserId, newRoles); err != nil {
c.Err = err
return
}
@@ -531,9 +531,9 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- teams, err = app.GetAllTeamsPage(c.Params.Page, c.Params.PerPage)
+ teams, err = c.App.GetAllTeamsPage(c.Params.Page, c.Params.PerPage)
} else {
- teams, err = app.GetAllOpenTeamsPage(c.Params.Page, c.Params.PerPage)
+ teams, err = c.App.GetAllOpenTeamsPage(c.Params.Page, c.Params.PerPage)
}
if err != nil {
@@ -560,9 +560,9 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- teams, err = app.SearchAllTeams(props.Term)
+ teams, err = c.App.SearchAllTeams(props.Term)
} else {
- teams, err = app.SearchOpenTeams(props.Term)
+ teams, err = c.App.SearchOpenTeams(props.Term)
}
if err != nil {
@@ -581,7 +581,7 @@ func teamExists(c *Context, w http.ResponseWriter, r *http.Request) {
resp := make(map[string]bool)
- if _, err := app.GetTeamByName(c.Params.TeamName); err != nil {
+ if _, err := c.App.GetTeamByName(c.Params.TeamName); err != nil {
resp["exists"] = false
} else {
resp["exists"] = true
@@ -646,7 +646,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.Params.TeamId); err != nil {
+ if err, log = c.App.SlackImport(fileData, fileSize, c.Params.TeamId); err != nil {
c.Err = err
c.Err.StatusCode = http.StatusBadRequest
}
@@ -683,7 +683,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err := app.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.Session.UserId)
+ err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.Session.UserId)
if err != nil {
c.Err = err
return
@@ -698,7 +698,7 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if team, err := app.GetTeamByInviteId(c.Params.InviteId); err != nil {
+ if team, err := c.App.GetTeamByInviteId(c.Params.InviteId); err != nil {
c.Err = err
return
} else {
diff --git a/api4/team_test.go b/api4/team_test.go
index 1f9772113..22fbb8a6f 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -14,7 +14,6 @@ import (
"encoding/base64"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
@@ -346,7 +345,7 @@ func TestSoftDeleteTeam(t *testing.T) {
t.Fatal("should have returned true")
}
- rteam, err := app.GetTeam(team.Id)
+ rteam, err := th.App.GetTeam(team.Id)
if err != nil {
t.Fatal("should have returned archived team")
}
@@ -390,7 +389,7 @@ func TestPermanentDeleteTeam(t *testing.T) {
// The team is deleted in the background, its only soft deleted at this
// time
- rteam, err := app.GetTeam(team.Id)
+ rteam, err := th.App.GetTeam(team.Id)
if err != nil {
t.Fatal("should have returned archived team")
}
@@ -515,7 +514,7 @@ func TestSearchAllTeams(t *testing.T) {
oTeam := th.BasicTeam
oTeam.AllowOpenInvite = true
- updatedTeam, _ := app.UpdateTeam(oTeam)
+ updatedTeam, _ := th.App.UpdateTeam(oTeam)
oTeam.UpdateAt = updatedTeam.UpdateAt
pTeam := &model.Team{DisplayName: "PName", Name: GenerateTestTeamName(), Email: GenerateTestEmail(), Type: model.TEAM_INVITE}
@@ -803,7 +802,7 @@ func TestAddTeamMember(t *testing.T) {
team := th.BasicTeam
otherUser := th.CreateUser()
- if err := app.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser2.Id); err != nil {
+ if err := th.App.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser2.Id); err != nil {
t.Fatalf(err.Error())
}
@@ -887,7 +886,7 @@ func TestAddTeamMember(t *testing.T) {
// Update user to 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{}})
@@ -913,7 +912,7 @@ func TestAddTeamMember(t *testing.T) {
// Change permission level to All
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -1019,7 +1018,7 @@ func TestAddTeamMembers(t *testing.T) {
otherUser.Id,
}
- if err := app.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser2.Id); err != nil {
+ if err := th.App.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser2.Id); err != nil {
t.Fatalf(err.Error())
}
@@ -1101,7 +1100,7 @@ func TestAddTeamMembers(t *testing.T) {
// Update user to 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{}})
@@ -1127,7 +1126,7 @@ func TestAddTeamMembers(t *testing.T) {
// Change permission level to All
UpdateUserToNonTeamAdmin(th.BasicUser, th.BasicTeam)
- app.InvalidateAllCaches()
+ th.App.InvalidateAllCaches()
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_ALL
utils.SetIsLicensed(true)
utils.SetLicense(&model.License{Features: &model.Features{}})
@@ -1493,7 +1492,7 @@ func TestInviteUsersToTeam(t *testing.T) {
}()
utils.Cfg.TeamSettings.RestrictCreationToDomains = "@example.com"
- err := app.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id)
+ err := th.App.InviteNewUsersToTeam(emailList, th.BasicTeam.Id, th.BasicUser.Id)
if err == nil {
t.Fatal("Adding users with non-restricted domains was allowed")
diff --git a/api4/user.go b/api4/user.go
index 805ec4241..ec9663208 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -77,13 +77,13 @@ 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 if c.IsSystemAdmin() {
- ruser, err = app.CreateUserAsAdmin(user)
+ ruser, err = c.App.CreateUserAsAdmin(user)
} else {
- ruser, err = app.CreateUserFromSignup(user)
+ ruser, err = c.App.CreateUserFromSignup(user)
}
if err != nil {
@@ -106,7 +106,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
var user *model.User
var err *model.AppError
- if user, err = app.GetUser(c.Params.UserId); err != nil {
+ if user, err = c.App.GetUser(c.Params.UserId); err != nil {
c.Err = err
return
}
@@ -138,7 +138,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
var user *model.User
var err *model.AppError
- if user, err = app.GetUserByUsername(c.Params.Username); err != nil {
+ if user, err = c.App.GetUserByUsername(c.Params.Username); err != nil {
c.Err = err
return
}
@@ -166,7 +166,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
var user *model.User
var err *model.AppError
- if user, err = app.GetUserByEmail(c.Params.Email); err != nil {
+ if user, err = c.App.GetUserByEmail(c.Params.Email); err != nil {
c.Err = err
return
}
@@ -189,7 +189,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if users, err := app.GetUsersByIds([]string{c.Params.UserId}, c.IsSystemAdmin()); err != nil {
+ if users, err := c.App.GetUsersByIds([]string{c.Params.UserId}, c.IsSystemAdmin()); err != nil {
c.Err = err
return
} else {
@@ -263,7 +263,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
imageData := imageArray[0]
- if err := app.SetProfileImage(c.Params.UserId, imageData); err != nil {
+ if err := c.App.SetProfileImage(c.Params.UserId, imageData); err != nil {
c.Err = err
return
}
@@ -307,26 +307,26 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- profiles, err = app.GetUsersWithoutTeamPage(c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersWithoutTeamPage(c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else if len(notInChannelId) > 0 {
- if !app.SessionHasPermissionToChannel(c.Session, notInChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, notInChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- profiles, err = app.GetUsersNotInChannelPage(inTeamId, notInChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else if len(notInTeamId) > 0 {
if !app.SessionHasPermissionToTeam(c.Session, notInTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
- etag = app.GetUsersNotInTeamEtag(inTeamId)
+ etag = c.App.GetUsersNotInTeamEtag(inTeamId)
if HandleEtag(etag, "Get Users Not in Team", w, r) {
return
}
- profiles, err = app.GetUsersNotInTeamPage(notInTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else if len(inTeamId) > 0 {
if !app.SessionHasPermissionToTeam(c.Session, inTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
@@ -334,32 +334,32 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
if sort == "last_activity_at" {
- profiles, err = app.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else if sort == "create_at" {
- profiles, err = app.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else {
- etag = app.GetUsersInTeamEtag(inTeamId)
+ etag = c.App.GetUsersInTeamEtag(inTeamId)
if HandleEtag(etag, "Get Users in Team", w, r) {
return
}
- profiles, err = app.GetUsersInTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersInTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
}
} else if len(inChannelId) > 0 {
- if !app.SessionHasPermissionToChannel(c.Session, inChannelId, model.PERMISSION_READ_CHANNEL) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, inChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
- profiles, err = app.GetUsersInChannelPage(inChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersInChannelPage(inChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
} else {
// No permission check required
- etag = app.GetUsersEtag()
+ etag = c.App.GetUsersEtag()
if HandleEtag(etag, "Get Users", w, r) {
return
}
- profiles, err = app.GetUsersPage(c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
+ profiles, err = c.App.GetUsersPage(c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
}
if err != nil {
@@ -383,7 +383,7 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
// No permission check required
- if users, err := app.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil {
+ if users, err := c.App.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil {
c.Err = err
return
} else {
@@ -401,7 +401,7 @@ func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
// No permission check required
- if users, err := app.GetUsersByUsernames(usernames, c.IsSystemAdmin()); err != nil {
+ if users, err := c.App.GetUsersByUsernames(usernames, c.IsSystemAdmin()); err != nil {
c.Err = err
return
} else {
@@ -426,12 +426,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
}
@@ -462,7 +462,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 {
@@ -488,12 +488,12 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
}
if len(channelId) > 0 {
- 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
}
- result, _ := app.AutocompleteUsersInChannel(teamId, channelId, name, searchOptions, c.IsSystemAdmin())
+ result, _ := c.App.AutocompleteUsersInChannel(teamId, channelId, name, searchOptions, c.IsSystemAdmin())
autocomplete.Users = result.InChannel
autocomplete.OutOfChannel = result.OutOfChannel
} else if len(teamId) > 0 {
@@ -502,11 +502,11 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- result, _ := app.AutocompleteUsersInTeam(teamId, name, searchOptions, c.IsSystemAdmin())
+ result, _ := c.App.AutocompleteUsersInTeam(teamId, name, searchOptions, c.IsSystemAdmin())
autocomplete.Users = result.InTeam
} else {
// No permission check required
- result, _ := app.SearchUsersInTeam("", name, searchOptions, c.IsSystemAdmin())
+ result, _ := c.App.SearchUsersInTeam("", name, searchOptions, c.IsSystemAdmin())
autocomplete.Users = result
}
@@ -535,7 +535,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 {
@@ -561,7 +561,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if ruser, err := app.PatchUser(c.Params.UserId, patch, c.IsSystemAdmin()); err != nil {
+ if ruser, err := c.App.PatchUser(c.Params.UserId, patch, c.IsSystemAdmin()); err != nil {
c.Err = err
return
} else {
@@ -586,12 +586,12 @@ func deleteUser(c *Context, w http.ResponseWriter, r *http.Request) {
var user *model.User
var err *model.AppError
- if user, err = app.GetUser(userId); err != nil {
+ if user, err = c.App.GetUser(userId); err != nil {
c.Err = err
return
}
- if _, err := app.UpdateActive(user, false); err != nil {
+ if _, err := c.App.UpdateActive(user, false); err != nil {
c.Err = err
return
}
@@ -618,7 +618,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if _, err := app.UpdateUserRoles(c.Params.UserId, newRoles); err != nil {
+ if _, err := c.App.UpdateUserRoles(c.Params.UserId, newRoles); err != nil {
c.Err = err
return
} else {
@@ -650,7 +650,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if ruser, err := app.UpdateActiveNoLdap(c.Params.UserId, active); err != nil {
+ if ruser, err := c.App.UpdateActiveNoLdap(c.Params.UserId, active); err != nil {
c.Err = err
} else {
c.LogAuditWithUserId(ruser.Id, fmt.Sprintf("active=%v", active))
@@ -675,7 +675,7 @@ func checkUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if user, err := app.GetUserForLogin(loginId, false); err == nil {
+ if user, err := c.App.GetUserForLogin(loginId, false); err == nil {
resp["mfa_required"] = user.MfaActive
}
@@ -712,7 +712,7 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- if err := app.UpdateMfa(activate, c.Params.UserId, code); err != nil {
+ if err := c.App.UpdateMfa(activate, c.Params.UserId, code); err != nil {
c.Err = err
return
}
@@ -732,7 +732,7 @@ func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- secret, err := app.GenerateMfaSecret(c.Params.UserId)
+ secret, err := c.App.GenerateMfaSecret(c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -764,9 +764,9 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err = app.UpdatePasswordAsUser(c.Params.UserId, currentPassword, newPassword)
+ err = c.App.UpdatePasswordAsUser(c.Params.UserId, currentPassword, newPassword)
} else if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- err = app.UpdatePasswordByUserIdSendEmail(c.Params.UserId, newPassword, c.T("api.user.reset_password.method"))
+ err = c.App.UpdatePasswordByUserIdSendEmail(c.Params.UserId, newPassword, c.T("api.user.reset_password.method"))
} else {
err = model.NewAppError("updatePassword", "api.user.update_password.context.app_error", nil, "", http.StatusForbidden)
}
@@ -794,7 +794,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt - token=" + token)
- if err := app.ResetPasswordFromToken(token, newPassword); err != nil {
+ if err := c.App.ResetPasswordFromToken(token, newPassword); err != nil {
c.LogAudit("fail - token=" + token)
c.Err = err
return
@@ -814,7 +814,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 {
@@ -835,7 +835,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
ldapOnly := props["ldap_only"] == "true"
c.LogAuditWithUserId(id, "attempt - 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.LogAuditWithUserId(id, "failure - login_id="+loginId)
c.Err = err
@@ -845,7 +845,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAuditWithUserId(user.Id, "authenticated")
var session *model.Session
- session, err = app.DoLogin(w, r, user, deviceId)
+ session, err = c.App.DoLogin(w, r, user, deviceId)
if err != nil {
c.Err = err
return
@@ -872,7 +872,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
}
@@ -892,7 +892,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if sessions, err := app.GetSessions(c.Params.UserId); err != nil {
+ if sessions, err := c.App.GetSessions(c.Params.UserId); err != nil {
c.Err = err
return
} else {
@@ -924,7 +924,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.RevokeSessionById(sessionId); err != nil {
+ if err := c.App.RevokeSessionById(sessionId); err != nil {
c.Err = err
return
}
@@ -942,7 +942,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
return
}
@@ -970,7 +970,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
}
@@ -990,7 +990,7 @@ func getUserAudits(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if audits, err := app.GetAuditsPage(c.Params.UserId, c.Params.Page, c.Params.PerPage); err != nil {
+ if audits, err := c.App.GetAuditsPage(c.Params.UserId, c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
@@ -1008,7 +1008,7 @@ func verifyUserEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.VerifyEmailFromToken(token); err != nil {
+ if err := c.App.VerifyEmailFromToken(token); err != nil {
c.Err = model.NewAppError("verifyUserEmail", "api.user.verify_email.bad_link.app_error", nil, err.Error(), http.StatusBadRequest)
return
} else {
@@ -1027,14 +1027,14 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- user, err := app.GetUserForLogin(email, false)
+ user, err := c.App.GetUserForLogin(email, false)
if err != nil {
// Don't want to leak whether the email is valid or not
ReturnStatusOK(w)
return
}
- err = app.SendEmailVerification(user)
+ err = c.App.SendEmailVerification(user)
if err != nil {
// Don't want to leak whether the email is valid or not
l4g.Error(err.Error())
@@ -1056,18 +1056,18 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if switchRequest.EmailToOAuth() {
- link, err = app.SwitchEmailToOAuth(w, r, switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.NewService)
+ link, err = c.App.SwitchEmailToOAuth(w, r, switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.NewService)
} else if switchRequest.OAuthToEmail() {
c.SessionRequired()
if c.Err != nil {
return
}
- link, err = app.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.Session.UserId)
+ link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.Session.UserId)
} else if switchRequest.EmailToLdap() {
- link, err = app.SwitchEmailToLdap(switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapId, switchRequest.NewPassword)
+ link, err = c.App.SwitchEmailToLdap(switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapId, switchRequest.NewPassword)
} else if switchRequest.LdapToEmail() {
- link, err = app.SwitchLdapToEmail(switchRequest.Password, switchRequest.MfaCode, switchRequest.Email, switchRequest.NewPassword)
+ link, err = c.App.SwitchLdapToEmail(switchRequest.Password, switchRequest.MfaCode, switchRequest.Email, switchRequest.NewPassword)
} else {
c.SetInvalidParam("switch_request")
return
@@ -1115,7 +1115,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
accessToken.Token = ""
var err *model.AppError
- accessToken, err = app.CreateUserAccessToken(accessToken)
+ accessToken, err = c.App.CreateUserAccessToken(accessToken)
if err != nil {
c.Err = err
return
@@ -1141,7 +1141,7 @@ func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- accessTokens, err := app.GetUserAccessTokensForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
+ accessTokens, err := c.App.GetUserAccessTokensForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
if err != nil {
c.Err = err
return
@@ -1161,7 +1161,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- accessToken, err := app.GetUserAccessToken(c.Params.TokenId, true)
+ accessToken, err := c.App.GetUserAccessToken(c.Params.TokenId, true)
if err != nil {
c.Err = err
return
@@ -1190,7 +1190,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- accessToken, err := app.GetUserAccessToken(tokenId, false)
+ accessToken, err := c.App.GetUserAccessToken(tokenId, false)
if err != nil {
c.Err = err
return
@@ -1201,7 +1201,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err = app.RevokeUserAccessToken(accessToken)
+ err = c.App.RevokeUserAccessToken(accessToken)
if err != nil {
c.Err = err
return
diff --git a/api4/user_test.go b/api4/user_test.go
index b80053f9f..3d7fc1630 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -11,7 +11,6 @@ import (
"testing"
"time"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"github.com/stretchr/testify/assert"
@@ -553,7 +552,7 @@ func TestSearchUsers(t *testing.T) {
t.Fatal("should have found user")
}
- _, err := app.UpdateActiveNoLdap(th.BasicUser2.Id, false)
+ _, err := th.App.UpdateActiveNoLdap(th.BasicUser2.Id, false)
if err != nil {
t.Fatal(err)
}
@@ -676,7 +675,7 @@ func TestSearchUsers(t *testing.T) {
utils.Cfg.PrivacySettings.ShowEmailAddress = false
utils.Cfg.PrivacySettings.ShowFullName = false
- _, err = app.UpdateActiveNoLdap(th.BasicUser2.Id, true)
+ _, err = th.App.UpdateActiveNoLdap(th.BasicUser2.Id, true)
if err != nil {
t.Fatal(err)
}
@@ -1261,7 +1260,7 @@ func TestGetRecentlyActiveUsersInTeam(t *testing.T) {
Client := th.Client
teamId := th.BasicTeam.Id
- app.SetStatusOnline(th.BasicUser.Id, "", true)
+ th.App.SetStatusOnline(th.BasicUser.Id, "", true)
rusers, resp := Client.GetRecentlyActiveUsersInTeam(teamId, 0, 60, "")
CheckNoError(t, resp)
@@ -1303,7 +1302,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
})
CheckNoError(t, resp)
LinkUserToTeam(user, th.BasicTeam)
- defer app.Srv.Store.User().PermanentDelete(user.Id)
+ defer th.App.Srv.Store.User().PermanentDelete(user.Id)
user2, resp := Client.CreateUser(&model.User{
Username: "a000000001" + model.NewId(),
@@ -1311,7 +1310,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
Password: "Password1",
})
CheckNoError(t, resp)
- defer app.Srv.Store.User().PermanentDelete(user2.Id)
+ defer th.App.Srv.Store.User().PermanentDelete(user2.Id)
rusers, resp := SystemAdminClient.GetUsersWithoutTeam(0, 100, "")
CheckNoError(t, resp)
@@ -1761,7 +1760,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 {
@@ -1917,7 +1916,7 @@ func TestAttachDeviceId(t *testing.T) {
t.Fatal("should have passed")
}
- if sessions, err := app.GetSessions(th.BasicUser.Id); err != nil {
+ if sessions, err := th.App.GetSessions(th.BasicUser.Id); err != nil {
t.Fatal(err)
} else {
if sessions[0].DeviceId != deviceId {
@@ -1968,7 +1967,7 @@ func TestVerifyUserEmail(t *testing.T) {
ruser, resp := Client.CreateUser(&user)
- token, err := app.CreateVerifyEmailToken(ruser.Id)
+ token, err := th.App.CreateVerifyEmailToken(ruser.Id)
if err != nil {
t.Fatal("Unable to create email verify token")
}
@@ -2042,13 +2041,13 @@ func TestSetProfileImage(t *testing.T) {
t.Fatal("Should have failed either forbidden or unauthorized")
}
- buser, err := app.GetUser(user.Id)
+ buser, err := th.App.GetUser(user.Id)
require.Nil(t, err)
_, resp = th.SystemAdminClient.SetProfileImage(user.Id, data)
CheckNoError(t, resp)
- ruser, err := app.GetUser(user.Id)
+ ruser, err := th.App.GetUser(user.Id)
require.Nil(t, err)
assert.True(t, buser.LastPictureUpdate < ruser.LastPictureUpdate, "Picture should have updated for user")
@@ -2088,7 +2087,7 @@ func TestSwitchAccount(t *testing.T) {
th.LoginBasic()
fakeAuthData := model.NewId()
- if result := <-app.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true); result.Err != nil {
+ if result := <-th.App.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true); result.Err != nil {
t.Fatal(result.Err)
}
@@ -2172,7 +2171,7 @@ func TestCreateUserAccessToken(t *testing.T) {
_, resp = Client.CreateUserAccessToken(th.BasicUser.Id, "")
CheckBadRequestStatus(t, resp)
- app.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
+ th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
*utils.Cfg.ServiceSettings.EnableUserAccessTokens = false
_, resp = Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
@@ -2243,7 +2242,7 @@ func TestGetUserAccessToken(t *testing.T) {
_, resp = Client.GetUserAccessToken(model.NewId())
CheckForbiddenStatus(t, resp)
- app.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
+ th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
CheckNoError(t, resp)
@@ -2308,7 +2307,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
}()
*utils.Cfg.ServiceSettings.EnableUserAccessTokens = true
- app.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
+ th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
CheckNoError(t, resp)
@@ -2355,7 +2354,7 @@ func TestUserAccessTokenInactiveUser(t *testing.T) {
}()
*utils.Cfg.ServiceSettings.EnableUserAccessTokens = true
- app.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
+ th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
CheckNoError(t, resp)
@@ -2363,7 +2362,7 @@ func TestUserAccessTokenInactiveUser(t *testing.T) {
_, resp = Client.GetMe("")
CheckNoError(t, resp)
- app.UpdateActive(th.BasicUser, false)
+ th.App.UpdateActive(th.BasicUser, false)
_, resp = Client.GetMe("")
CheckUnauthorizedStatus(t, resp)
@@ -2382,7 +2381,7 @@ func TestUserAccessTokenDisableConfig(t *testing.T) {
}()
*utils.Cfg.ServiceSettings.EnableUserAccessTokens = true
- app.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
+ th.App.UpdateUserRoles(th.BasicUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_USER_ACCESS_TOKEN.Id)
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
CheckNoError(t, resp)
diff --git a/api4/webhook.go b/api4/webhook.go
index 6d332e8fc..b98e054df 100644
--- a/api4/webhook.go
+++ b/api4/webhook.go
@@ -45,7 +45,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
@@ -58,13 +58,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 {
@@ -90,7 +90,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempt")
- oldHook, err := app.GetIncomingWebhook(hookId)
+ oldHook, err := c.App.GetIncomingWebhook(hookId)
if err != nil {
c.Err = err
return
@@ -116,19 +116,19 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- channel, err := app.GetChannel(updatedHook.ChannelId)
+ channel, err := c.App.GetChannel(updatedHook.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
}
- if incomingHook, err := app.UpdateIncomingWebhook(oldHook, updatedHook); err != nil {
+ if incomingHook, err := c.App.UpdateIncomingWebhook(oldHook, updatedHook); err != nil {
c.Err = err
return
} else {
@@ -150,14 +150,14 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- hooks, err = app.GetIncomingWebhooksForTeamPage(teamId, c.Params.Page, c.Params.PerPage)
+ hooks, err = c.App.GetIncomingWebhooksForTeamPage(teamId, c.Params.Page, c.Params.PerPage)
} else {
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
}
- hooks, err = app.GetIncomingWebhooksPage(c.Params.Page, c.Params.PerPage)
+ hooks, err = c.App.GetIncomingWebhooksPage(c.Params.Page, c.Params.PerPage)
}
if err != nil {
@@ -180,18 +180,18 @@ func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook *model.IncomingWebhook
var channel *model.Channel
- if hook, err = app.GetIncomingWebhook(hookId); err != nil {
+ if hook, err = c.App.GetIncomingWebhook(hookId); err != nil {
c.Err = err
return
} else {
- channel, err = app.GetChannel(hook.ChannelId)
+ channel, err = c.App.GetChannel(hook.ChannelId)
if err != nil {
c.Err = err
return
}
if !app.SessionHasPermissionToTeam(c.Session, hook.TeamId, model.PERMISSION_MANAGE_WEBHOOKS) ||
- (channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
+ (channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
c.LogAudit("fail - bad permissions")
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
@@ -214,23 +214,23 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook *model.IncomingWebhook
var channel *model.Channel
- if hook, err = app.GetIncomingWebhook(hookId); err != nil {
+ if hook, err = c.App.GetIncomingWebhook(hookId); err != nil {
c.Err = err
return
} else {
- channel, err = app.GetChannel(hook.ChannelId)
+ channel, err = c.App.GetChannel(hook.ChannelId)
if err != nil {
c.Err = err
return
}
if !app.SessionHasPermissionToTeam(c.Session, hook.TeamId, model.PERMISSION_MANAGE_WEBHOOKS) ||
- (channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
+ (channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
c.LogAudit("fail - bad permissions")
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
} else {
- if err = app.DeleteIncomingWebhook(hookId); err != nil {
+ if err = c.App.DeleteIncomingWebhook(hookId); err != nil {
c.Err = err
return
}
@@ -261,7 +261,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- oldHook, err := app.GetOutgoingWebhook(toUpdateHook.Id)
+ oldHook, err := c.App.GetOutgoingWebhook(toUpdateHook.Id)
if err != nil {
c.Err = err
return
@@ -273,7 +273,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- rhook, err := app.UpdateOutgoingWebhook(oldHook, toUpdateHook)
+ rhook, err := c.App.UpdateOutgoingWebhook(oldHook, toUpdateHook)
if err != nil {
c.Err = err
return
@@ -299,7 +299,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
@@ -318,26 +318,26 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if len(channelId) > 0 {
- if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_WEBHOOKS) {
+ if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
}
- hooks, err = app.GetOutgoingWebhooksForChannelPage(channelId, c.Params.Page, c.Params.PerPage)
+ hooks, err = c.App.GetOutgoingWebhooksForChannelPage(channelId, c.Params.Page, c.Params.PerPage)
} else if len(teamId) > 0 {
if !app.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_MANAGE_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
}
- hooks, err = app.GetOutgoingWebhooksForTeamPage(teamId, c.Params.Page, c.Params.PerPage)
+ hooks, err = c.App.GetOutgoingWebhooksForTeamPage(teamId, c.Params.Page, c.Params.PerPage)
} else {
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_WEBHOOKS) {
c.SetPermissionError(model.PERMISSION_MANAGE_WEBHOOKS)
return
}
- hooks, err = app.GetOutgoingWebhooksPage(c.Params.Page, c.Params.PerPage)
+ hooks, err = c.App.GetOutgoingWebhooksPage(c.Params.Page, c.Params.PerPage)
}
if err != nil {
@@ -354,7 +354,7 @@ func getOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- hook, err := app.GetOutgoingWebhook(c.Params.HookId)
+ hook, err := c.App.GetOutgoingWebhook(c.Params.HookId)
if err != nil {
c.Err = err
return
@@ -383,7 +383,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
return
}
- hook, err := app.GetOutgoingWebhook(c.Params.HookId)
+ hook, err := c.App.GetOutgoingWebhook(c.Params.HookId)
if err != nil {
c.Err = err
return
@@ -402,7 +402,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 {
@@ -416,7 +416,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- hook, err := app.GetOutgoingWebhook(c.Params.HookId)
+ hook, err := c.App.GetOutgoingWebhook(c.Params.HookId)
if err != nil {
c.Err = err
return
@@ -435,7 +435,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- if err := app.DeleteOutgoingWebhook(hook.Id); err != nil {
+ if err := c.App.DeleteOutgoingWebhook(hook.Id); err != nil {
c.LogAudit("fail")
c.Err = err
return
@@ -478,7 +478,7 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- err := app.HandleIncomingWebhook(id, parsedRequest)
+ err := c.App.HandleIncomingWebhook(id, parsedRequest)
if err != nil {
c.Err = err
return
@@ -494,7 +494,7 @@ func commandWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
response := model.CommandResponseFromHTTPBody(r.Header.Get("Content-Type"), r.Body)
- err := app.HandleCommandWebhook(id, response)
+ err := c.App.HandleCommandWebhook(id, response)
if err != nil {
c.Err = err
return
diff --git a/api4/webhook_test.go b/api4/webhook_test.go
index 8cab85c99..28b98bf42 100644
--- a/api4/webhook_test.go
+++ b/api4/webhook_test.go
@@ -8,7 +8,6 @@ import (
"net/http"
"testing"
- "github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
@@ -914,7 +913,7 @@ func TestCommandWebhooks(t *testing.T) {
UserId: th.BasicUser.Id,
ChannelId: th.BasicChannel.Id,
}
- hook, err := app.CreateCommandWebhook(cmd.Id, args)
+ hook, err := th.App.CreateCommandWebhook(cmd.Id, args)
if err != nil {
t.Fatal(err)
}
diff --git a/api4/websocket.go b/api4/websocket.go
index fade548cb..08bb2e709 100644
--- a/api4/websocket.go
+++ b/api4/websocket.go
@@ -35,7 +35,7 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- wc := app.NewWebConn(ws, c.Session, c.T, "")
+ wc := c.App.NewWebConn(ws, c.Session, c.T, "")
if len(c.Session.UserId) > 0 {
app.HubRegister(wc)