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

app type transition (#7167)

parent b84bd210
......@@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) {
if audits, err := app.GetAudits("", 200); err != nil {
if audits, err := c.App.GetAudits("", 200); err != nil {
c.Err = err
return
} else if HandleEtag(audits.Etag(), "Get All Audits", w, r) {
......@@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
func invalidateAllCaches(c *Context, w http.ResponseWriter, r *http.Request) {
err := app.InvalidateAllCaches()
err := c.App.InvalidateAllCaches()
if err != nil {
c.Err = err
return
......@@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) {
app.RecycleDatabaseConnection()
c.App.RecycleDatabaseConnection()
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
ReturnStatusOK(w)
}
......@@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
err := app.TestEmail(c.Session.UserId, cfg)
err := c.App.TestEmail(c.Session.UserId, cfg)
if err != nil {
c.Err = err
return
......@@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
crs, err := app.GetComplianceReports(0, 10000)
crs, err := c.App.GetComplianceReports(0, 10000)
if err != nil {
c.Err = err
return
......@@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
job.UserId = c.Session.UserId
rjob, err := app.SaveComplianceReport(job)
rjob, err := c.App.SaveComplianceReport(job)
if err != nil {
c.Err = err
return
......@@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return
}
job, err := app.GetComplianceReport(id)
job, err := c.App.GetComplianceReport(id)
if err != nil {
c.Err = err
return
......@@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
teamId := params["id"]
name := params["name"]
rows, err := app.GetAnalytics(name, teamId)
rows, err := c.App.GetAnalytics(name, teamId)
if err != nil {
c.Err = err
return
......@@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := app.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil {
if err := c.App.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil {
c.Err = err
return
}
......@@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getRecentlyActiveUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if profiles, err := app.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil {
if profiles, err := c.App.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil {
c.Err = err
return
} else {
......
......@@ -8,7 +8,6 @@ import (
"strings"
"testing"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
......@@ -597,7 +596,7 @@ func TestAdminResetPassword(t *testing.T) {
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
LinkUserToTeam(user, team)
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
if _, err := Client.AdminResetPassword("", "newpwd1"); err == nil {
t.Fatal("Should have errored - empty user id")
......@@ -619,7 +618,7 @@ func TestAdminResetPassword(t *testing.T) {
user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"}
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
LinkUserToTeam(user2, team)
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
if _, err := Client.AdminResetPassword(user.Id, "newpwd1"); err != nil {
t.Fatal(err)
......
......@@ -60,14 +60,14 @@ type Routes struct {
var BaseRoutes *Routes
func InitRouter() {
app.Srv.Router = mux.NewRouter()
app.Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
app.Global().Srv.Router = mux.NewRouter()
app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
}
func InitApi() {
BaseRoutes = &Routes{}
BaseRoutes.Root = app.Srv.Router
BaseRoutes.ApiRoot = app.Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
BaseRoutes.Root = app.Global().Srv.Router
BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter()
......@@ -111,7 +111,7 @@ func InitApi() {
InitDeprecated()
// 404 on any api route before web.go has a chance to serve it
app.Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
utils.InitHTML()
......
......@@ -17,6 +17,8 @@ import (
)
type TestHelper struct {
App *app.App
BasicClient *model.Client
BasicTeam *model.Team
BasicUser *model.User
......@@ -32,7 +34,7 @@ type TestHelper struct {
}
func SetupEnterprise() *TestHelper {
if app.Srv == nil {
if app.Global().Srv == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
......@@ -40,17 +42,17 @@ func SetupEnterprise() *TestHelper {
*utils.Cfg.RateLimitSettings.Enable = false
utils.DisableDebugLogForTest()
utils.License().Features.SetDefaults()
app.NewServer()
app.InitStores()
app.Global().NewServer()
app.Global().InitStores()
InitRouter()
wsapi.InitRouter()
app.StartServer()
app.Global().StartServer()
utils.InitHTML()
api4.InitApi(false)
InitApi()
wsapi.InitApi()
utils.EnableDebugLogForTest()
app.Srv.Store.MarkSystemRanUnitTests()
app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
......@@ -59,7 +61,7 @@ func SetupEnterprise() *TestHelper {
}
func Setup() *TestHelper {
if app.Srv == nil {
if app.Global().Srv == nil {
utils.TranslationsPreInit()
utils.LoadConfig("config.json")
utils.InitTranslations(utils.Cfg.LocalizationSettings)
......@@ -70,16 +72,16 @@ func Setup() *TestHelper {
utils.Cfg.EmailSettings.SMTPPort = "2500"
utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
utils.DisableDebugLogForTest()
app.NewServer()
app.InitStores()
app.Global().NewServer()
app.Global().InitStores()
InitRouter()
wsapi.InitRouter()
app.StartServer()
app.Global().StartServer()
api4.InitApi(false)
InitApi()
wsapi.InitApi()
utils.EnableDebugLogForTest()
app.Srv.Store.MarkSystemRanUnitTests()
app.Global().Srv.Store.MarkSystemRanUnitTests()
*utils.Cfg.TeamSettings.EnableOpenServer = true
}
......@@ -100,6 +102,7 @@ func ReloadConfigForSetup() {
}
func (me *TestHelper) InitBasic() *TestHelper {
me.App = app.Global()
me.BasicClient = me.CreateClient()
me.BasicUser = me.CreateUser(me.BasicClient)
me.LoginBasic()
......@@ -119,6 +122,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
}
func (me *TestHelper) InitSystemAdmin() *TestHelper {
me.App = app.Global()
me.SystemAdminClient = me.CreateClient()
me.SystemAdminUser = me.CreateUser(me.SystemAdminClient)
me.SystemAdminUser.Password = "Password1"
......@@ -126,7 +130,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper {
me.SystemAdminTeam = me.CreateTeam(me.SystemAdminClient)
LinkUserToTeam(me.SystemAdminUser, me.SystemAdminTeam)
me.SystemAdminClient.SetTeamId(me.SystemAdminTeam.Id)
app.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id)
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.ROLE_SYSTEM_USER.Id+" "+model.ROLE_SYSTEM_ADMIN.Id)
me.SystemAdminChannel = me.CreateChannel(me.SystemAdminClient, me.SystemAdminTeam)
return me
......@@ -168,7 +172,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
utils.DisableDebugLogForTest()
ruser := client.Must(client.CreateUser(user, "")).Data.(*model.User)
ruser.Password = "Password1"
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
store.Must(app.Global().Srv.Store.User().VerifyEmail(ruser.Id))
utils.EnableDebugLogForTest()
return ruser
}
......@@ -176,7 +180,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
func LinkUserToTeam(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
err := app.JoinUserToTeam(team, user, "")
err := app.Global().JoinUserToTeam(team, user, "")
if err != nil {
l4g.Error(err.Error())
l4g.Close()
......@@ -191,7 +195,7 @@ func UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id + " " + model.ROLE_TEAM_ADMIN.Id}
if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
if tmr := <-app.Global().Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
utils.EnableDebugLogForTest()
l4g.Error(tmr.Err.Error())
l4g.Close()
......@@ -205,7 +209,7 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
utils.DisableDebugLogForTest()
tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id}
if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
if tmr := <-app.Global().Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
utils.EnableDebugLogForTest()
l4g.Error(tmr.Err.Error())
l4g.Close()
......@@ -218,10 +222,10 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest()
if cmr := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil {
if cmr := <-app.Global().Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil {
cm := cmr.Data.(*model.ChannelMember)
cm.Roles = "channel_admin channel_user"
if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
if sr := <-app.Global().Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
utils.EnableDebugLogForTest()
panic(sr.Err)
}
......@@ -236,10 +240,10 @@ func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
func MakeUserChannelUser(user *model.User, channel *model.Channel) {
utils.DisableDebugLogForTest()
if cmr := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil {
if cmr := <-app.Global().Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil {
cm := cmr.Data.(*model.ChannelMember)
cm.Roles = "channel_user"
if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
if sr := <-app.Global().Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
utils.EnableDebugLogForTest()
panic(sr.Err)
}
......@@ -323,7 +327,7 @@ func (me *TestHelper) LoginSystemAdmin() {
}
func TearDown() {
if app.Srv != nil {
app.StopServer()
if app.Global().Srv != nil {
app.Global().StopServer()
}
}
......@@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if sc, err := app.CreateChannelWithUser(channel, c.Session.UserId); err != nil {
if sc, err := c.App.CreateChannelWithUser(channel, c.Session.UserId); err != nil {
c.Err = err
return
} else {
......@@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if sc, err := app.CreateDirectChannel(c.Session.UserId, userId); err != nil {
if sc, err := c.App.CreateDirectChannel(c.Session.UserId, userId); err != nil {
c.Err = err
return
} else {
......@@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
userIds = append(userIds, c.Session.UserId)
}
if sc, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
if sc, err := c.App.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
c.Err = err
return
} else {
......@@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CanManageChannel(c *Context, channel *model.Channel) bool {
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
return false
}
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
return false
}
......@@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var oldChannel *model.Channel
var err *model.AppError
if oldChannel, err = app.GetChannel(channel.Id); err != nil {
if oldChannel, err = c.App.GetChannel(channel.Id); err != nil {
c.Err = err
return
}
if _, err = app.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
if _, err = c.App.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
c.Err = err
return
}
......@@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel.Type = channel.Type
}
if _, err := app.UpdateChannel(oldChannel); err != nil {
if _, err := c.App.UpdateChannel(oldChannel); err != nil {
c.Err = err
return
} else {
if oldChannelDisplayName != channel.DisplayName {
if err := app.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
if err := c.App.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
l4g.Error(err.Error())
}
}
......@@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(channelId); err != nil {
if channel, err = c.App.GetChannel(channelId); err != nil {
c.Err = err
return
}
if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil {
if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil {
c.Err = err
return
}
......@@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader := channel.Header
channel.Header = channelHeader
if _, err := app.UpdateChannel(channel); err != nil {
if _, err := c.App.UpdateChannel(channel); err != nil {
c.Err = err
return
} else {
if err := app.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil {
if err := c.App.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil {
l4g.Error(err.Error())
}
c.LogAudit("name=" + channel.Name)
......@@ -278,12 +278,12 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(channelId); err != nil {
if channel, err = c.App.GetChannel(channelId); err != nil {
c.Err = err
return
}
if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil {
if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil {
c.Err = err
return
}
......@@ -295,11 +295,11 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelPurpose := channel.Purpose
channel.Purpose = channelPurpose
if _, err := app.UpdateChannel(channel); err != nil {
if _, err := c.App.UpdateChannel(channel); err != nil {
c.Err = err
return
} else {
if err := app.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil {
if err := c.App.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil {
l4g.Error(err.Error())
}
c.LogAudit("name=" + channel.Name)
......@@ -315,10 +315,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
// Get's all channels the user is a member of
if channels, err := app.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil {
if channels, err := c.App.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil {
if err.Id == "store.sql_channel.get_channels.not_found.app_error" {
// lets make sure the user is valid
if _, err := app.GetUser(c.Session.UserId); err != nil {
if _, err := c.App.GetUser(c.Session.UserId); err != nil {
c.Err = err
c.RemoveSessionCookie(w, r)
l4g.Error(utils.T("api.channel.get_channels.error"), c.Session.UserId)
......@@ -356,7 +356,7 @@ func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if channels, err := app.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil {
if channels, err := c.App.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil {
c.Err = err
return
} else {
......@@ -369,7 +369,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if counts, err := app.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil {
if counts, err := c.App.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil {
c.Err = model.NewAppError("getChannelCounts", "api.channel.get_channel_counts.app_error", nil, err.Message, http.StatusInternalServerError)
return
} else if HandleEtag(counts.Etag(), "Get Channel Counts", w, r) {
......@@ -389,9 +389,9 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channelId != "" {
channel, err = app.GetChannel(channelId)
channel, err = c.App.GetChannel(channelId)
} else if channelName != "" {
channel, err = app.GetChannelByName(channelName, c.TeamId)
channel, err = c.App.GetChannelByName(channelName, c.TeamId)
} else {
c.SetInvalidParam("join", "channel_id, channel_name")
return
......@@ -409,7 +409,7 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if err = app.JoinChannel(channel, c.Session.UserId); err != nil {
if err = c.App.JoinChannel(channel, c.Session.UserId); err != nil {
c.Err = err
return
}
......@@ -422,7 +422,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["channel_id"]
err := app.LeaveChannel(id, c.Session.UserId)
err := c.App.LeaveChannel(id, c.Session.UserId)
if err != nil {
c.Err = err
return
......@@ -440,22 +440,22 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(id); err != nil {
if channel, err = c.App.GetChannel(id); err != nil {
c.Err = err
return
}
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
return
}
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
return
}
err = app.DeleteChannel(channel, c.Session.UserId)
err = c.App.DeleteChannel(channel, c.Session.UserId)
if err != nil {
c.Err = err
return
......@@ -474,7 +474,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(id); err != nil {
if channel, err = c.App.GetChannel(id); err != nil {
c.Err = err
return
}
......@@ -485,7 +485,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
var member *model.ChannelMember
if member, err = app.GetChannelMember(id, c.Session.UserId); err != nil {
if member, err = c.App.GetChannelMember(id, c.Session.UserId); err != nil {
c.Err = err
return
}
......@@ -506,11 +506,11 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelName := params["channel_name"]
if channel, err := app.GetChannelByName(channelName, c.TeamId); err != nil {
if channel, err := c.App.GetChannelByName(channelName, c.TeamId); err != nil {
c.Err = err
return
} else {
if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
......@@ -535,7 +535,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(id); err != nil {
if channel, err = c.App.GetChannel(id); err != nil {
c.Err = err
return
}
......@@ -545,12 +545,12 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
if memberCount, err := app.GetChannelMemberCount(id); err != nil {
if memberCount, err := c.App.GetChannelMemberCount(id); err != nil {
c.Err = err
return
} else {
......@@ -564,12 +564,12 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
channelId := params["channel_id"]
userId := params["user_id"]
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
if member, err := app.GetChannelMember(channelId, userId); err != nil {
if member, err := c.App.GetChannelMember(channelId, userId); err != nil {
c.Err = err
return
} else {
......@@ -578,7 +578,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
func getMyChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
if members, err := app.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil {
if members, err := c.App.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil {
c.Err = err
return
} else {
......@@ -590,7 +590,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelId := params["channel_id"]
if result := <-app.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil {
if result := <-c.App.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil {
c.Err = result.Err
return
} else {
......@@ -614,28 +614,28 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
var err *model.AppError
if channel, err = app.GetChannel(id); err != nil {
if channel, err = c.App.GetChannel(id); err != nil {
c.Err = err
return