Commit 1adfd0e9 authored by Chris's avatar Chris Committed by GitHub
Browse files

app type transition (#7167)

parent b84bd210
...@@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) { func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) {
if audits, err := app.GetAudits("", 200); err != nil { if audits, err := c.App.GetAudits("", 200); err != nil {
c.Err = err c.Err = err
return return
} else if HandleEtag(audits.Etag(), "Get All Audits", w, r) { } else if HandleEtag(audits.Etag(), "Get All Audits", w, r) {
...@@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func invalidateAllCaches(c *Context, w http.ResponseWriter, r *http.Request) { func invalidateAllCaches(c *Context, w http.ResponseWriter, r *http.Request) {
err := app.InvalidateAllCaches() err := c.App.InvalidateAllCaches()
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) { func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) {
app.RecycleDatabaseConnection() c.App.RecycleDatabaseConnection()
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
ReturnStatusOK(w) ReturnStatusOK(w)
} }
...@@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
err := app.TestEmail(c.Session.UserId, cfg) err := c.App.TestEmail(c.Session.UserId, cfg)
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) { func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
crs, err := app.GetComplianceReports(0, 10000) crs, err := c.App.GetComplianceReports(0, 10000)
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
job.UserId = c.Session.UserId job.UserId = c.Session.UserId
rjob, err := app.SaveComplianceReport(job) rjob, err := c.App.SaveComplianceReport(job)
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request ...@@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return return
} }
job, err := app.GetComplianceReport(id) job, err := c.App.GetComplianceReport(id)
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
teamId := params["id"] teamId := params["id"]
name := params["name"] name := params["name"]
rows, err := app.GetAnalytics(name, teamId) rows, err := c.App.GetAnalytics(name, teamId)
if err != nil { if err != nil {
c.Err = err c.Err = err
return return
...@@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if err := app.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil { if err := c.App.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil {
c.Err = err c.Err = err
return return
} }
...@@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func getRecentlyActiveUsers(c *Context, w http.ResponseWriter, r *http.Request) { func getRecentlyActiveUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if profiles, err := app.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil { if profiles, err := c.App.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil {
c.Err = err c.Err = err
return return
} else { } else {
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model" "github.com/mattermost/platform/model"
"github.com/mattermost/platform/store" "github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils" "github.com/mattermost/platform/utils"
...@@ -597,7 +596,7 @@ func TestAdminResetPassword(t *testing.T) { ...@@ -597,7 +596,7 @@ func TestAdminResetPassword(t *testing.T) {
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"} user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
LinkUserToTeam(user, team) LinkUserToTeam(user, team)
store.Must(app.Srv.Store.User().VerifyEmail(user.Id)) store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
if _, err := Client.AdminResetPassword("", "newpwd1"); err == nil { if _, err := Client.AdminResetPassword("", "newpwd1"); err == nil {
t.Fatal("Should have errored - empty user id") t.Fatal("Should have errored - empty user id")
...@@ -619,7 +618,7 @@ func TestAdminResetPassword(t *testing.T) { ...@@ -619,7 +618,7 @@ func TestAdminResetPassword(t *testing.T) {
user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"} user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
LinkUserToTeam(user2, team) LinkUserToTeam(user2, team)
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id)) store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
if _, err := Client.AdminResetPassword(user.Id, "newpwd1"); err != nil { if _, err := Client.AdminResetPassword(user.Id, "newpwd1"); err != nil {
t.Fatal(err) t.Fatal(err)
......
...@@ -60,14 +60,14 @@ type Routes struct { ...@@ -60,14 +60,14 @@ type Routes struct {
var BaseRoutes *Routes var BaseRoutes *Routes
func InitRouter() { func InitRouter() {
app.Srv.Router = mux.NewRouter() app.Global().Srv.Router = mux.NewRouter()
app.Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404) app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
} }
func InitApi() { func InitApi() {
BaseRoutes = &Routes{} BaseRoutes = &Routes{}
BaseRoutes.Root = app.Srv.Router BaseRoutes.Root = app.Global().Srv.Router
BaseRoutes.ApiRoot = app.Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter() BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter() BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter() BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter() BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter()
...@@ -111,7 +111,7 @@ func InitApi() { ...@@ -111,7 +111,7 @@ func InitApi() {
InitDeprecated() InitDeprecated()
// 404 on any api route before web.go has a chance to serve it // 404 on any api route before web.go has a chance to serve it
app.Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404)) app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
utils.InitHTML() utils.InitHTML()
......
...@@ -17,6 +17,8 @@ import ( ...@@ -17,6 +17,8 @@ import (
) )
type TestHelper struct { type TestHelper struct {
App *app.App
BasicClient *model.Client BasicClient *model.Client
BasicTeam *model.Team BasicTeam *model.Team
BasicUser *model.User BasicUser *model.User
...@@ -32,7 +34,7 @@ type TestHelper struct { ...@@ -32,7 +34,7 @@ type TestHelper struct {
} }
func SetupEnterprise() *TestHelper { func SetupEnterprise() *TestHelper {
if app.Srv == nil { if app.Global().Srv == nil {
utils.TranslationsPreInit() utils.TranslationsPreInit()
utils.LoadConfig("config.json") utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings) utils.InitTranslations(utils.Cfg.LocalizationSettings)
...@@ -40,17 +42,17 @@ func SetupEnterprise() *TestHelper { ...@@ -40,17 +42,17 @@ func SetupEnterprise() *TestHelper {
*utils.Cfg.RateLimitSettings.Enable = false *utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
utils.License().Features.SetDefaults() utils.License().Features.SetDefaults()
app.NewServer() app.Global().NewServer()
app.InitStores() app.Global().InitStores()
InitRouter() InitRouter()
wsapi.InitRouter() wsapi.InitRouter()
app.StartServer() app.Global().StartServer()
utils.InitHTML() utils.InitHTML()
api4.InitApi(false) api4.InitApi(false)
InitApi() InitApi()
wsapi.InitApi() wsapi.InitApi()
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
app.Srv.Store.MarkSystemRanUnitTests() app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true *utils.Cfg.TeamSettings.EnableOpenServer = true
} }
...@@ -59,7 +61,7 @@ func SetupEnterprise() *TestHelper { ...@@ -59,7 +61,7 @@ func SetupEnterprise() *TestHelper {
} }
func Setup() *TestHelper { func Setup() *TestHelper {
if app.Srv == nil { if app.Global().Srv == nil {
utils.TranslationsPreInit() utils.TranslationsPreInit()
utils.LoadConfig("config.json") utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings) utils.InitTranslations(utils.Cfg.LocalizationSettings)
...@@ -70,16 +72,16 @@ func Setup() *TestHelper { ...@@ -70,16 +72,16 @@ func Setup() *TestHelper {
utils.Cfg.EmailSettings.SMTPPort = "2500" utils.Cfg.EmailSettings.SMTPPort = "2500"
utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com" utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
app.NewServer() app.Global().NewServer()
app.InitStores() app.Global().InitStores()
InitRouter() InitRouter()
wsapi.InitRouter() wsapi.InitRouter()
app.StartServer() app.Global().StartServer()
api4.InitApi(false) api4.InitApi(false)
InitApi() InitApi()
wsapi.InitApi() wsapi.InitApi()
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
app.Srv.Store.MarkSystemRanUnitTests() app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true *utils.Cfg.TeamSettings.EnableOpenServer = true
} }
...@@ -100,6 +102,7 @@ func ReloadConfigForSetup() { ...@@ -100,6 +102,7 @@ func ReloadConfigForSetup() {
} }
func (me *TestHelper) InitBasic() *TestHelper { func (me *TestHelper) InitBasic() *TestHelper {
me.App = app.Global()
me.BasicClient = me.CreateClient() me.BasicClient = me.CreateClient()
me.BasicUser = me.CreateUser(me.BasicClient) me.BasicUser = me.CreateUser(me.BasicClient)
me.LoginBasic() me.LoginBasic()
...@@ -119,6 +122,7 @@ func (me *TestHelper) InitBasic() *TestHelper { ...@@ -119,6 +122,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
} }
func (me *TestHelper) InitSystemAdmin() *TestHelper { func (me *TestHelper) InitSystemAdmin() *TestHelper {
me.App = app.Global()
me.SystemAdminClient = me.CreateClient() me.SystemAdminClient = me.CreateClient()
me.SystemAdminUser = me.CreateUser(me.SystemAdminClient) me.SystemAdminUser = me.CreateUser(me.SystemAdminClient)
me.SystemAdminUser.Password = "Password1" me.SystemAdminUser.Password = "Password1"
...@@ -126,7 +130,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { ...@@ -126,7 +130,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper {
me.SystemAdminTeam = me.CreateTeam(me.SystemAdminClient) me.SystemAdminTeam = me.CreateTeam(me.SystemAdminClient)
LinkUserToTeam(me.SystemAdminUser, me.SystemAdminTeam) LinkUserToTeam(me.SystemAdminUser, me.SystemAdminTeam)
me.SystemAdminClient.SetTeamId(me.SystemAdminTeam.Id) me.SystemAdminClient.SetTeamId(me.SystemAdminTeam.Id)
app.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id) me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id)
me.SystemAdminChannel = me.CreateChannel(me.SystemAdminClient, me.SystemAdminTeam) me.SystemAdminChannel = me.CreateChannel(me.SystemAdminClient, me.SystemAdminTeam)
return me return me
...@@ -168,7 +172,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User { ...@@ -168,7 +172,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User) ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User)
ruser.Password = "Password1" ruser.Password = "Password1"
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id)) store.Must(app.Global().Srv.Store.User().VerifyEmail(ruser.Id))
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
return ruser return ruser
} }
...@@ -176,7 +180,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User { ...@@ -176,7 +180,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
func LinkUserToTeam(user *model.User, team *model.Team) { func LinkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
err := app.JoinUserToTeam(team, user, "") err := app.Global().JoinUserToTeam(team, user, "")
if err != nil { if err != nil {
l4g.Error(err.Error()) l4g.Error(err.Error())
l4g.Close() l4g.Close()
...@@ -191,7 +195,7 @@ func UpdateUserToTeamAdmin(user *model.User, team *model.Team) { ...@@ -191,7 +195,7 @@ func UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id + " " + model.ROLE_TEAM_ADMIN.Id} 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() utils.EnableDebugLogForTest()
l4g.Error(tmr.Err.Error()) l4g.Error(tmr.Err.Error())
l4g.Close() l4g.Close()
...@@ -205,7 +209,7 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) { ...@@ -205,7 +209,7 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest() utils.DisableDebugLogForTest()
tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id} 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() utils.EnableDebugLogForTest()
l4g.Error(tmr.Err.Error()) l4g.Error(tmr.Err.Error())
l4g.Close() l4g.Close()
...@@ -218,10 +222,10 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) { ...@@ -218,10 +222,10 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
func MakeUserChannelAdmin(user *model.User, channel *model.Channel) { func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest() 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 := cmr.Data.(*model.ChannelMember)
cm.Roles = "channel_admin channel_user" 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() utils.EnableDebugLogForTest()
panic(sr.Err) panic(sr.Err)
} }
...@@ -236,10 +240,10 @@ func MakeUserChannelAdmin(user *model.User, channel *model.Channel) { ...@@ -236,10 +240,10 @@ func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
func MakeUserChannelUser(user *model.User, channel *model.Channel) { func MakeUserChannelUser(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest() 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 := cmr.Data.(*model.ChannelMember)
cm.Roles = "channel_user" cm.Roles = "channel_user"
if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil { if sr := <-app.Global().Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
utils.EnableDebugLogForTest() utils.EnableDebugLogForTest()
panic(sr.Err) panic(sr.Err)
} }
...@@ -323,7 +327,7 @@ func (me *TestHelper) LoginSystemAdmin() { ...@@ -323,7 +327,7 @@ func (me *TestHelper) LoginSystemAdmin() {
} }
func TearDown() { func TearDown() {
if app.Srv != nil { if app.Global().Srv != nil {
app.StopServer() app.Global().StopServer()
} }
} }
...@@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return 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 c.Err = err
return return
} else { } else {
...@@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
if sc, err := app.CreateDirectChannel(c.Session.UserId, userId); err != nil { if sc, err := c.App.CreateDirectChannel(c.Session.UserId, userId); err != nil {
c.Err = err c.Err = err
return return
} else { } else {
...@@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
userIds = append(userIds, c.Session.UserId) userIds = append(userIds, c.Session.UserId)
} }
if sc, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil { if sc, err := c.App.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
c.Err = err c.Err = err
return return
} else { } else {
...@@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func CanManageChannel(c *Context, channel *model.Channel) bool { 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) c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
return false 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) c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
return false return false
} }
...@@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var oldChannel *model.Channel var oldChannel *model.Channel
var err *model.AppError 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 c.Err = err
return 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 c.Err = err
return return
} }
...@@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type oldChannel.Type = channel.Type
} }
if _, err := app.UpdateChannel(oldChannel); err != nil { if _, err := c.App.UpdateChannel(oldChannel); err != nil {
c.Err = err c.Err = err
return return
} else { } else {
if oldChannelDisplayName != channel.DisplayName { 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()) l4g.Error(err.Error())
} }
} }
...@@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel var channel *model.Channel
var err *model.AppError var err *model.AppError
if channel, err = app.GetChannel(channelId); err != nil { if channel, err = c.App.GetChannel(channelId); err != nil {
c.Err = err c.Err = err
return return
} }
if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil { if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil {
c.Err = err c.Err = err
return return
} }
...@@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) { ...@@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header oldChannelHeader := channel.Header
channel.Header = channelHeader channel.Header = channelHeader
if _, err := app.UpdateChannel(channel); err != nil { if _, err := c.App.UpdateChannel(channel); err != nil {
c.Err = err c.Err = err
return return
} else { } else {
if err := app.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil { if err := c.App.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil