app type transition (#7167)
Этот коммит содержится в:
20
api/admin.go
20
api/admin.go
@@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if audits, err := app.GetAudits("", 200); err != nil {
|
||||
if audits, err := c.App.GetAudits("", 200); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(audits.Etag(), "Get All Audits", w, r) {
|
||||
@@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func invalidateAllCaches(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
err := app.InvalidateAllCaches()
|
||||
err := c.App.InvalidateAllCaches()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
app.RecycleDatabaseConnection()
|
||||
c.App.RecycleDatabaseConnection()
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := app.TestEmail(c.Session.UserId, cfg)
|
||||
err := c.App.TestEmail(c.Session.UserId, cfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
crs, err := app.GetComplianceReports(0, 10000)
|
||||
crs, err := c.App.GetComplianceReports(0, 10000)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
job.UserId = c.Session.UserId
|
||||
|
||||
rjob, err := app.SaveComplianceReport(job)
|
||||
rjob, err := c.App.SaveComplianceReport(job)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
job, err := app.GetComplianceReport(id)
|
||||
job, err := c.App.GetComplianceReport(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamId := params["id"]
|
||||
name := params["name"]
|
||||
|
||||
rows, err := app.GetAnalytics(name, teamId)
|
||||
rows, err := c.App.GetAnalytics(name, teamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil {
|
||||
if err := c.App.UpdatePasswordByUserIdSendEmail(userId, newPassword, c.T("api.user.reset_password.method")); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getRecentlyActiveUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if profiles, err := app.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil {
|
||||
if profiles, err := c.App.GetRecentlyActiveUsersForTeam(c.TeamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -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)
|
||||
|
||||
10
api/api.go
10
api/api.go
@@ -60,14 +60,14 @@ type Routes struct {
|
||||
var BaseRoutes *Routes
|
||||
|
||||
func InitRouter() {
|
||||
app.Srv.Router = mux.NewRouter()
|
||||
app.Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
app.Global().Srv.Router = mux.NewRouter()
|
||||
app.Global().Srv.Router.NotFoundHandler = http.HandlerFunc(Handle404)
|
||||
}
|
||||
|
||||
func InitApi() {
|
||||
BaseRoutes = &Routes{}
|
||||
BaseRoutes.Root = app.Srv.Router
|
||||
BaseRoutes.ApiRoot = app.Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
|
||||
BaseRoutes.Root = app.Global().Srv.Router
|
||||
BaseRoutes.ApiRoot = app.Global().Srv.Router.PathPrefix(model.API_URL_SUFFIX_V3).Subrouter()
|
||||
BaseRoutes.Users = BaseRoutes.ApiRoot.PathPrefix("/users").Subrouter()
|
||||
BaseRoutes.NeedUser = BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
|
||||
BaseRoutes.Teams = BaseRoutes.ApiRoot.PathPrefix("/teams").Subrouter()
|
||||
@@ -111,7 +111,7 @@ func InitApi() {
|
||||
InitDeprecated()
|
||||
|
||||
// 404 on any api route before web.go has a chance to serve it
|
||||
app.Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
app.Global().Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
|
||||
|
||||
utils.InitHTML()
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
120
api/channel.go
120
api/channel.go
@@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sc, err := app.CreateChannelWithUser(channel, c.Session.UserId); err != nil {
|
||||
if sc, err := c.App.CreateChannelWithUser(channel, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sc, err := app.CreateDirectChannel(c.Session.UserId, userId); err != nil {
|
||||
if sc, err := c.App.CreateDirectChannel(c.Session.UserId, userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds = append(userIds, c.Session.UserId)
|
||||
}
|
||||
|
||||
if sc, err := app.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
|
||||
if sc, err := c.App.CreateGroupChannel(userIds, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func CanManageChannel(c *Context, channel *model.Channel) bool {
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
|
||||
return false
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
|
||||
return false
|
||||
}
|
||||
@@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var oldChannel *model.Channel
|
||||
var err *model.AppError
|
||||
if oldChannel, err = app.GetChannel(channel.Id); err != nil {
|
||||
if oldChannel, err = c.App.GetChannel(channel.Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = app.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetChannelMember(channel.Id, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oldChannel.Type = channel.Type
|
||||
}
|
||||
|
||||
if _, err := app.UpdateChannel(oldChannel); err != nil {
|
||||
if _, err := c.App.UpdateChannel(oldChannel); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if oldChannelDisplayName != channel.DisplayName {
|
||||
if err := app.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
|
||||
if err := c.App.PostUpdateChannelDisplayNameMessage(c.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(channelId); err != nil {
|
||||
if channel, err = c.App.GetChannel(channelId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oldChannelHeader := channel.Header
|
||||
channel.Header = channelHeader
|
||||
|
||||
if _, err := app.UpdateChannel(channel); err != nil {
|
||||
if _, err := c.App.UpdateChannel(channel); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if err := app.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil {
|
||||
if err := c.App.PostUpdateChannelHeaderMessage(c.Session.UserId, channel, oldChannelHeader, channelHeader); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
c.LogAudit("name=" + channel.Name)
|
||||
@@ -278,12 +278,12 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(channelId); err != nil {
|
||||
if channel, err = c.App.GetChannel(channelId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = app.GetChannelMember(channelId, c.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetChannelMember(channelId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -295,11 +295,11 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
oldChannelPurpose := channel.Purpose
|
||||
channel.Purpose = channelPurpose
|
||||
|
||||
if _, err := app.UpdateChannel(channel); err != nil {
|
||||
if _, err := c.App.UpdateChannel(channel); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if err := app.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil {
|
||||
if err := c.App.PostUpdateChannelPurposeMessage(c.Session.UserId, channel, oldChannelPurpose, channelPurpose); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
c.LogAudit("name=" + channel.Name)
|
||||
@@ -315,10 +315,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// user is already in the team
|
||||
// Get's all channels the user is a member of
|
||||
|
||||
if channels, err := app.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil {
|
||||
if channels, err := c.App.GetChannelsForUser(c.TeamId, c.Session.UserId); err != nil {
|
||||
if err.Id == "store.sql_channel.get_channels.not_found.app_error" {
|
||||
// lets make sure the user is valid
|
||||
if _, err := app.GetUser(c.Session.UserId); err != nil {
|
||||
if _, err := c.App.GetUser(c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
c.RemoveSessionCookie(w, r)
|
||||
l4g.Error(utils.T("api.channel.get_channels.error"), c.Session.UserId)
|
||||
@@ -356,7 +356,7 @@ func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if channels, err := app.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil {
|
||||
if channels, err := c.App.GetChannelsUserNotIn(c.TeamId, c.Session.UserId, offset, limit); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -369,7 +369,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// user is already in the team
|
||||
|
||||
if counts, err := app.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil {
|
||||
if counts, err := c.App.GetChannelCounts(c.TeamId, c.Session.UserId); err != nil {
|
||||
c.Err = model.NewAppError("getChannelCounts", "api.channel.get_channel_counts.app_error", nil, err.Message, http.StatusInternalServerError)
|
||||
return
|
||||
} else if HandleEtag(counts.Etag(), "Get Channel Counts", w, r) {
|
||||
@@ -389,9 +389,9 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channelId != "" {
|
||||
channel, err = app.GetChannel(channelId)
|
||||
channel, err = c.App.GetChannel(channelId)
|
||||
} else if channelName != "" {
|
||||
channel, err = app.GetChannelByName(channelName, c.TeamId)
|
||||
channel, err = c.App.GetChannelByName(channelName, c.TeamId)
|
||||
} else {
|
||||
c.SetInvalidParam("join", "channel_id, channel_name")
|
||||
return
|
||||
@@ -409,7 +409,7 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if err = app.JoinChannel(channel, c.Session.UserId); err != nil {
|
||||
if err = c.App.JoinChannel(channel, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
id := params["channel_id"]
|
||||
|
||||
err := app.LeaveChannel(id, c.Session.UserId)
|
||||
err := c.App.LeaveChannel(id, c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -440,22 +440,22 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(id); err != nil {
|
||||
if channel, err = c.App.GetChannel(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteChannel(channel, c.Session.UserId)
|
||||
err = c.App.DeleteChannel(channel, c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -474,7 +474,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(id); err != nil {
|
||||
if channel, err = c.App.GetChannel(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -485,7 +485,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var member *model.ChannelMember
|
||||
if member, err = app.GetChannelMember(id, c.Session.UserId); err != nil {
|
||||
if member, err = c.App.GetChannelMember(id, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -506,11 +506,11 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
channelName := params["channel_name"]
|
||||
|
||||
if channel, err := app.GetChannelByName(channelName, c.TeamId); err != nil {
|
||||
if channel, err := c.App.GetChannelByName(channelName, c.TeamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -535,7 +535,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(id); err != nil {
|
||||
if channel, err = c.App.GetChannel(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -545,12 +545,12 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if memberCount, err := app.GetChannelMemberCount(id); err != nil {
|
||||
if memberCount, err := c.App.GetChannelMemberCount(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -564,12 +564,12 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channelId := params["channel_id"]
|
||||
userId := params["user_id"]
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if member, err := app.GetChannelMember(channelId, userId); err != nil {
|
||||
if member, err := c.App.GetChannelMember(channelId, userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -578,7 +578,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getMyChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if members, err := app.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil {
|
||||
if members, err := c.App.GetChannelMembersForUser(c.TeamId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -590,7 +590,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
channelId := params["channel_id"]
|
||||
|
||||
if result := <-app.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Channel().GetPinnedPosts(channelId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -614,28 +614,28 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(id); err != nil {
|
||||
if channel, err = c.App.GetChannel(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
||||
var nUser *model.User
|
||||
if nUser, err = app.GetUser(userId); err != nil {
|
||||
if nUser, err = c.App.GetUser(userId); err != nil {
|
||||
c.Err = model.NewAppError("addMember", "api.channel.add_member.find_user.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
cm, err := app.AddUserToChannel(nUser, channel)
|
||||
cm, err := c.App.AddUserToChannel(nUser, channel)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -644,14 +644,14 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("name=" + channel.Name + " user_id=" + userId)
|
||||
|
||||
var oUser *model.User
|
||||
if oUser, err = app.GetUser(c.Session.UserId); err != nil {
|
||||
if oUser, err = c.App.GetUser(c.Session.UserId); err != nil {
|
||||
c.Err = model.NewAppError("addMember", "api.channel.add_member.user_adding.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
go app.PostAddToChannelMessage(oUser, nUser, channel)
|
||||
go c.App.PostAddToChannelMessage(oUser, nUser, channel)
|
||||
|
||||
app.UpdateChannelLastViewedAt([]string{id}, oUser.Id)
|
||||
c.App.UpdateChannelLastViewedAt([]string{id}, oUser.Id)
|
||||
w.Write([]byte(cm.ToJson()))
|
||||
}
|
||||
|
||||
@@ -669,22 +669,22 @@ func removeMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var channel *model.Channel
|
||||
var err *model.AppError
|
||||
if channel, err = app.GetChannel(channelId); err != nil {
|
||||
if channel, err = c.App.GetChannel(channelId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
||||
if err = app.RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil {
|
||||
if err = c.App.RemoveUserFromChannel(userIdToRemove, c.Session.UserId, channel); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -717,7 +717,7 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
member, err := app.UpdateChannelMemberNotifyProps(data, channelId, userId)
|
||||
member, err := c.App.UpdateChannelMemberNotifyProps(data, channelId, userId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -745,7 +745,7 @@ func searchMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if channels, err := app.SearchChannelsUserNotIn(c.TeamId, c.Session.UserId, props.Term); err != nil {
|
||||
if channels, err := c.App.SearchChannelsUserNotIn(c.TeamId, c.Session.UserId, props.Term); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -763,7 +763,7 @@ func autocompleteChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if channels, err := app.SearchChannels(c.TeamId, term); err != nil {
|
||||
if channels, err := c.App.SearchChannels(c.TeamId, term); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -779,7 +779,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.ViewChannel(view, c.Session.UserId, !c.Session.IsMobileApp()); err != nil {
|
||||
if err := c.App.ViewChannel(view, c.Session.UserId, !c.Session.IsMobileApp()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -797,12 +797,12 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if members, err := app.GetChannelMembersByIds(channelId, userIds); err != nil {
|
||||
if members, err := c.App.GetChannelMembersByIds(channelId, userIds); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -822,7 +822,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_CHANNEL_ROLES)
|
||||
return
|
||||
}
|
||||
@@ -833,7 +833,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := app.UpdateChannelMemberRoles(channelId, userId, newRoles); err != nil {
|
||||
if _, err := c.App.UpdateChannelMemberRoles(channelId, userId, newRoles); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
@@ -404,7 +403,7 @@ func TestUpdateChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
UpdateUserToTeamAdmin(th.BasicUser, team)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
if _, err := Client.UpdateChannel(channel2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -412,7 +411,7 @@ func TestUpdateChannel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
UpdateUserToNonTeamAdmin(th.BasicUser, team)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
|
||||
MakeUserChannelAdmin(th.BasicUser, channel2)
|
||||
MakeUserChannelAdmin(th.BasicUser, channel3)
|
||||
@@ -1188,7 +1187,7 @@ func TestJoinChannelByNameDisabledUser(t *testing.T) {
|
||||
|
||||
Client.Must(th.BasicClient.RemoveUserFromTeam(th.BasicTeam.Id, th.BasicUser.Id))
|
||||
|
||||
if _, err := app.AddUserToChannel(th.BasicUser, channel1); err == nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser, channel1); err == nil {
|
||||
t.Fatal("shoudn't be able to join channel")
|
||||
} else {
|
||||
if err.Id != "api.channel.add_user.to.channel.failed.deleted.app_error" {
|
||||
@@ -1406,7 +1405,7 @@ func TestDeleteChannel(t *testing.T) {
|
||||
UpdateUserToTeamAdmin(th.BasicUser, team)
|
||||
|
||||
Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
|
||||
if _, err := Client.DeleteChannel(channel2.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -1416,7 +1415,7 @@ func TestDeleteChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
UpdateUserToNonTeamAdmin(th.BasicUser, team)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
@@ -1634,7 +1633,7 @@ func TestAddChannelMember(t *testing.T) {
|
||||
}
|
||||
|
||||
MakeUserChannelAdmin(user1, channel5)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
utils.License().Features.SetDefaults()
|
||||
@@ -1659,7 +1658,7 @@ func TestAddChannelMember(t *testing.T) {
|
||||
}
|
||||
|
||||
UpdateUserToTeamAdmin(user1, team)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
utils.License().Features.SetDefaults()
|
||||
@@ -1810,7 +1809,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
}
|
||||
|
||||
MakeUserChannelAdmin(user1, channel5)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
utils.License().Features.SetDefaults()
|
||||
@@ -1835,7 +1834,7 @@ func TestRemoveChannelMember(t *testing.T) {
|
||||
}
|
||||
|
||||
UpdateUserToTeamAdmin(user1, team)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
utils.License().Features.SetDefaults()
|
||||
@@ -2255,7 +2254,7 @@ func TestGetChannelByName(t *testing.T) {
|
||||
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
Client.SetTeamId(th.BasicTeam.Id)
|
||||
|
||||
@@ -2314,7 +2313,7 @@ func TestViewChannel(t *testing.T) {
|
||||
func TestGetChannelMembersByIds(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if _, err := app.AddUserToChannel(th.BasicUser2, th.BasicChannel); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel); err != nil {
|
||||
t.Fatal("Could not add second user to channel")
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func TestCliCreateUserWithoutTeam(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.User().GetByEmail(email); result.Err != nil {
|
||||
if result := <-app.Global().Srv.Store.User().GetByEmail(email); result.Err != nil {
|
||||
t.Fatal()
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
@@ -131,7 +131,7 @@ func TestCliAssignRole(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.User().GetByEmail(th.BasicUser.Email); result.Err != nil {
|
||||
t.Fatal()
|
||||
} else {
|
||||
user := result.Data.(*model.User)
|
||||
@@ -369,7 +369,7 @@ func TestCliLeaveTeam(t *testing.T) {
|
||||
t.Fatal("profile should not be on team")
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil {
|
||||
teamMembers := result.Data.([]*model.TeamMember)
|
||||
if len(teamMembers) > 0 {
|
||||
t.Fatal("Shouldn't be in team")
|
||||
|
||||
@@ -34,7 +34,7 @@ func InitCommand() {
|
||||
}
|
||||
|
||||
func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
commands, err := app.ListAutocompleteCommands(c.TeamId, c.T)
|
||||
commands, err := c.App.ListAutocompleteCommands(c.TeamId, c.T)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -56,7 +56,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if len(commandArgs.ChannelId) > 0 {
|
||||
if !app.SessionHasPermissionToChannel(c.Session, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
c.SetPermissionError(model.PERMISSION_USE_SLASH_COMMANDS)
|
||||
return
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
commandArgs.Session = c.Session
|
||||
commandArgs.SiteURL = c.GetSiteURLHeader()
|
||||
|
||||
response, err := app.ExecuteCommand(commandArgs)
|
||||
response, err := c.App.ExecuteCommand(commandArgs)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -95,7 +95,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cmd.CreatorId = c.Session.UserId
|
||||
cmd.TeamId = c.TeamId
|
||||
|
||||
rcmd, err := app.CreateCommand(cmd)
|
||||
rcmd, err := c.App.CreateCommand(cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -115,7 +115,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
oldCmd, err := app.GetCommand(cmd.Id)
|
||||
oldCmd, err := c.App.GetCommand(cmd.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -138,7 +138,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rcmd, err := app.UpdateCommand(oldCmd, cmd)
|
||||
rcmd, err := c.App.UpdateCommand(oldCmd, cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -155,7 +155,7 @@ func listTeamCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cmds, err := app.ListTeamCommands(c.TeamId)
|
||||
cmds, err := c.App.ListTeamCommands(c.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -175,7 +175,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
cmd, err := app.GetCommand(id)
|
||||
cmd, err := c.App.GetCommand(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -198,7 +198,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rcmd, err := app.RegenCommandToken(cmd)
|
||||
rcmd, err := c.App.RegenCommandToken(cmd)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -218,7 +218,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
cmd, err := app.GetCommand(id)
|
||||
cmd, err := c.App.GetCommand(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -241,7 +241,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteCommand(cmd.Id)
|
||||
err = c.App.DeleteCommand(cmd.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHelpCommand(t *testing.T) {
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func TestMsgCommands(t *testing.T) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
App *app.App
|
||||
Session model.Session
|
||||
RequestId string
|
||||
IpAddress string
|
||||
@@ -107,6 +108,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c := &Context{}
|
||||
c.App = app.Global()
|
||||
c.T, c.Locale = utils.GetTranslationsAndLocale(w, r)
|
||||
c.RequestId = model.NewId()
|
||||
c.IpAddress = utils.GetIpAddress(r)
|
||||
@@ -165,7 +167,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if len(token) != 0 {
|
||||
session, err := app.GetSession(token)
|
||||
session, err := app.Global().GetSession(token)
|
||||
|
||||
if err != nil {
|
||||
l4g.Error(utils.T("api.context.invalid_session.error"), err.Error())
|
||||
@@ -206,8 +208,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if c.Err == nil && h.isUserActivity && token != "" && len(c.Session.UserId) > 0 {
|
||||
app.SetStatusOnline(c.Session.UserId, c.Session.Id, false)
|
||||
app.UpdateLastActivityAtIfNeeded(c.Session)
|
||||
app.Global().SetStatusOnline(c.Session.UserId, c.Session.Id, false)
|
||||
app.Global().UpdateLastActivityAtIfNeeded(c.Session)
|
||||
}
|
||||
|
||||
if c.Err == nil && (h.requireUser || h.requireSystemAdmin) {
|
||||
@@ -258,7 +260,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (c *Context) LogAudit(extraInfo string) {
|
||||
audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
|
||||
if r := <-app.Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
if r := <-app.Global().Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
c.LogError(r.Err)
|
||||
}
|
||||
}
|
||||
@@ -270,7 +272,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
}
|
||||
|
||||
audit := &model.Audit{UserId: userId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
|
||||
if r := <-app.Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
if r := <-app.Global().Srv.Store.Audit().Save(audit); r.Err != nil {
|
||||
c.LogError(r.Err)
|
||||
}
|
||||
}
|
||||
@@ -314,7 +316,7 @@ func (c *Context) MfaRequired() {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
|
||||
if result := <-app.Global().Srv.Store.User().Get(c.Session.UserId); result.Err != nil {
|
||||
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "MfaRequired", http.StatusUnauthorized)
|
||||
return
|
||||
} else {
|
||||
@@ -391,7 +393,7 @@ func (c *Context) setTeamURL(url string, valid bool) {
|
||||
}
|
||||
|
||||
func (c *Context) SetTeamURLFromSession() {
|
||||
if result := <-app.Srv.Store.Team().Get(c.TeamId); result.Err == nil {
|
||||
if result := <-app.Global().Srv.Store.Team().Get(c.TeamId); result.Err == nil {
|
||||
c.setTeamURL(c.GetSiteURLHeader()+"/"+result.Data.(*model.Team).Name, true)
|
||||
}
|
||||
}
|
||||
@@ -445,7 +447,7 @@ func Handle404(w http.ResponseWriter, r *http.Request) {
|
||||
func (c *Context) CheckTeamId() {
|
||||
if c.TeamId != "" && c.Session.GetTeamByTeamId(c.TeamId) == nil {
|
||||
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if result := <-app.Srv.Store.Team().Get(c.TeamId); result.Err != nil {
|
||||
if result := <-app.Global().Srv.Store.Team().Get(c.TeamId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
c.Err.StatusCode = http.StatusBadRequest
|
||||
return
|
||||
|
||||
15
api/emoji.go
15
api/emoji.go
@@ -10,6 +10,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"image/color/palette"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -17,7 +19,6 @@ import (
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"image/color/palette"
|
||||
)
|
||||
|
||||
func InitEmoji() {
|
||||
@@ -35,7 +36,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
listEmoji, err := app.GetEmojiList(0, 100000)
|
||||
listEmoji, err := c.App.GetEmojiList(0, 100000)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -97,7 +98,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Emoji().GetByName(emoji.Name); result.Err == nil && result.Data != nil {
|
||||
if result := <-c.App.Srv.Store.Emoji().GetByName(emoji.Name); result.Err == nil && result.Data != nil {
|
||||
c.Err = model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -110,7 +111,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Emoji().Save(emoji); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Emoji().Save(emoji); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -141,7 +142,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
emoji, err := app.GetEmoji(id)
|
||||
emoji, err := c.App.GetEmoji(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -152,7 +153,7 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteEmoji(emoji)
|
||||
err = c.App.DeleteEmoji(emoji)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -180,7 +181,7 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
image, imageType, err := app.GetEmojiImage(id)
|
||||
image, imageType, err := c.App.GetEmojiImage(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -42,11 +42,11 @@ func TestGetEmoji(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, emoji := range emojis {
|
||||
emojis[i] = store.Must(app.Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
emojis[i] = store.Must(th.App.Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
}
|
||||
defer func() {
|
||||
for _, emoji := range emojis {
|
||||
store.Must(app.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
store.Must(th.App.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestGetEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
DeleteAt: 1,
|
||||
}
|
||||
deleted = store.Must(app.Srv.Store.Emoji().Save(deleted)).(*model.Emoji)
|
||||
deleted = store.Must(th.App.Srv.Store.Emoji().Save(deleted)).(*model.Emoji)
|
||||
|
||||
if returnedEmojis, err := Client.ListEmoji(); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -264,10 +264,10 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
}
|
||||
|
||||
func createTestEmoji(t *testing.T, emoji *model.Emoji, imageData []byte) *model.Emoji {
|
||||
emoji = store.Must(app.Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
emoji = store.Must(app.Global().Srv.Store.Emoji().Save(emoji)).(*model.Emoji)
|
||||
|
||||
if err := utils.WriteFile(imageData, "emoji/"+emoji.Id+"/image"); err != nil {
|
||||
store.Must(app.Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
store.Must(app.Global().Srv.Store.Emoji().Delete(emoji.Id, time.Now().Unix()))
|
||||
t.Fatalf("failed to write image: %v", err.Error())
|
||||
}
|
||||
|
||||
|
||||
10
api/file.go
10
api/file.go
@@ -74,12 +74,12 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
c.SetPermissionError(model.PERMISSION_UPLOAD_FILE)
|
||||
return
|
||||
}
|
||||
|
||||
resStruct, err := app.UploadFiles(c.TeamId, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"])
|
||||
resStruct, err := c.App.UploadFiles(c.TeamId, channelId, c.Session.UserId, m.File["files"], m.Value["client_ids"])
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -205,7 +205,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool)
|
||||
return nil, NewInvalidParamError("getFileInfoForRequest", "file_id")
|
||||
}
|
||||
|
||||
info, err := app.GetFileInfo(fileId)
|
||||
info, err := c.App.GetFileInfo(fileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool)
|
||||
}
|
||||
|
||||
if requireFileVisible {
|
||||
if !app.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return nil, c.Err
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
path := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
|
||||
|
||||
var info *model.FileInfo
|
||||
if result := <-app.Srv.Store.FileInfo().GetByPath(path); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.FileInfo().GetByPath(path); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestUploadFile(t *testing.T) {
|
||||
}
|
||||
|
||||
var info *model.FileInfo
|
||||
if result := <-app.Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.FileInfo().Get(uploadInfo.Id); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
info = result.Data.(*model.FileInfo)
|
||||
@@ -170,7 +170,7 @@ func TestGetFileInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
// Other user shouldn't be able to get file info for this file if they're not in the channel for it
|
||||
if _, err := Client.GetFileInfo(fileId); err == nil {
|
||||
@@ -186,7 +186,7 @@ func TestGetFileInfo(t *testing.T) {
|
||||
t.Fatal("other user got incorrect file")
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func TestGetFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
// Other user shouldn't be able to get file for this file if they're not in the channel for it
|
||||
if _, err := Client.GetFile(fileId); err == nil {
|
||||
@@ -268,7 +268,7 @@ func TestGetFile(t *testing.T) {
|
||||
body.Close()
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func TestGetFileThumbnail(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
// Other user shouldn't be able to get thumbnail for this file if they're not in the channel for it
|
||||
if _, err := Client.GetFileThumbnail(fileId); err == nil {
|
||||
@@ -324,7 +324,7 @@ func TestGetFileThumbnail(t *testing.T) {
|
||||
body.Close()
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ func TestGetFilePreview(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
// Other user shouldn't be able to get preview for this file if they're not in the channel for it
|
||||
if _, err := Client.GetFilePreview(fileId); err == nil {
|
||||
@@ -380,7 +380,7 @@ func TestGetFilePreview(t *testing.T) {
|
||||
body.Close()
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -413,7 +413,7 @@ func TestGetPublicFile(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
link := Client.MustGeneric(Client.GetPublicLink(fileId)).(string)
|
||||
|
||||
@@ -447,7 +447,7 @@ func TestGetPublicFile(t *testing.T) {
|
||||
t.Fatal("should've failed to get image with public link after salt changed")
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -483,12 +483,12 @@ func TestGetPublicFileOld(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Path: fmt.Sprintf("teams/%s/channels/%s/users/%s/%s/%s", th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId, "test.png"),
|
||||
}
|
||||
store.Must(app.Srv.Store.FileInfo().Save(&fileInfo))
|
||||
store.Must(th.App.Srv.Store.FileInfo().Save(&fileInfo))
|
||||
uploadFileOld(t, data, fmt.Sprintf("data/teams/%s/channels/%s/users/%s/%s", th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId), "test.png")
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
// reconstruct old style of link
|
||||
siteURL := *utils.Cfg.ServiceSettings.SiteURL
|
||||
@@ -526,7 +526,7 @@ func TestGetPublicFileOld(t *testing.T) {
|
||||
t.Fatal("should've failed to get image with public link after salt changed")
|
||||
}
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -565,7 +565,7 @@ func TestGetPublicLink(t *testing.T) {
|
||||
}
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
|
||||
|
||||
utils.Cfg.FileSettings.EnablePublicLink = false
|
||||
|
||||
@@ -600,7 +600,7 @@ func TestGetPublicLink(t *testing.T) {
|
||||
// Wait a bit for files to ready
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
if err := cleanupTestFile(store.Must(app.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
if err := cleanupTestFile(store.Must(th.App.Srv.Store.FileInfo().Get(fileId)).(*model.FileInfo)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -635,7 +635,7 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
|
||||
}
|
||||
|
||||
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
|
||||
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
|
||||
post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel1.Id,
|
||||
Message: "test",
|
||||
@@ -757,20 +757,20 @@ func TestFindTeamIdForFilename(t *testing.T) {
|
||||
}
|
||||
|
||||
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
|
||||
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
|
||||
post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel1.Id,
|
||||
Message: "test",
|
||||
Filenames: []string{fmt.Sprintf("/%s/%s/%s/%s", channel1.Id, user1.Id, fileId1, "test.png")},
|
||||
})).(*model.Post)
|
||||
|
||||
if teamId := app.FindTeamIdForFilename(post1, post1.Filenames[0]); teamId != team1.Id {
|
||||
if teamId := th.App.FindTeamIdForFilename(post1, post1.Filenames[0]); teamId != team1.Id {
|
||||
t.Log(teamId)
|
||||
t.Fatal("file should've been found under team1")
|
||||
}
|
||||
|
||||
Client.SetTeamId(team2.Id)
|
||||
post2 := store.Must(app.Srv.Store.Post().Save(&model.Post{
|
||||
post2 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel2.Id,
|
||||
Message: "test",
|
||||
@@ -778,7 +778,7 @@ func TestFindTeamIdForFilename(t *testing.T) {
|
||||
})).(*model.Post)
|
||||
Client.SetTeamId(team1.Id)
|
||||
|
||||
if teamId := app.FindTeamIdForFilename(post2, post2.Filenames[0]); teamId != team2.Id {
|
||||
if teamId := th.App.FindTeamIdForFilename(post2, post2.Filenames[0]); teamId != team2.Id {
|
||||
t.Fatal("file should've been found under team2")
|
||||
}
|
||||
}
|
||||
@@ -808,13 +808,13 @@ func TestGetInfoForFilename(t *testing.T) {
|
||||
} else {
|
||||
fileId1 = Client.MustGeneric(Client.UploadPostAttachment(data, channel1.Id, "test.png")).(*model.FileUploadResponse).FileInfos[0].Id
|
||||
uploadFileOld(t, data, fmt.Sprintf("data/teams/%s/channels/%s/users/%s/%s", team1.Id, channel1.Id, user1.Id, fileId1), "test.png")
|
||||
path = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path
|
||||
thumbnailPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath
|
||||
previewPath = store.Must(app.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath
|
||||
path = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).Path
|
||||
thumbnailPath = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).ThumbnailPath
|
||||
previewPath = store.Must(th.App.Srv.Store.FileInfo().Get(fileId1)).(*model.FileInfo).PreviewPath
|
||||
}
|
||||
|
||||
// Bypass the Client whenever possible since we're trying to simulate a pre-3.5 post
|
||||
post1 := store.Must(app.Srv.Store.Post().Save(&model.Post{
|
||||
post1 := store.Must(th.App.Srv.Store.Post().Save(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel1.Id,
|
||||
Message: "test",
|
||||
|
||||
@@ -55,7 +55,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
io.Copy(buf, file)
|
||||
|
||||
if license, err := app.SaveLicense(buf.Bytes()); err != nil {
|
||||
if license, err := c.App.SaveLicense(buf.Bytes()); err != nil {
|
||||
if err.Id == model.EXPIRED_LICENSE_ERROR {
|
||||
c.LogAudit("failed - expired or non-started license")
|
||||
} else if err.Id == model.INVALID_LICENSE_ERROR {
|
||||
@@ -74,7 +74,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
|
||||
if err := app.RemoveLicense(); err != nil {
|
||||
if err := c.App.RemoveLicense(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/utils"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func TestGetLicenceConfig(t *testing.T) {
|
||||
|
||||
30
api/oauth.go
30
api/oauth.go
@@ -43,7 +43,7 @@ func registerOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
oauthApp.CreatorId = c.Session.UserId
|
||||
|
||||
rapp, err := app.CreateOAuthApp(oauthApp)
|
||||
rapp, err := c.App.CreateOAuthApp(oauthApp)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -63,9 +63,9 @@ func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var apps []*model.OAuthApp
|
||||
var err *model.AppError
|
||||
if app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
apps, err = app.GetOAuthApps(0, 100000)
|
||||
apps, err = c.App.GetOAuthApps(0, 100000)
|
||||
} else {
|
||||
apps, err = app.GetOAuthAppsByCreator(c.Session.UserId, 0, 100000)
|
||||
apps, err = c.App.GetOAuthAppsByCreator(c.Session.UserId, 0, 100000)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -80,7 +80,7 @@ func getOAuthAppInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
clientId := params["client_id"]
|
||||
|
||||
oauthApp, err := app.GetOAuthApp(clientId)
|
||||
oauthApp, err := c.App.GetOAuthApp(clientId)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -123,7 +123,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
State: state,
|
||||
}
|
||||
|
||||
redirectUrl, err := app.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
|
||||
redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.Session.UserId, authRequest)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -136,7 +136,7 @@ func allowOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getAuthorizedApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
apps, err := app.GetAuthorizedAppsForUser(c.Session.UserId, 0, 10000)
|
||||
apps, err := c.App.GetAuthorizedAppsForUser(c.Session.UserId, 0, 10000)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -151,13 +151,13 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
loginHint := r.URL.Query().Get("login_hint")
|
||||
redirectTo := r.URL.Query().Get("redirect_to")
|
||||
|
||||
teamId, err := app.GetTeamIdFromQuery(r.URL.Query())
|
||||
teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if authUrl, err := app.GetOAuthLoginEndpoint(w, r, service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
|
||||
if authUrl, err := c.App.GetOAuthLoginEndpoint(w, r, service, teamId, model.OAUTH_ACTION_LOGIN, redirectTo, loginHint); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -174,13 +174,13 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
teamId, err := app.GetTeamIdFromQuery(r.URL.Query())
|
||||
teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if authUrl, err := app.GetOAuthSignupEndpoint(w, r, service, teamId); err != nil {
|
||||
if authUrl, err := c.App.GetOAuthSignupEndpoint(w, r, service, teamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -204,7 +204,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oauthApp, err := app.GetOAuthApp(id)
|
||||
oauthApp, err := c.App.GetOAuthApp(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -216,7 +216,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = app.DeleteOAuthApp(id)
|
||||
err = c.App.DeleteOAuthApp(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -230,7 +230,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
id := params["id"]
|
||||
|
||||
err := app.DeauthorizeOAuthAppForUser(c.Session.UserId, id)
|
||||
err := c.App.DeauthorizeOAuthAppForUser(c.Session.UserId, id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -244,7 +244,7 @@ func regenerateOAuthSecret(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
id := params["id"]
|
||||
|
||||
oauthApp, err := app.GetOAuthApp(id)
|
||||
oauthApp, err := c.App.GetOAuthApp(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -255,7 +255,7 @@ func regenerateOAuthSecret(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oauthApp, err = app.RegenerateOAuthAppSecret(oauthApp)
|
||||
oauthApp, err = c.App.RegenerateOAuthAppSecret(oauthApp)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
@@ -77,7 +76,7 @@ func TestOAuthRegisterApp(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true}
|
||||
|
||||
ruser := Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
app.UpdateUserRoles(ruser.Id, "")
|
||||
th.App.UpdateUserRoles(ruser.Id, "")
|
||||
|
||||
Client.Logout()
|
||||
Client.Login(user.Email, user.Password)
|
||||
@@ -233,7 +232,7 @@ func TestOAuthGetAppsByUser(t *testing.T) {
|
||||
|
||||
user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true}
|
||||
ruser := Client.Must(AdminClient.CreateUser(user, "")).Data.(*model.User)
|
||||
app.UpdateUserRoles(ruser.Id, "")
|
||||
th.App.UpdateUserRoles(ruser.Id, "")
|
||||
|
||||
Client.Logout()
|
||||
Client.Login(user.Email, user.Password)
|
||||
@@ -338,7 +337,7 @@ func TestOAuthDeauthorizeApp(t *testing.T) {
|
||||
a1.RefreshToken = model.NewId()
|
||||
a1.ExpiresAt = model.GetMillis()
|
||||
a1.RedirectUri = "http://example.com"
|
||||
<-app.Srv.Store.OAuth().SaveAccessData(&a1)
|
||||
<-th.App.Srv.Store.OAuth().SaveAccessData(&a1)
|
||||
|
||||
if err := Client.OAuthDeauthorizeApp(oauthApp.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -446,7 +445,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
|
||||
user := &model.User{Email: strings.ToLower("test+"+model.NewId()) + "@simulator.amazonses.com", Password: "hello1", Username: "n" + model.NewId(), EmailVerified: true}
|
||||
ruser := Client.Must(AdminClient.CreateUser(user, "")).Data.(*model.User)
|
||||
app.UpdateUserRoles(ruser.Id, "")
|
||||
th.App.UpdateUserRoles(ruser.Id, "")
|
||||
|
||||
Client.Logout()
|
||||
Client.Login(user.Email, user.Password)
|
||||
@@ -675,7 +674,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
}
|
||||
|
||||
authData := &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: -1}
|
||||
<-app.Srv.Store.OAuth().SaveAuthData(authData)
|
||||
<-th.App.Srv.Store.OAuth().SaveAuthData(authData)
|
||||
|
||||
data.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE)
|
||||
data.Set("client_id", oauthApp.Id)
|
||||
@@ -688,7 +687,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
}
|
||||
|
||||
authData = &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: model.AUTHCODE_EXPIRE_TIME}
|
||||
<-app.Srv.Store.OAuth().SaveAuthData(authData)
|
||||
<-th.App.Srv.Store.OAuth().SaveAuthData(authData)
|
||||
|
||||
data.Set("code", authData.Code)
|
||||
if _, err := Client.GetAccessToken(data); err == nil {
|
||||
@@ -787,7 +786,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
closeBody(r)
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.User().UpdateAuthData(
|
||||
if result := <-th.App.Srv.Store.User().UpdateAuthData(
|
||||
th.BasicUser.Id, model.SERVICE_GITLAB, &th.BasicUser.Email, th.BasicUser.Email, true); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
62
api/post.go
62
api/post.go
@@ -52,9 +52,9 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
post.UserId = c.Session.UserId
|
||||
|
||||
hasPermission := false
|
||||
if app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) {
|
||||
if c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_CREATE_POST) {
|
||||
hasPermission = true
|
||||
} else if channel, err := app.GetChannel(post.ChannelId); err == nil {
|
||||
} else if channel, err := c.App.GetChannel(post.ChannelId); err == nil {
|
||||
// Temporary permission check method until advanced permissions, please do not copy
|
||||
if channel.Type == model.CHANNEL_OPEN && app.SessionHasPermissionToTeam(c.Session, channel.TeamId, model.PERMISSION_CREATE_POST_PUBLIC) {
|
||||
hasPermission = true
|
||||
@@ -70,7 +70,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
post.CreateAt = 0
|
||||
}
|
||||
|
||||
rp, err := app.CreatePostAsUser(post)
|
||||
rp, err := c.App.CreatePostAsUser(post)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -87,14 +87,14 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_EDIT_POST) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_EDIT_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
||||
return
|
||||
}
|
||||
|
||||
post.UserId = c.Session.UserId
|
||||
|
||||
rpost, err := app.UpdatePost(post, true)
|
||||
rpost, err := c.App.UpdatePost(post, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -118,7 +118,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
|
||||
return
|
||||
}
|
||||
|
||||
pchan := app.Srv.Store.Post().Get(postId)
|
||||
pchan := c.App.Srv.Store.Post().Get(postId)
|
||||
|
||||
var oldPost *model.Post
|
||||
if result := <-pchan; result.Err != nil {
|
||||
@@ -130,7 +130,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
|
||||
*newPost = *oldPost
|
||||
newPost.IsPinned = isPinned
|
||||
|
||||
if result := <-app.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -141,7 +141,7 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
|
||||
|
||||
go app.Publish(message)
|
||||
|
||||
app.InvalidateCacheForChannelPosts(rpost.ChannelId)
|
||||
c.App.InvalidateCacheForChannelPosts(rpost.ChannelId)
|
||||
|
||||
w.Write([]byte(rpost.ToJson()))
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func getFlaggedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if posts, err := app.GetFlaggedPostsForTeam(c.Session.UserId, c.TeamId, offset, limit); err != nil {
|
||||
if posts, err := c.App.GetFlaggedPostsForTeam(c.Session.UserId, c.TeamId, offset, limit); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -205,18 +205,18 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_CREATE_POST) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_CREATE_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_POST)
|
||||
return
|
||||
}
|
||||
|
||||
etag := app.GetPostsEtag(id)
|
||||
etag := c.App.GetPostsEtag(id)
|
||||
|
||||
if HandleEtag(etag, "Get Posts", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if list, err := app.GetPosts(id, offset, limit); err != nil {
|
||||
if list, err := c.App.GetPosts(id, offset, limit); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -241,12 +241,12 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if list, err := app.GetPostsSince(id, time); err != nil {
|
||||
if list, err := c.App.GetPostsSince(id, time); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -270,12 +270,12 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if list, err := app.GetPostThread(postId); err != nil {
|
||||
if list, err := c.App.GetPostThread(postId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(list.Etag(), "Get Post", w, r) {
|
||||
@@ -300,7 +300,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if list, err := app.GetPostThread(postId); err != nil {
|
||||
if list, err := c.App.GetPostThread(postId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -310,7 +310,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
post := list.Posts[list.Order[0]]
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
if result := <-app.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
if result := <-c.App.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
channel = result.Data.(*model.Channel)
|
||||
} else {
|
||||
c.SetInvalidParam("getPermalinkTmp", "postId")
|
||||
@@ -342,18 +342,18 @@ func getPermalinkTmp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if !app.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
|
||||
if !c.App.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_JOIN_PUBLIC_CHANNELS)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !app.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.HasPermissionToChannelByPost(c.Session.UserId, postId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if list, err := app.GetPermalinkPost(postId, c.Session.UserId); err != nil {
|
||||
if list, err := c.App.GetPermalinkPost(postId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(list.Etag(), "Get Permalink TMP", w, r) {
|
||||
@@ -379,17 +379,17 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_DELETE_POST) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_DELETE_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_POST)
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToPost(c.Session, postId, model.PERMISSION_DELETE_OTHERS_POSTS) {
|
||||
if !c.App.SessionHasPermissionToPost(c.Session, postId, model.PERMISSION_DELETE_OTHERS_POSTS) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_OTHERS_POSTS)
|
||||
return
|
||||
}
|
||||
|
||||
if post, err := app.DeletePost(postId); err != nil {
|
||||
if post, err := c.App.DeletePost(postId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -439,19 +439,19 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
// We can do better than this etag in this situation
|
||||
etag := app.GetPostsEtag(id)
|
||||
etag := c.App.GetPostsEtag(id)
|
||||
|
||||
if HandleEtag(etag, "Get Posts Before or After", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if list, err := app.GetPostsAroundPost(postId, id, offset, numPosts, before); err != nil {
|
||||
if list, err := c.App.GetPostsAroundPost(postId, id, offset, numPosts, before); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -474,7 +474,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
isOrSearch = val.(bool)
|
||||
}
|
||||
|
||||
posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch)
|
||||
posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -499,12 +499,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if infos, err := app.GetFileInfosForPost(postId, false); err != nil {
|
||||
if infos, err := c.App.GetFileInfosForPost(postId, false); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(model.GetEtagForFileInfos(infos), "Get File Infos For Post", w, r) {
|
||||
|
||||
@@ -142,7 +142,7 @@ func TestCreatePost(t *testing.T) {
|
||||
} else if rpost9 := resp.Data.(*model.Post); len(rpost9.FileIds) != 3 {
|
||||
t.Fatal("post should have 3 files")
|
||||
} else {
|
||||
infos := store.Must(app.Srv.Store.FileInfo().GetForPost(rpost9.Id, true, true)).([]*model.FileInfo)
|
||||
infos := store.Must(adm.App.Srv.Store.FileInfo().GetForPost(rpost9.Id, true, true)).([]*model.FileInfo)
|
||||
|
||||
if len(infos) != 3 {
|
||||
t.Fatal("should've attached all 3 files to post")
|
||||
@@ -164,7 +164,7 @@ func TestCreatePost(t *testing.T) {
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
utils.License().Features.SetDefaults()
|
||||
|
||||
defaultChannel := store.Must(app.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
||||
defaultChannel := store.Must(adm.App.Srv.Store.Channel().GetByName(team.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
||||
defaultPost := &model.Post{
|
||||
ChannelId: defaultChannel.Id,
|
||||
Message: "Default Channel Post",
|
||||
@@ -173,7 +173,7 @@ func TestCreatePost(t *testing.T) {
|
||||
t.Fatal("should have failed -- ExperimentalTownSquareIsReadOnly is true and it's a read only channel")
|
||||
}
|
||||
|
||||
adminDefaultChannel := store.Must(app.Srv.Store.Channel().GetByName(adminTeam.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
||||
adminDefaultChannel := store.Must(adm.App.Srv.Store.Channel().GetByName(adminTeam.Id, model.DEFAULT_CHANNEL, true)).(*model.Channel)
|
||||
adminDefaultPost := &model.Post{
|
||||
ChannelId: adminDefaultChannel.Id,
|
||||
Message: "Admin Default Channel Post",
|
||||
@@ -1085,7 +1085,7 @@ func TestEmailMention(t *testing.T) {
|
||||
data["comments"] = "any"
|
||||
Client.Must(Client.UpdateUserNotify(data))
|
||||
|
||||
store.Must(app.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser2.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
@@ -1189,28 +1189,28 @@ func TestGetFlaggedPosts(t *testing.T) {
|
||||
func TestGetMessageForNotification(t *testing.T) {
|
||||
Setup().InitBasic()
|
||||
|
||||
testPng := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
testPng := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
CreatorId: model.NewId(),
|
||||
Path: "test1.png",
|
||||
Name: "test1.png",
|
||||
MimeType: "image/png",
|
||||
})).(*model.FileInfo)
|
||||
|
||||
testJpg1 := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
testJpg1 := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
CreatorId: model.NewId(),
|
||||
Path: "test2.jpg",
|
||||
Name: "test2.jpg",
|
||||
MimeType: "image/jpeg",
|
||||
})).(*model.FileInfo)
|
||||
|
||||
testFile := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
testFile := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
CreatorId: model.NewId(),
|
||||
Path: "test1.go",
|
||||
Name: "test1.go",
|
||||
MimeType: "text/plain",
|
||||
})).(*model.FileInfo)
|
||||
|
||||
testJpg2 := store.Must(app.Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
testJpg2 := store.Must(app.Global().Srv.Store.FileInfo().Save(&model.FileInfo{
|
||||
CreatorId: model.NewId(),
|
||||
Path: "test3.jpg",
|
||||
Name: "test3.jpg",
|
||||
@@ -1224,39 +1224,39 @@ func TestGetMessageForNotification(t *testing.T) {
|
||||
Message: "test",
|
||||
}
|
||||
|
||||
if app.GetMessageForNotification(post, translateFunc) != "test" {
|
||||
if app.Global().GetMessageForNotification(post, translateFunc) != "test" {
|
||||
t.Fatal("should've returned message text")
|
||||
}
|
||||
|
||||
post.FileIds = model.StringArray{testPng.Id}
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(testPng.Id, post.Id))
|
||||
if app.GetMessageForNotification(post, translateFunc) != "test" {
|
||||
store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testPng.Id, post.Id))
|
||||
if app.Global().GetMessageForNotification(post, translateFunc) != "test" {
|
||||
t.Fatal("should've returned message text, even with attachments")
|
||||
}
|
||||
|
||||
post.Message = ""
|
||||
if message := app.GetMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" {
|
||||
if message := app.Global().GetMessageForNotification(post, translateFunc); message != "1 image sent: test1.png" {
|
||||
t.Fatal("should've returned number of images:", message)
|
||||
}
|
||||
|
||||
post.FileIds = model.StringArray{testPng.Id, testJpg1.Id}
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(testJpg1.Id, post.Id))
|
||||
app.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id)
|
||||
if message := app.GetMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" && message != "2 images sent: test2.jpg, test1.png" {
|
||||
store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testJpg1.Id, post.Id))
|
||||
app.Global().Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id)
|
||||
if message := app.Global().GetMessageForNotification(post, translateFunc); message != "2 images sent: test1.png, test2.jpg" && message != "2 images sent: test2.jpg, test1.png" {
|
||||
t.Fatal("should've returned number of images:", message)
|
||||
}
|
||||
|
||||
post.Id = model.NewId()
|
||||
post.FileIds = model.StringArray{testFile.Id}
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(testFile.Id, post.Id))
|
||||
if message := app.GetMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" {
|
||||
store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testFile.Id, post.Id))
|
||||
if message := app.Global().GetMessageForNotification(post, translateFunc); message != "1 file sent: test1.go" {
|
||||
t.Fatal("should've returned number of files:", message)
|
||||
}
|
||||
|
||||
store.Must(app.Srv.Store.FileInfo().AttachToPost(testJpg2.Id, post.Id))
|
||||
app.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id)
|
||||
store.Must(app.Global().Srv.Store.FileInfo().AttachToPost(testJpg2.Id, post.Id))
|
||||
app.Global().Srv.Store.FileInfo().InvalidateFileInfosForPostCache(post.Id)
|
||||
post.FileIds = model.StringArray{testFile.Id, testJpg2.Id}
|
||||
if message := app.GetMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test3.jpg" && message != "2 files sent: test3.jpg, test1.go" {
|
||||
if message := app.Global().GetMessageForNotification(post, translateFunc); message != "2 files sent: test1.go, test3.jpg" && message != "2 files sent: test3.jpg, test1.go" {
|
||||
t.Fatal("should've returned number of mixed files:", message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitPreference() {
|
||||
@@ -23,7 +23,7 @@ func InitPreference() {
|
||||
}
|
||||
|
||||
func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if result := <-app.Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preferences)
|
||||
@@ -39,7 +39,7 @@ func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.UpdatePreferences(c.Session.UserId, preferences); err != nil {
|
||||
if err := c.App.UpdatePreferences(c.Session.UserId, preferences); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
category := params["category"]
|
||||
|
||||
if result := <-app.Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preferences)
|
||||
@@ -65,7 +65,7 @@ func getPreference(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
category := params["category"]
|
||||
name := params["name"]
|
||||
|
||||
if result := <-app.Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
} else {
|
||||
data := result.Data.(model.Preference)
|
||||
@@ -80,7 +80,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.DeletePreferences(c.Session.UserId, preferences); err != nil {
|
||||
if err := c.App.DeletePreferences(c.Session.UserId, preferences); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func TestGetAllPreferences(t *testing.T) {
|
||||
|
||||
@@ -41,7 +41,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var post *model.Post
|
||||
|
||||
if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else if post = result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId {
|
||||
@@ -63,7 +63,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if reaction, err := app.SaveReactionForPost(reaction); err != nil {
|
||||
if reaction, err := c.App.SaveReactionForPost(reaction); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -92,7 +92,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := app.DeleteReactionForPost(reaction)
|
||||
err := c.App.DeleteReactionForPost(reaction)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -120,7 +120,7 @@ func sendReactionEvent(event string, channelId string, reaction *model.Reaction,
|
||||
app.Publish(message)
|
||||
|
||||
// THe post is always modified since the UpdateAt always changes
|
||||
app.InvalidateCacheForChannelPosts(post.ChannelId)
|
||||
app.Global().InvalidateCacheForChannelPosts(post.ChannelId)
|
||||
post.HasReactions = true
|
||||
post.UpdateAt = model.GetMillis()
|
||||
umessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil)
|
||||
@@ -144,9 +144,9 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
pchan := app.Srv.Store.Post().Get(postId)
|
||||
pchan := c.App.Srv.Store.Post().Get(postId)
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Reaction().GetForPost(postId, true); result.Err != nil {
|
||||
if result := <-c.App.Srv.Store.Reaction().GetForPost(postId, true); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,7 @@ func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
statusMap, err := app.GetStatusesByIds(userIds)
|
||||
statusMap, err := c.App.GetStatusesByIds(userIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
@@ -35,12 +34,12 @@ func TestStatuses(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser2, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -138,7 +137,7 @@ func TestStatuses(t *testing.T) {
|
||||
|
||||
WebSocketClient2.Close()
|
||||
|
||||
app.SetStatusAwayIfNeeded(th.BasicUser.Id, false)
|
||||
th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, false)
|
||||
|
||||
awayTimeout := *utils.Cfg.TeamSettings.UserStatusAwayTimeout
|
||||
defer func() {
|
||||
@@ -148,8 +147,8 @@ func TestStatuses(t *testing.T) {
|
||||
|
||||
time.Sleep(1500 * time.Millisecond)
|
||||
|
||||
app.SetStatusAwayIfNeeded(th.BasicUser.Id, false)
|
||||
app.SetStatusOnline(th.BasicUser.Id, "junk", false)
|
||||
th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, false)
|
||||
th.App.SetStatusOnline(th.BasicUser.Id, "junk", false)
|
||||
|
||||
time.Sleep(1500 * time.Millisecond)
|
||||
|
||||
|
||||
46
api/team.go
46
api/team.go
@@ -61,7 +61,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rteam, err := app.CreateTeamWithUser(team, c.Session.UserId)
|
||||
rteam, err := c.App.CreateTeamWithUser(team, c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -74,7 +74,7 @@ func GetAllTeamListings(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var teams []*model.Team
|
||||
var err *model.AppError
|
||||
|
||||
if teams, err = app.GetAllOpenTeams(); err != nil {
|
||||
if teams, err = c.App.GetAllOpenTeams(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -96,10 +96,10 @@ func getAll(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var teams []*model.Team
|
||||
var err *model.AppError
|
||||
|
||||
if app.HasPermissionTo(c.Session.UserId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
teams, err = app.GetAllTeams()
|
||||
if c.App.HasPermissionTo(c.Session.UserId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
teams, err = c.App.GetAllTeams()
|
||||
} else {
|
||||
teams, err = app.GetTeamsForUser(c.Session.UserId)
|
||||
teams, err = c.App.GetTeamsForUser(c.Session.UserId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -130,7 +130,7 @@ func inviteMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.InviteNewUsersToTeam(invites.ToEmailList(), c.TeamId, c.Session.UserId); err != nil {
|
||||
if err := c.App.InviteNewUsersToTeam(invites.ToEmailList(), c.TeamId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -152,7 +152,7 @@ func addUserToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := app.AddUserToTeam(c.TeamId, userId, ""); err != nil {
|
||||
if _, err := c.App.AddUserToTeam(c.TeamId, userId, ""); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func removeUserFromTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := app.RemoveUserFromTeam(c.TeamId, userId); err != nil {
|
||||
if err := c.App.RemoveUserFromTeam(c.TeamId, userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -194,9 +194,9 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
var err *model.AppError
|
||||
|
||||
if len(hash) > 0 {
|
||||
team, err = app.AddUserToTeamByHash(c.Session.UserId, hash, data)
|
||||
team, err = c.App.AddUserToTeamByHash(c.Session.UserId, hash, data)
|
||||
} else if len(inviteId) > 0 {
|
||||
team, err = app.AddUserToTeamByInviteId(inviteId, c.Session.UserId)
|
||||
team, err = c.App.AddUserToTeamByInviteId(inviteId, c.Session.UserId)
|
||||
} else {
|
||||
c.Err = model.NewAppError("addUserToTeamFromInvite", "api.user.create_user.signup_link_invalid.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
@@ -217,7 +217,7 @@ func findTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := model.MapFromJson(r.Body)
|
||||
name := strings.ToLower(strings.TrimSpace(m["name"]))
|
||||
|
||||
found := app.FindTeamByName(name)
|
||||
found := c.App.FindTeamByName(name)
|
||||
|
||||
if found {
|
||||
w.Write([]byte("true"))
|
||||
@@ -230,7 +230,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
teamname := params["team_name"]
|
||||
|
||||
if team, err := app.GetTeamByName(teamname); err != nil {
|
||||
if team, err := c.App.GetTeamByName(teamname); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -250,7 +250,7 @@ func getMyTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if len(c.Session.TeamMembers) > 0 {
|
||||
w.Write([]byte(model.TeamMembersToJson(c.Session.TeamMembers)))
|
||||
} else {
|
||||
if members, err := app.GetTeamMembersForUser(c.Session.UserId); err != nil {
|
||||
if members, err := c.App.GetTeamMembersForUser(c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -262,7 +262,7 @@ func getMyTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func getMyTeamsUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamId := r.URL.Query().Get("id")
|
||||
|
||||
if unreads, err := app.GetTeamsUnreadForUser(teamId, c.Session.UserId); err != nil {
|
||||
if unreads, err := c.App.GetTeamsUnreadForUser(teamId, c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -288,7 +288,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var err *model.AppError
|
||||
var updatedTeam *model.Team
|
||||
|
||||
updatedTeam, err = app.UpdateTeam(team)
|
||||
updatedTeam, err = c.App.UpdateTeam(team)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -319,7 +319,7 @@ func updateMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := app.UpdateTeamMemberRoles(teamId, userId, newRoles); err != nil {
|
||||
if _, err := c.App.UpdateTeamMemberRoles(teamId, userId, newRoles); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -335,7 +335,7 @@ func getMyTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if team, err := app.GetTeam(c.TeamId); err != nil {
|
||||
if team, err := c.App.GetTeam(c.TeamId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(team.Etag(), "Get My Team", w, r) {
|
||||
@@ -355,7 +355,7 @@ func getTeamStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
stats, err := app.GetTeamStats(c.TeamId)
|
||||
stats, err := c.App.GetTeamStats(c.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -414,7 +414,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
switch importFrom {
|
||||
case "slack":
|
||||
var err *model.AppError
|
||||
if err, log = app.SlackImport(fileData, fileSize, c.TeamId); err != nil {
|
||||
if err, log = c.App.SlackImport(fileData, fileSize, c.TeamId); err != nil {
|
||||
c.Err = err
|
||||
c.Err.StatusCode = http.StatusBadRequest
|
||||
}
|
||||
@@ -433,7 +433,7 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := model.MapFromJson(r.Body)
|
||||
inviteId := m["invite_id"]
|
||||
|
||||
if team, err := app.GetTeamByInviteId(inviteId); err != nil {
|
||||
if team, err := c.App.GetTeamByInviteId(inviteId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -473,7 +473,7 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if members, err := app.GetTeamMembers(c.TeamId, offset, limit); err != nil {
|
||||
if members, err := c.App.GetTeamMembers(c.TeamId, offset, limit); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -498,7 +498,7 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if member, err := app.GetTeamMember(c.TeamId, userId); err != nil {
|
||||
if member, err := c.App.GetTeamMember(c.TeamId, userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -521,7 +521,7 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if members, err := app.GetTeamMembersByIds(c.TeamId, userIds); err != nil {
|
||||
if members, err := c.App.GetTeamMembersByIds(c.TeamId, userIds); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@ package api
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
@@ -25,7 +24,7 @@ func TestCreateTeam(t *testing.T) {
|
||||
user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(rteam.Data.(*model.Team).Id)
|
||||
@@ -128,7 +127,7 @@ func TestAddUserToTeam(t *testing.T) {
|
||||
|
||||
// Should work as team admin.
|
||||
UpdateUserToTeamAdmin(th.BasicUser, th.BasicTeam)
|
||||
app.InvalidateAllCaches()
|
||||
th.App.InvalidateAllCaches()
|
||||
*utils.Cfg.TeamSettings.RestrictTeamInvite = model.PERMISSIONS_TEAM_ADMIN
|
||||
utils.SetIsLicensed(true)
|
||||
utils.SetLicense(&model.License{Features: &model.Features{}})
|
||||
@@ -219,7 +218,7 @@ func TestGetAllTeams(t *testing.T) {
|
||||
user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -258,7 +257,7 @@ func TestGetAllTeamListings(t *testing.T) {
|
||||
user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -275,7 +274,7 @@ func TestGetAllTeamListings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
app.UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
th.App.UpdateUserRoles(user.Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -305,7 +304,7 @@ func TestTeamPermDelete(t *testing.T) {
|
||||
user1 := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user1, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user1.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user1.Id))
|
||||
|
||||
Client.Login(user1.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -329,7 +328,7 @@ func TestTeamPermDelete(t *testing.T) {
|
||||
c.RequestId = model.NewId()
|
||||
c.IpAddress = "test"
|
||||
|
||||
err := app.PermanentDeleteTeam(team)
|
||||
err := th.App.PermanentDeleteTeam(team)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -350,7 +349,7 @@ func TestInviteMembers(t *testing.T) {
|
||||
user := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -437,7 +436,7 @@ func TestUpdateTeamDisplayName(t *testing.T) {
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
Client.Login(user2.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -498,7 +497,7 @@ func TestGetMyTeam(t *testing.T) {
|
||||
user := model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -743,7 +742,7 @@ func TestGetTeamStats(t *testing.T) {
|
||||
|
||||
user := model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
@@ -764,7 +763,7 @@ func TestUpdateTeamDescription(t *testing.T) {
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
Client.Login(user2.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -817,7 +816,7 @@ func TestGetTeamByName(t *testing.T) {
|
||||
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Jabba the Hutt", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
Client.Login(user2.Email, "passwd1")
|
||||
|
||||
|
||||
110
api/user.go
110
api/user.go
@@ -85,11 +85,11 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var ruser *model.User
|
||||
var err *model.AppError
|
||||
if len(hash) > 0 {
|
||||
ruser, err = app.CreateUserWithHash(user, hash, r.URL.Query().Get("d"))
|
||||
ruser, err = c.App.CreateUserWithHash(user, hash, r.URL.Query().Get("d"))
|
||||
} else if len(inviteId) > 0 {
|
||||
ruser, err = app.CreateUserWithInviteId(user, inviteId)
|
||||
ruser, err = c.App.CreateUserWithInviteId(user, inviteId)
|
||||
} else {
|
||||
ruser, err = app.CreateUserFromSignup(user)
|
||||
ruser, err = c.App.CreateUserFromSignup(user)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -111,7 +111,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ldapOnly := props["ldap_only"] == "true"
|
||||
|
||||
c.LogAudit("attempt - user_id=" + id + " login_id=" + loginId)
|
||||
user, err := app.AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId, ldapOnly)
|
||||
user, err := c.App.AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId, ldapOnly)
|
||||
if err != nil {
|
||||
c.LogAudit("failure - user_id=" + id + " login_id=" + loginId)
|
||||
c.Err = err
|
||||
@@ -132,7 +132,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// User MUST be authenticated completely before calling Login
|
||||
func doLogin(c *Context, w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) {
|
||||
session, err := app.DoLogin(w, r, user, deviceId)
|
||||
session, err := c.App.DoLogin(w, r, user, deviceId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -145,7 +145,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
id := props["id"]
|
||||
|
||||
if err := app.RevokeSessionById(id); err != nil {
|
||||
if err := c.App.RevokeSessionById(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// A special case where we logout of all other sessions with the same device id
|
||||
if err := app.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil {
|
||||
if err := c.App.RevokeSessionsForDeviceId(c.Session.UserId, deviceId, c.Session.Id); err != nil {
|
||||
c.Err = err
|
||||
c.Err.StatusCode = http.StatusInternalServerError
|
||||
return
|
||||
@@ -192,7 +192,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
http.SetCookie(w, sessionCookie)
|
||||
|
||||
if err := app.AttachDeviceId(c.Session.Id, deviceId, c.Session.ExpiresAt); err != nil {
|
||||
if err := c.App.AttachDeviceId(c.Session.Id, deviceId, c.Session.ExpiresAt); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sessions, err := app.GetSessions(id); err != nil {
|
||||
if sessions, err := c.App.GetSessions(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -236,7 +236,7 @@ func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
c.RemoveSessionCookie(w, r)
|
||||
if c.Session.Id != "" {
|
||||
if err := app.RevokeSessionById(c.Session.Id); err != nil {
|
||||
if err := c.App.RevokeSessionById(c.Session.Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func getMe(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if user, err := app.GetUser(c.Session.UserId); err != nil {
|
||||
if user, err := c.App.GetUser(c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
c.RemoveSessionCookie(w, r)
|
||||
l4g.Error(utils.T("api.user.get_me.getting.error"), c.Session.UserId)
|
||||
@@ -267,20 +267,20 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if len(c.Session.UserId) != 0 {
|
||||
var err *model.AppError
|
||||
|
||||
il.User, err = app.GetUser(c.Session.UserId)
|
||||
il.User, err = c.App.GetUser(c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
il.User.Sanitize(map[string]bool{})
|
||||
|
||||
il.Preferences, err = app.GetPreferencesForUser(c.Session.UserId)
|
||||
il.Preferences, err = c.App.GetPreferencesForUser(c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
il.Teams, err = app.GetTeamsForUser(c.Session.UserId)
|
||||
il.Teams, err = c.App.GetTeamsForUser(c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -297,7 +297,7 @@ func getInitialLoad(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// Below is a special case when intializating a new server
|
||||
// Lets check to make sure the server is really empty
|
||||
|
||||
il.NoAccounts = app.IsFirstUserAccount()
|
||||
il.NoAccounts = c.App.IsFirstUserAccount()
|
||||
}
|
||||
|
||||
il.ClientCfg = utils.ClientCfg
|
||||
@@ -317,7 +317,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var user *model.User
|
||||
var err *model.AppError
|
||||
|
||||
if user, err = app.GetUser(id); err != nil {
|
||||
if user, err = c.App.GetUser(id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func getByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var user *model.User
|
||||
var err *model.AppError
|
||||
|
||||
if user, err = app.GetUserByUsername(username); err != nil {
|
||||
if user, err = c.App.GetUserByUsername(username); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Username", w, r) {
|
||||
@@ -359,7 +359,7 @@ func getByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
email := params["email"]
|
||||
|
||||
if user, err := app.GetUserByEmail(email); err != nil {
|
||||
if user, err := c.App.GetUserByEmail(email); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if HandleEtag(user.Etag(utils.Cfg.PrivacySettings.ShowFullName, utils.Cfg.PrivacySettings.ShowEmailAddress), "Get By Email", w, r) {
|
||||
@@ -388,12 +388,12 @@ func getProfiles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
etag := app.GetUsersEtag() + params["offset"] + "." + params["limit"]
|
||||
etag := c.App.GetUsersEtag() + params["offset"] + "." + params["limit"]
|
||||
if HandleEtag(etag, "Get Profiles", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if profiles, err := app.GetUsersMap(offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.GetUsersMap(offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -424,12 +424,12 @@ func getProfilesInTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
etag := app.GetUsersInTeamEtag(teamId)
|
||||
etag := c.App.GetUsersInTeamEtag(teamId)
|
||||
if HandleEtag(etag, "Get Profiles In Team", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if profiles, err := app.GetUsersInTeamMap(teamId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.GetUsersInTeamMap(teamId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -461,12 +461,12 @@ func getProfilesInChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if profiles, err := app.GetUsersInChannelMap(channelId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.GetUsersInChannelMap(channelId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -485,7 +485,7 @@ func getProfilesNotInChannel(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -502,7 +502,7 @@ func getProfilesNotInChannel(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
if profiles, err := app.GetUsersNotInChannelMap(c.TeamId, channelId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.GetUsersNotInChannelMap(c.TeamId, channelId, offset, limit, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -519,7 +519,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if audits, err := app.GetAudits(id, 20); err != nil {
|
||||
if audits, err := c.App.GetAudits(id, 20); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -545,7 +545,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var etag string
|
||||
|
||||
if users, err := app.GetUsersByIds([]string{id}, false); err != nil {
|
||||
if users, err := c.App.GetUsersByIds([]string{id}, false); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -610,7 +610,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
imageData := imageArray[0]
|
||||
|
||||
if err := app.SetProfileImage(c.Session.UserId, imageData); err != nil {
|
||||
if err := c.App.SetProfileImage(c.Session.UserId, imageData); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -634,7 +634,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if ruser, err := app.UpdateUserAsUser(user, c.IsSystemAdmin()); err != nil {
|
||||
if ruser, err := c.App.UpdateUserAsUser(user, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -666,7 +666,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.UpdatePasswordAsUser(userId, currentPassword, newPassword); err != nil {
|
||||
if err := c.App.UpdatePasswordAsUser(userId, currentPassword, newPassword); err != nil {
|
||||
c.LogAudit("failed")
|
||||
c.Err = err
|
||||
return
|
||||
@@ -700,7 +700,7 @@ func updateRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := app.UpdateUserRoles(userId, newRoles); err != nil {
|
||||
if _, err := c.App.UpdateUserRoles(userId, newRoles); err != nil {
|
||||
return
|
||||
} else {
|
||||
c.LogAuditWithUserId(userId, "roles="+newRoles)
|
||||
@@ -730,7 +730,7 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if ruser, err := app.UpdateActiveNoLdap(userId, active); err != nil {
|
||||
if ruser, err := c.App.UpdateActiveNoLdap(userId, active); err != nil {
|
||||
c.Err = err
|
||||
} else {
|
||||
c.LogAuditWithUserId(ruser.Id, fmt.Sprintf("active=%v", active))
|
||||
@@ -747,7 +747,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if sent, err := app.SendPasswordReset(email, utils.GetSiteURL()); err != nil {
|
||||
if sent, err := c.App.SendPasswordReset(email, utils.GetSiteURL()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else if sent {
|
||||
@@ -770,7 +770,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt - token=" + code)
|
||||
|
||||
if err := app.ResetPasswordFromToken(code, newPassword); err != nil {
|
||||
if err := c.App.ResetPasswordFromToken(code, newPassword); err != nil {
|
||||
c.LogAudit("fail - token=" + code)
|
||||
c.Err = err
|
||||
return
|
||||
@@ -823,7 +823,7 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ruser, err := app.UpdateUserNotifyProps(userId, props)
|
||||
ruser, err := c.App.UpdateUserNotifyProps(userId, props)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -860,7 +860,7 @@ func emailToOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
link, err := app.SwitchEmailToOAuth(w, r, email, password, mfaToken, service)
|
||||
link, err := c.App.SwitchEmailToOAuth(w, r, email, password, mfaToken, service)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -885,7 +885,7 @@ func oauthToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
link, err := app.SwitchOAuthToEmail(email, password, c.Session.UserId)
|
||||
link, err := c.App.SwitchOAuthToEmail(email, password, c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -931,7 +931,7 @@ func emailToLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
link, err := app.SwitchEmailToLdap(email, emailPassword, token, ldapId, ldapPassword)
|
||||
link, err := c.App.SwitchEmailToLdap(email, emailPassword, token, ldapId, ldapPassword)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -971,7 +971,7 @@ func ldapToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
link, err := app.SwitchLdapToEmail(ldapPassword, token, email, emailPassword)
|
||||
link, err := c.App.SwitchLdapToEmail(ldapPassword, token, email, emailPassword)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1036,7 +1036,7 @@ func resendVerification(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}*/
|
||||
|
||||
func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
secret, err := app.GenerateMfaSecret(c.Session.UserId)
|
||||
secret, err := c.App.GenerateMfaSecret(c.Session.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1069,7 +1069,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if activate {
|
||||
if err := app.ActivateMfa(c.Session.UserId, token); err != nil {
|
||||
if err := c.App.ActivateMfa(c.Session.UserId, token); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -1085,7 +1085,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
go func() {
|
||||
var user *model.User
|
||||
var err *model.AppError
|
||||
if user, err = app.GetUser(c.Session.UserId); err != nil {
|
||||
if user, err = c.App.GetUser(c.Session.UserId); err != nil {
|
||||
l4g.Warn(err.Error())
|
||||
return
|
||||
}
|
||||
@@ -1117,7 +1117,7 @@ func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
rdata := map[string]string{}
|
||||
if user, err := app.GetUserForLogin(loginId, false); err != nil {
|
||||
if user, err := c.App.GetUserForLogin(loginId, false); err != nil {
|
||||
rdata["mfa_required"] = "false"
|
||||
} else {
|
||||
rdata["mfa_required"] = strconv.FormatBool(user.MfaActive)
|
||||
@@ -1133,7 +1133,7 @@ func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
teamId, err := app.GetTeamIdFromQuery(r.URL.Query())
|
||||
teamId, err := c.App.GetTeamIdFromQuery(r.URL.Query())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1213,11 +1213,11 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
case model.OAUTH_ACTION_SIGNUP:
|
||||
teamId := relayProps["team_id"]
|
||||
if len(teamId) > 0 {
|
||||
go app.AddDirectChannels(teamId, user)
|
||||
go c.App.AddDirectChannels(teamId, user)
|
||||
}
|
||||
break
|
||||
case model.OAUTH_ACTION_EMAIL_TO_SSO:
|
||||
if err := app.RevokeAllSessions(user.Id); err != nil {
|
||||
if err := c.App.RevokeAllSessions(user.Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -1273,12 +1273,12 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if props.InChannelId != "" && !app.SessionHasPermissionToChannel(c.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(c.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if props.NotInChannelId != "" && !app.SessionHasPermissionToChannel(c.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(c.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -1299,7 +1299,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if profiles, err := app.SearchUsers(props, searchOptions, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.SearchUsers(props, searchOptions, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -1315,7 +1315,7 @@ func getProfilesByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if profiles, err := app.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err := c.App.GetUsersByIds(userIds, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -1340,7 +1340,7 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
}
|
||||
|
||||
if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
@@ -1354,7 +1354,7 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true
|
||||
}
|
||||
|
||||
autocomplete, err := app.AutocompleteUsersInChannel(teamId, channelId, term, searchOptions, c.IsSystemAdmin())
|
||||
autocomplete, err := c.App.AutocompleteUsersInChannel(teamId, channelId, term, searchOptions, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1384,7 +1384,7 @@ func autocompleteUsersInTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true
|
||||
}
|
||||
|
||||
autocomplete, err := app.AutocompleteUsersInTeam(teamId, term, searchOptions, c.IsSystemAdmin())
|
||||
autocomplete, err := c.App.AutocompleteUsersInTeam(teamId, term, searchOptions, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1408,7 +1408,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var profiles []*model.User
|
||||
var err *model.AppError
|
||||
|
||||
if profiles, err = app.SearchUsersInTeam("", term, searchOptions, c.IsSystemAdmin()); err != nil {
|
||||
if profiles, err = c.App.SearchUsersInTeam("", term, searchOptions, c.IsSystemAdmin()); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestLogin(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Username: "corey" + model.NewId(), Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
if result, err := Client.LoginById(ruser.Data.(*model.User).Id, user.Password); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -203,7 +203,7 @@ func TestLogin(t *testing.T) {
|
||||
AuthService: model.USER_AUTH_SERVICE_LDAP,
|
||||
}
|
||||
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
|
||||
if _, err := Client.Login(user3.Id, user3.Password); err == nil {
|
||||
t.Fatal("AD/LDAP user should not be able to log in with AD/LDAP disabled")
|
||||
@@ -222,7 +222,7 @@ func TestLoginByLdap(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Username: "corey" + model.NewId(), Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
if _, err := Client.LoginByLdap(ruser.Data.(*model.User).Id, user.Password); err == nil {
|
||||
t.Fatal("should have failed to log in with non AD/LDAP user")
|
||||
@@ -249,7 +249,7 @@ func TestLoginWithDeviceId(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if sresult := <-app.Srv.Store.Session().Get(sessions[0].Id); sresult.Err == nil {
|
||||
if sresult := <-th.App.Srv.Store.Session().Get(sessions[0].Id); sresult.Err == nil {
|
||||
t.Fatal("session should have been removed")
|
||||
}
|
||||
}
|
||||
@@ -355,17 +355,17 @@ func TestGetUser(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", FirstName: "Corey", LastName: "Hulen"}
|
||||
ruser2, _ := Client.CreateUser(&user2, "")
|
||||
LinkUserToTeam(ruser2.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Data.(*model.User).Id))
|
||||
|
||||
user3 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser3, _ := Client.CreateUser(&user3, "")
|
||||
LinkUserToTeam(ruser3.Data.(*model.User), rteam2.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser3.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser3.Data.(*model.User).Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
@@ -488,7 +488,7 @@ func TestGetUser(t *testing.T) {
|
||||
t.Fatal("shouldn't have accss")
|
||||
}
|
||||
|
||||
app.UpdateUserRoles(ruser.Data.(*model.User).Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
th.App.UpdateUserRoles(ruser.Data.(*model.User).Id, model.ROLE_SYSTEM_ADMIN.Id)
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
|
||||
@@ -620,7 +620,7 @@ func TestGetAudits(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
@@ -675,7 +675,7 @@ func TestUserCreateImage(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
|
||||
@@ -724,7 +724,7 @@ func TestUserUploadProfileImage(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
if *utils.Cfg.FileSettings.DriverName != "" {
|
||||
|
||||
@@ -837,7 +837,7 @@ func TestUserUpdate(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", Roles: ""}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
if _, err := Client.UpdateUser(user); err == nil {
|
||||
t.Fatal("Should have errored")
|
||||
@@ -867,7 +867,7 @@ func TestUserUpdate(t *testing.T) {
|
||||
user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
Client.Login(user2.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -892,7 +892,7 @@ func TestUserUpdatePassword(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
if _, err := Client.UpdateUserPassword(user.Id, "passwd1", "newpasswd1"); err == nil {
|
||||
t.Fatal("Should have errored")
|
||||
@@ -976,12 +976,12 @@ func TestUserUpdateRoles(t *testing.T) {
|
||||
user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
if _, err := Client.UpdateUserRoles(user.Id, ""); err == nil {
|
||||
t.Fatal("Should have errored, not logged in")
|
||||
@@ -1000,7 +1000,7 @@ func TestUserUpdateRoles(t *testing.T) {
|
||||
user3 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user3, team2)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
|
||||
Client.Login(user3.Email, "passwd1")
|
||||
Client.SetTeamId(team2.Id)
|
||||
@@ -1095,7 +1095,7 @@ func TestUserUpdateDeviceId(t *testing.T) {
|
||||
user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -1105,7 +1105,7 @@ func TestUserUpdateDeviceId(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
sessions := result.Data.([]*model.Session)
|
||||
@@ -1126,7 +1126,7 @@ func TestUserUpdateDeviceId2(t *testing.T) {
|
||||
user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -1136,7 +1136,7 @@ func TestUserUpdateDeviceId2(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result := <-app.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Session().GetSessions(user.Id); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
sessions := result.Data.([]*model.Session)
|
||||
@@ -1163,12 +1163,12 @@ func TestUserUpdateActive(t *testing.T) {
|
||||
user := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
user2 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
if _, err := Client.UpdateActive(user.Id, false); err == nil {
|
||||
t.Fatal("Should have errored, not logged in")
|
||||
@@ -1186,7 +1186,7 @@ func TestUserUpdateActive(t *testing.T) {
|
||||
user3 := &model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team2)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user3.Id))
|
||||
|
||||
Client.Login(user3.Email, "passwd1")
|
||||
Client.SetTeamId(team2.Id)
|
||||
@@ -1206,13 +1206,13 @@ func TestUserUpdateActive(t *testing.T) {
|
||||
t.Fatal("Should have errored, bad id")
|
||||
}
|
||||
|
||||
app.SetStatusOnline(user3.Id, "", false)
|
||||
th.App.SetStatusOnline(user3.Id, "", false)
|
||||
|
||||
if _, err := SystemAdminClient.UpdateActive(user3.Id, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if status, err := app.GetStatus(user3.Id); err != nil {
|
||||
if status, err := th.App.GetStatus(user3.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if status.Status != model.STATUS_OFFLINE {
|
||||
t.Fatal("status should have been set to offline")
|
||||
@@ -1229,7 +1229,7 @@ func TestUserPermDelete(t *testing.T) {
|
||||
user1 := &model.User{Email: model.NewId() + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user1, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user1.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user1.Id))
|
||||
|
||||
Client.Login(user1.Email, "passwd1")
|
||||
Client.SetTeamId(team.Id)
|
||||
@@ -1253,7 +1253,7 @@ func TestUserPermDelete(t *testing.T) {
|
||||
c.RequestId = model.NewId()
|
||||
c.IpAddress = "test"
|
||||
|
||||
err := app.PermanentDeleteUser(user1)
|
||||
err := th.App.PermanentDeleteUser(user1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1271,7 +1271,7 @@ func TestSendPasswordReset(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
Client.Logout()
|
||||
|
||||
@@ -1296,7 +1296,7 @@ func TestSendPasswordReset(t *testing.T) {
|
||||
user2 := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", AuthData: &authData, AuthService: "random"}
|
||||
user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user2, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user2.Id))
|
||||
|
||||
if _, err := Client.SendPasswordReset(user2.Email); err == nil {
|
||||
t.Fatal("should have errored - SSO user can't send reset password link")
|
||||
@@ -1311,7 +1311,7 @@ func TestResetPassword(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
//Delete all the messages before check the reset password
|
||||
utils.DeleteMailBox(user.Email)
|
||||
@@ -1350,7 +1350,7 @@ func TestResetPassword(t *testing.T) {
|
||||
}
|
||||
|
||||
var recoveryToken *model.Token
|
||||
if result := <-app.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil {
|
||||
t.Log(recoveryTokenString)
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
@@ -1412,7 +1412,7 @@ func TestUserUpdateNotify(t *testing.T) {
|
||||
user := &model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1", Roles: ""}
|
||||
user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(user, team)
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(user.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(user.Id))
|
||||
|
||||
data := make(map[string]string)
|
||||
data["user_id"] = user.Id
|
||||
@@ -1527,7 +1527,7 @@ func TestEmailToOAuth(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
m := map[string]string{}
|
||||
if _, err := Client.EmailToOAuth(m); err == nil {
|
||||
@@ -1580,12 +1580,12 @@ func TestOAuthToEmail(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser2, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser2.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser2.Id))
|
||||
|
||||
m := map[string]string{}
|
||||
if _, err := Client.OAuthToEmail(m); err == nil {
|
||||
@@ -1631,7 +1631,7 @@ func TestLDAPToEmail(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
@@ -1684,7 +1684,7 @@ func TestEmailToLDAP(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
|
||||
LinkUserToTeam(ruser, rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
||||
@@ -1815,7 +1815,7 @@ func TestGenerateMfaSecret(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
Client.Logout()
|
||||
|
||||
@@ -1856,7 +1856,7 @@ func TestUpdateMfa(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
Client.Logout()
|
||||
|
||||
@@ -1897,7 +1897,7 @@ func TestCheckMfa(t *testing.T) {
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _ := Client.CreateUser(&user, "")
|
||||
LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team))
|
||||
store.Must(app.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
store.Must(th.App.Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id))
|
||||
|
||||
if result, err := Client.CheckMfa(user.Email); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -34,7 +34,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := app.GetChannel(hook.ChannelId)
|
||||
channel, err := c.App.GetChannel(hook.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -47,13 +47,13 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.LogAudit("fail - bad channel permissions")
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if incomingHook, err := app.CreateIncomingWebhookForChannel(c.Session.UserId, channel, hook); err != nil {
|
||||
if incomingHook, err := c.App.CreateIncomingWebhookForChannel(c.Session.UserId, channel, hook); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -73,7 +73,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
oldHook, err := app.GetIncomingWebhook(hook.Id)
|
||||
oldHook, err := c.App.GetIncomingWebhook(hook.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -95,19 +95,19 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := app.GetChannel(hook.ChannelId)
|
||||
channel, err := c.App.GetChannel(hook.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN && !app.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.LogAudit("fail - bad channel permissions")
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
rhook, err := app.UpdateIncomingWebhook(oldHook, hook)
|
||||
rhook, err := c.App.UpdateIncomingWebhook(oldHook, hook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -126,7 +126,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
hook, err := app.GetIncomingWebhook(id)
|
||||
hook, err := c.App.GetIncomingWebhook(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -145,7 +145,7 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.DeleteIncomingWebhook(id); err != nil {
|
||||
if err := c.App.DeleteIncomingWebhook(id); err != nil {
|
||||
c.LogAudit("fail")
|
||||
c.Err = err
|
||||
return
|
||||
@@ -161,7 +161,7 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if hooks, err := app.GetIncomingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil {
|
||||
if hooks, err := c.App.GetIncomingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -186,7 +186,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if rhook, err := app.CreateOutgoingWebhook(hook); err != nil {
|
||||
if rhook, err := c.App.CreateOutgoingWebhook(hook); err != nil {
|
||||
c.LogAudit("fail")
|
||||
c.Err = err
|
||||
return
|
||||
@@ -202,7 +202,7 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if hooks, err := app.GetOutgoingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil {
|
||||
if hooks, err := c.App.GetOutgoingWebhooksForTeamPage(c.TeamId, 0, 100); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
@@ -220,7 +220,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
oldHook, err := app.GetOutgoingWebhook(hook.Id)
|
||||
oldHook, err := c.App.GetOutgoingWebhook(hook.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -243,7 +243,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rhook, err := app.UpdateOutgoingWebhook(oldHook, hook)
|
||||
rhook, err := c.App.UpdateOutgoingWebhook(oldHook, hook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -269,7 +269,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
hook, err := app.GetOutgoingWebhook(id)
|
||||
hook, err := c.App.GetOutgoingWebhook(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -281,7 +281,7 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.DeleteOutgoingWebhook(id); err != nil {
|
||||
if err := c.App.DeleteOutgoingWebhook(id); err != nil {
|
||||
c.LogAudit("fail")
|
||||
c.Err = err
|
||||
return
|
||||
@@ -300,7 +300,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
hook, err := app.GetOutgoingWebhook(id)
|
||||
hook, err := c.App.GetOutgoingWebhook(id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -324,7 +324,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
if rhook, err := app.RegenOutgoingWebhookToken(hook); err != nil {
|
||||
if rhook, err := c.App.RegenOutgoingWebhookToken(hook); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -34,7 +34,7 @@ func connect(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
wc := app.NewWebConn(ws, c.Session, c.T, c.Locale)
|
||||
wc := c.App.NewWebConn(ws, c.Session, c.T, c.Locale)
|
||||
|
||||
if len(c.Session.UserId) > 0 {
|
||||
app.HubRegister(wc)
|
||||
|
||||
10
api4/api.go
10
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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
108
api4/channel.go
108
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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHelpCommand(t *testing.T) {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
26
api4/file.go
26
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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
72
api4/post.go
72
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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
58
api4/team.go
58
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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
128
api4/user.go
128
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
23
app/admin.go
23
app/admin.go
@@ -11,13 +11,14 @@ import (
|
||||
|
||||
"runtime/debug"
|
||||
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/jobs"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
@@ -95,9 +96,9 @@ func GetClusterStatus() []*model.ClusterInfo {
|
||||
return infos
|
||||
}
|
||||
|
||||
func InvalidateAllCaches() *model.AppError {
|
||||
func (a *App) InvalidateAllCaches() *model.AppError {
|
||||
debug.FreeOSMemory()
|
||||
InvalidateAllCachesSkipSend()
|
||||
a.InvalidateAllCachesSkipSend()
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
|
||||
@@ -113,7 +114,7 @@ func InvalidateAllCaches() *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func InvalidateAllCachesSkipSend() {
|
||||
func (a *App) InvalidateAllCachesSkipSend() {
|
||||
l4g.Info(utils.T("api.context.invalidate_all_caches"))
|
||||
sessionCache.Purge()
|
||||
ClearStatusCache()
|
||||
@@ -121,7 +122,7 @@ func InvalidateAllCachesSkipSend() {
|
||||
store.ClearUserCaches()
|
||||
store.ClearPostCaches()
|
||||
store.ClearWebhookCaches()
|
||||
LoadLicense()
|
||||
a.LoadLicense()
|
||||
}
|
||||
|
||||
func GetConfig() *model.Config {
|
||||
@@ -183,13 +184,13 @@ func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.A
|
||||
return nil
|
||||
}
|
||||
|
||||
func RecycleDatabaseConnection() {
|
||||
oldStore := Srv.Store
|
||||
func (a *App) RecycleDatabaseConnection() {
|
||||
oldStore := a.Srv.Store
|
||||
|
||||
l4g.Warn(utils.T("api.admin.recycle_db_start.warn"))
|
||||
Srv.Store = store.NewLayeredStore()
|
||||
a.Srv.Store = store.NewLayeredStore()
|
||||
|
||||
jobs.Srv.Store = Srv.Store
|
||||
jobs.Srv.Store = a.Srv.Store
|
||||
|
||||
time.Sleep(20 * time.Second)
|
||||
oldStore.Close()
|
||||
@@ -197,7 +198,7 @@ func RecycleDatabaseConnection() {
|
||||
l4g.Warn(utils.T("api.admin.recycle_db_end.warn"))
|
||||
}
|
||||
|
||||
func TestEmail(userId string, cfg *model.Config) *model.AppError {
|
||||
func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
|
||||
if len(cfg.EmailSettings.SMTPServer) == 0 {
|
||||
return model.NewAppError("testEmail", "api.admin.test_email.missing_server", nil, utils.T("api.context.invalid_param.app_error", map[string]interface{}{"Name": "SMTPServer"}), http.StatusBadRequest)
|
||||
}
|
||||
@@ -213,7 +214,7 @@ func TestEmail(userId string, cfg *model.Config) *model.AppError {
|
||||
return model.NewAppError("testEmail", "api.admin.test_email.reenter_password", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
if user, err := GetUser(userId); err != nil {
|
||||
if user, err := a.GetUser(userId); err != nil {
|
||||
return err
|
||||
} else {
|
||||
T := utils.GetUserTranslations(user.Locale)
|
||||
|
||||
@@ -16,10 +16,10 @@ const (
|
||||
MONTH_MILLISECONDS = 31 * DAY_MILLISECONDS
|
||||
)
|
||||
|
||||
func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||
skipIntensiveQueries := false
|
||||
var systemUserCount int64
|
||||
if r := <-Srv.Store.User().AnalyticsUniqueUserCount(""); r.Err != nil {
|
||||
if r := <-a.Srv.Store.User().AnalyticsUniqueUserCount(""); r.Err != nil {
|
||||
return nil, r.Err
|
||||
} else {
|
||||
systemUserCount = r.Data.(int64)
|
||||
@@ -42,22 +42,22 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
rows[8] = &model.AnalyticsRow{Name: "daily_active_users", Value: 0}
|
||||
rows[9] = &model.AnalyticsRow{Name: "monthly_active_users", Value: 0}
|
||||
|
||||
openChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
privateChan := Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
teamChan := Srv.Store.Team().AnalyticsTeamCount()
|
||||
openChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
privateChan := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
teamChan := a.Srv.Store.Team().AnalyticsTeamCount()
|
||||
|
||||
var userChan store.StoreChannel
|
||||
if teamId != "" {
|
||||
userChan = Srv.Store.User().AnalyticsUniqueUserCount(teamId)
|
||||
userChan = a.Srv.Store.User().AnalyticsUniqueUserCount(teamId)
|
||||
}
|
||||
|
||||
var postChan store.StoreChannel
|
||||
if !skipIntensiveQueries {
|
||||
postChan = Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
|
||||
postChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
|
||||
}
|
||||
|
||||
dailyActiveChan := Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||
monthlyActiveChan := Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
|
||||
monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
|
||||
|
||||
if r := <-openChan; r.Err != nil {
|
||||
return nil, r.Err
|
||||
@@ -105,8 +105,8 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
}
|
||||
|
||||
totalSockets := TotalWebsocketConnections()
|
||||
totalMasterDb := Srv.Store.TotalMasterDbConnections()
|
||||
totalReadDb := Srv.Store.TotalReadDbConnections()
|
||||
totalMasterDb := a.Srv.Store.TotalMasterDbConnections()
|
||||
totalReadDb := a.Srv.Store.TotalReadDbConnections()
|
||||
|
||||
for _, stat := range stats {
|
||||
totalSockets = totalSockets + stat.TotalWebsocketConnections
|
||||
@@ -120,8 +120,8 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
|
||||
} else {
|
||||
rows[5].Value = float64(TotalWebsocketConnections())
|
||||
rows[6].Value = float64(Srv.Store.TotalMasterDbConnections())
|
||||
rows[7].Value = float64(Srv.Store.TotalReadDbConnections())
|
||||
rows[6].Value = float64(a.Srv.Store.TotalMasterDbConnections())
|
||||
rows[7].Value = float64(a.Srv.Store.TotalReadDbConnections())
|
||||
}
|
||||
|
||||
if r := <-dailyActiveChan; r.Err != nil {
|
||||
@@ -143,7 +143,7 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil {
|
||||
if r := <-a.Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil {
|
||||
return nil, r.Err
|
||||
} else {
|
||||
return r.Data.(model.AnalyticsRows), nil
|
||||
@@ -154,7 +154,7 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil {
|
||||
if r := <-a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil {
|
||||
return nil, r.Err
|
||||
} else {
|
||||
return r.Data.(model.AnalyticsRows), nil
|
||||
@@ -168,16 +168,16 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
rows[4] = &model.AnalyticsRow{Name: "command_count", Value: 0}
|
||||
rows[5] = &model.AnalyticsRow{Name: "session_count", Value: 0}
|
||||
|
||||
iHookChan := Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
oHookChan := Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
commandChan := Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
sessionChan := Srv.Store.Session().AnalyticsSessionCount()
|
||||
iHookChan := a.Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
oHookChan := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
commandChan := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
sessionChan := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||
|
||||
var fileChan store.StoreChannel
|
||||
var hashtagChan store.StoreChannel
|
||||
if !skipIntensiveQueries {
|
||||
fileChan = Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
|
||||
hashtagChan = Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
|
||||
fileChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
|
||||
hashtagChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
|
||||
}
|
||||
|
||||
if fileChan == nil {
|
||||
@@ -230,8 +230,8 @@ func GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppEr
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError) {
|
||||
if result := <-Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100); result.Err != nil {
|
||||
func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError) {
|
||||
if result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
users := result.Data.([]*model.User)
|
||||
@@ -245,9 +245,9 @@ func GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *mode
|
||||
}
|
||||
}
|
||||
|
||||
func GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||
func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||
var users []*model.User
|
||||
if result := <-Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
users = result.Data.([]*model.User)
|
||||
@@ -256,9 +256,9 @@ func GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin
|
||||
return sanitizeProfiles(users, asAdmin), nil
|
||||
}
|
||||
|
||||
func GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||
func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool) ([]*model.User, *model.AppError) {
|
||||
var users []*model.User
|
||||
if result := <-Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
users = result.Data.([]*model.User)
|
||||
|
||||
10
app/app.go
10
app/app.go
@@ -8,6 +8,16 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Srv *Server
|
||||
}
|
||||
|
||||
var globalApp App
|
||||
|
||||
func Global() *App {
|
||||
return &globalApp
|
||||
}
|
||||
|
||||
func CloseBody(r *http.Response) {
|
||||
if r.Body != nil {
|
||||
ioutil.ReadAll(r.Body)
|
||||
|
||||
@@ -20,8 +20,8 @@ type TestHelper struct {
|
||||
BasicPost *model.Post
|
||||
}
|
||||
|
||||
func SetupEnterprise() *TestHelper {
|
||||
if Srv == nil {
|
||||
func (a *App) SetupEnterprise() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
@@ -29,12 +29,12 @@ func SetupEnterprise() *TestHelper {
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
utils.License().Features.SetDefaults()
|
||||
NewServer()
|
||||
InitStores()
|
||||
StartServer()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
Srv.Store.MarkSystemRanUnitTests()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
@@ -42,20 +42,20 @@ func SetupEnterprise() *TestHelper {
|
||||
return &TestHelper{}
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
if Srv == nil {
|
||||
func (a *App) Setup() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
NewServer()
|
||||
InitStores()
|
||||
StartServer()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
Srv.Store.MarkSystemRanUnitTests()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
@@ -66,9 +66,9 @@ func Setup() *TestHelper {
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.BasicTeam = me.CreateTeam()
|
||||
me.BasicUser = me.CreateUser()
|
||||
LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
Global().LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
Global().LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.BasicChannel = me.CreateChannel(me.BasicTeam)
|
||||
me.BasicPost = me.CreatePost(me.BasicChannel)
|
||||
|
||||
@@ -94,7 +94,7 @@ func (me *TestHelper) CreateTeam() *model.Team {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if team, err = CreateTeam(team); err != nil {
|
||||
if team, err = Global().CreateTeam(team); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -117,7 +117,7 @@ func (me *TestHelper) CreateUser() *model.User {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if user, err = CreateUser(user); err != nil {
|
||||
if user, err = Global().CreateUser(user); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -148,7 +148,7 @@ func (me *TestHelper) createChannel(team *model.Team, channelType string) *model
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if channel, err = CreateChannel(channel, true); err != nil {
|
||||
if channel, err = Global().CreateChannel(channel, true); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -169,7 +169,7 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = CreatePost(post, channel, false); err != nil {
|
||||
if post, err = Global().CreatePost(post, channel, false); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -179,10 +179,10 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
return post
|
||||
}
|
||||
|
||||
func LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
func (a *App) LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
err := JoinUserToTeam(team, user, "")
|
||||
err := a.JoinUserToTeam(team, user, "")
|
||||
if err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
@@ -193,8 +193,8 @@ func LinkUserToTeam(user *model.User, team *model.Team) {
|
||||
utils.EnableDebugLogForTest()
|
||||
}
|
||||
|
||||
func TearDown() {
|
||||
if Srv != nil {
|
||||
StopServer()
|
||||
func (a *App) TearDown() {
|
||||
if a.Srv != nil {
|
||||
a.StopServer()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ import (
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
||||
if result := <-Srv.Store.Audit().Get(userId, 0, limit); result.Err != nil {
|
||||
func (a *App) GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
||||
if result := <-a.Srv.Store.Audit().Get(userId, 0, limit); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(model.Audits), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
||||
if result := <-Srv.Store.Audit().Get(userId, page*perPage, perPage); result.Err != nil {
|
||||
func (a *App) GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
||||
if result := <-a.Srv.Store.Audit().Get(userId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(model.Audits), nil
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError {
|
||||
func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError {
|
||||
if err := CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := checkUserPassword(user, password); err != nil {
|
||||
if err := a.checkUserPassword(user, password); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,27 +25,27 @@ func CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken str
|
||||
}
|
||||
|
||||
// This to be used for places we check the users password when they are already logged in
|
||||
func doubleCheckPassword(user *model.User, password string) *model.AppError {
|
||||
func (a *App) doubleCheckPassword(user *model.User, password string) *model.AppError {
|
||||
if err := checkUserLoginAttempts(user); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := checkUserPassword(user, password); err != nil {
|
||||
if err := a.checkUserPassword(user, password); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkUserPassword(user *model.User, password string) *model.AppError {
|
||||
func (a *App) checkUserPassword(user *model.User, password string) *model.AppError {
|
||||
if !model.ComparePassword(user.Password, password) {
|
||||
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
return model.NewAppError("checkUserPassword", "api.user.check_user_password.invalid.app_error", nil, "user_id="+user.Id, http.StatusUnauthorized)
|
||||
} else {
|
||||
if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func checkUserNotDisabled(user *model.User) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
|
||||
func (a *App) authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
|
||||
ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP
|
||||
|
||||
if user.AuthService == model.USER_AUTH_SERVICE_LDAP {
|
||||
@@ -164,7 +164,7 @@ func authenticateUser(user *model.User, password, mfaToken string) (*model.User,
|
||||
err := model.NewAppError("login", "api.user.login.use_auth_service.app_error", map[string]interface{}{"AuthService": authService}, "", http.StatusBadRequest)
|
||||
return user, err
|
||||
} else {
|
||||
if err := CheckPasswordAndAllCriteria(user, password, mfaToken); err != nil {
|
||||
if err := a.CheckPasswordAndAllCriteria(user, password, mfaToken); err != nil {
|
||||
err.StatusCode = http.StatusUnauthorized
|
||||
return user, err
|
||||
} else {
|
||||
|
||||
@@ -29,12 +29,12 @@ func SessionHasPermissionToTeam(session model.Session, teamId string, permission
|
||||
return SessionHasPermissionTo(session, permission)
|
||||
}
|
||||
|
||||
func SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool {
|
||||
func (a *App) SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool {
|
||||
if channelId == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
cmc := Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true)
|
||||
cmc := a.Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true)
|
||||
|
||||
var channelRoles []string
|
||||
if cmcresult := <-cmc; cmcresult.Err == nil {
|
||||
@@ -47,7 +47,7 @@ func SessionHasPermissionToChannel(session model.Session, channelId string, perm
|
||||
}
|
||||
}
|
||||
|
||||
channel, err := GetChannel(channelId)
|
||||
channel, err := a.GetChannel(channelId)
|
||||
if err == nil && channel.TeamId != "" {
|
||||
return SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||
}
|
||||
@@ -55,9 +55,9 @@ func SessionHasPermissionToChannel(session model.Session, channelId string, perm
|
||||
return SessionHasPermissionTo(session, permission)
|
||||
}
|
||||
|
||||
func SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool {
|
||||
func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool {
|
||||
var channelMember *model.ChannelMember
|
||||
if result := <-Srv.Store.Channel().GetMemberForPost(postId, session.UserId); result.Err == nil {
|
||||
if result := <-a.Srv.Store.Channel().GetMemberForPost(postId, session.UserId); result.Err == nil {
|
||||
channelMember = result.Data.(*model.ChannelMember)
|
||||
|
||||
if CheckIfRolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||
@@ -65,7 +65,7 @@ func SessionHasPermissionToChannelByPost(session model.Session, postId string, p
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
if result := <-a.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
channel := result.Data.(*model.Channel)
|
||||
return SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||
}
|
||||
@@ -89,8 +89,8 @@ func SessionHasPermissionToUser(session model.Session, userId string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func SessionHasPermissionToPost(session model.Session, postId string, permission *model.Permission) bool {
|
||||
post, err := GetSinglePost(postId)
|
||||
func (a *App) SessionHasPermissionToPost(session model.Session, postId string, permission *model.Permission) bool {
|
||||
post, err := a.GetSinglePost(postId)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -99,11 +99,11 @@ func SessionHasPermissionToPost(session model.Session, postId string, permission
|
||||
return true
|
||||
}
|
||||
|
||||
return SessionHasPermissionToChannel(session, post.ChannelId, permission)
|
||||
return a.SessionHasPermissionToChannel(session, post.ChannelId, permission)
|
||||
}
|
||||
|
||||
func HasPermissionTo(askingUserId string, permission *model.Permission) bool {
|
||||
user, err := GetUser(askingUserId)
|
||||
func (a *App) HasPermissionTo(askingUserId string, permission *model.Permission) bool {
|
||||
user, err := a.GetUser(askingUserId)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -113,12 +113,12 @@ func HasPermissionTo(askingUserId string, permission *model.Permission) bool {
|
||||
return CheckIfRolesGrantPermission(roles, permission.Id)
|
||||
}
|
||||
|
||||
func HasPermissionToTeam(askingUserId string, teamId string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToTeam(askingUserId string, teamId string, permission *model.Permission) bool {
|
||||
if teamId == "" || askingUserId == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
teamMember, err := GetTeamMember(teamId, askingUserId)
|
||||
teamMember, err := a.GetTeamMember(teamId, askingUserId)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@@ -129,15 +129,15 @@ func HasPermissionToTeam(askingUserId string, teamId string, permission *model.P
|
||||
return true
|
||||
}
|
||||
|
||||
return HasPermissionTo(askingUserId, permission)
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
}
|
||||
|
||||
func HasPermissionToChannel(askingUserId string, channelId string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToChannel(askingUserId string, channelId string, permission *model.Permission) bool {
|
||||
if channelId == "" || askingUserId == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
channelMember, err := GetChannelMember(channelId, askingUserId)
|
||||
channelMember, err := a.GetChannelMember(channelId, askingUserId)
|
||||
if err == nil {
|
||||
roles := channelMember.GetRoles()
|
||||
if CheckIfRolesGrantPermission(roles, permission.Id) {
|
||||
@@ -146,17 +146,17 @@ func HasPermissionToChannel(askingUserId string, channelId string, permission *m
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
channel, err = GetChannel(channelId)
|
||||
channel, err = a.GetChannel(channelId)
|
||||
if err == nil {
|
||||
return HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
|
||||
return HasPermissionTo(askingUserId, permission)
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
}
|
||||
|
||||
func HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool {
|
||||
func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool {
|
||||
var channelMember *model.ChannelMember
|
||||
if result := <-Srv.Store.Channel().GetMemberForPost(postId, askingUserId); result.Err == nil {
|
||||
if result := <-a.Srv.Store.Channel().GetMemberForPost(postId, askingUserId); result.Err == nil {
|
||||
channelMember = result.Data.(*model.ChannelMember)
|
||||
|
||||
if CheckIfRolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||
@@ -164,20 +164,20 @@ func HasPermissionToChannelByPost(askingUserId string, postId string, permission
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
if result := <-a.Srv.Store.Channel().GetForPost(postId); result.Err == nil {
|
||||
channel := result.Data.(*model.Channel)
|
||||
return HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
|
||||
return HasPermissionTo(askingUserId, permission)
|
||||
return a.HasPermissionTo(askingUserId, permission)
|
||||
}
|
||||
|
||||
func HasPermissionToUser(askingUserId string, userId string) bool {
|
||||
func (a *App) HasPermissionToUser(askingUserId string, userId string) bool {
|
||||
if askingUserId == userId {
|
||||
return true
|
||||
}
|
||||
|
||||
if HasPermissionTo(askingUserId, model.PERMISSION_EDIT_OTHER_USERS) {
|
||||
if a.HasPermissionTo(askingUserId, model.PERMISSION_EDIT_OTHER_USERS) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCheckIfRolesGrantPermission(t *testing.T) {
|
||||
Setup()
|
||||
a := Global()
|
||||
a.Setup()
|
||||
|
||||
cases := []struct {
|
||||
roles []string
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
type TestEnvironment struct {
|
||||
|
||||
@@ -5,10 +5,11 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
type AutoPostCreator struct {
|
||||
|
||||
@@ -34,7 +34,7 @@ func NewAutoUserCreator(client *model.Client, team *model.Team) *AutoUserCreator
|
||||
}
|
||||
|
||||
// Basic test team and user so you always know one
|
||||
func CreateBasicUser(client *model.Client) *model.AppError {
|
||||
func (a *App) CreateBasicUser(client *model.Client) *model.AppError {
|
||||
result, _ := client.FindTeamByName(BTEST_TEAM_NAME)
|
||||
if result.Data.(bool) == false {
|
||||
newteam := &model.Team{DisplayName: BTEST_TEAM_DISPLAY_NAME, Name: BTEST_TEAM_NAME, Email: BTEST_TEAM_EMAIL, Type: BTEST_TEAM_TYPE}
|
||||
@@ -49,8 +49,8 @@ func CreateBasicUser(client *model.Client) *model.AppError {
|
||||
return err
|
||||
}
|
||||
ruser := result.Data.(*model.User)
|
||||
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}))
|
||||
store.Must(a.Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -81,14 +81,14 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
|
||||
ruser := result.Data.(*model.User)
|
||||
|
||||
status := &model.Status{UserId: ruser.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||
if result := <-Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
|
||||
if result := <-Global().Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
|
||||
result.Err.Translate(utils.T)
|
||||
l4g.Error(result.Err.Error())
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// We need to cheat to verify the user's email
|
||||
store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
store.Must(Global().Srv.Store.User().VerifyEmail(ruser.Id))
|
||||
|
||||
return result.Data.(*model.User), true
|
||||
}
|
||||
|
||||
384
app/channel.go
384
app/channel.go
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -8,7 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPermanentDeleteChannel(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
incomingWasEnabled := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
||||
outgoingWasEnabled := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
|
||||
@@ -19,25 +20,25 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = outgoingWasEnabled
|
||||
}()
|
||||
|
||||
channel, err := CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
channel, err := a.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer func() {
|
||||
PermanentDeleteChannel(channel)
|
||||
a.PermanentDeleteChannel(channel)
|
||||
}()
|
||||
|
||||
incoming, err := CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
incoming, err := a.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer DeleteIncomingWebhook(incoming.Id)
|
||||
defer a.DeleteIncomingWebhook(incoming.Id)
|
||||
|
||||
if incoming, err = GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
t.Fatal("unable to get new incoming webhook")
|
||||
}
|
||||
|
||||
outgoing, err := CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
outgoing, err := a.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: channel.TeamId,
|
||||
CreatorId: th.BasicUser.Id,
|
||||
@@ -46,64 +47,65 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer DeleteOutgoingWebhook(outgoing.Id)
|
||||
defer a.DeleteOutgoingWebhook(outgoing.Id)
|
||||
|
||||
if outgoing, err = GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
t.Fatal("unable to get new outgoing webhook")
|
||||
}
|
||||
|
||||
if err := PermanentDeleteChannel(channel); err != nil {
|
||||
if err := a.PermanentDeleteChannel(channel); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if incoming, err = GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
t.Error("incoming webhook wasn't deleted")
|
||||
}
|
||||
|
||||
if outgoing, err = GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
t.Error("outgoing webhook wasn't deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveChannel(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
sourceTeam := th.CreateTeam()
|
||||
targetTeam := th.CreateTeam()
|
||||
channel1 := th.CreateChannel(sourceTeam)
|
||||
defer func() {
|
||||
PermanentDeleteChannel(channel1)
|
||||
PermanentDeleteTeam(sourceTeam)
|
||||
PermanentDeleteTeam(targetTeam)
|
||||
a.PermanentDeleteChannel(channel1)
|
||||
a.PermanentDeleteTeam(sourceTeam)
|
||||
a.PermanentDeleteTeam(targetTeam)
|
||||
}()
|
||||
|
||||
if _, err := AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
if _, err := a.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
if _, err := a.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := MoveChannel(targetTeam, channel1); err == nil {
|
||||
if err := a.MoveChannel(targetTeam, channel1); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
if _, err := AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := MoveChannel(targetTeam, channel1); err != nil {
|
||||
if err := a.MoveChannel(targetTeam, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,19 +31,19 @@ func NewClusterDiscoveryService() *ClusterDiscoveryService {
|
||||
|
||||
func (me *ClusterDiscoveryService) Start() {
|
||||
|
||||
<-Srv.Store.ClusterDiscovery().Cleanup()
|
||||
<-Global().Srv.Store.ClusterDiscovery().Cleanup()
|
||||
|
||||
if cresult := <-Srv.Store.ClusterDiscovery().Exists(&me.ClusterDiscovery); cresult.Err != nil {
|
||||
if cresult := <-Global().Srv.Store.ClusterDiscovery().Exists(&me.ClusterDiscovery); cresult.Err != nil {
|
||||
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to check if row exists for %v with err=%v", me.ClusterDiscovery.ToJson(), cresult.Err))
|
||||
} else {
|
||||
if cresult.Data.(bool) {
|
||||
if u := <-Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
|
||||
if u := <-Global().Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
|
||||
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to start clean for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.ClusterDiscovery().Save(&me.ClusterDiscovery); result.Err != nil {
|
||||
if result := <-Global().Srv.Store.ClusterDiscovery().Save(&me.ClusterDiscovery); result.Err != nil {
|
||||
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to save for %v with err=%v", me.ClusterDiscovery.ToJson(), result.Err))
|
||||
return
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (me *ClusterDiscoveryService) Start() {
|
||||
ticker := time.NewTicker(DISCOVERY_SERVICE_WRITE_PING)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
if u := <-Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
|
||||
if u := <-Global().Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); u.Err != nil {
|
||||
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to cleanup for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
|
||||
}
|
||||
l4g.Debug(fmt.Sprintf("ClusterDiscoveryService ping writer stopped for %v", me.ClusterDiscovery.ToJson()))
|
||||
@@ -62,7 +62,7 @@ func (me *ClusterDiscoveryService) Start() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if u := <-Srv.Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); u.Err != nil {
|
||||
if u := <-Global().Srv.Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); u.Err != nil {
|
||||
l4g.Error(fmt.Sprintf("ClusterDiscoveryService failed to write ping for %v with err=%v", me.ClusterDiscovery.ToJson(), u.Err))
|
||||
}
|
||||
case <-me.stop:
|
||||
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestClusterDiscoveryService(t *testing.T) {
|
||||
Setup()
|
||||
a := Global()
|
||||
a.Setup()
|
||||
|
||||
ds := NewClusterDiscoveryService()
|
||||
ds.Type = model.CDS_TYPE_APP
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
"github.com/mattermost/platform/model"
|
||||
)
|
||||
|
||||
func RegisterAllClusterMessageHandlers() {
|
||||
func (a *App) RegisterAllClusterMessageHandlers() {
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, ClusterPublishHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, ClusterUpdateStatusHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, ClusterInvalidateAllCachesHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, ClusterInvalidateCacheForWebhookHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, ClusterInvalidateCacheForChannelPostsHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, ClusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, ClusterInvalidateCacheForChannelMembersHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, ClusterInvalidateCacheForChannelByNameHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, ClusterInvalidateCacheForChannelHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, ClusterInvalidateCacheForUserHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler)
|
||||
|
||||
}
|
||||
@@ -35,36 +35,36 @@ func ClusterUpdateStatusHandler(msg *model.ClusterMessage) {
|
||||
AddStatusCacheSkipClusterSend(status)
|
||||
}
|
||||
|
||||
func ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) {
|
||||
InvalidateAllCachesSkipSend()
|
||||
func (a *App) ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateAllCachesSkipSend()
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForWebhookHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForWebhookSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForWebhookHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForWebhookSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForChannelPostsHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForChannelPostsSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForChannelPostsHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForChannelPostsSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForChannelMembersNotifyPropHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForChannelMembersNotifyPropHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForChannelMembersHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForChannelMembersSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForChannelMembersHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForChannelMembersSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForChannelByNameHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForChannelByNameSkipClusterSend(msg.Props["id"], msg.Props["name"])
|
||||
func (a *App) ClusterInvalidateCacheForChannelByNameHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForChannelByNameSkipClusterSend(msg.Props["id"], msg.Props["name"])
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForChannelHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForChannelSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForChannelHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForChannelSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterInvalidateCacheForUserHandler(msg *model.ClusterMessage) {
|
||||
InvalidateCacheForUserSkipClusterSend(msg.Data)
|
||||
func (a *App) ClusterInvalidateCacheForUserHandler(msg *model.ClusterMessage) {
|
||||
a.InvalidateCacheForUserSkipClusterSend(msg.Data)
|
||||
}
|
||||
|
||||
func ClusterClearSessionCacheForUserHandler(msg *model.ClusterMessage) {
|
||||
|
||||
@@ -37,7 +37,7 @@ func GetCommandProvider(name string) CommandProvider {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse) (*model.Post, *model.AppError) {
|
||||
func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse) (*model.Post, *model.AppError) {
|
||||
post.Message = parseSlackLinksToMarkdown(response.Text)
|
||||
post.CreateAt = model.GetMillis()
|
||||
|
||||
@@ -46,7 +46,7 @@ func CreateCommandPost(post *model.Post, teamId string, response *model.CommandR
|
||||
}
|
||||
|
||||
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
|
||||
return CreatePostMissingChannel(post, true)
|
||||
return a.CreatePostMissingChannel(post, true)
|
||||
} else if response.ResponseType == "" || response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL {
|
||||
if response.Text == "" {
|
||||
return post, nil
|
||||
@@ -60,7 +60,7 @@ func CreateCommandPost(post *model.Post, teamId string, response *model.CommandR
|
||||
}
|
||||
|
||||
// previous ListCommands now ListAutocompleteCommands
|
||||
func ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
commands := make([]*model.Command, 0, 32)
|
||||
seen := make(map[string]bool)
|
||||
for _, value := range commandProviders {
|
||||
@@ -73,7 +73,7 @@ func ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableCommands {
|
||||
if result := <-Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
@@ -90,19 +90,19 @@ func ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func ListTeamCommands(teamId string) ([]*model.Command, *model.AppError) {
|
||||
func (a *App) ListTeamCommands(teamId string) ([]*model.Command, *model.AppError) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("ListTeamCommands", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.Command), nil
|
||||
}
|
||||
}
|
||||
|
||||
func ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
commands := make([]*model.Command, 0, 32)
|
||||
seen := make(map[string]bool)
|
||||
for _, value := range commandProviders {
|
||||
@@ -115,7 +115,7 @@ func ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *
|
||||
}
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableCommands {
|
||||
if result := <-Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().GetByTeam(teamId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
@@ -132,7 +132,7 @@ func ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
func (a *App) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
parts := strings.Split(args.Command, " ")
|
||||
trigger := parts[0][1:]
|
||||
trigger = strings.ToLower(trigger)
|
||||
@@ -141,17 +141,17 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App
|
||||
|
||||
if provider != nil {
|
||||
response := provider.DoCommand(args, message)
|
||||
return HandleCommandResponse(provider.GetCommand(args.T), args, response, true)
|
||||
return a.HandleCommandResponse(provider.GetCommand(args.T), args, response, true)
|
||||
} else {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
chanChan := Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
teamChan := Srv.Store.Team().Get(args.TeamId)
|
||||
userChan := Srv.Store.User().Get(args.UserId)
|
||||
chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
teamChan := a.Srv.Store.Team().Get(args.TeamId)
|
||||
userChan := a.Srv.Store.User().Get(args.UserId)
|
||||
|
||||
if result := <-Srv.Store.Command().GetByTeam(args.TeamId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().GetByTeam(args.TeamId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
|
||||
@@ -196,7 +196,7 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App
|
||||
p.Set("command", "/"+trigger)
|
||||
p.Set("text", message)
|
||||
|
||||
if hook, err := CreateCommandWebhook(cmd.Id, args); err != nil {
|
||||
if hook, err := a.CreateCommandWebhook(cmd.Id, args); err != nil {
|
||||
return nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": trigger}, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
p.Set("response_url", args.SiteURL+"/hooks/commands/"+hook.Id)
|
||||
@@ -221,7 +221,7 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App
|
||||
if response == nil {
|
||||
return nil, model.NewAppError("command", "api.command.execute_command.failed_empty.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusInternalServerError)
|
||||
} else {
|
||||
return HandleCommandResponse(cmd, args, response, false)
|
||||
return a.HandleCommandResponse(cmd, args, response, false)
|
||||
}
|
||||
} else {
|
||||
defer resp.Body.Close()
|
||||
@@ -237,7 +237,7 @@ func ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.App
|
||||
return nil, model.NewAppError("command", "api.command.execute_command.not_found.app_error", map[string]interface{}{"Trigger": trigger}, "", http.StatusNotFound)
|
||||
}
|
||||
|
||||
func HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
||||
func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
||||
post := &model.Post{}
|
||||
post.ChannelId = args.ChannelId
|
||||
post.RootId = args.RootId
|
||||
@@ -266,21 +266,21 @@ func HandleCommandResponse(command *model.Command, args *model.CommandArgs, resp
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := CreateCommandPost(post, args.TeamId, response); err != nil {
|
||||
if _, err := a.CreateCommandPost(post, args.TeamId, response); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func CreateCommand(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("CreateCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
||||
|
||||
if result := <-Srv.Store.Command().GetByTeam(cmd.TeamId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().GetByTeam(cmd.TeamId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
@@ -297,19 +297,19 @@ func CreateCommand(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Command().Save(cmd); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().Save(cmd); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.Command), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetCommand(commandId string) (*model.Command, *model.AppError) {
|
||||
func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Command().Get(commandId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().Get(commandId); result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
} else {
|
||||
@@ -317,7 +317,7 @@ func GetCommand(commandId string) (*model.Command, *model.AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
|
||||
func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("UpdateCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -331,33 +331,33 @@ func UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.Ap
|
||||
updatedCmd.CreatorId = oldCmd.CreatorId
|
||||
updatedCmd.TeamId = oldCmd.TeamId
|
||||
|
||||
if result := <-Srv.Store.Command().Update(updatedCmd); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().Update(updatedCmd); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.Command), nil
|
||||
}
|
||||
}
|
||||
|
||||
func RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppError) {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return nil, model.NewAppError("RegenCommandToken", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
cmd.Token = model.NewId()
|
||||
|
||||
if result := <-Srv.Store.Command().Update(cmd); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().Update(cmd); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.Command), nil
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteCommand(commandId string) *model.AppError {
|
||||
func (a *App) DeleteCommand(commandId string) *model.AppError {
|
||||
if !*utils.Cfg.ServiceSettings.EnableCommands {
|
||||
return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if err := (<-Srv.Store.Command().Delete(commandId, model.GetMillis())).Err; err != nil {
|
||||
if err := (<-a.Srv.Store.Command().Delete(commandId, model.GetMillis())).Err; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func (me *AwayProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *AwayProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
SetStatusAwayIfNeeded(args.UserId, true)
|
||||
Global().SetStatusAwayIfNeeded(args.UserId, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_away.success")}
|
||||
}
|
||||
|
||||
@@ -35,16 +35,16 @@ func (me *HeaderProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *HeaderProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := GetChannel(args.ChannelId)
|
||||
channel, err := Global().GetChannel(args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_header.channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_header.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_header.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func (me *HeaderProvider) DoCommand(args *model.CommandArgs, message string) *mo
|
||||
}
|
||||
*patch.Header = message
|
||||
|
||||
_, err = PatchChannel(channel, patch, args.UserId)
|
||||
_, err = Global().PatchChannel(channel, patch, args.UserId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_header.update_channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,16 @@ func (me *PurposeProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *PurposeProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := GetChannel(args.ChannelId)
|
||||
channel, err := Global().GetChannel(args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_purpose.channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_purpose.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_purpose.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func (me *PurposeProvider) DoCommand(args *model.CommandArgs, message string) *m
|
||||
}
|
||||
*patch.Purpose = message
|
||||
|
||||
_, err = PatchChannel(channel, patch, args.UserId)
|
||||
_, err = Global().PatchChannel(channel, patch, args.UserId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_purpose.update_channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -34,16 +34,16 @@ func (me *RenameProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *RenameProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
channel, err := GetChannel(args.ChannelId)
|
||||
channel, err := Global().GetChannel(args.ChannelId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !Global().SessionHasPermissionToChannel(args.Session, args.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ func (me *RenameProvider) DoCommand(args *model.CommandArgs, message string) *mo
|
||||
}
|
||||
*patch.DisplayName = message
|
||||
|
||||
_, err = PatchChannel(channel, patch, args.UserId)
|
||||
_, err = Global().PatchChannel(channel, patch, args.UserId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.update_channel.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestRenameProviderDoCommand(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
rp := RenameProvider{}
|
||||
args := &model.CommandArgs{
|
||||
|
||||
@@ -88,7 +88,7 @@ func (me *EchoProvider) DoCommand(args *model.CommandArgs, message string) *mode
|
||||
|
||||
time.Sleep(time.Duration(delay) * time.Second)
|
||||
|
||||
if _, err := CreatePostMissingChannel(post, true); err != nil {
|
||||
if _, err := Global().CreatePostMissingChannel(post, true); err != nil {
|
||||
l4g.Error(args.T("api.command_echo.create.app_error"), err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -53,14 +53,14 @@ func (me *CollapseProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *ExpandProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return setCollapsePreference(args, false)
|
||||
return Global().setCollapsePreference(args, false)
|
||||
}
|
||||
|
||||
func (me *CollapseProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return setCollapsePreference(args, true)
|
||||
return Global().setCollapsePreference(args, true)
|
||||
}
|
||||
|
||||
func setCollapsePreference(args *model.CommandArgs, isCollapse bool) *model.CommandResponse {
|
||||
func (a *App) setCollapsePreference(args *model.CommandArgs, isCollapse bool) *model.CommandResponse {
|
||||
pref := model.Preference{
|
||||
UserId: args.UserId,
|
||||
Category: model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS,
|
||||
@@ -68,7 +68,7 @@ func setCollapsePreference(args *model.CommandArgs, isCollapse bool) *model.Comm
|
||||
Value: strconv.FormatBool(isCollapse),
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Preference().Save(&model.Preferences{pref}); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Preference().Save(&model.Preferences{pref}); result.Err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_expand_collapse.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ func (me *InvitePeopleProvider) DoCommand(args *model.CommandArgs, message strin
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.no_email")}
|
||||
}
|
||||
|
||||
if err := InviteNewUsersToTeam(emailList, args.TeamId, args.UserId); err != nil {
|
||||
if err := Global().InviteNewUsersToTeam(emailList, args.TeamId, args.UserId); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command.invite_people.fail")}
|
||||
}
|
||||
|
||||
@@ -34,14 +34,14 @@ func (me *JoinProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *JoinProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if result := <-Srv.Store.Channel().GetByName(args.TeamId, message, true); result.Err != nil {
|
||||
if result := <-Global().Srv.Store.Channel().GetByName(args.TeamId, message, true); result.Err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
if channel.Name == message {
|
||||
allowed := false
|
||||
if (channel.Type == model.CHANNEL_PRIVATE && SessionHasPermissionToChannel(args.Session, channel.Id, model.PERMISSION_READ_CHANNEL)) || channel.Type == model.CHANNEL_OPEN {
|
||||
if (channel.Type == model.CHANNEL_PRIVATE && Global().SessionHasPermissionToChannel(args.Session, channel.Id, model.PERMISSION_READ_CHANNEL)) || channel.Type == model.CHANNEL_OPEN {
|
||||
allowed = true
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ func (me *JoinProvider) DoCommand(args *model.CommandArgs, message string) *mode
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
if err := JoinChannel(channel, args.UserId); err != nil {
|
||||
if err := Global().JoinChannel(channel, args.UserId); err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
team, err := GetTeam(channel.TeamId)
|
||||
team, err := Global().GetTeam(channel.TeamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,18 @@ func (me *LeaveProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
func (me *LeaveProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var channel *model.Channel
|
||||
var noChannelErr *model.AppError
|
||||
if channel, noChannelErr = GetChannel(args.ChannelId); noChannelErr != nil {
|
||||
if channel, noChannelErr = Global().GetChannel(args.ChannelId); noChannelErr != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
if channel.Name == model.DEFAULT_CHANNEL {
|
||||
return &model.CommandResponse{Text: args.T("api.channel.leave.default.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
err := LeaveChannel(args.ChannelId, args.UserId)
|
||||
err := Global().LeaveChannel(args.ChannelId, args.UserId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
team, err := GetTeam(args.TeamId)
|
||||
team, err := Global().GetTeam(args.TeamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_leave.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (me *LoadTestProvider) SetupCommand(args *model.CommandArgs, message string
|
||||
client := model.NewClient(args.SiteURL)
|
||||
|
||||
if doTeams {
|
||||
if err := CreateBasicUser(client); err != nil {
|
||||
if err := Global().CreateBasicUser(client); err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
client.Login(BTEST_USER_EMAIL, BTEST_USER_PASSWORD)
|
||||
@@ -184,7 +184,7 @@ func (me *LoadTestProvider) SetupCommand(args *model.CommandArgs, message string
|
||||
} else {
|
||||
|
||||
var team *model.Team
|
||||
if tr := <-Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
if tr := <-Global().Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
team = tr.Data.(*model.Team)
|
||||
@@ -219,7 +219,7 @@ func (me *LoadTestProvider) UsersCommand(args *model.CommandArgs, message string
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
if tr := <-Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
if tr := <-Global().Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
team = tr.Data.(*model.Team)
|
||||
@@ -249,7 +249,7 @@ func (me *LoadTestProvider) ChannelsCommand(args *model.CommandArgs, message str
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
if tr := <-Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
if tr := <-Global().Srv.Store.Team().Get(args.TeamId); tr.Err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
team = tr.Data.(*model.Team)
|
||||
@@ -288,7 +288,7 @@ func (me *LoadTestProvider) PostsCommand(args *model.CommandArgs, message string
|
||||
}
|
||||
|
||||
var usernames []string
|
||||
if result := <-Srv.Store.User().GetProfiles(args.TeamId, 0, 1000); result.Err == nil {
|
||||
if result := <-Global().Srv.Store.User().GetProfiles(args.TeamId, 0, 1000); result.Err == nil {
|
||||
profileUsers := result.Data.([]*model.User)
|
||||
usernames = make([]string, len(profileUsers))
|
||||
i := 0
|
||||
@@ -357,7 +357,7 @@ func (me *LoadTestProvider) UrlCommand(args *model.CommandArgs, message string)
|
||||
post.ChannelId = args.ChannelId
|
||||
post.UserId = args.UserId
|
||||
|
||||
if _, err := CreatePostMissingChannel(post, false); err != nil {
|
||||
if _, err := Global().CreatePostMissingChannel(post, false); err != nil {
|
||||
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ func (me *LoadTestProvider) JsonCommand(args *model.CommandArgs, message string)
|
||||
post.Message = message
|
||||
}
|
||||
|
||||
if _, err := CreatePostMissingChannel(post, false); err != nil {
|
||||
if _, err := Global().CreatePostMissingChannel(post, false); err != nil {
|
||||
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
return &model.CommandResponse{Text: "Loaded data", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (me *LogoutProvider) DoCommand(args *model.CommandArgs, message string) *mo
|
||||
|
||||
// We can't actually remove the user's cookie from here so we just dump their session and let the browser figure it out
|
||||
if args.Session.Id != "" {
|
||||
if err := RevokeSessionById(args.Session.Id); err != nil {
|
||||
if err := Global().RevokeSessionById(args.Session.Id); err != nil {
|
||||
return FAIL
|
||||
}
|
||||
return SUCCESS
|
||||
|
||||
@@ -51,7 +51,7 @@ func (me *msgProvider) DoCommand(args *model.CommandArgs, message string) *model
|
||||
targetUsername = strings.TrimPrefix(targetUsername, "@")
|
||||
|
||||
var userProfile *model.User
|
||||
if result := <-Srv.Store.User().GetByUsername(targetUsername); result.Err != nil {
|
||||
if result := <-Global().Srv.Store.User().GetByUsername(targetUsername); result.Err != nil {
|
||||
l4g.Error(result.Err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
@@ -66,9 +66,9 @@ func (me *msgProvider) DoCommand(args *model.CommandArgs, message string) *model
|
||||
channelName := model.GetDMNameFromIds(args.UserId, userProfile.Id)
|
||||
|
||||
targetChannelId := ""
|
||||
if channel := <-Srv.Store.Channel().GetByName(args.TeamId, channelName, true); channel.Err != nil {
|
||||
if channel := <-Global().Srv.Store.Channel().GetByName(args.TeamId, channelName, true); channel.Err != nil {
|
||||
if channel.Err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||
if directChannel, err := CreateDirectChannel(args.UserId, userProfile.Id); err != nil {
|
||||
if directChannel, err := Global().CreateDirectChannel(args.UserId, userProfile.Id); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.dm_fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else {
|
||||
@@ -89,7 +89,7 @@ func (me *msgProvider) DoCommand(args *model.CommandArgs, message string) *model
|
||||
post.Message = parsedMessage
|
||||
post.ChannelId = targetChannelId
|
||||
post.UserId = args.UserId
|
||||
if _, err := CreatePostMissingChannel(post, true); err != nil {
|
||||
if _, err := Global().CreatePostMissingChannel(post, true); err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func (me *msgProvider) DoCommand(args *model.CommandArgs, message string) *model
|
||||
teamId = args.Session.TeamMembers[0].TeamId
|
||||
}
|
||||
|
||||
team, err := GetTeam(teamId)
|
||||
team, err := Global().GetTeam(teamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (me *OfflineProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *OfflineProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
SetStatusOffline(args.UserId, true)
|
||||
Global().SetStatusOffline(args.UserId, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_offline.success")}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (me *OnlineProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||
}
|
||||
|
||||
func (me *OnlineProvider) DoCommand(args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
SetStatusOnline(args.UserId, args.Session.Id, true)
|
||||
Global().SetStatusOnline(args.UserId, args.Session.Id, true)
|
||||
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_online.success")}
|
||||
}
|
||||
|
||||
@@ -6,32 +6,33 @@ package app
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
|
||||
func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError) {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance {
|
||||
return nil, model.NewAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Compliance().GetAll(page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Compliance().GetAll(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(model.Compliances), nil
|
||||
}
|
||||
}
|
||||
|
||||
func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
|
||||
func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
|
||||
return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
job.Type = model.COMPLIANCE_TYPE_ADHOC
|
||||
|
||||
if result := <-Srv.Store.Compliance().Save(job); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Compliance().Save(job); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
job = result.Data.(*model.Compliance)
|
||||
@@ -41,12 +42,12 @@ func SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppE
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
|
||||
func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
|
||||
return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Compliance().Get(reportId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Compliance().Get(reportId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.Compliance), nil
|
||||
|
||||
@@ -50,13 +50,13 @@ const (
|
||||
|
||||
var client *analytics.Client
|
||||
|
||||
func SendDailyDiagnostics() {
|
||||
func (a *App) SendDailyDiagnostics() {
|
||||
if *utils.Cfg.LogSettings.EnableDiagnostics && utils.IsLeader() {
|
||||
initDiagnostics("")
|
||||
trackActivity()
|
||||
a.trackActivity()
|
||||
trackConfig()
|
||||
trackLicense()
|
||||
trackServer()
|
||||
a.trackServer()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func pluginSetting(plugin, key string, defaultValue interface{}) interface{} {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func trackActivity() {
|
||||
func (a *App) trackActivity() {
|
||||
var userCount int64
|
||||
var activeUserCount int64
|
||||
var inactiveUserCount int64
|
||||
@@ -120,43 +120,43 @@ func trackActivity() {
|
||||
var deletedPrivateChannelCount int64
|
||||
var postsCount int64
|
||||
|
||||
if ucr := <-Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
|
||||
if ucr := <-a.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
|
||||
userCount = ucr.Data.(int64)
|
||||
}
|
||||
|
||||
if ucr := <-Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
||||
if ucr := <-a.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
||||
activeUserCount = ucr.Data.(int64)
|
||||
}
|
||||
|
||||
if iucr := <-Srv.Store.Status().GetTotalActiveUsersCount(); iucr.Err == nil {
|
||||
if iucr := <-a.Srv.Store.Status().GetTotalActiveUsersCount(); iucr.Err == nil {
|
||||
inactiveUserCount = iucr.Data.(int64)
|
||||
}
|
||||
|
||||
if tcr := <-Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
||||
if tcr := <-a.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
||||
teamCount = tcr.Data.(int64)
|
||||
}
|
||||
|
||||
if ucc := <-Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil {
|
||||
if ucc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil {
|
||||
publicChannelCount = ucc.Data.(int64)
|
||||
}
|
||||
|
||||
if pcc := <-Srv.Store.Channel().AnalyticsTypeCount("", "P"); pcc.Err == nil {
|
||||
if pcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "P"); pcc.Err == nil {
|
||||
privateChannelCount = pcc.Data.(int64)
|
||||
}
|
||||
|
||||
if dcc := <-Srv.Store.Channel().AnalyticsTypeCount("", "D"); dcc.Err == nil {
|
||||
if dcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "D"); dcc.Err == nil {
|
||||
directChannelCount = dcc.Data.(int64)
|
||||
}
|
||||
|
||||
if duccr := <-Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil {
|
||||
if duccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil {
|
||||
deletedPublicChannelCount = duccr.Data.(int64)
|
||||
}
|
||||
|
||||
if dpccr := <-Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil {
|
||||
if dpccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil {
|
||||
deletedPrivateChannelCount = dpccr.Data.(int64)
|
||||
}
|
||||
|
||||
if pcr := <-Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil {
|
||||
if pcr := <-a.Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil {
|
||||
postsCount = pcr.Data.(int64)
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ func trackLicense() {
|
||||
}
|
||||
}
|
||||
|
||||
func trackServer() {
|
||||
func (a *App) trackServer() {
|
||||
data := map[string]interface{}{
|
||||
"edition": model.BuildEnterpriseReady,
|
||||
"version": model.CurrentVersion,
|
||||
@@ -475,7 +475,7 @@ func trackServer() {
|
||||
"operating_system": runtime.GOOS,
|
||||
}
|
||||
|
||||
if scr := <-Srv.Store.User().AnalyticsGetSystemAdminCount(); scr.Err == nil {
|
||||
if scr := <-a.Srv.Store.User().AnalyticsGetSystemAdminCount(); scr.Err == nil {
|
||||
data["system_admins"] = scr.Data.(int64)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ func TestPluginSetting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiagnostics(t *testing.T) {
|
||||
Setup().InitBasic()
|
||||
a := Global()
|
||||
a.Setup().InitBasic()
|
||||
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
@@ -91,7 +92,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("SendDailyDiagnostics", func(t *testing.T) {
|
||||
SendDailyDiagnostics()
|
||||
a.SendDailyDiagnostics()
|
||||
|
||||
info := ""
|
||||
// Collect the info sent.
|
||||
@@ -151,7 +152,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
*utils.Cfg.LogSettings.EnableDiagnostics = oldSetting
|
||||
}()
|
||||
|
||||
SendDailyDiagnostics()
|
||||
a.SendDailyDiagnostics()
|
||||
|
||||
select {
|
||||
case <-data:
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
|
||||
@@ -120,7 +121,7 @@ func SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppErro
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError {
|
||||
func (a *App) SendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError {
|
||||
T := utils.GetUserTranslations(locale)
|
||||
|
||||
rawUrl, _ := url.Parse(siteURL)
|
||||
@@ -144,7 +145,7 @@ func SendWelcomeEmail(userId string, email string, verified bool, locale, siteUR
|
||||
}
|
||||
|
||||
if !verified {
|
||||
token, err := CreateVerifyEmailToken(userId)
|
||||
token, err := a.CreateVerifyEmailToken(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Ссылка в новой задаче
Block a user