mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-23 01:40:32 -05:00
MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
This commit is contained in:
parent
66fc096768
commit
17523fa5d9
200 changed files with 4553 additions and 2361 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -101,3 +101,5 @@ tags
|
|||
|
||||
debug
|
||||
client
|
||||
__debug_bin
|
||||
report.xml
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -202,6 +202,10 @@ ifneq ($(MM_NO_ENTERPRISE_LINT),true)
|
|||
endif
|
||||
endif
|
||||
|
||||
app-layers: ## Extract interface from App struct
|
||||
env GO111MODULE=off $(GO) get -u github.com/reflog/struct2interface
|
||||
$(GOBIN)/struct2interface -f "app" -o "app/app_iface.go" -p "app" -s "App" -i "AppIface" -t ./app/layer_generators/app_iface.go.tmpl
|
||||
|
||||
i18n-extract: ## Extract strings for translation from the source code
|
||||
env GO111MODULE=off $(GO) get -u github.com/mattermost/mattermost-utilities/mmgotool
|
||||
$(GOBIN)/mmgotool i18n extract
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ func setupTestHelper(enterprise bool, updateConfig func(*model.Config)) *TestHel
|
|||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
|
||||
Init(th.Server, th.Server.AppOptions, th.App.Srv.Router)
|
||||
web.New(th.Server, th.Server.AppOptions, th.App.Srv.Router)
|
||||
wsapi.Init(th.App, th.App.Srv.WebSocketRouter)
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
Init(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
wsapi.Init(th.App, th.App.Srv().WebSocketRouter)
|
||||
th.App.Srv().Store.MarkSystemRanUnitTests()
|
||||
th.App.DoAppMigrations()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
|
||||
|
|
@ -227,7 +227,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
|
|||
|
||||
func (me *TestHelper) waitForConnectivity() {
|
||||
for i := 0; i < 1000; i++ {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", me.App.Srv.ListenAddr.Port))
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", me.App.Srv().ListenAddr.Port))
|
||||
if err == nil {
|
||||
conn.Close()
|
||||
return
|
||||
|
|
@ -238,19 +238,19 @@ func (me *TestHelper) waitForConnectivity() {
|
|||
}
|
||||
|
||||
func (me *TestHelper) CreateClient() *model.Client4 {
|
||||
return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", me.App.Srv.ListenAddr.Port))
|
||||
return model.NewAPIv4Client(fmt.Sprintf("http://localhost:%v", me.App.Srv().ListenAddr.Port))
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv.ListenAddr.Port), me.Client.AuthToken)
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.Client.AuthToken)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateWebSocketSystemAdminClient() (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv.ListenAddr.Port), me.SystemAdminClient.AuthToken)
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), me.SystemAdminClient.AuthToken)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateWebSocketClientWithClient(client *model.Client4) (*model.WebSocketClient, *model.AppError) {
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv.ListenAddr.Port), client.AuthToken)
|
||||
return model.NewWebSocketClient4(fmt.Sprintf("ws://localhost:%v", me.App.Srv().ListenAddr.Port), client.AuthToken)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CreateBotWithSystemAdminClient() *model.Bot {
|
||||
|
|
@ -318,7 +318,7 @@ func (me *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
|||
}
|
||||
|
||||
ruser.Password = "Pa$$word11"
|
||||
_, err := me.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err := me.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ func (me *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel
|
|||
}
|
||||
|
||||
func (me *TestHelper) CreateMessagePostNoClient(channel *model.Channel, message string, createAtTime int64) *model.Post {
|
||||
post, err := me.App.Srv.Store.Post().Save(&model.Post{
|
||||
post, err := me.App.Srv().Store.Post().Save(&model.Post{
|
||||
UserId: me.BasicUser.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: message,
|
||||
|
|
@ -751,9 +751,9 @@ func (me *TestHelper) cleanupTestFile(info *model.FileInfo) error {
|
|||
func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
if cm, err := me.App.Srv.Store.Channel().GetMember(channel.Id, user.Id); err == nil {
|
||||
if cm, err := me.App.Srv().Store.Channel().GetMember(channel.Id, user.Id); err == nil {
|
||||
cm.SchemeAdmin = true
|
||||
if _, err = me.App.Srv.Store.Channel().UpdateMember(cm); err != nil {
|
||||
if _, err = me.App.Srv().Store.Channel().UpdateMember(cm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -768,9 +768,9 @@ func (me *TestHelper) MakeUserChannelAdmin(user *model.User, channel *model.Chan
|
|||
func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
if tm, err := me.App.Srv.Store.Team().GetMember(team.Id, user.Id); err == nil {
|
||||
if tm, err := me.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil {
|
||||
tm.SchemeAdmin = true
|
||||
if _, err = me.App.Srv.Store.Team().UpdateMember(tm); err != nil {
|
||||
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -788,9 +788,9 @@ func (me *TestHelper) UpdateUserToTeamAdmin(user *model.User, team *model.Team)
|
|||
func (me *TestHelper) UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
if tm, err := me.App.Srv.Store.Team().GetMember(team.Id, user.Id); err == nil {
|
||||
if tm, err := me.App.Srv().Store.Team().GetMember(team.Id, user.Id); err == nil {
|
||||
tm.SchemeAdmin = false
|
||||
if _, err = me.App.Srv.Store.Team().UpdateMember(tm); err != nil {
|
||||
if _, err = me.App.Srv().Store.Team().UpdateMember(tm); err != nil {
|
||||
utils.EnableDebugLogForTest()
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
30
api4/bot.go
30
api4/bot.go
|
|
@ -35,16 +35,16 @@ func createBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
bot := &model.Bot{
|
||||
OwnerId: c.App.Session.UserId,
|
||||
OwnerId: c.App.Session().UserId,
|
||||
}
|
||||
bot.Patch(botPatch)
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_BOT) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_BOT) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_BOT)
|
||||
return
|
||||
}
|
||||
|
||||
if user, err := c.App.GetUser(c.App.Session.UserId); err == nil {
|
||||
if user, err := c.App.GetUser(c.App.Session().UserId); err == nil {
|
||||
if user.IsBot {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_BOT)
|
||||
return
|
||||
|
|
@ -79,7 +79,7 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.App.Session, botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.App.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -108,10 +108,10 @@ func getBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_OTHERS_BOTS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_OTHERS_BOTS) {
|
||||
// Allow access to any bot.
|
||||
} else if bot.OwnerId == c.App.Session.UserId {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_BOTS) {
|
||||
} else if bot.OwnerId == c.App.Session().UserId {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_BOTS) {
|
||||
// Pretend like the bot doesn't exist at all to avoid revealing that the
|
||||
// user is a bot. It's kind of silly in this case, sine we created the bot,
|
||||
// but we don't have read bot permissions.
|
||||
|
|
@ -137,12 +137,12 @@ func getBots(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
onlyOrphaned := r.URL.Query().Get("only_orphaned") == "true"
|
||||
|
||||
var OwnerId string
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_OTHERS_BOTS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_OTHERS_BOTS) {
|
||||
// Get bots created by any user.
|
||||
OwnerId = ""
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_BOTS) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_BOTS) {
|
||||
// Only get bots created by this user.
|
||||
OwnerId = c.App.Session.UserId
|
||||
OwnerId = c.App.Session().UserId
|
||||
} else {
|
||||
c.SetPermissionError(model.PERMISSION_READ_BOTS)
|
||||
return
|
||||
|
|
@ -182,7 +182,7 @@ func updateBotActive(c *Context, w http.ResponseWriter, r *http.Request, active
|
|||
}
|
||||
botUserId := c.Params.BotUserId
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.App.Session, botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.App.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -205,7 +205,7 @@ func assignBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
botUserId := c.Params.BotUserId
|
||||
userId := c.Params.UserId
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.App.Session, botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.App.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ func getBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
botUserId := c.Params.BotUserId
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, botUserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, botUserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -276,7 +276,7 @@ func setBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
botUserId := c.Params.BotUserId
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.App.Session, botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.App.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ func deleteBotIconImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
botUserId := c.Params.BotUserId
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.App.Session, botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.App.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func deleteBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
166
api4/channel.go
166
api4/channel.go
|
|
@ -66,17 +66,17 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_CREATE_PUBLIC_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_CREATE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_CREATE_PRIVATE_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_CREATE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
sc, err := c.App.CreateChannelWithUser(channel, c.App.Session.UserId)
|
||||
sc, err := c.App.CreateChannelWithUser(channel, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -115,20 +115,20 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
switch oldChannel.Type {
|
||||
case model.CHANNEL_OPEN:
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
|
||||
return
|
||||
}
|
||||
|
||||
case model.CHANNEL_PRIVATE:
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
|
||||
return
|
||||
}
|
||||
|
||||
case model.CHANNEL_GROUP, model.CHANNEL_DIRECT:
|
||||
// Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
|
||||
if _, err := c.App.GetChannelMember(channel.Id, c.App.Session.UserId); err != nil {
|
||||
if _, err := c.App.GetChannelMember(channel.Id, c.App.Session().UserId); err != nil {
|
||||
c.Err = model.NewAppError("updateChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if oldChannelDisplayName != channel.DisplayName {
|
||||
if err := c.App.PostUpdateChannelDisplayNameMessage(c.App.Session.UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
|
||||
if err := c.App.PostUpdateChannelDisplayNameMessage(c.App.Session().UserId, channel, oldChannelDisplayName, channel.DisplayName); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ func convertChannelToPrivate(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, oldPublicChannel.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), oldPublicChannel.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func convertChannelToPrivate(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.App.Session.UserId)
|
||||
user, err := c.App.GetUser(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -251,7 +251,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ func updateChannelPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.App.Session.UserId)
|
||||
user, err := c.App.GetUser(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -301,20 +301,20 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
switch oldChannel.Type {
|
||||
case model.CHANNEL_OPEN:
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES)
|
||||
return
|
||||
}
|
||||
|
||||
case model.CHANNEL_PRIVATE:
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES)
|
||||
return
|
||||
}
|
||||
|
||||
case model.CHANNEL_GROUP, model.CHANNEL_DIRECT:
|
||||
// Modifying the header is not linked to any specific permission for group/dm channels, so just check for membership.
|
||||
if _, err = c.App.GetChannelMember(c.Params.ChannelId, c.App.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetChannelMember(c.Params.ChannelId, c.App.Session().UserId); err != nil {
|
||||
c.Err = model.NewAppError("patchChannel", "api.channel.patch_update_channel.forbidden.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
rchannel, err := c.App.PatchChannel(oldChannel, patch, c.App.Session.UserId)
|
||||
rchannel, err := c.App.PatchChannel(oldChannel, patch, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -353,12 +353,12 @@ func restoreChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
teamId := channel.TeamId
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
channel, err = c.App.RestoreChannel(channel, c.App.Session.UserId)
|
||||
channel, err = c.App.RestoreChannel(channel, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -383,27 +383,27 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.SetInvalidParam("user_id")
|
||||
return
|
||||
}
|
||||
if id == c.App.Session.UserId {
|
||||
if id == c.App.Session().UserId {
|
||||
allowed = true
|
||||
}
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_DIRECT_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_DIRECT_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_DIRECT_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if !allowed && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !allowed && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
otherUserId := userIds[0]
|
||||
if c.App.Session.UserId == otherUserId {
|
||||
if c.App.Session().UserId == otherUserId {
|
||||
otherUserId = userIds[1]
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, otherUserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, otherUserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -431,7 +431,7 @@ func searchGroupChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
groupChannels, err := c.App.SearchGroupChannels(c.App.Session.UserId, props.Term)
|
||||
groupChannels, err := c.App.SearchGroupChannels(c.App.Session().UserId, props.Term)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -454,24 +454,24 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.SetInvalidParam("user_id")
|
||||
return
|
||||
}
|
||||
if id == c.App.Session.UserId {
|
||||
if id == c.App.Session().UserId {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
userIds = append(userIds, c.App.Session.UserId)
|
||||
userIds = append(userIds, c.App.Session().UserId)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_GROUP_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_GROUP_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_GROUP_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
canSeeAll := true
|
||||
for _, id := range userIds {
|
||||
if c.App.Session.UserId != id {
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, id)
|
||||
if c.App.Session().UserId != id {
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -487,7 +487,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
groupChannel, err := c.App.CreateGroupChannel(userIds, c.App.Session.UserId)
|
||||
groupChannel, err := c.App.CreateGroupChannel(userIds, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -510,12 +510,12 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) && !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) && !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -536,12 +536,12 @@ func getChannelUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -561,7 +561,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -594,7 +594,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -616,7 +616,7 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getAllChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -657,7 +657,7 @@ func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS)
|
||||
return
|
||||
}
|
||||
|
|
@ -683,7 +683,7 @@ func getDeletedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Reques
|
|||
return
|
||||
}
|
||||
|
||||
channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage, c.App.Session.UserId)
|
||||
channels, err := c.App.GetDeletedChannels(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -717,7 +717,7 @@ func getPublicChannelsByIdsForTeam(c *Context, w http.ResponseWriter, r *http.Re
|
|||
}
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -743,12 +743,12 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -779,7 +779,7 @@ func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Requ
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS)
|
||||
return
|
||||
}
|
||||
|
|
@ -803,14 +803,14 @@ func autocompleteChannelsForTeamForSearch(c *Context, w http.ResponseWriter, r *
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS)
|
||||
return
|
||||
}
|
||||
|
||||
name := r.URL.Query().Get("name")
|
||||
|
||||
channels, err := c.App.AutocompleteChannelsForSearch(c.Params.TeamId, c.App.Session.UserId, name)
|
||||
channels, err := c.App.AutocompleteChannelsForSearch(c.Params.TeamId, c.App.Session().UserId, name)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -835,16 +835,16 @@ func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var channels *model.ChannelList
|
||||
var err *model.AppError
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
channels, err = c.App.SearchChannels(c.Params.TeamId, props.Term)
|
||||
} else {
|
||||
// If the user is not a team member, return a 404
|
||||
if _, err = c.App.GetTeamMember(c.Params.TeamId, c.App.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetTeamMember(c.Params.TeamId, c.App.Session().UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
channels, err = c.App.SearchChannelsForUser(c.App.Session.UserId, c.Params.TeamId, props.Term)
|
||||
channels, err = c.App.SearchChannelsForUser(c.App.Session().UserId, c.Params.TeamId, props.Term)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -871,16 +871,16 @@ func searchArchivedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Re
|
|||
|
||||
var channels *model.ChannelList
|
||||
var err *model.AppError
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session.UserId)
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
|
||||
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session().UserId)
|
||||
} else {
|
||||
// If the user is not a team member, return a 404
|
||||
if _, err = c.App.GetTeamMember(c.Params.TeamId, c.App.Session.UserId); err != nil {
|
||||
if _, err = c.App.GetTeamMember(c.Params.TeamId, c.App.Session().UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session.UserId)
|
||||
channels, err = c.App.SearchArchivedChannels(c.Params.TeamId, props.Term, c.App.Session().UserId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -900,7 +900,7 @@ func searchAllChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -950,17 +950,17 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_DELETE_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_DELETE_PRIVATE_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_PRIVATE_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.DeleteChannel(channel, c.App.Session.UserId)
|
||||
err = c.App.DeleteChannel(channel, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -986,12 +986,12 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.Err = model.NewAppError("getChannelByName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
@ -1020,7 +1020,7 @@ func getChannelByNameForTeamName(c *Context, w http.ResponseWriter, r *http.Requ
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.Err = model.NewAppError("getChannelByNameForTeamName", store.MISSING_CHANNEL_ERROR, nil, "teamId="+channel.TeamId+", "+"name="+channel.Name+"", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
|
@ -1040,7 +1040,7 @@ func getChannelMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -1060,7 +1060,7 @@ func getChannelMembersTimezones(c *Context, w http.ResponseWriter, r *http.Reque
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -1086,7 +1086,7 @@ func getChannelMembersByIds(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -1106,7 +1106,7 @@ func getChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -1126,12 +1126,12 @@ func getChannelMembersForUser(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != c.Params.UserId && !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.Session().UserId != c.Params.UserId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1151,7 +1151,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1173,13 +1173,13 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
times, err := c.App.ViewChannel(view, c.Params.UserId, c.App.Session.Id)
|
||||
times, err := c.App.ViewChannel(view, c.Params.UserId, c.App.Session().Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
|
||||
|
||||
// Returning {"status": "OK", ...} for backwards compatibility
|
||||
resp := &model.ChannelViewResponse{
|
||||
|
|
@ -1204,7 +1204,7 @@ func updateChannelMemberRoles(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_CHANNEL_ROLES)
|
||||
return
|
||||
}
|
||||
|
|
@ -1229,7 +1229,7 @@ func updateChannelMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.R
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_CHANNEL_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_CHANNEL_ROLES)
|
||||
return
|
||||
}
|
||||
|
|
@ -1254,7 +1254,7 @@ func updateChannelMemberNotifyProps(c *Context, w http.ResponseWriter, r *http.R
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1325,18 +1325,18 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
isSelfAdd := member.UserId == c.App.Session.UserId
|
||||
isSelfAdd := member.UserId == c.App.Session().UserId
|
||||
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if isSelfAdd && isNewMembership {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
|
||||
c.SetPermissionError(model.PERMISSION_JOIN_PUBLIC_CHANNELS)
|
||||
return
|
||||
}
|
||||
} else if isSelfAdd && !isNewMembership {
|
||||
// nothing to do, since already in the channel
|
||||
} else if !isSelfAdd {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1345,14 +1345,14 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if channel.Type == model.CHANNEL_PRIVATE {
|
||||
if isSelfAdd && isNewMembership {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
} else if isSelfAdd && !isNewMembership {
|
||||
// nothing to do, since already in the channel
|
||||
} else if !isSelfAdd {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1375,7 +1375,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
cm, err := c.App.AddChannelMember(member.UserId, channel, c.App.Session.UserId, postRootId)
|
||||
cm, err := c.App.AddChannelMember(member.UserId, channel, c.App.Session().UserId, postRootId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -1409,24 +1409,24 @@ func removeChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if channel.IsGroupConstrained() && (c.Params.UserId != c.App.Session.UserId) && !user.IsBot {
|
||||
if channel.IsGroupConstrained() && (c.Params.UserId != c.App.Session().UserId) && !user.IsBot {
|
||||
c.Err = model.NewAppError("removeChannelMember", "api.channel.remove_member.group_constrained.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if c.Params.UserId != c.App.Session.UserId {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
if c.Params.UserId != c.App.Session().UserId {
|
||||
if channel.Type == model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
if channel.Type == model.CHANNEL_PRIVATE && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_PRIVATE_CHANNEL_MEMBERS)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = c.App.RemoveUserFromChannel(c.Params.UserId, c.App.Session.UserId, channel); err != nil {
|
||||
if err = c.App.RemoveUserFromChannel(c.Params.UserId, c.App.Session().UserId, channel); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -1453,7 +1453,7 @@ func updateChannelScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1508,7 +1508,7 @@ func channelMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.
|
|||
groupIDs = append(groupIDs, gid)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1298,7 +1298,7 @@ func TestDeleteChannel2(t *testing.T) {
|
|||
// successful delete by channel admin
|
||||
th.MakeUserChannelAdmin(user, publicChannel6)
|
||||
th.MakeUserChannelAdmin(user, privateChannel7)
|
||||
th.App.Srv.Store.Channel().ClearCaches()
|
||||
th.App.Srv().Store.Channel().ClearCaches()
|
||||
|
||||
_, resp = Client.DeleteChannel(publicChannel6.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func (api *API) InitCluster() {
|
|||
}
|
||||
|
||||
func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS)
|
||||
return
|
||||
}
|
||||
|
||||
cmd.CreatorId = c.App.Session.UserId
|
||||
cmd.CreatorId = c.App.Session().UserId
|
||||
|
||||
rcmd, err := c.App.CreateCommand(cmd)
|
||||
if err != nil {
|
||||
|
|
@ -73,11 +73,11 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if cmd.TeamId != oldCmd.TeamId {
|
||||
c.Err = model.NewAppError("updateCommand", "api.command.team_mismatch.app_error", nil, "user_id="+c.App.Session.UserId, http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("updateCommand", "api.command.team_mismatch.app_error", nil, "user_id="+c.App.Session().UserId, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, oldCmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), oldCmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
// here we return Not_found instead of a permissions error so we don't leak the existence of
|
||||
// a command to someone without permissions for the team it belongs to.
|
||||
|
|
@ -85,7 +85,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != oldCmd.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, oldCmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
if c.App.Session().UserId != oldCmd.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), oldCmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS)
|
||||
return
|
||||
|
|
@ -122,7 +122,7 @@ func moveCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, newTeam.Id, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), newTeam.Id, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS)
|
||||
return
|
||||
|
|
@ -134,7 +134,7 @@ func moveCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
// here we return Not_found instead of a permissions error so we don't leak the existence of
|
||||
// a command to someone without permissions for the team it belongs to.
|
||||
|
|
@ -165,7 +165,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
// here we return Not_found instead of a permissions error so we don't leak the existence of
|
||||
// a command to someone without permissions for the team it belongs to.
|
||||
|
|
@ -173,7 +173,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != cmd.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
if c.App.Session().UserId != cmd.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS)
|
||||
return
|
||||
|
|
@ -202,7 +202,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var commands []*model.Command
|
||||
var err *model.AppError
|
||||
if customOnly {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SLASH_COMMANDS)
|
||||
return
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
} else {
|
||||
//User with no permission should see only system commands
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
commands, err = c.App.ListAutocompleteCommands(teamId, c.App.T)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
|
@ -254,13 +254,13 @@ func getCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
// check for permissions to view this command; must have perms to view team and
|
||||
// PERMISSION_MANAGE_SLASH_COMMANDS for the team the command belongs to.
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
// here we return Not_found instead of a permissions error so we don't leak the existence of
|
||||
// a command to someone without permissions for the team it belongs to.
|
||||
c.SetCommandNotFoundError()
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
// again, return not_found to ensure id existence does not leak.
|
||||
c.SetCommandNotFoundError()
|
||||
return
|
||||
|
|
@ -281,7 +281,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// checks that user is a member of the specified channel, and that they have permission to use slash commands in it
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), commandArgs.ChannelId, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
c.SetPermissionError(model.PERMISSION_USE_SLASH_COMMANDS)
|
||||
return
|
||||
}
|
||||
|
|
@ -299,17 +299,17 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
// if the slash command was used in a DM or GM, ensure that the user is a member of the specified team, so that
|
||||
// they can't just execute slash commands against arbitrary teams
|
||||
if c.App.Session.GetTeamByTeamId(commandArgs.TeamId) == nil {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
if c.App.Session().GetTeamByTeamId(commandArgs.TeamId) == nil {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_USE_SLASH_COMMANDS) {
|
||||
c.SetPermissionError(model.PERMISSION_USE_SLASH_COMMANDS)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commandArgs.UserId = c.App.Session.UserId
|
||||
commandArgs.UserId = c.App.Session().UserId
|
||||
commandArgs.T = c.App.T
|
||||
commandArgs.Session = c.App.Session
|
||||
commandArgs.Session = *c.App.Session()
|
||||
commandArgs.SiteURL = c.GetSiteURLHeader()
|
||||
|
||||
response, err := c.App.ExecuteCommand(commandArgs)
|
||||
|
|
@ -327,7 +327,7 @@ func listAutocompleteCommands(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
// here we return Not_found instead of a permissions error so we don't leak the existence of
|
||||
// a command to someone without permissions for the team it belongs to.
|
||||
|
|
@ -362,7 +362,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != cmd.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, cmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
if c.App.Session().UserId != cmd.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), cmd.TeamId, model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_SLASH_COMMANDS)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
||||
job.UserId = c.App.Session.UserId
|
||||
job.UserId = c.App.Session().UserId
|
||||
|
||||
rjob, err := c.App.SaveComplianceReport(job)
|
||||
if err != nil {
|
||||
|
|
@ -44,7 +44,7 @@ func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ func getComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func (api *API) InitConfig() {
|
|||
}
|
||||
|
||||
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func configReload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
var config map[string]string
|
||||
if len(c.App.Session.UserId) == 0 {
|
||||
if len(c.App.Session().UserId) == 0 {
|
||||
config = c.App.LimitedClientConfigWithComputed()
|
||||
} else {
|
||||
config = c.App.ClientConfigWithComputed()
|
||||
|
|
@ -131,7 +131,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getEnvironmentConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func TestCORSRequestHandling(t *testing.T) {
|
|||
})
|
||||
defer th.TearDown()
|
||||
|
||||
port := th.App.Srv.ListenAddr.Port
|
||||
port := th.App.Srv().ListenAddr.Port
|
||||
host := fmt.Sprintf("http://localhost:%v", port)
|
||||
url := fmt.Sprintf("%v/api/v4/system/ping", host)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,17 +48,17 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Allow any user with CREATE_EMOJIS permission at Team level to create emojis at system level
|
||||
memberships, err := c.App.GetTeamMembersForUser(c.App.Session.UserId)
|
||||
memberships, err := c.App.GetTeamMembersForUser(c.App.Session().UserId)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_EMOJIS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_EMOJIS) {
|
||||
hasPermission := false
|
||||
for _, membership := range memberships {
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, membership.TeamId, model.PERMISSION_CREATE_EMOJIS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), membership.TeamId, model.PERMISSION_CREATE_EMOJIS) {
|
||||
hasPermission = true
|
||||
break
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
newEmoji, err := c.App.CreateEmoji(c.App.Session.UserId, emoji, m)
|
||||
newEmoji, err := c.App.CreateEmoji(c.App.Session().UserId, emoji, m)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -126,17 +126,17 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Allow any user with DELETE_EMOJIS permission at Team level to delete emojis at system level
|
||||
memberships, err := c.App.GetTeamMembersForUser(c.App.Session.UserId)
|
||||
memberships, err := c.App.GetTeamMembersForUser(c.App.Session().UserId)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_DELETE_EMOJIS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_DELETE_EMOJIS) {
|
||||
hasPermission := false
|
||||
for _, membership := range memberships {
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, membership.TeamId, model.PERMISSION_DELETE_EMOJIS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), membership.TeamId, model.PERMISSION_DELETE_EMOJIS) {
|
||||
hasPermission = true
|
||||
break
|
||||
}
|
||||
|
|
@ -147,11 +147,11 @@ func deleteEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != emoji.CreatorId {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_DELETE_OTHERS_EMOJIS) {
|
||||
if c.App.Session().UserId != emoji.CreatorId {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_DELETE_OTHERS_EMOJIS) {
|
||||
hasPermission := false
|
||||
for _, membership := range memberships {
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, membership.TeamId, model.PERMISSION_DELETE_OTHERS_EMOJIS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), membership.TeamId, model.PERMISSION_DELETE_OTHERS_EMOJIS) {
|
||||
hasPermission = true
|
||||
break
|
||||
}
|
||||
|
|
|
|||
22
api4/file.go
22
api4/file.go
|
|
@ -153,7 +153,7 @@ func uploadFileSimple(c *Context, r *http.Request, timestamp time.Time) *model.F
|
|||
return nil
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
c.SetPermissionError(model.PERMISSION_UPLOAD_FILE)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ func uploadFileSimple(c *Context, r *http.Request, timestamp time.Time) *model.F
|
|||
clientId := r.Form.Get("client_id")
|
||||
info, appErr := c.App.UploadFileX(c.Params.ChannelId, c.Params.Filename, r.Body,
|
||||
app.UploadFileSetTeamId(FILE_TEAM_ID),
|
||||
app.UploadFileSetUserId(c.App.Session.UserId),
|
||||
app.UploadFileSetUserId(c.App.Session().UserId),
|
||||
app.UploadFileSetTimestamp(timestamp),
|
||||
app.UploadFileSetContentLength(r.ContentLength),
|
||||
app.UploadFileSetClientId(clientId))
|
||||
|
|
@ -294,7 +294,7 @@ NEXT_PART:
|
|||
if c.Err != nil {
|
||||
return nil
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
c.SetPermissionError(model.PERMISSION_UPLOAD_FILE)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -318,7 +318,7 @@ NEXT_PART:
|
|||
|
||||
info, appErr := c.App.UploadFileX(c.Params.ChannelId, filename, part,
|
||||
app.UploadFileSetTeamId(FILE_TEAM_ID),
|
||||
app.UploadFileSetUserId(c.App.Session.UserId),
|
||||
app.UploadFileSetUserId(c.App.Session().UserId),
|
||||
app.UploadFileSetTimestamp(timestamp),
|
||||
app.UploadFileSetContentLength(-1),
|
||||
app.UploadFileSetClientId(clientId))
|
||||
|
|
@ -374,7 +374,7 @@ func uploadFileMultipartLegacy(c *Context, mr *multipart.Reader,
|
|||
if c.Err != nil {
|
||||
return nil
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_UPLOAD_FILE) {
|
||||
c.SetPermissionError(model.PERMISSION_UPLOAD_FILE)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -411,7 +411,7 @@ func uploadFileMultipartLegacy(c *Context, mr *multipart.Reader,
|
|||
|
||||
info, appErr := c.App.UploadFileX(c.Params.ChannelId, fileHeader.Filename, f,
|
||||
app.UploadFileSetTeamId(FILE_TEAM_ID),
|
||||
app.UploadFileSetUserId(c.App.Session.UserId),
|
||||
app.UploadFileSetUserId(c.App.Session().UserId),
|
||||
app.UploadFileSetTimestamp(timestamp),
|
||||
app.UploadFileSetContentLength(-1),
|
||||
app.UploadFileSetClientId(clientId))
|
||||
|
|
@ -447,7 +447,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if info.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.App.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if info.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -484,7 +484,7 @@ func getFileThumbnail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if info.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.App.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if info.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -526,7 +526,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if info.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.App.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if info.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -559,7 +559,7 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if info.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.App.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if info.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -596,7 +596,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if info.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionToChannelByPost(c.App.Session, info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if info.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), info.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -567,7 +567,7 @@ func TestUploadFiles(t *testing.T) {
|
|||
fmt.Sprintf("Wrong clientId returned, expected %v, got %v", tc.clientIds[i], fileResp.ClientIds[i]))
|
||||
}
|
||||
|
||||
dbInfo, err := th.App.Srv.Store.FileInfo().Get(ri.Id)
|
||||
dbInfo, err := th.App.Srv().Store.FileInfo().Get(ri.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, dbInfo.Id, ri.Id, "File id from response should match one stored in database")
|
||||
assert.Equal(t, dbInfo.CreatorId, tc.expectedCreatorId, "F ile should be assigned to user")
|
||||
|
|
@ -801,7 +801,7 @@ func TestGetFileLink(t *testing.T) {
|
|||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
err = th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
err = th.App.Srv().Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
|
||||
|
|
@ -835,7 +835,7 @@ func TestGetFileLink(t *testing.T) {
|
|||
_, resp = th.SystemAdminClient.GetFileLink(fileId)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
fileInfo, err := th.App.Srv.Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
require.Nil(t, err)
|
||||
th.cleanupTestFile(fileInfo)
|
||||
}
|
||||
|
|
@ -955,10 +955,10 @@ func TestGetPublicFile(t *testing.T) {
|
|||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
// Hacky way to assign file to a post (usually would be done by CreatePost call)
|
||||
err = th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
err = th.App.Srv().Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
info, err := th.App.Srv.Store.FileInfo().Get(fileId)
|
||||
info, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
require.Nil(t, err)
|
||||
link := th.App.GeneratePublicLink(Client.Url, info)
|
||||
|
||||
|
|
@ -991,7 +991,7 @@ func TestGetPublicFile(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode, "should've failed to get image with public link after salt changed")
|
||||
|
||||
fileInfo, err := th.App.Srv.Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := th.App.Srv().Store.FileInfo().Get(fileId)
|
||||
require.Nil(t, err)
|
||||
require.Nil(t, th.cleanupTestFile(fileInfo))
|
||||
th.cleanupTestFile(info)
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -230,7 +230,7 @@ func getGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ func getGroupSyncables(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ func unlinkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType, syncableID string) *model.AppError {
|
||||
switch syncableType {
|
||||
case model.GroupSyncableTypeTeam:
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, syncableID, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), syncableID, model.PERMISSION_MANAGE_TEAM) {
|
||||
return c.App.MakePermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
}
|
||||
case model.GroupSyncableTypeChannel:
|
||||
|
|
@ -418,7 +418,7 @@ func verifyLinkUnlinkPermission(c *Context, syncableType model.GroupSyncableType
|
|||
permission = model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, syncableID, permission) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), syncableID, permission) {
|
||||
return c.App.MakePermissionError(permission)
|
||||
}
|
||||
}
|
||||
|
|
@ -437,7 +437,7 @@ func getGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -485,7 +485,7 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
permission = model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, c.Params.ChannelId, permission) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), c.Params.ChannelId, permission) {
|
||||
c.SetPermissionError(permission)
|
||||
return
|
||||
}
|
||||
|
|
@ -531,7 +531,7 @@ func getGroupsByTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -597,7 +597,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.Err = err
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamID, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamID, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -616,7 +616,7 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
permission = model.PERMISSION_MANAGE_PUBLIC_CHANNEL_MEMBERS
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelID, permission) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelID, permission) {
|
||||
c.SetPermissionError(permission)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ func getImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
url := r.URL.Query().Get("url")
|
||||
|
||||
if *c.App.Config().ImageProxySettings.Enable {
|
||||
c.App.ImageProxy.GetImage(w, r, url)
|
||||
c.App.ImageProxy().GetImage(w, r, url)
|
||||
} else {
|
||||
http.Redirect(w, r, url, http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, cookie.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), cookie.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var appErr *model.AppError
|
||||
resp := &model.PostActionAPIResponse{Status: "OK"}
|
||||
|
||||
resp.TriggerId, appErr = c.App.DoPostActionWithCookie(c.Params.PostId, c.Params.ActionId, c.App.Session.UserId,
|
||||
resp.TriggerId, appErr = c.App.DoPostActionWithCookie(c.Params.PostId, c.Params.ActionId, c.App.Session().UserId,
|
||||
actionRequest.SelectedOption, cookie)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
|
|
@ -101,14 +101,14 @@ func submitDialog(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
submit.UserId = c.App.Session.UserId
|
||||
submit.UserId = c.App.Session().UserId
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, submit.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), submit.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, submit.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), submit.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
10
api4/job.go
10
api4/job.go
|
|
@ -23,7 +23,7 @@ func getJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_JOBS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_JOBS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_JOBS)
|
||||
return
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_JOBS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_JOBS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_JOBS)
|
||||
return
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ func getJobs(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_JOBS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_JOBS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_JOBS)
|
||||
return
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_JOBS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_JOBS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_JOBS)
|
||||
return
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ func cancelJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_JOBS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_JOBS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_JOBS)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ func TestCreateJob(t *testing.T) {
|
|||
received, resp := th.SystemAdminClient.CreateJob(job)
|
||||
require.Nil(t, resp.Error)
|
||||
|
||||
defer th.App.Srv.Store.Job().Delete(received.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(received.Id)
|
||||
|
||||
job = &model.Job{
|
||||
Type: model.NewId(),
|
||||
|
|
@ -46,10 +46,10 @@ func TestGetJob(t *testing.T) {
|
|||
Id: model.NewId(),
|
||||
Status: model.JOB_STATUS_PENDING,
|
||||
}
|
||||
_, err := th.App.Srv.Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
require.Nil(t, err)
|
||||
|
||||
defer th.App.Srv.Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
|
||||
received, resp := th.SystemAdminClient.GetJob(job.Id)
|
||||
require.Nil(t, resp.Error)
|
||||
|
|
@ -93,9 +93,9 @@ func TestGetJobs(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv.Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
require.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, resp := th.SystemAdminClient.GetJobs(0, 2)
|
||||
|
|
@ -144,9 +144,9 @@ func TestGetJobsByType(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv.Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
require.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, resp := th.SystemAdminClient.GetJobsByType(jobType, 0, 2)
|
||||
|
|
@ -195,9 +195,9 @@ func TestCancelJob(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, job := range jobs {
|
||||
_, err := th.App.Srv.Store.Job().Save(job)
|
||||
_, err := th.App.Srv().Store.Job().Save(job)
|
||||
require.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(job.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
_, resp := th.Client.CancelJob(jobs[0].Id)
|
||||
|
|
|
|||
10
api4/ldap.go
10
api4/ldap.go
|
|
@ -38,7 +38,7 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getLdapGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func unlinkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var clientLicense map[string]string
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
clientLicense = c.App.ClientLicense()
|
||||
} else {
|
||||
clientLicense = c.App.GetSanitizedClientLicense()
|
||||
|
|
@ -44,7 +44,7 @@ func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
oauthApp.IsTrusted = false
|
||||
}
|
||||
|
||||
oauthApp.CreatorId = c.App.Session.UserId
|
||||
oauthApp.CreatorId = c.App.Session().UserId
|
||||
|
||||
rapp, err := c.App.CreateOAuthApp(oauthApp)
|
||||
if err != nil {
|
||||
|
|
@ -57,7 +57,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -82,12 +82,12 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != oldOauthApp.CreatorId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
if c.App.Session().UserId != oldOauthApp.CreatorId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
oauthApp.IsTrusted = oldOauthApp.IsTrusted
|
||||
}
|
||||
|
||||
|
|
@ -103,17 +103,17 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.Err = model.NewAppError("getOAuthApps", "api.command.admin_only.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
var apps []*model.OAuthApp
|
||||
var err *model.AppError
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
apps, err = c.App.GetOAuthApps(c.Params.Page, c.Params.PerPage)
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
apps, err = c.App.GetOAuthAppsByCreator(c.App.Session.UserId, c.Params.Page, c.Params.PerPage)
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
apps, err = c.App.GetOAuthAppsByCreator(c.App.Session().UserId, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
|
|
@ -133,7 +133,7 @@ func getOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ func getOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if oauthApp.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
if oauthApp.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ func deleteOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != oauthApp.CreatorId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
if c.App.Session().UserId != oauthApp.CreatorId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -208,7 +208,7 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OAUTH) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if oauthApp.CreatorId != c.App.Session.UserId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
if oauthApp.CreatorId != c.App.Session().UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH)
|
||||
return
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ func getAuthorizedOAuthApps(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ func installPluginFromUrl(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ func installMarketplacePlugin(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ func getPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ func getPluginStatuses(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func removePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -243,7 +243,7 @@ func getMarketplacePlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -280,7 +280,7 @@ func enablePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -304,7 +304,7 @@ func disablePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
72
api4/post.go
72
api4/post.go
|
|
@ -41,14 +41,14 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
post.UserId = c.App.Session.UserId
|
||||
post.UserId = c.App.Session().UserId
|
||||
|
||||
hasPermission := false
|
||||
if c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_CREATE_POST) {
|
||||
if c.App.SessionHasPermissionToChannel(*c.App.Session(), post.ChannelId, model.PERMISSION_CREATE_POST) {
|
||||
hasPermission = true
|
||||
} 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 && c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_CREATE_POST_PUBLIC) {
|
||||
if channel.Type == model.CHANNEL_OPEN && c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_CREATE_POST_PUBLIC) {
|
||||
hasPermission = true
|
||||
}
|
||||
}
|
||||
|
|
@ -58,11 +58,11 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if post.CreateAt != 0 && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if post.CreateAt != 0 && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
post.CreateAt = 0
|
||||
}
|
||||
|
||||
rp, err := c.App.CreatePostAsUser(c.App.PostWithProxyRemovedFromImageURLs(post), c.App.Session.Id)
|
||||
rp, err := c.App.CreatePostAsUser(c.App.PostWithProxyRemovedFromImageURLs(post), c.App.Session().Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -79,10 +79,10 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
if setOnlineBool {
|
||||
c.App.SetStatusOnline(c.App.Session.UserId, false)
|
||||
c.App.SetStatusOnline(c.App.Session().UserId, false)
|
||||
}
|
||||
|
||||
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
|
|
@ -104,10 +104,10 @@ func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
ephRequest.Post.UserId = c.App.Session.UserId
|
||||
ephRequest.Post.UserId = c.App.Session().UserId
|
||||
ephRequest.Post.CreateAt = model.GetMillis()
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_POST_EPHEMERAL) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_POST_EPHEMERAL) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_POST_EPHEMERAL)
|
||||
return
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
page := c.Params.Page
|
||||
perPage := c.Params.PerPage
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -213,13 +213,13 @@ func getPostsForChannelAroundLastUnread(c *Context, w http.ResponseWriter, r *ht
|
|||
}
|
||||
|
||||
userId := c.Params.UserId
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, userId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), userId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
channelId := c.Params.ChannelId
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
if !ok {
|
||||
allowed = false
|
||||
|
||||
if c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if c.App.SessionHasPermissionToChannel(*c.App.Session(), post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
allowed = true
|
||||
}
|
||||
|
||||
|
|
@ -334,9 +334,9 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -368,19 +368,19 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId == post.UserId {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_DELETE_POST) {
|
||||
if c.App.Session().UserId == post.UserId {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), post.ChannelId, model.PERMISSION_DELETE_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_POST)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_DELETE_OTHERS_POSTS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), post.ChannelId, model.PERMISSION_DELETE_OTHERS_POSTS) {
|
||||
c.SetPermissionError(model.PERMISSION_DELETE_OTHERS_POSTS)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := c.App.DeletePost(c.Params.PostId, c.App.Session.UserId); err != nil {
|
||||
if _, err := c.App.DeletePost(c.Params.PostId, c.App.Session().UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -412,9 +412,9 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_READ_PUBLIC_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_PUBLIC_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -441,7 +441,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -481,10 +481,10 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
startTime := time.Now()
|
||||
|
||||
results, err := c.App.SearchPostsInTeamForUser(terms, c.App.Session.UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
||||
results, err := c.App.SearchPostsInTeamForUser(terms, c.App.Session().UserId, c.Params.TeamId, isOrSearch, includeDeletedChannels, timeZoneOffset, page, perPage)
|
||||
|
||||
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||
metrics := c.App.Metrics
|
||||
metrics := c.App.Metrics()
|
||||
if metrics != nil {
|
||||
metrics.IncrementPostsSearchCounter()
|
||||
metrics.ObservePostsSearchDuration(elapsedTime)
|
||||
|
|
@ -522,7 +522,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
||||
return
|
||||
}
|
||||
|
|
@ -536,8 +536,8 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
// Updating the file_ids of a post is not a supported operation and will be ignored
|
||||
post.FileIds = originalPost.FileIds
|
||||
|
||||
if c.App.Session.UserId != originalPost.UserId {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
|
||||
if c.App.Session().UserId != originalPost.UserId {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
|
||||
return
|
||||
}
|
||||
|
|
@ -570,7 +570,7 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
// Updating the file_ids of a post is not a supported operation and will be ignored
|
||||
post.FileIds = nil
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_POST) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_POST)
|
||||
return
|
||||
}
|
||||
|
|
@ -581,8 +581,8 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != originalPost.UserId {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
|
||||
if c.App.Session().UserId != originalPost.UserId {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_EDIT_OTHERS_POSTS) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHERS_POSTS)
|
||||
return
|
||||
}
|
||||
|
|
@ -602,11 +602,11 @@ func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
if c.App.Session.UserId != c.Params.UserId && !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if c.App.Session().UserId != c.Params.UserId && !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -625,13 +625,13 @@ func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinn
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
// Restrict pinning if the experimental read-only-town-square setting is on.
|
||||
user, err := c.App.GetUser(c.App.Session.UserId)
|
||||
user, err := c.App.GetUser(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -683,7 +683,7 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1617,12 +1617,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
|
||||
// Set channel member's last viewed to 0.
|
||||
// All returned posts are latest posts as if all previous posts were already read by the user.
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 0
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 20, 20)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1638,12 +1638,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
postIdNames[systemPost1.Id] = "system post 1"
|
||||
|
||||
// Set channel member's last viewed before post1.
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = post1.CreateAt - 1
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 3, 3)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1662,12 +1662,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
}, posts)
|
||||
|
||||
// Set channel member's last viewed before post6.
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = post6.CreateAt - 1
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 3, 3)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1689,12 +1689,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
}, posts)
|
||||
|
||||
// Set channel member's last viewed before post10.
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = post10.CreateAt - 1
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 3, 3)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1714,12 +1714,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
}, posts)
|
||||
|
||||
// Set channel member's last viewed equal to post10.
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = post10.CreateAt
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 3, 3)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1754,12 +1754,12 @@ func TestGetPostsForChannelAroundLastUnread(t *testing.T) {
|
|||
postIdNames[post12.Id] = "post12 (reply to post4)"
|
||||
postIdNames[post13.Id] = "post13"
|
||||
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = post12.CreateAt - 1
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
th.App.Srv.Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
th.App.Srv().Store.Post().InvalidateLastPostTimeCache(channelId)
|
||||
|
||||
posts, resp = Client.GetPostsAroundLastUnread(userId, channelId, 1, 2)
|
||||
CheckNoError(t, resp)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func getPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ func getPreferencesByCategory(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ func getPreferenceByCategoryAndName(c *Context, w http.ResponseWriter, r *http.R
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), post.ChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if reaction.UserId != c.App.Session.UserId {
|
||||
if reaction.UserId != c.App.Session().UserId {
|
||||
c.Err = model.NewAppError("saveReaction", "api.reaction.save_reaction.user_id.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, reaction.PostId, model.PERMISSION_ADD_REACTION) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), reaction.PostId, model.PERMISSION_ADD_REACTION) {
|
||||
c.SetPermissionError(model.PERMISSION_ADD_REACTION)
|
||||
return
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ func getReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -83,12 +83,12 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, c.Params.PostId, model.PERMISSION_REMOVE_REACTION) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), c.Params.PostId, model.PERMISSION_REMOVE_REACTION) {
|
||||
c.SetPermissionError(model.PERMISSION_REMOVE_REACTION)
|
||||
return
|
||||
}
|
||||
|
||||
if c.Params.UserId != c.App.Session.UserId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_REMOVE_OTHERS_REACTIONS) {
|
||||
if c.Params.UserId != c.App.Session().UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_REMOVE_OTHERS_REACTIONS) {
|
||||
c.SetPermissionError(model.PERMISSION_REMOVE_OTHERS_REACTIONS)
|
||||
return
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func getBulkReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
postIds := model.ArrayFromJson(r.Body)
|
||||
for _, postId := range postIds {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(c.App.Session, postId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannelByPost(*c.App.Session(), postId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ func TestGetReactions(t *testing.T) {
|
|||
var reactions []*model.Reaction
|
||||
|
||||
for _, userReaction := range userReactions {
|
||||
reaction, err := th.App.Srv.Store.Reaction().Save(userReaction)
|
||||
reaction, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
require.Nil(t, err)
|
||||
reactions = append(reactions, reaction)
|
||||
}
|
||||
|
|
@ -595,7 +595,7 @@ func TestGetBulkReactions(t *testing.T) {
|
|||
|
||||
for _, userReaction := range userReactions {
|
||||
reactions := expectedPostIdsReactionsMap[userReaction.PostId]
|
||||
reaction, err := th.App.Srv.Store.Reaction().Save(userReaction)
|
||||
reaction, err := th.App.Srv().Store.Reaction().Save(userReaction)
|
||||
require.Nil(t, err)
|
||||
reactions = append(reactions, reaction)
|
||||
expectedPostIdsReactionsMap[userReaction.PostId] = reactions
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ func TestGetRole(t *testing.T) {
|
|||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err := th.App.Srv.Store.Role().Save(role)
|
||||
role, err := th.App.Srv().Store.Role().Save(role)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
|
||||
received, resp := th.Client.GetRole(role.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -58,9 +58,9 @@ func TestGetRoleByName(t *testing.T) {
|
|||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err := th.App.Srv.Store.Role().Save(role)
|
||||
role, err := th.App.Srv().Store.Role().Save(role)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
|
||||
received, resp := th.Client.GetRoleByName(role.Name)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -105,17 +105,17 @@ func TestGetRolesByNames(t *testing.T) {
|
|||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role1, err := th.App.Srv.Store.Role().Save(role1)
|
||||
role1, err := th.App.Srv().Store.Role().Save(role1)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role1.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role1.Id)
|
||||
|
||||
role2, err = th.App.Srv.Store.Role().Save(role2)
|
||||
role2, err = th.App.Srv().Store.Role().Save(role2)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role2.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role2.Id)
|
||||
|
||||
role3, err = th.App.Srv.Store.Role().Save(role3)
|
||||
role3, err = th.App.Srv().Store.Role().Save(role3)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role3.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role3.Id)
|
||||
|
||||
// Check all three roles can be found.
|
||||
received, resp := th.Client.GetRolesByNames([]string{role1.Name, role2.Name, role3.Name})
|
||||
|
|
@ -154,9 +154,9 @@ func TestPatchRole(t *testing.T) {
|
|||
SchemeManaged: true,
|
||||
}
|
||||
|
||||
role, err := th.App.Srv.Store.Role().Save(role)
|
||||
role, err := th.App.Srv().Store.Role().Save(role)
|
||||
assert.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(role.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(role.Id)
|
||||
|
||||
patch := &model.RolePatch{
|
||||
Permissions: &[]string{"manage_system", "create_public_channel", "manage_incoming_webhooks", "manage_outgoing_webhooks"},
|
||||
|
|
@ -214,7 +214,7 @@ func TestPatchRole(t *testing.T) {
|
|||
license.Features.GuestAccountsPermissions = model.NewBool(false)
|
||||
th.App.SetLicense(license)
|
||||
|
||||
guestRole, err := th.App.Srv.Store.Role().GetByName("system_guest")
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName("system_guest")
|
||||
require.Nil(t, err)
|
||||
received, resp = th.SystemAdminClient.PatchRole(guestRole.Id, patch)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
|
@ -224,7 +224,7 @@ func TestPatchRole(t *testing.T) {
|
|||
license := model.NewTestLicense()
|
||||
license.Features.GuestAccountsPermissions = model.NewBool(true)
|
||||
th.App.SetLicense(license)
|
||||
guestRole, err := th.App.Srv.Store.Role().GetByName("system_guest")
|
||||
guestRole, err := th.App.Srv().Store.Role().GetByName("system_guest")
|
||||
require.Nil(t, err)
|
||||
_, resp = th.SystemAdminClient.PatchRole(guestRole.Id, patch)
|
||||
CheckNoError(t, resp)
|
||||
|
|
|
|||
16
api4/saml.go
16
api4/saml.go
|
|
@ -61,7 +61,7 @@ func parseSamlCertificateRequest(r *http.Request, maxFileSize int64) (*multipart
|
|||
}
|
||||
|
||||
func addSamlPublicCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func addSamlPublicCertificate(c *Context, w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
func addSamlPrivateCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ func addSamlPrivateCertificate(c *Context, w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
|
||||
func addSamlIdpCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ func addSamlIdpCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func removeSamlPublicCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ func removeSamlPublicCertificate(c *Context, w http.ResponseWriter, r *http.Requ
|
|||
}
|
||||
|
||||
func removeSamlPrivateCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ func removeSamlPrivateCertificate(c *Context, w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
func removeSamlIdpCertificate(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ func removeSamlIdpCertificate(c *Context, w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
func getSamlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func getSamlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
func getSamlMetadataFromIdp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ func getScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func getScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getSchemes(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ func getTeamsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ func getChannelsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -172,7 +172,7 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func deleteScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
team1, err := th.App.Srv.Store.Team().Save(team1)
|
||||
team1, err := th.App.Srv().Store.Team().Save(team1)
|
||||
require.Nil(t, err)
|
||||
|
||||
l2, r2 := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -316,7 +316,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
assert.Zero(t, len(l2))
|
||||
|
||||
team1.SchemeId = &scheme1.Id
|
||||
team1, err = th.App.Srv.Store.Team().Update(team1)
|
||||
team1, err = th.App.Srv().Store.Team().Update(team1)
|
||||
assert.Nil(t, err)
|
||||
|
||||
l3, r3 := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -330,7 +330,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
|||
Type: model.TEAM_OPEN,
|
||||
SchemeId: &scheme1.Id,
|
||||
}
|
||||
team2, err = th.App.Srv.Store.Team().Save(team2)
|
||||
team2, err = th.App.Srv().Store.Team().Save(team2)
|
||||
require.Nil(t, err)
|
||||
|
||||
l4, r4 := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -401,7 +401,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
Type: model.CHANNEL_OPEN,
|
||||
}
|
||||
|
||||
channel1, errCh := th.App.Srv.Store.Channel().Save(channel1, 1000000)
|
||||
channel1, errCh := th.App.Srv().Store.Channel().Save(channel1, 1000000)
|
||||
assert.Nil(t, errCh)
|
||||
|
||||
l2, r2 := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -409,7 +409,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
assert.Zero(t, len(l2))
|
||||
|
||||
channel1.SchemeId = &scheme1.Id
|
||||
channel1, err := th.App.Srv.Store.Channel().Update(channel1)
|
||||
channel1, err := th.App.Srv().Store.Channel().Update(channel1)
|
||||
assert.Nil(t, err)
|
||||
|
||||
l3, r3 := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -424,7 +424,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
|||
Type: model.CHANNEL_OPEN,
|
||||
SchemeId: &scheme1.Id,
|
||||
}
|
||||
channel2, err = th.App.Srv.Store.Channel().Save(channel2, 1000000)
|
||||
channel2, err = th.App.Srv().Store.Channel().Save(channel2, 1000000)
|
||||
assert.Nil(t, err)
|
||||
|
||||
l4, r4 := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
|
|
@ -620,7 +620,7 @@ func TestDeleteScheme(t *testing.T) {
|
|||
assert.Zero(t, role6.DeleteAt)
|
||||
|
||||
// Make sure this scheme is in use by a team.
|
||||
team, err := th.App.Srv.Store.Team().Save(&model.Team{
|
||||
team, err := th.App.Srv().Store.Team().Save(&model.Team{
|
||||
Name: "zz" + model.NewId(),
|
||||
DisplayName: model.NewId(),
|
||||
Email: model.NewId() + "@nowhere.com",
|
||||
|
|
@ -689,7 +689,7 @@ func TestDeleteScheme(t *testing.T) {
|
|||
assert.Zero(t, role6.DeleteAt)
|
||||
|
||||
// Make sure this scheme is in use by a team.
|
||||
channel, err := th.App.Srv.Store.Channel().Save(&model.Channel{
|
||||
channel, err := th.App.Srv().Store.Channel().Save(&model.Channel{
|
||||
TeamId: model.NewId(),
|
||||
DisplayName: model.NewId(),
|
||||
Name: model.NewId(),
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
currentTime := fmt.Sprintf("%d", time.Now().Unix())
|
||||
healthCheckKey := "health_check"
|
||||
|
||||
writeErr := c.App.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
writeErr := c.App.Srv().Store.System().SaveOrUpdate(&model.System{
|
||||
Name: healthCheckKey,
|
||||
Value: currentTime,
|
||||
})
|
||||
|
|
@ -89,7 +89,7 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
s[dbStatusKey] = model.STATUS_UNHEALTHY
|
||||
s[model.STATUS] = model.STATUS_UNHEALTHY
|
||||
} else {
|
||||
healthCheck, readErr := c.App.Srv.Store.System().GetByName(healthCheckKey)
|
||||
healthCheck, readErr := c.App.Srv().Store.System().GetByName(healthCheckKey)
|
||||
if readErr != nil {
|
||||
mlog.Debug("Unable to read from database.", mlog.Err(readErr))
|
||||
s[dbStatusKey] = model.STATUS_UNHEALTHY
|
||||
|
|
@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
err := c.App.TestEmail(c.App.Session.UserId, cfg)
|
||||
err := c.App.TestEmail(c.App.Session().UserId, cfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -156,7 +156,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func testSiteURL(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ func testSiteURL(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ func databaseRecycle(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -235,7 +235,7 @@ func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -253,12 +253,12 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
forceToDebug := false
|
||||
|
||||
if !*c.App.Config().ServiceSettings.EnableDeveloper {
|
||||
if c.App.Session.UserId == "" {
|
||||
if c.App.Session().UserId == "" {
|
||||
c.Err = model.NewAppError("postLog", "api.context.permissions.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
forceToDebug = true
|
||||
}
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
msg = "Client Logs API Endpoint Message: " + msg
|
||||
fields := []mlog.Field{
|
||||
mlog.String("type", "client_message"),
|
||||
mlog.String("user_agent", c.App.UserAgent),
|
||||
mlog.String("user_agent", c.App.UserAgent()),
|
||||
}
|
||||
|
||||
if !forceToDebug && lvl == "ERROR" {
|
||||
|
|
@ -295,7 +295,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
name = "standard"
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
supportedTimezones := c.App.Timezones.GetSupported()
|
||||
supportedTimezones := c.App.Timezones().GetSupported()
|
||||
if supportedTimezones == nil {
|
||||
supportedTimezones = make([]string, 0)
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -389,7 +389,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
client := c.App.HTTPService.MakeClient(false)
|
||||
client := c.App.HTTPService().MakeClient(false)
|
||||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
|
|
@ -431,7 +431,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
if ack.IsIdLoaded {
|
||||
if err != nil {
|
||||
// Log the error only, then continue to fetch notification message
|
||||
c.App.NotificationsLog.Error("Notification ack not sent to push proxy",
|
||||
c.App.NotificationsLog().Error("Notification ack not sent to push proxy",
|
||||
mlog.String("ackId", ack.Id),
|
||||
mlog.String("type", ack.NotificationType),
|
||||
mlog.String("postId", ack.PostId),
|
||||
|
|
@ -439,14 +439,14 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
}
|
||||
|
||||
notificationInterface := c.App.Notification
|
||||
notificationInterface := c.App.Notification()
|
||||
|
||||
if notificationInterface == nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.system.id_loaded.not_available.app_error", nil, "", http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
msg, appError := notificationInterface.GetNotificationMessage(ack, c.App.Session.UserId)
|
||||
msg, appError := notificationInterface.GetNotificationMessage(ack, c.App.Session().UserId)
|
||||
if appError != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.id_loaded.fetch.app_error", nil, appError.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -464,7 +464,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func setServerBusy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -481,25 +481,25 @@ func setServerBusy(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.Srv.Busy.Set(time.Second * time.Duration(i))
|
||||
c.App.Srv().Busy.Set(time.Second * time.Duration(i))
|
||||
mlog.Warn("server busy state activated - non-critical services disabled", mlog.Int64("seconds", i))
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func clearServerBusy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
c.App.Srv.Busy.Clear()
|
||||
c.App.Srv().Busy.Clear()
|
||||
mlog.Info("server busy state cleared - non-critical services enabled")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func getServerBusyExpires(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
w.Write([]byte(c.App.Srv.Busy.ToJson()))
|
||||
w.Write([]byte(c.App.Srv().Busy.ToJson()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ func TestSupportedTimezones(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
supportedTimezonesFromConfig := th.App.Timezones.GetSupported()
|
||||
supportedTimezonesFromConfig := th.App.Timezones().GetSupported()
|
||||
supportedTimezones, resp := Client.GetSupportedTimezone()
|
||||
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -524,14 +524,14 @@ func TestSetServerBusy(t *testing.T) {
|
|||
ok, resp := th.Client.SetServerBusy(secs)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not set server busy due to no permission")
|
||||
require.False(t, th.App.Srv.Busy.IsBusy(), "server should not be marked busy")
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.SetServerBusy(secs)
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok, "should set server busy successfully")
|
||||
require.True(t, th.App.Srv.Busy.IsBusy(), "server should be marked busy")
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +545,7 @@ func TestSetServerBusyInvalidParam(t *testing.T) {
|
|||
ok, resp := th.SystemAdminClient.SetServerBusy(p)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, ok, "should not set server busy due to invalid param ", p)
|
||||
require.False(t, th.App.Srv.Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -554,20 +554,20 @@ func TestClearServerBusy(t *testing.T) {
|
|||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv.Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
ok, resp := th.Client.ClearServerBusy()
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, ok, "should not clear server busy flag due to no permission.")
|
||||
require.True(t, th.App.Srv.Busy.IsBusy(), "server should be marked busy")
|
||||
require.True(t, th.App.Srv().Busy.IsBusy(), "server should be marked busy")
|
||||
})
|
||||
|
||||
th.App.Srv.Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
ok, resp := th.SystemAdminClient.ClearServerBusy()
|
||||
CheckNoError(t, resp)
|
||||
require.True(t, ok, "should clear server busy flag successfully")
|
||||
require.False(t, th.App.Srv.Busy.IsBusy(), "server should not be marked busy")
|
||||
require.False(t, th.App.Srv().Busy.IsBusy(), "server should not be marked busy")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -575,7 +575,7 @@ func TestGetServerBusyExpires(t *testing.T) {
|
|||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv.Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp := th.Client.GetServerBusyExpires()
|
||||
|
|
@ -593,7 +593,7 @@ func TestServerBusy503(t *testing.T) {
|
|||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.Srv.Busy.Set(time.Second * 30)
|
||||
th.App.Srv().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("search users while busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
|
|
@ -619,7 +619,7 @@ func TestServerBusy503(t *testing.T) {
|
|||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
th.App.Srv.Busy.Clear()
|
||||
th.App.Srv().Busy.Clear()
|
||||
|
||||
t.Run("search users while not busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
|
|
|
|||
136
api4/team.go
136
api4/team.go
|
|
@ -81,12 +81,12 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
team.Email = strings.ToLower(team.Email)
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_TEAM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_TEAM) {
|
||||
c.Err = model.NewAppError("createTeam", "api.team.is_team_creation_allowed.disabled.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
rteam, err := c.App.CreateTeamWithUser(team, c.App.Session.UserId)
|
||||
rteam, err := c.App.CreateTeamWithUser(team, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -110,12 +110,12 @@ func getTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !c.App.SessionHasPermissionToTeam(c.App.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !c.App.SessionHasPermissionToTeam(*c.App.Session(), team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, team)
|
||||
c.App.SanitizeTeam(*c.App.Session(), team)
|
||||
w.Write([]byte(team.ToJson()))
|
||||
}
|
||||
|
||||
|
|
@ -131,12 +131,12 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !c.App.SessionHasPermissionToTeam(c.App.Session, team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
if (!team.AllowOpenInvite || team.Type != model.TEAM_OPEN) && !c.App.SessionHasPermissionToTeam(*c.App.Session(), team.Id, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, team)
|
||||
c.App.SanitizeTeam(*c.App.Session(), team)
|
||||
w.Write([]byte(team.ToJson()))
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, updatedTeam)
|
||||
c.App.SanitizeTeam(*c.App.Session(), updatedTeam)
|
||||
w.Write([]byte(updatedTeam.ToJson()))
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, patchedTeam)
|
||||
c.App.SanitizeTeam(*c.App.Session(), patchedTeam)
|
||||
|
||||
c.LogAudit("")
|
||||
w.Write([]byte(patchedTeam.ToJson()))
|
||||
|
|
@ -212,7 +212,7 @@ func regenerateTeamInviteId(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ func regenerateTeamInviteId(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeam(c.App.Session, patchedTeam)
|
||||
c.App.SanitizeTeam(*c.App.Session(), patchedTeam)
|
||||
|
||||
c.LogAudit("")
|
||||
w.Write([]byte(patchedTeam.ToJson()))
|
||||
|
|
@ -235,7 +235,7 @@ func deleteTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != c.Params.UserId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.Session().UserId != c.Params.UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeams(c.App.Session, teams)
|
||||
c.App.SanitizeTeams(*c.App.Session(), teams)
|
||||
w.Write([]byte(model.TeamListToJson(teams)))
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != c.Params.UserId && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.Session().UserId != c.Params.UserId && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -305,12 +305,12 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -336,12 +336,12 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -362,12 +362,12 @@ func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -400,12 +400,12 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -438,7 +438,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if member.UserId == c.App.Session.UserId {
|
||||
if member.UserId == c.App.Session().UserId {
|
||||
var team *model.Team
|
||||
team, err = c.App.GetTeam(member.TeamId)
|
||||
if err != nil {
|
||||
|
|
@ -446,16 +446,16 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if team.AllowOpenInvite && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_JOIN_PUBLIC_TEAMS) {
|
||||
if team.AllowOpenInvite && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_JOIN_PUBLIC_TEAMS) {
|
||||
c.SetPermissionError(model.PERMISSION_JOIN_PUBLIC_TEAMS)
|
||||
return
|
||||
}
|
||||
if !team.AllowOpenInvite && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_JOIN_PRIVATE_TEAMS) {
|
||||
if !team.AllowOpenInvite && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_JOIN_PRIVATE_TEAMS) {
|
||||
c.SetPermissionError(model.PERMISSION_JOIN_PRIVATE_TEAMS)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, member.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), member.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_ADD_USER_TO_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -502,14 +502,14 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
var err *model.AppError
|
||||
|
||||
if len(tokenId) > 0 {
|
||||
member, err = c.App.AddTeamMemberByToken(c.App.Session.UserId, tokenId)
|
||||
member, err = c.App.AddTeamMemberByToken(c.App.Session().UserId, tokenId)
|
||||
} else if len(inviteId) > 0 {
|
||||
if c.App.Session.Props[model.SESSION_PROP_IS_GUEST] == "true" {
|
||||
if c.App.Session().Props[model.SESSION_PROP_IS_GUEST] == "true" {
|
||||
c.Err = model.NewAppError("addUserToTeamFromInvite", "api.team.add_user_to_team_from_invite.guest.app_error", nil, "", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
member, err = c.App.AddTeamMemberByInviteId(inviteId, c.App.Session.UserId)
|
||||
member, err = c.App.AddTeamMemberByInviteId(inviteId, c.App.Session().UserId)
|
||||
} else {
|
||||
err = model.NewAppError("addTeamMember", "api.team.add_user_to_team.missing_parameter.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -586,12 +586,12 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
userIds = append(userIds, member.UserId)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_ADD_USER_TO_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
membersWithErrors, err := c.App.AddTeamMembers(c.Params.TeamId, userIds, c.App.Session.UserId, graceful)
|
||||
membersWithErrors, err := c.App.AddTeamMembers(c.Params.TeamId, userIds, c.App.Session().UserId, graceful)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
|
@ -615,8 +615,8 @@ func removeTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != c.Params.UserId {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_REMOVE_USER_FROM_TEAM) {
|
||||
if c.App.Session().UserId != c.Params.UserId {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_REMOVE_USER_FROM_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_REMOVE_USER_FROM_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -634,12 +634,12 @@ func removeTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if team.IsGroupConstrained() && (c.Params.UserId != c.App.Session.UserId) && !user.IsBot {
|
||||
if team.IsGroupConstrained() && (c.Params.UserId != c.App.Session().UserId) && !user.IsBot {
|
||||
c.Err = model.NewAppError("removeTeamMember", "api.team.remove_member.group_constrained.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId, c.App.Session.UserId); err != nil {
|
||||
if err := c.App.RemoveUserFromTeam(c.Params.TeamId, c.Params.UserId, c.App.Session().UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -653,12 +653,12 @@ func getTeamUnread(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -678,12 +678,12 @@ func getTeamStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -712,7 +712,7 @@ func updateTeamMemberRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM_ROLES) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM_ROLES)
|
||||
return
|
||||
}
|
||||
|
|
@ -737,7 +737,7 @@ func updateTeamMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.Requ
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM_ROLES) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM_ROLES)
|
||||
return
|
||||
}
|
||||
|
|
@ -755,19 +755,19 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var err *model.AppError
|
||||
var teamsWithCount *model.TeamsWithCount
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) && c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS) && c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPrivateTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
teams, err = c.App.GetAllPrivateTeamsPage(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
}
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllPublicTeamsPageWithCount(c.Params.Page*c.Params.PerPage, c.Params.PerPage)
|
||||
} else {
|
||||
|
|
@ -780,7 +780,7 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeams(c.App.Session, teams)
|
||||
c.App.SanitizeTeams(*c.App.Session(), teams)
|
||||
|
||||
var resBody []byte
|
||||
|
||||
|
|
@ -809,15 +809,15 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var totalCount int64
|
||||
var err *model.AppError
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) && c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS) && c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
teams, totalCount, err = c.App.SearchAllTeams(props)
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.private_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
teams, err = c.App.SearchPrivateTeams(props.Term)
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.public_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
|
|
@ -832,7 +832,7 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeams(c.App.Session, teams)
|
||||
c.App.SanitizeTeams(*c.App.Session(), teams)
|
||||
|
||||
var payload []byte
|
||||
if props.Page != nil && props.PerPage != nil {
|
||||
|
|
@ -861,7 +861,7 @@ func teamExists(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if team != nil {
|
||||
var teamMember *model.TeamMember
|
||||
teamMember, err = c.App.GetTeamMember(team.Id, c.App.Session.UserId)
|
||||
teamMember, err = c.App.GetTeamMember(team.Id, c.App.Session().UserId)
|
||||
if err != nil && err.StatusCode != http.StatusNotFound {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -869,8 +869,8 @@ func teamExists(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Verify that the user can see the team (be a member or have the permission to list the team)
|
||||
if (teamMember != nil && teamMember.DeleteAt == 0) ||
|
||||
(team.AllowOpenInvite && c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PUBLIC_TEAMS)) ||
|
||||
(!team.AllowOpenInvite && c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_PRIVATE_TEAMS)) {
|
||||
(team.AllowOpenInvite && c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PUBLIC_TEAMS)) ||
|
||||
(!team.AllowOpenInvite && c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_PRIVATE_TEAMS)) {
|
||||
exists = true
|
||||
}
|
||||
}
|
||||
|
|
@ -885,7 +885,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_IMPORT_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_IMPORT_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_IMPORT_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -960,12 +960,12 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_INVITE_USER) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_INVITE_USER) {
|
||||
c.SetPermissionError(model.PERMISSION_INVITE_USER)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_ADD_USER_TO_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_INVITE_USER)
|
||||
return
|
||||
}
|
||||
|
|
@ -981,7 +981,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if graceful {
|
||||
invitesWithError, err := c.App.InviteNewUsersToTeamGracefully(emailList, c.Params.TeamId, c.App.Session.UserId)
|
||||
invitesWithError, err := c.App.InviteNewUsersToTeamGracefully(emailList, c.Params.TeamId, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -989,7 +989,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
// in graceful mode we return both the succesful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
} else {
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.App.Session.UserId)
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -1015,7 +1015,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_INVITE_GUEST) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_INVITE_GUEST) {
|
||||
c.SetPermissionError(model.PERMISSION_INVITE_GUEST)
|
||||
return
|
||||
}
|
||||
|
|
@ -1030,7 +1030,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
if graceful {
|
||||
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -1038,7 +1038,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
// in graceful mode we return both the succesful ones and the failed ones
|
||||
w.Write([]byte(model.EmailInviteWithErrorToJson(invitesWithError)))
|
||||
} else {
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, guestsInvite, c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -1073,7 +1073,7 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func invalidateAllEmailInvites(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1099,7 +1099,7 @@ func getTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_VIEW_TEAM) &&
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_VIEW_TEAM) &&
|
||||
(team.Type != model.TEAM_OPEN || !team.AllowOpenInvite) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
|
|
@ -1131,7 +1131,7 @@ func setTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1176,7 +1176,7 @@ func removeTeamIcon(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1207,7 +1207,7 @@ func updateTeamScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), c.Params.TeamId, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1264,7 +1264,7 @@ func teamMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.Req
|
|||
groupIDs = append(groupIDs, gid)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1457,7 +1457,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
tm, resp = Client.AddTeamMemberFromInvite(token.Token, "")
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -1468,7 +1468,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||
|
||||
require.Equal(t, tm.TeamId, team.Id, "team ids should have matched")
|
||||
|
||||
_, err = th.App.Srv.Store.Token().GetByToken(token.Token)
|
||||
_, err = th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
require.NotNil(t, err, "The token must be deleted after be used")
|
||||
|
||||
tm, resp = Client.AddTeamMemberFromInvite("junk", "")
|
||||
|
|
@ -1479,7 +1479,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||
// expired token of more than 50 hours
|
||||
token = model.NewToken(app.TOKEN_TYPE_TEAM_INVITATION, "")
|
||||
token.CreateAt = model.GetMillis() - 1000*60*60*50
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
_, resp = Client.AddTeamMemberFromInvite(token.Token, "")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
|
@ -1491,7 +1491,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": testId}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
_, resp = Client.AddTeamMemberFromInvite(token.Token, "")
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
|
@ -1533,7 +1533,7 @@ func TestAddTeamMember(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": team.Id}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
tm, resp = Client.AddTeamMemberFromInvite(token.Token, "")
|
||||
require.Equal(t, "app.team.invite_token.group_constrained.error", resp.Error.Id)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func getLatestTermsOfService(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
props := model.MapFromJson(r.Body)
|
||||
text := props["text"]
|
||||
userId := c.App.Session.UserId
|
||||
userId := c.App.Session().UserId
|
||||
|
||||
if text == "" {
|
||||
c.Err = model.NewAppError("Config.IsValid", "api.create_terms_of_service.empty_text.app_error", nil, "", http.StatusBadRequest)
|
||||
|
|
|
|||
176
api4/user.go
176
api4/user.go
|
|
@ -98,7 +98,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var err *model.AppError
|
||||
if len(tokenId) > 0 {
|
||||
var token *model.Token
|
||||
token, err = c.App.Srv.Store.Token().GetByToken(tokenId)
|
||||
token, err = c.App.Srv().Store.Token().GetByToken(tokenId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("CreateUserWithToken", "api.user.create_user.signup_link_invalid.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
|
@ -138,7 +138,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_MEMBERS)
|
||||
return
|
||||
|
|
@ -155,7 +155,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.IsSystemAdmin() || c.App.Session.UserId == user.Id {
|
||||
if c.IsSystemAdmin() || c.App.Session().UserId == user.Id {
|
||||
userTermsOfService, err := c.App.GetUserTermsOfService(user.Id)
|
||||
if err != nil && err.StatusCode != http.StatusNotFound {
|
||||
c.Err = err
|
||||
|
|
@ -174,12 +174,12 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId == user.Id {
|
||||
if c.App.Session().UserId == user.Id {
|
||||
user.Sanitize(map[string]bool{})
|
||||
} else {
|
||||
c.App.SanitizeProfile(user, c.IsSystemAdmin())
|
||||
}
|
||||
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||
w.Write([]byte(user.ToJson()))
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
user, err := c.App.GetUserByUsername(c.Params.Username)
|
||||
if err != nil {
|
||||
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err2 != nil {
|
||||
c.Err = err2
|
||||
return
|
||||
|
|
@ -205,7 +205,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, user.Id)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, user.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -216,7 +216,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.IsSystemAdmin() || c.App.Session.UserId == user.Id {
|
||||
if c.IsSystemAdmin() || c.App.Session().UserId == user.Id {
|
||||
userTermsOfService, err := c.App.GetUserTermsOfService(user.Id)
|
||||
if err != nil && err.StatusCode != http.StatusNotFound {
|
||||
c.Err = err
|
||||
|
|
@ -235,7 +235,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId == user.Id {
|
||||
if c.App.Session().UserId == user.Id {
|
||||
user.Sanitize(map[string]bool{})
|
||||
} else {
|
||||
c.App.SanitizeProfile(user, c.IsSystemAdmin())
|
||||
|
|
@ -252,13 +252,13 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
sanitizeOptions := c.App.GetSanitizeOptions(c.IsSystemAdmin())
|
||||
if !sanitizeOptions["email"] {
|
||||
c.Err = model.NewAppError("getUserByEmail", "api.user.get_user_by_email.permissions.app_error", nil, "userId="+c.App.Session.UserId, http.StatusForbidden)
|
||||
c.Err = model.NewAppError("getUserByEmail", "api.user.get_user_by_email.permissions.app_error", nil, "userId="+c.App.Session().UserId, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUserByEmail(c.Params.Email)
|
||||
if err != nil {
|
||||
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err2 != nil {
|
||||
c.Err = err2
|
||||
return
|
||||
|
|
@ -271,7 +271,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, user.Id)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, user.Id)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -299,7 +299,7 @@ func getDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -333,7 +333,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -380,7 +380,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -428,7 +428,7 @@ func setDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -458,7 +458,7 @@ func getTotalUsersStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -527,7 +527,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
groupConstrainedBool, _ := strconv.ParseBool(groupConstrained)
|
||||
inactiveBool, _ := strconv.ParseBool(inactive)
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -553,21 +553,21 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if withoutTeamBool, _ := strconv.ParseBool(withoutTeam); withoutTeamBool {
|
||||
// Use a special permission for now
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_USERS_WITHOUT_TEAM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_USERS_WITHOUT_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_LIST_USERS_WITHOUT_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
} else if len(notInChannelId) > 0 {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, notInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), notInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else if len(notInTeamId) > 0 {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, notInTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), notInTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -579,7 +579,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else if len(inTeamId) > 0 {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, inTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), inTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -596,7 +596,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
} else if len(inChannelId) > 0 {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, inChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), inChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
|
@ -606,7 +606,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
profiles, err = c.App.GetUsersInChannelPage(inChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
|
||||
}
|
||||
} else {
|
||||
userGetOptions, err = c.App.RestrictUsersGetByPermissions(c.App.Session.UserId, userGetOptions)
|
||||
userGetOptions, err = c.App.RestrictUsersGetByPermissions(c.App.Session().UserId, userGetOptions)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -622,7 +622,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
if len(etag) > 0 {
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||
}
|
||||
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
|
||||
w.Write([]byte(model.UserListToJson(profiles)))
|
||||
}
|
||||
|
||||
|
|
@ -649,7 +649,7 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
options.Since = since
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -673,7 +673,7 @@ func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -705,22 +705,22 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(c.App.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.App.Session(), props.InChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(c.App.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.App.Session(), props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
if props.TeamId != "" && !c.App.SessionHasPermissionToTeam(c.App.Session, props.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if props.TeamId != "" && !c.App.SessionHasPermissionToTeam(*c.App.Session(), props.TeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
||||
if props.NotInTeamId != "" && !c.App.SessionHasPermissionToTeam(c.App.Session, props.NotInTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if props.NotInTeamId != "" && !c.App.SessionHasPermissionToTeam(*c.App.Session(), props.NotInTeamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -738,7 +738,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
Role: props.Role,
|
||||
}
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
options.AllowEmails = true
|
||||
options.AllowFullNames = true
|
||||
} else {
|
||||
|
|
@ -746,7 +746,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
|
||||
}
|
||||
|
||||
options, err := c.App.RestrictUsersSearchByPermissions(c.App.Session.UserId, options)
|
||||
options, err := c.App.RestrictUsersSearchByPermissions(c.App.Session().UserId, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -780,21 +780,21 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
Limit: limit,
|
||||
}
|
||||
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
options.AllowFullNames = true
|
||||
} else {
|
||||
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
|
||||
}
|
||||
|
||||
if len(channelId) > 0 {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_READ_CHANNEL) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(teamId) > 0 {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_VIEW_TEAM) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_VIEW_TEAM) {
|
||||
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
|
||||
return
|
||||
}
|
||||
|
|
@ -803,7 +803,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
var autocomplete model.UserAutocomplete
|
||||
|
||||
var err *model.AppError
|
||||
options, err = c.App.RestrictUsersSearchByPermissions(c.App.Session.UserId, options)
|
||||
options, err = c.App.RestrictUsersSearchByPermissions(c.App.Session().UserId, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -859,7 +859,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, user.Id) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), user.Id) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -870,7 +870,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.IsOAuth {
|
||||
if c.App.Session().IsOAuth {
|
||||
if ouser.Email != user.Email {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
c.Err.DetailedError += ", attempted email update by oauth app"
|
||||
|
|
@ -879,7 +879,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// If eMail update is attempted by the currently logged in user, check if correct password was provided
|
||||
if user.Email != "" && ouser.Email != user.Email && c.App.Session.UserId == c.Params.UserId {
|
||||
if user.Email != "" && ouser.Email != user.Email && c.App.Session().UserId == c.Params.UserId {
|
||||
err = c.App.DoubleCheckPassword(ouser, user.Password)
|
||||
if err != nil {
|
||||
c.SetInvalidParam("password")
|
||||
|
|
@ -909,7 +909,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -920,7 +920,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.IsOAuth && patch.Email != nil {
|
||||
if c.App.Session().IsOAuth && patch.Email != nil {
|
||||
if ouser.Email != *patch.Email {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
c.Err.DetailedError += ", attempted email update by oauth app"
|
||||
|
|
@ -929,7 +929,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// If eMail update is attempted by the currently logged in user, check if correct password was provided
|
||||
if patch.Email != nil && ouser.Email != *patch.Email && c.App.Session.UserId == c.Params.UserId {
|
||||
if patch.Email != nil && ouser.Email != *patch.Email && c.App.Session().UserId == c.Params.UserId {
|
||||
if patch.Password == nil {
|
||||
c.SetInvalidParam("password")
|
||||
return
|
||||
|
|
@ -960,13 +960,13 @@ func deleteUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
userId := c.Params.UserId
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, userId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), userId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
||||
// if EnableUserDeactivation flag is disabled the user cannot deactivate himself.
|
||||
if c.Params.UserId == c.App.Session.UserId && !*c.App.Config().TeamSettings.EnableUserDeactivation && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if c.Params.UserId == c.App.Session().UserId && !*c.App.Config().TeamSettings.EnableUserDeactivation && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.Err = model.NewAppError("deleteUser", "api.user.update_active.not_enable.app_error", nil, "userId="+c.Params.UserId, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
|
@ -999,7 +999,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_ROLES) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_ROLES) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_ROLES)
|
||||
return
|
||||
}
|
||||
|
|
@ -1028,9 +1028,9 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// true when you're trying to de-activate yourself
|
||||
isSelfDeactive := !active && c.Params.UserId == c.App.Session.UserId
|
||||
isSelfDeactive := !active && c.Params.UserId == c.App.Session().UserId
|
||||
|
||||
if !isSelfDeactive && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !isSelfDeactive && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.Err = model.NewAppError("updateUserActive", "api.user.update_active.permissions.app_error", nil, "userId="+c.Params.UserId, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
|
@ -1058,7 +1058,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit(fmt.Sprintf("user_id=%s active=%v", user.Id, active))
|
||||
if isSelfDeactive {
|
||||
c.App.Srv.Go(func() {
|
||||
c.App.Srv().Go(func() {
|
||||
if err = c.App.SendDeactivateAccountEmail(user.Email, user.Locale, c.App.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
|
@ -1134,13 +1134,13 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.IsOAuth {
|
||||
if c.App.Session().IsOAuth {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
c.Err.DetailedError += ", attempted access by oauth app"
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1178,13 +1178,13 @@ func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.IsOAuth {
|
||||
if c.App.Session().IsOAuth {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
c.Err.DetailedError += ", attempted access by oauth app"
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1213,7 +1213,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.LogAudit("attempted")
|
||||
|
||||
var err *model.AppError
|
||||
if c.Params.UserId == c.App.Session.UserId {
|
||||
if c.Params.UserId == c.App.Session().UserId {
|
||||
currentPassword := props["current_password"]
|
||||
if len(currentPassword) <= 0 {
|
||||
c.SetInvalidParam("current_password")
|
||||
|
|
@ -1221,7 +1221,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = c.App.UpdatePasswordAsUser(c.Params.UserId, currentPassword, newPassword)
|
||||
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
err = c.App.UpdatePasswordByUserIdSendEmail(c.Params.UserId, newPassword, c.App.T("api.user.reset_password.method"))
|
||||
} else {
|
||||
err = model.NewAppError("updatePassword", "api.user.update_password.context.app_error", nil, "", http.StatusForbidden)
|
||||
|
|
@ -1431,8 +1431,8 @@ func logout(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
c.RemoveSessionCookie(w, r)
|
||||
if c.App.Session.Id != "" {
|
||||
if err := c.App.RevokeSessionById(c.App.Session.Id); err != nil {
|
||||
if c.App.Session().Id != "" {
|
||||
if err := c.App.RevokeSessionById(c.App.Session().Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -1447,7 +1447,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1471,7 +1471,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1508,7 +1508,7 @@ func revokeAllSessionsForUser(c *Context, w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1522,7 +1522,7 @@ func revokeAllSessionsForUser(c *Context, w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
func revokeAllSessionsAllUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1545,13 +1545,13 @@ 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 := c.App.RevokeSessionsForDeviceId(c.App.Session.UserId, deviceId, c.App.Session.Id); err != nil {
|
||||
if err := c.App.RevokeSessionsForDeviceId(c.App.Session().UserId, deviceId, c.App.Session().Id); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
c.App.ClearSessionCacheForUser(c.App.Session.UserId)
|
||||
c.App.Session.SetExpireInDays(*c.App.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||
c.App.ClearSessionCacheForUser(c.App.Session().UserId)
|
||||
c.App.Session().SetExpireInDays(*c.App.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||
|
||||
maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
|
||||
|
||||
|
|
@ -1565,7 +1565,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0)
|
||||
sessionCookie := &http.Cookie{
|
||||
Name: model.SESSION_COOKIE_TOKEN,
|
||||
Value: c.App.Session.Token,
|
||||
Value: c.App.Session().Token,
|
||||
Path: subpath,
|
||||
MaxAge: maxAge,
|
||||
Expires: expiresAt,
|
||||
|
|
@ -1576,7 +1576,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
http.SetCookie(w, sessionCookie)
|
||||
|
||||
if err := c.App.AttachDeviceId(c.App.Session.Id, deviceId, c.App.Session.ExpiresAt); err != nil {
|
||||
if err := c.App.AttachDeviceId(c.App.Session().Id, deviceId, c.App.Session().ExpiresAt); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -1591,7 +1591,7 @@ func getUserAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1668,7 +1668,7 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.App.Session.UserId)
|
||||
link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.App.Session().UserId)
|
||||
} else if switchRequest.EmailToLdap() {
|
||||
link, err = c.App.SwitchEmailToLdap(switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapLoginId, switchRequest.NewPassword)
|
||||
} else if switchRequest.LdapToEmail() {
|
||||
|
|
@ -1693,7 +1693,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if c.App.Session.IsOAuth {
|
||||
if c.App.Session().IsOAuth {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
|
||||
c.Err.DetailedError += ", attempted access by oauth app"
|
||||
return
|
||||
|
|
@ -1712,12 +1712,12 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1736,7 +1736,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1761,7 +1761,7 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
|
||||
return
|
||||
}
|
||||
|
|
@ -1781,12 +1781,12 @@ func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Reque
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1806,7 +1806,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_READ_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
|
@ -1817,7 +1817,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1835,7 +1835,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("")
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
|
@ -1846,7 +1846,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1871,7 +1871,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
c.LogAudit("")
|
||||
|
||||
// No separate permission for this action for now
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
|
@ -1882,7 +1882,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1907,7 +1907,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
c.LogAudit("")
|
||||
|
||||
// No separate permission for this action for now
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
|
||||
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
|
||||
return
|
||||
}
|
||||
|
|
@ -1918,7 +1918,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
return
|
||||
}
|
||||
|
|
@ -1935,7 +1935,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.StringInterfaceFromJson(r.Body)
|
||||
|
||||
userId := c.App.Session.UserId
|
||||
userId := c.App.Session().UserId
|
||||
termsOfServiceId := props["termsOfServiceId"].(string)
|
||||
accepted := props["accepted"].(bool)
|
||||
|
||||
|
|
@ -1954,7 +1954,7 @@ func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func getUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userId := c.App.Session.UserId
|
||||
userId := c.App.Session().UserId
|
||||
result, err := c.App.GetUserTermsOfService(userId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
|
@ -1969,7 +1969,7 @@ func promoteGuestToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_PROMOTE_GUEST) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_PROMOTE_GUEST) {
|
||||
c.SetPermissionError(model.PERMISSION_PROMOTE_GUEST)
|
||||
return
|
||||
}
|
||||
|
|
@ -1985,7 +1985,7 @@ func promoteGuestToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := c.App.PromoteGuestToUser(user, c.App.Session.UserId); err != nil {
|
||||
if err := c.App.PromoteGuestToUser(user, c.App.Session().UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
|
@ -2009,7 +2009,7 @@ func demoteUserToGuest(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_DEMOTE_TO_GUEST) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_DEMOTE_TO_GUEST) {
|
||||
c.SetPermissionError(model.PERMISSION_DEMOTE_TO_GUEST)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
ruser, resp := th.Client.CreateUserWithToken(&user, token.Token)
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -165,7 +165,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
require.Equal(t, user.Nickname, ruser.Nickname)
|
||||
require.Equal(t, model.SYSTEM_USER_ROLE_ID, ruser.Roles, "should clear roles")
|
||||
CheckUserSanitization(t, ruser)
|
||||
_, err := th.App.Srv.Store.Token().GetByToken(token.Token)
|
||||
_, err := th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
require.NotNil(t, err, "The token must be deleted after being used")
|
||||
|
||||
teams, err := th.App.GetTeamsForUser(ruser.Id)
|
||||
|
|
@ -180,7 +180,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
_, resp := th.Client.CreateUserWithToken(&user, "")
|
||||
|
|
@ -197,7 +197,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
token.CreateAt = past49Hours
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
_, resp := th.Client.CreateUserWithToken(&user, token.Token)
|
||||
|
|
@ -226,7 +226,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
defer th.App.DeleteToken(token)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false })
|
||||
|
|
@ -244,7 +244,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
app.TOKEN_TYPE_TEAM_INVITATION,
|
||||
model.MapToJson(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}),
|
||||
)
|
||||
require.Nil(t, th.App.Srv.Store.Token().Save(token))
|
||||
require.Nil(t, th.App.Srv().Store.Token().Save(token))
|
||||
|
||||
enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
|
||||
defer func() {
|
||||
|
|
@ -261,7 +261,7 @@ func TestCreateUserWithToken(t *testing.T) {
|
|||
require.Equal(t, user.Nickname, ruser.Nickname)
|
||||
require.Equal(t, model.SYSTEM_USER_ROLE_ID, ruser.Roles, "should clear roles")
|
||||
CheckUserSanitization(t, ruser)
|
||||
_, err := th.App.Srv.Store.Token().GetByToken(token.Token)
|
||||
_, err := th.App.Srv().Store.Token().GetByToken(token.Token)
|
||||
require.NotNil(t, err, "The token must be deleted after be used")
|
||||
})
|
||||
}
|
||||
|
|
@ -1558,7 +1558,7 @@ func TestUpdateUserAuth(t *testing.T) {
|
|||
user := th.CreateUser()
|
||||
|
||||
th.LinkUserToTeam(user, team)
|
||||
_, err := th.App.Srv.Store.User().VerifyEmail(user.Id, user.Email)
|
||||
_, err := th.App.Srv().Store.User().VerifyEmail(user.Id, user.Email)
|
||||
require.Nil(t, err)
|
||||
|
||||
userAuth := &model.UserAuth{}
|
||||
|
|
@ -1591,7 +1591,7 @@ func TestUpdateUserAuth(t *testing.T) {
|
|||
// Regular user can not use endpoint
|
||||
user2 := th.CreateUser()
|
||||
th.LinkUserToTeam(user2, team)
|
||||
_, err = th.App.Srv.Store.User().VerifyEmail(user2.Id, user2.Email)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(user2.Id, user2.Email)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.SystemAdminClient.Login(user2.Email, "passwd1")
|
||||
|
|
@ -1742,7 +1742,7 @@ func TestUpdateUserActive(t *testing.T) {
|
|||
CheckNoError(t, resp)
|
||||
|
||||
authData := model.NewId()
|
||||
_, err := th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
_, err := th.App.Srv().Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, resp = th.SystemAdminClient.UpdateUserActive(user.Id, false)
|
||||
|
|
@ -1933,7 +1933,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
|
|||
})
|
||||
CheckNoError(t, resp)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
defer th.App.Srv.Store.User().PermanentDelete(user.Id)
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
|
||||
|
||||
user2, resp := th.Client.CreateUser(&model.User{
|
||||
Username: "a000000001" + model.NewId(),
|
||||
|
|
@ -1941,7 +1941,7 @@ func TestGetUsersWithoutTeam(t *testing.T) {
|
|||
Password: "Password1",
|
||||
})
|
||||
CheckNoError(t, resp)
|
||||
defer th.App.Srv.Store.User().PermanentDelete(user2.Id)
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user2.Id)
|
||||
|
||||
rusers, resp := th.SystemAdminClient.GetUsersWithoutTeam(0, 100, "")
|
||||
CheckNoError(t, resp)
|
||||
|
|
@ -2377,7 +2377,7 @@ func TestResetPassword(t *testing.T) {
|
|||
loc += 6
|
||||
recoveryTokenString = resultsEmail.Body.Text[loc : loc+model.TOKEN_SIZE]
|
||||
}
|
||||
recoveryToken, err := th.App.Srv.Store.Token().GetByToken(recoveryTokenString)
|
||||
recoveryToken, err := th.App.Srv().Store.Token().GetByToken(recoveryTokenString)
|
||||
require.Nil(t, err, "Recovery token not found (%s)", recoveryTokenString)
|
||||
|
||||
_, resp = th.Client.ResetPassword(recoveryToken.Token, "")
|
||||
|
|
@ -2402,7 +2402,7 @@ func TestResetPassword(t *testing.T) {
|
|||
_, resp = th.Client.ResetPassword(recoveryToken.Token, "newpwd")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
authData := model.NewId()
|
||||
_, err = th.App.Srv.Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
_, err = th.App.Srv().Store.User().UpdateAuthData(user.Id, "random", &authData, "", true)
|
||||
require.Nil(t, err)
|
||||
_, resp = th.Client.SendPasswordResetEmail(user.Email)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
|
@ -3074,7 +3074,7 @@ func TestSwitchAccount(t *testing.T) {
|
|||
th.LoginBasic()
|
||||
|
||||
fakeAuthData := model.NewId()
|
||||
_, err := th.App.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true)
|
||||
_, err := th.App.Srv().Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true)
|
||||
require.Nil(t, err)
|
||||
|
||||
sr = &model.SwitchRequest{
|
||||
|
|
|
|||
|
|
@ -39,18 +39,18 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.LogAudit("fail - bad channel permissions")
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
}
|
||||
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(c.App.Session.UserId, channel, hook)
|
||||
incomingHook, err := c.App.CreateIncomingWebhookForChannel(c.App.Session().UserId, channel, hook)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
|
@ -92,7 +92,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if updatedHook.TeamId != oldHook.TeamId {
|
||||
c.Err = model.NewAppError("updateIncomingHook", "api.webhook.team_mismatch.app_error", nil, "user_id="+c.App.Session.UserId, http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("updateIncomingHook", "api.webhook.team_mismatch.app_error", nil, "user_id="+c.App.Session().UserId, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -107,18 +107,18 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != oldHook.UserId && !c.App.SessionHasPermissionToTeam(c.App.Session, channel.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != oldHook.UserId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), channel.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
c.LogAudit("fail - bad channel permissions")
|
||||
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
|
||||
return
|
||||
|
|
@ -137,31 +137,31 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamId := r.URL.Query().Get("team_id")
|
||||
userId := c.App.Session.UserId
|
||||
userId := c.App.Session().UserId
|
||||
|
||||
var hooks []*model.IncomingWebhook
|
||||
var err *model.AppError
|
||||
|
||||
if len(teamId) > 0 {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
userId = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetIncomingWebhooksForTeamPageByUser(teamId, userId, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
userId = ""
|
||||
}
|
||||
|
||||
|
|
@ -200,14 +200,14 @@ func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) ||
|
||||
(channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) ||
|
||||
(channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
|
||||
c.LogAudit("fail - bad permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != hook.UserId && !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != hook.UserId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS)
|
||||
return
|
||||
|
|
@ -240,14 +240,14 @@ func deleteIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) ||
|
||||
(channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(c.App.Session, hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_INCOMING_WEBHOOKS) ||
|
||||
(channel.Type != model.CHANNEL_OPEN && !c.App.SessionHasPermissionToChannel(*c.App.Session(), hook.ChannelId, model.PERMISSION_READ_CHANNEL)) {
|
||||
c.LogAudit("fail - bad permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_INCOMING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != hook.UserId && !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != hook.UserId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_INCOMING_WEBHOOKS)
|
||||
return
|
||||
|
|
@ -292,22 +292,22 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if updatedHook.TeamId != oldHook.TeamId {
|
||||
c.Err = model.NewAppError("updateOutgoingHook", "api.webhook.team_mismatch.app_error", nil, "user_id="+c.App.Session.UserId, http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("updateOutgoingHook", "api.webhook.team_mismatch.app_error", nil, "user_id="+c.App.Session().UserId, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, updatedHook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), updatedHook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != oldHook.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, updatedHook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != oldHook.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), updatedHook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
updatedHook.CreatorId = c.App.Session.UserId
|
||||
updatedHook.CreatorId = c.App.Session().UserId
|
||||
|
||||
rhook, err := c.App.UpdateOutgoingWebhook(oldHook, updatedHook)
|
||||
if err != nil {
|
||||
|
|
@ -328,9 +328,9 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
hook.CreatorId = c.App.Session.UserId
|
||||
hook.CreatorId = c.App.Session().UserId
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
|
@ -350,43 +350,43 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channelId := r.URL.Query().Get("channel_id")
|
||||
teamId := r.URL.Query().Get("team_id")
|
||||
userId := c.App.Session.UserId
|
||||
userId := c.App.Session().UserId
|
||||
|
||||
var hooks []*model.OutgoingWebhook
|
||||
var err *model.AppError
|
||||
|
||||
if len(channelId) > 0 {
|
||||
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
userId = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetOutgoingWebhooksForChannelPageByUser(channelId, userId, c.Params.Page, c.Params.PerPage)
|
||||
} else if len(teamId) > 0 {
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
userId = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetOutgoingWebhooksForTeamPageByUser(teamId, userId, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
userId = ""
|
||||
}
|
||||
|
||||
|
|
@ -415,12 +415,12 @@ func getOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
|
|
@ -444,12 +444,12 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
|
|
@ -478,12 +478,12 @@ func deleteOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS) {
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session.UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(c.App.Session, hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
if c.App.Session().UserId != hook.CreatorId && !c.App.SessionHasPermissionToTeam(*c.App.Session(), hook.TeamId, model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS) {
|
||||
c.LogAudit("fail - inappropriate permissions")
|
||||
c.SetPermissionError(model.PERMISSION_MANAGE_OTHERS_OUTGOING_WEBHOOKS)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
wc := c.App.NewWebConn(ws, c.App.Session, c.App.T, "")
|
||||
wc := c.App.NewWebConn(ws, *c.App.Session(), c.App.T, "")
|
||||
|
||||
if len(c.App.Session.UserId) > 0 {
|
||||
if len(c.App.Session().UserId) > 0 {
|
||||
c.App.HubRegister(wc)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func TestWebSocketTrailingSlash(t *testing.T) {
|
|||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv.ListenAddr.Port)
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port)
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket/", nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
@ -216,7 +216,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
|
|||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv.ListenAddr.Port)
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port)
|
||||
|
||||
// Should fail because origin doesn't match
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
|
|
@ -227,7 +227,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
|
|||
|
||||
// We are not a browser so we can spoof this just fine
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
"Origin": []string{fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port)},
|
||||
"Origin": []string{fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port)},
|
||||
})
|
||||
require.Nil(t, err, err)
|
||||
|
||||
|
|
@ -282,13 +282,13 @@ func TestWebSocketStatuses(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)).(*model.User)
|
||||
th.LinkUserToTeam(ruser, rteam)
|
||||
_, err = th.App.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
require.Nil(t, err)
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser2 := Client.Must(Client.CreateUser(&user2)).(*model.User)
|
||||
th.LinkUserToTeam(ruser2, rteam)
|
||||
_, err = th.App.Srv.Store.User().VerifyEmail(ruser2.Id, ruser2.Email)
|
||||
_, err = th.App.Srv().Store.User().VerifyEmail(ruser2.Id, ruser2.Email)
|
||||
require.Nil(t, err)
|
||||
|
||||
Client.Login(user.Email, user.Password)
|
||||
|
|
|
|||
42
app/admin.go
42
app/admin.go
|
|
@ -21,10 +21,10 @@ import (
|
|||
|
||||
func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
var lines []string
|
||||
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
|
||||
if a.Cluster() != nil && *a.Config().ClusterSettings.Enable {
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, a.Cluster.GetMyClusterInfo().Hostname)
|
||||
lines = append(lines, a.Cluster().GetMyClusterInfo().Hostname)
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
}
|
||||
|
|
@ -36,8 +36,8 @@ func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
|
|||
|
||||
lines = append(lines, melines...)
|
||||
|
||||
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
|
||||
clines, err := a.Cluster.GetLogs(page, perPage)
|
||||
if a.Cluster() != nil && *a.Config().ClusterSettings.Enable {
|
||||
clines, err := a.Cluster().GetLogs(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -122,8 +122,8 @@ func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
|||
func (a *App) GetClusterStatus() []*model.ClusterInfo {
|
||||
infos := make([]*model.ClusterInfo, 0)
|
||||
|
||||
if a.Cluster != nil {
|
||||
infos = a.Cluster.GetClusterInfos()
|
||||
if a.Cluster() != nil {
|
||||
infos = a.Cluster().GetClusterInfos()
|
||||
}
|
||||
|
||||
return infos
|
||||
|
|
@ -133,7 +133,7 @@ func (a *App) InvalidateAllCaches() *model.AppError {
|
|||
debug.FreeOSMemory()
|
||||
a.InvalidateAllCachesSkipSend()
|
||||
|
||||
if a.Cluster != nil {
|
||||
if a.Cluster() != nil {
|
||||
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES,
|
||||
|
|
@ -141,7 +141,7 @@ func (a *App) InvalidateAllCaches() *model.AppError {
|
|||
WaitForAllToSend: true,
|
||||
}
|
||||
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
a.Cluster().SendClusterMessage(msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -149,25 +149,25 @@ func (a *App) InvalidateAllCaches() *model.AppError {
|
|||
|
||||
func (a *App) InvalidateAllCachesSkipSend() {
|
||||
mlog.Info("Purging all caches")
|
||||
a.Srv.sessionCache.Purge()
|
||||
a.Srv.statusCache.Purge()
|
||||
a.Srv.Store.Team().ClearCaches()
|
||||
a.Srv.Store.Channel().ClearCaches()
|
||||
a.Srv.Store.User().ClearCaches()
|
||||
a.Srv.Store.Post().ClearCaches()
|
||||
a.Srv.Store.FileInfo().ClearCaches()
|
||||
a.Srv.Store.Webhook().ClearCaches()
|
||||
a.Srv().sessionCache.Purge()
|
||||
a.Srv().statusCache.Purge()
|
||||
a.Srv().Store.Team().ClearCaches()
|
||||
a.Srv().Store.Channel().ClearCaches()
|
||||
a.Srv().Store.User().ClearCaches()
|
||||
a.Srv().Store.Post().ClearCaches()
|
||||
a.Srv().Store.FileInfo().ClearCaches()
|
||||
a.Srv().Store.Webhook().ClearCaches()
|
||||
a.LoadLicense()
|
||||
}
|
||||
|
||||
func (a *App) RecycleDatabaseConnection() {
|
||||
oldStore := a.Srv.Store
|
||||
oldStore := a.Srv().Store
|
||||
|
||||
mlog.Warn("Attempting to recycle the database connection.")
|
||||
a.Srv.Store = a.Srv.newStore()
|
||||
a.Srv.Jobs.Store = a.Srv.Store
|
||||
a.Srv().Store = a.Srv().newStore()
|
||||
a.Srv().Jobs.Store = a.Srv().Store
|
||||
|
||||
if a.Srv.Store != oldStore {
|
||||
if a.Srv().Store != oldStore {
|
||||
time.Sleep(20 * time.Second)
|
||||
oldStore.Close()
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError {
|
|||
|
||||
// ServerBusyStateChanged is called when a CLUSTER_EVENT_BUSY_STATE_CHANGED is received.
|
||||
func (a *App) ServerBusyStateChanged(sbs *model.ServerBusyState) {
|
||||
a.Srv.Busy.ClusterEventChanged(sbs)
|
||||
a.Srv().Busy.ClusterEventChanged(sbs)
|
||||
if sbs.Busy {
|
||||
mlog.Warn("server busy state activitated via cluster event - non-critical services disabled", mlog.Int64("expires_sec", sbs.Expires))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const (
|
|||
func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError) {
|
||||
skipIntensiveQueries := false
|
||||
var systemUserCount int64
|
||||
systemUserCount, err := a.Srv.Store.User().Count(model.UserCountOptions{})
|
||||
systemUserCount, err := a.Srv().Store.User().Count(model.UserCountOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -44,12 +44,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
openChan := make(chan store.StoreResult, 1)
|
||||
privateChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
|
||||
openChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(openChan)
|
||||
}()
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
|
||||
privateChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(privateChan)
|
||||
}()
|
||||
|
|
@ -59,14 +59,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
if teamId == "" {
|
||||
userInactiveChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.User().AnalyticsGetInactiveUsersCount()
|
||||
count, err := a.Srv().Store.User().AnalyticsGetInactiveUsersCount()
|
||||
userInactiveChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(userInactiveChan)
|
||||
}()
|
||||
} else {
|
||||
userChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.User().Count(model.UserCountOptions{TeamId: teamId})
|
||||
count, err := a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamId})
|
||||
userChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
|
|
@ -76,7 +76,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
if !skipIntensiveQueries {
|
||||
postChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
|
||||
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false)
|
||||
postChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(postChan)
|
||||
}()
|
||||
|
|
@ -84,21 +84,21 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
|
||||
teamCountChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
teamCount, err := a.Srv().Store.Team().AnalyticsTeamCount(false)
|
||||
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
|
||||
close(teamCountChan)
|
||||
}()
|
||||
|
||||
dailyActiveChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
dailyActive, err := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
dailyActive, err := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err}
|
||||
close(dailyActiveChan)
|
||||
}()
|
||||
|
||||
monthlyActiveChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
monthlyActive, err := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
monthlyActive, err := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err}
|
||||
close(monthlyActiveChan)
|
||||
}()
|
||||
|
|
@ -152,15 +152,15 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
rows[4].Value = float64(r.Data.(int64))
|
||||
|
||||
// If in HA mode then aggregrate all the stats
|
||||
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
|
||||
stats, err := a.Cluster.GetClusterStats()
|
||||
if a.Cluster() != nil && *a.Config().ClusterSettings.Enable {
|
||||
stats, err := a.Cluster().GetClusterStats()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalSockets := a.TotalWebsocketConnections()
|
||||
totalMasterDb := a.Srv.Store.TotalMasterDbConnections()
|
||||
totalReadDb := a.Srv.Store.TotalReadDbConnections()
|
||||
totalMasterDb := a.Srv().Store.TotalMasterDbConnections()
|
||||
totalReadDb := a.Srv().Store.TotalReadDbConnections()
|
||||
|
||||
for _, stat := range stats {
|
||||
totalSockets = totalSockets + stat.TotalWebsocketConnections
|
||||
|
|
@ -174,8 +174,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
|
||||
} else {
|
||||
rows[5].Value = float64(a.TotalWebsocketConnections())
|
||||
rows[6].Value = float64(a.Srv.Store.TotalMasterDbConnections())
|
||||
rows[7].Value = float64(a.Srv.Store.TotalReadDbConnections())
|
||||
rows[6].Value = float64(a.Srv().Store.TotalMasterDbConnections())
|
||||
rows[7].Value = float64(a.Srv().Store.TotalReadDbConnections())
|
||||
}
|
||||
|
||||
r = <-dailyActiveChan
|
||||
|
|
@ -196,7 +196,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||
return rows, nil
|
||||
}
|
||||
return a.Srv.Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
return a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
TeamId: teamId,
|
||||
BotsOnly: true,
|
||||
YesterdayOnly: false,
|
||||
|
|
@ -206,7 +206,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
rows := model.AnalyticsRows{&model.AnalyticsRow{Name: "", Value: -1}}
|
||||
return rows, nil
|
||||
}
|
||||
return a.Srv.Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
return a.Srv().Store.Post().AnalyticsPostCountsByDay(&model.AnalyticsPostCountsOptions{
|
||||
TeamId: teamId,
|
||||
BotsOnly: false,
|
||||
YesterdayOnly: false,
|
||||
|
|
@ -217,7 +217,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
return rows, nil
|
||||
}
|
||||
|
||||
return a.Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
return a.Srv().Store.Post().AnalyticsUserCountsWithPostsByDay(teamId)
|
||||
} else if name == "extra_counts" {
|
||||
var rows model.AnalyticsRows = make([]*model.AnalyticsRow, 6)
|
||||
rows[0] = &model.AnalyticsRow{Name: "file_post_count", Value: 0}
|
||||
|
|
@ -229,28 +229,28 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
|
||||
iHookChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
c, err := a.Srv().Store.Webhook().AnalyticsIncomingCount(teamId)
|
||||
iHookChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(iHookChan)
|
||||
}()
|
||||
|
||||
oHookChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
c, err := a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamId)
|
||||
oHookChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(oHookChan)
|
||||
}()
|
||||
|
||||
commandChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
c, err := a.Srv.Store.Command().AnalyticsCommandCount(teamId)
|
||||
c, err := a.Srv().Store.Command().AnalyticsCommandCount(teamId)
|
||||
commandChan <- store.StoreResult{Data: c, Err: err}
|
||||
close(commandChan)
|
||||
}()
|
||||
|
||||
sessionChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Session().AnalyticsSessionCount()
|
||||
count, err := a.Srv().Store.Session().AnalyticsSessionCount()
|
||||
sessionChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(sessionChan)
|
||||
}()
|
||||
|
|
@ -261,14 +261,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
if !skipIntensiveQueries {
|
||||
fileChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
|
||||
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false)
|
||||
fileChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(fileChan)
|
||||
}()
|
||||
|
||||
hashtagChan = make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
|
||||
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true)
|
||||
hashtagChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(hashtagChan)
|
||||
}()
|
||||
|
|
@ -325,7 +325,7 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||
}
|
||||
|
||||
func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError) {
|
||||
users, err := a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100, nil)
|
||||
users, err := a.Srv().Store.User().GetRecentlyActiveUsersForTeam(teamId, 0, 100, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ func (a *App) GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.Us
|
|||
}
|
||||
|
||||
func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||
users, err := a.Srv.Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage, viewRestrictions)
|
||||
users, err := a.Srv().Store.User().GetRecentlyActiveUsersForTeam(teamId, page*perPage, perPage, viewRestrictions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -349,7 +349,7 @@ func (a *App) GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int
|
|||
}
|
||||
|
||||
func (a *App) GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) {
|
||||
users, err := a.Srv.Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage, viewRestrictions)
|
||||
users, err := a.Srv().Store.User().GetNewUsersForTeam(teamId, page*perPage, perPage, viewRestrictions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
179
app/app.go
179
app/app.go
|
|
@ -4,6 +4,7 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
|
@ -20,33 +21,35 @@ import (
|
|||
)
|
||||
|
||||
type App struct {
|
||||
Srv *Server
|
||||
srv *Server
|
||||
|
||||
Log *mlog.Logger
|
||||
NotificationsLog *mlog.Logger
|
||||
log *mlog.Logger
|
||||
notificationsLog *mlog.Logger
|
||||
|
||||
T goi18n.TranslateFunc
|
||||
Session model.Session
|
||||
RequestId string
|
||||
IpAddress string
|
||||
Path string
|
||||
UserAgent string
|
||||
AcceptLanguage string
|
||||
t goi18n.TranslateFunc
|
||||
session model.Session
|
||||
requestId string
|
||||
ipAddress string
|
||||
path string
|
||||
userAgent string
|
||||
acceptLanguage string
|
||||
|
||||
AccountMigration einterfaces.AccountMigrationInterface
|
||||
Cluster einterfaces.ClusterInterface
|
||||
Compliance einterfaces.ComplianceInterface
|
||||
DataRetention einterfaces.DataRetentionInterface
|
||||
Elasticsearch einterfaces.ElasticsearchInterface
|
||||
Ldap einterfaces.LdapInterface
|
||||
MessageExport einterfaces.MessageExportInterface
|
||||
Metrics einterfaces.MetricsInterface
|
||||
Notification einterfaces.NotificationInterface
|
||||
Saml einterfaces.SamlInterface
|
||||
accountMigration einterfaces.AccountMigrationInterface
|
||||
cluster einterfaces.ClusterInterface
|
||||
compliance einterfaces.ComplianceInterface
|
||||
dataRetention einterfaces.DataRetentionInterface
|
||||
elasticsearch einterfaces.ElasticsearchInterface
|
||||
ldap einterfaces.LdapInterface
|
||||
messageExport einterfaces.MessageExportInterface
|
||||
metrics einterfaces.MetricsInterface
|
||||
notification einterfaces.NotificationInterface
|
||||
saml einterfaces.SamlInterface
|
||||
|
||||
HTTPService httpservice.HTTPService
|
||||
ImageProxy *imageproxy.ImageProxy
|
||||
Timezones *timezones.Timezones
|
||||
httpService httpservice.HTTPService
|
||||
imageProxy *imageproxy.ImageProxy
|
||||
timezones *timezones.Timezones
|
||||
|
||||
context context.Context
|
||||
}
|
||||
|
||||
func New(options ...AppOption) *App {
|
||||
|
|
@ -63,8 +66,8 @@ func New(options ...AppOption) *App {
|
|||
// This is to avoid having to change all the code in cmd/mattermost/commands/* for now
|
||||
// shutdown should be called directly on the server
|
||||
func (a *App) Shutdown() {
|
||||
a.Srv.Shutdown()
|
||||
a.Srv = nil
|
||||
a.Srv().Shutdown()
|
||||
a.srv = nil
|
||||
}
|
||||
|
||||
func (a *App) configOrLicenseListener() {
|
||||
|
|
@ -99,18 +102,18 @@ func (s *Server) initJobs() {
|
|||
}
|
||||
|
||||
func (a *App) DiagnosticId() string {
|
||||
return a.Srv.diagnosticId
|
||||
return a.Srv().diagnosticId
|
||||
}
|
||||
|
||||
func (a *App) SetDiagnosticId(id string) {
|
||||
a.Srv.diagnosticId = id
|
||||
a.Srv().diagnosticId = id
|
||||
}
|
||||
|
||||
func (a *App) EnsureDiagnosticId() {
|
||||
if a.Srv.diagnosticId != "" {
|
||||
if a.Srv().diagnosticId != "" {
|
||||
return
|
||||
}
|
||||
props, err := a.Srv.Store.System().Get()
|
||||
props, err := a.Srv().Store.System().Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -119,15 +122,15 @@ func (a *App) EnsureDiagnosticId() {
|
|||
if len(id) == 0 {
|
||||
id = model.NewId()
|
||||
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
|
||||
a.Srv.Store.System().Save(systemId)
|
||||
a.Srv().Store.System().Save(systemId)
|
||||
}
|
||||
|
||||
a.Srv.diagnosticId = id
|
||||
a.Srv().diagnosticId = id
|
||||
}
|
||||
|
||||
func (a *App) HTMLTemplates() *template.Template {
|
||||
if a.Srv.htmlTemplateWatcher != nil {
|
||||
return a.Srv.htmlTemplateWatcher.Templates()
|
||||
if a.Srv().htmlTemplateWatcher != nil {
|
||||
return a.Srv().htmlTemplateWatcher.Templates()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -146,7 +149,7 @@ func (a *App) Handle404(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (a *App) getSystemInstallDate() (int64, *model.AppError) {
|
||||
systemData, appErr := a.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
systemData, appErr := a.Srv().Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
if appErr != nil {
|
||||
return 0, appErr
|
||||
}
|
||||
|
|
@ -156,3 +159,111 @@ func (a *App) getSystemInstallDate() (int64, *model.AppError) {
|
|||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (a *App) Srv() *Server {
|
||||
return a.srv
|
||||
}
|
||||
func (a *App) Log() *mlog.Logger {
|
||||
return a.log
|
||||
}
|
||||
func (a *App) NotificationsLog() *mlog.Logger {
|
||||
return a.notificationsLog
|
||||
}
|
||||
func (a *App) T(translationID string, args ...interface{}) string {
|
||||
return a.t(translationID, args...)
|
||||
}
|
||||
func (a *App) Session() *model.Session {
|
||||
return &a.session
|
||||
}
|
||||
func (a *App) RequestId() string {
|
||||
return a.requestId
|
||||
}
|
||||
func (a *App) IpAddress() string {
|
||||
return a.ipAddress
|
||||
}
|
||||
func (a *App) Path() string {
|
||||
return a.path
|
||||
}
|
||||
func (a *App) UserAgent() string {
|
||||
return a.userAgent
|
||||
}
|
||||
func (a *App) AcceptLanguage() string {
|
||||
return a.acceptLanguage
|
||||
}
|
||||
func (a *App) AccountMigration() einterfaces.AccountMigrationInterface {
|
||||
return a.accountMigration
|
||||
}
|
||||
func (a *App) Cluster() einterfaces.ClusterInterface {
|
||||
return a.cluster
|
||||
}
|
||||
func (a *App) Compliance() einterfaces.ComplianceInterface {
|
||||
return a.compliance
|
||||
}
|
||||
func (a *App) DataRetention() einterfaces.DataRetentionInterface {
|
||||
return a.dataRetention
|
||||
}
|
||||
func (a *App) Elasticsearch() einterfaces.ElasticsearchInterface {
|
||||
return a.elasticsearch
|
||||
}
|
||||
func (a *App) Ldap() einterfaces.LdapInterface {
|
||||
return a.ldap
|
||||
}
|
||||
func (a *App) MessageExport() einterfaces.MessageExportInterface {
|
||||
return a.messageExport
|
||||
}
|
||||
func (a *App) Metrics() einterfaces.MetricsInterface {
|
||||
return a.metrics
|
||||
}
|
||||
func (a *App) Notification() einterfaces.NotificationInterface {
|
||||
return a.notification
|
||||
}
|
||||
func (a *App) Saml() einterfaces.SamlInterface {
|
||||
return a.saml
|
||||
}
|
||||
func (a *App) HTTPService() httpservice.HTTPService {
|
||||
return a.httpService
|
||||
}
|
||||
func (a *App) ImageProxy() *imageproxy.ImageProxy {
|
||||
return a.imageProxy
|
||||
}
|
||||
func (a *App) Timezones() *timezones.Timezones {
|
||||
return a.timezones
|
||||
}
|
||||
func (a *App) Context() context.Context {
|
||||
return a.context
|
||||
}
|
||||
|
||||
func (a *App) SetSession(s *model.Session) {
|
||||
a.session = *s
|
||||
}
|
||||
|
||||
func (a *App) SetT(t goi18n.TranslateFunc) {
|
||||
a.t = t
|
||||
}
|
||||
func (a *App) SetRequestId(s string) {
|
||||
a.requestId = s
|
||||
}
|
||||
func (a *App) SetIpAddress(s string) {
|
||||
a.ipAddress = s
|
||||
}
|
||||
func (a *App) SetUserAgent(s string) {
|
||||
a.userAgent = s
|
||||
}
|
||||
func (a *App) SetAcceptLanguage(s string) {
|
||||
a.acceptLanguage = s
|
||||
}
|
||||
func (a *App) SetPath(s string) {
|
||||
a.path = s
|
||||
}
|
||||
func (a *App) SetContext(c context.Context) {
|
||||
a.context = c
|
||||
}
|
||||
func (a *App) SetServer(srv *Server) {
|
||||
a.srv = srv
|
||||
}
|
||||
func (a *App) GetT() goi18n.TranslateFunc {
|
||||
return a.t
|
||||
}
|
||||
func (a *App) SetLog(l *mlog.Logger) {
|
||||
a.log = l
|
||||
}
|
||||
|
|
|
|||
834
app/app_iface.go
Normal file
834
app/app_iface.go
Normal file
|
|
@ -0,0 +1,834 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make store-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"html/template"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/dyatlov/go-opengraph/opengraph"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/mattermost/go-i18n/i18n"
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/services/filesstore"
|
||||
"github.com/mattermost/mattermost-server/v5/services/httpservice"
|
||||
"github.com/mattermost/mattermost-server/v5/services/imageproxy"
|
||||
"github.com/mattermost/mattermost-server/v5/services/timezones"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
// AppIface is extracted from App struct and contains all it's exported methods. It's provided to allow partial interface passing and app layers creation.
|
||||
type AppIface interface {
|
||||
AcceptLanguage() string
|
||||
AccountMigration() einterfaces.AccountMigrationInterface
|
||||
ActivateMfa(userId, token string) *model.AppError
|
||||
AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError)
|
||||
AddConfigListener(listener func(*model.Config, *model.Config)) string
|
||||
AddCursorIdsForPostList(originalList *model.PostList, afterPost, beforePost string, since int64, page, perPage int)
|
||||
AddDirectChannels(teamId string, user *model.User) *model.AppError
|
||||
AddLicenseListener(listener func()) string
|
||||
AddNotificationEmailToBatch(user *model.User, post *model.Post, team *model.Team) *model.AppError
|
||||
AddPublicKey(name string, key io.Reader) *model.AppError
|
||||
AddSamlIdpCertificate(fileData *multipart.FileHeader) *model.AppError
|
||||
AddSamlPrivateCertificate(fileData *multipart.FileHeader) *model.AppError
|
||||
AddSamlPublicCertificate(fileData *multipart.FileHeader) *model.AppError
|
||||
AddSessionToCache(session *model.Session)
|
||||
AddStatusCache(status *model.Status)
|
||||
AddStatusCacheSkipClusterSend(status *model.Status)
|
||||
AddTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
|
||||
AddTeamMemberByInviteId(inviteId, userId string) (*model.TeamMember, *model.AppError)
|
||||
AddTeamMemberByToken(userId, tokenId string) (*model.TeamMember, *model.AppError)
|
||||
AddTeamMembers(teamId string, userIds []string, userRequestorId string, graceful bool) ([]*model.TeamMemberWithError, *model.AppError)
|
||||
AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError)
|
||||
AddUserToTeam(teamId string, userId string, userRequestorId string) (*model.Team, *model.AppError)
|
||||
AddUserToTeamByInviteId(inviteId string, userId string) (*model.Team, *model.AppError)
|
||||
AddUserToTeamByTeamId(teamId string, user *model.User) *model.AppError
|
||||
AddUserToTeamByToken(userId string, tokenId string) (*model.Team, *model.AppError)
|
||||
AllowOAuthAppAccessToUser(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
AsymmetricSigningKey() *ecdsa.PrivateKey
|
||||
AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.AppError
|
||||
AttachSessionCookies(w http.ResponseWriter, r *http.Request)
|
||||
AuthenticateUserForLogin(id, loginId, password, mfaToken string, ldapOnly bool) (*model.User, *model.AppError)
|
||||
AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectUri string) (io.ReadCloser, string, map[string]string, *model.AppError)
|
||||
AutocompleteChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
|
||||
AutocompleteChannelsForSearch(teamId string, userId string, term string) (*model.ChannelList, *model.AppError)
|
||||
AutocompleteUsersInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInChannel, *model.AppError)
|
||||
AutocompleteUsersInTeam(teamId string, term string, options *model.UserSearchOptions) (*model.UserAutocompleteInTeam, *model.AppError)
|
||||
BroadcastStatus(status *model.Status)
|
||||
BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError)
|
||||
BuildPushNotificationMessage(contentsConfig string, post *model.Post, user *model.User, channel *model.Channel, channelName string, senderName string, explicitMention bool, channelWideMention bool, replyToThreadType string) (*model.PushNotification, *model.AppError)
|
||||
BuildSamlMetadataObject(idpMetadata []byte) (*model.SamlMetadataResponse, *model.AppError)
|
||||
BulkExport(writer io.Writer, file string, pathToEmojiDir string, dirNameToExportEmoji string) *model.AppError
|
||||
BulkImport(fileReader io.Reader, dryRun bool, workers int) (*model.AppError, int)
|
||||
CancelJob(jobId string) *model.AppError
|
||||
ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError)
|
||||
ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError)
|
||||
ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError)
|
||||
CheckForClientSideCert(r *http.Request) (string, string, string)
|
||||
CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError
|
||||
CheckRolesExist(roleNames []string) *model.AppError
|
||||
CheckUserAllAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError
|
||||
CheckUserMfa(user *model.User, token string) *model.AppError
|
||||
CheckUserPostflightAuthenticationCriteria(user *model.User) *model.AppError
|
||||
CheckUserPreflightAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError
|
||||
ClearChannelMembersCache(channelID string)
|
||||
ClearPushNotification(currentSessionId, userId, channelId string)
|
||||
ClearPushNotificationSync(currentSessionId, userId, channelId string) *model.AppError
|
||||
ClearSessionCacheForAllUsers()
|
||||
ClearSessionCacheForAllUsersSkipClusterSend()
|
||||
ClearSessionCacheForUser(userId string)
|
||||
ClearSessionCacheForUserSkipClusterSend(userId string)
|
||||
ClearTeamMembersCache(teamID string)
|
||||
ClientConfig() map[string]string
|
||||
ClientConfigHash() string
|
||||
ClientConfigWithComputed() map[string]string
|
||||
ClientLicense() map[string]string
|
||||
Cluster() einterfaces.ClusterInterface
|
||||
CompareAndDeletePluginKey(pluginId string, key string, oldValue []byte) (bool, *model.AppError)
|
||||
CompareAndSetPluginKey(pluginId string, key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||
CompleteOAuth(service string, body io.ReadCloser, teamId string, props map[string]string) (*model.User, *model.AppError)
|
||||
CompleteSwitchWithOAuth(service string, userData io.Reader, email string) (*model.User, *model.AppError)
|
||||
Compliance() einterfaces.ComplianceInterface
|
||||
Config() *model.Config
|
||||
Context() context.Context
|
||||
ConvertUserToBot(user *model.User) (*model.Bot, *model.AppError)
|
||||
CopyFileInfos(userId string, fileIds []string) ([]string, *model.AppError)
|
||||
CreateBasicUser(client *model.Client4) *model.AppError
|
||||
CreateBot(bot *model.Bot) (*model.Bot, *model.AppError)
|
||||
CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError)
|
||||
CreateChannelWithUser(channel *model.Channel, userId string) (*model.Channel, *model.AppError)
|
||||
CreateCommand(cmd *model.Command) (*model.Command, *model.AppError)
|
||||
CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError)
|
||||
CreateCommandWebhook(commandId string, args *model.CommandArgs) (*model.CommandWebhook, *model.AppError)
|
||||
CreateDefaultChannels(teamID string) ([]*model.Channel, *model.AppError)
|
||||
CreateDefaultMemberships(since int64) error
|
||||
CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartImageData *multipart.Form) (*model.Emoji, *model.AppError)
|
||||
CreateGroup(group *model.Group) (*model.Group, *model.AppError)
|
||||
CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError)
|
||||
CreateGuest(user *model.User) (*model.User, *model.AppError)
|
||||
CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
CreateJob(job *model.Job) (*model.Job, *model.AppError)
|
||||
CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
CreateOAuthStateToken(extra string) (*model.Token, *model.AppError)
|
||||
CreateOAuthUser(service string, userData io.Reader, teamId string) (*model.User, *model.AppError)
|
||||
CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
CreatePasswordRecoveryToken(userId, email string) (*model.Token, *model.AppError)
|
||||
CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (*model.Post, *model.AppError)
|
||||
CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError)
|
||||
CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError)
|
||||
CreatePushNotificationsHub()
|
||||
CreateRole(role *model.Role) (*model.Role, *model.AppError)
|
||||
CreateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
CreateSession(session *model.Session) (*model.Session, *model.AppError)
|
||||
CreateTeam(team *model.Team) (*model.Team, *model.AppError)
|
||||
CreateTeamWithUser(team *model.Team, userId string) (*model.Team, *model.AppError)
|
||||
CreateTermsOfService(text, userId string) (*model.TermsOfService, *model.AppError)
|
||||
CreateUser(user *model.User) (*model.User, *model.AppError)
|
||||
CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError)
|
||||
CreateUserAsAdmin(user *model.User) (*model.User, *model.AppError)
|
||||
CreateUserFromSignup(user *model.User) (*model.User, *model.AppError)
|
||||
CreateUserWithInviteId(user *model.User, inviteId string) (*model.User, *model.AppError)
|
||||
CreateUserWithToken(user *model.User, token *model.Token) (*model.User, *model.AppError)
|
||||
CreateVerifyEmailToken(userId string, newEmail string) (*model.Token, *model.AppError)
|
||||
CreateWebhookPost(userId string, channel *model.Channel, text, overrideUsername, overrideIconUrl, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError)
|
||||
DataRetention() einterfaces.DataRetentionInterface
|
||||
DeactivateGuests() *model.AppError
|
||||
DeactivateMfa(userId string) *model.AppError
|
||||
DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError
|
||||
DefaultChannelNames() []string
|
||||
DeleteAllExpiredPluginKeys() *model.AppError
|
||||
DeleteAllKeysForPlugin(pluginId string) *model.AppError
|
||||
DeleteBotIconImage(botUserId string) *model.AppError
|
||||
DeleteBrandImage() *model.AppError
|
||||
DeleteChannel(channel *model.Channel, userId string) *model.AppError
|
||||
DeleteCommand(commandId string) *model.AppError
|
||||
DeleteEmoji(emoji *model.Emoji) *model.AppError
|
||||
DeleteEphemeralPost(userId, postId string)
|
||||
DeleteFlaggedPosts(postId string)
|
||||
DeleteGroup(groupID string) (*model.Group, *model.AppError)
|
||||
DeleteGroupConstrainedMemberships() error
|
||||
DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||
DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||
DeleteIncomingWebhook(hookId string) *model.AppError
|
||||
DeleteOAuthApp(appId string) *model.AppError
|
||||
DeleteOutgoingWebhook(hookId string) *model.AppError
|
||||
DeletePluginKey(pluginId string, key string) *model.AppError
|
||||
DeletePost(postId, deleteByID string) (*model.Post, *model.AppError)
|
||||
DeletePostFiles(post *model.Post)
|
||||
DeletePreferences(userId string, preferences model.Preferences) *model.AppError
|
||||
DeletePublicKey(name string) *model.AppError
|
||||
DeleteReactionForPost(reaction *model.Reaction) *model.AppError
|
||||
DeleteScheme(schemeId string) (*model.Scheme, *model.AppError)
|
||||
DeleteToken(token *model.Token) *model.AppError
|
||||
DemoteUserToGuest(user *model.User) *model.AppError
|
||||
DiagnosticId() string
|
||||
DisableAutoResponder(userId string, asAdmin bool) *model.AppError
|
||||
DisablePlugin(id string) *model.AppError
|
||||
DisableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
DoActionRequest(rawURL string, body []byte) (*http.Response, *model.AppError)
|
||||
DoAdvancedPermissionsMigration()
|
||||
DoAppMigrations()
|
||||
DoEmojisPermissionsMigration()
|
||||
DoGuestRolesCreationMigration()
|
||||
DoLocalRequest(rawURL string, body []byte) (*http.Response, *model.AppError)
|
||||
DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId string) *model.AppError
|
||||
DoPermissionsMigrations() *model.AppError
|
||||
DoPostAction(postId, actionId, userId, selectedOption string) (string, *model.AppError)
|
||||
DoPostActionWithCookie(postId, actionId, userId, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError)
|
||||
DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError)
|
||||
DoUploadFileExpectModification(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, []byte, *model.AppError)
|
||||
DoubleCheckPassword(user *model.User, password string) *model.AppError
|
||||
DownloadFromURL(downloadURL string) ([]byte, error)
|
||||
Elasticsearch() einterfaces.ElasticsearchInterface
|
||||
EnablePlugin(id string) *model.AppError
|
||||
EnableUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
EnsureDiagnosticId()
|
||||
EnvironmentConfig() map[string]interface{}
|
||||
ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
|
||||
ExportAllChannels(writer io.Writer) *model.AppError
|
||||
ExportAllDirectChannels(writer io.Writer) *model.AppError
|
||||
ExportAllDirectPosts(writer io.Writer) *model.AppError
|
||||
ExportAllPosts(writer io.Writer) *model.AppError
|
||||
ExportAllTeams(writer io.Writer) *model.AppError
|
||||
ExportAllUsers(writer io.Writer) *model.AppError
|
||||
ExportCustomEmoji(writer io.Writer, file string, pathToEmojiDir string, dirNameToExportEmoji string) *model.AppError
|
||||
ExportPermissions(w io.Writer) error
|
||||
ExportVersion(writer io.Writer) *model.AppError
|
||||
ExportWriteLine(writer io.Writer, line *LineImportData) *model.AppError
|
||||
FetchSamlMetadataFromIdp(url string) ([]byte, *model.AppError)
|
||||
FileBackend() (filesstore.FileBackend, *model.AppError)
|
||||
FileExists(path string) (bool, *model.AppError)
|
||||
FileReader(path string) (filesstore.ReadCloseSeeker, *model.AppError)
|
||||
FillInChannelProps(channel *model.Channel) *model.AppError
|
||||
FillInChannelsProps(channelList *model.ChannelList) *model.AppError
|
||||
FillInPostProps(post *model.Post, channel *model.Channel) *model.AppError
|
||||
FilterNonGroupChannelMembers(userIds []string, channel *model.Channel) ([]string, error)
|
||||
FilterNonGroupTeamMembers(userIds []string, team *model.Team) ([]string, error)
|
||||
FindTeamByName(name string) bool
|
||||
GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppError)
|
||||
GeneratePublicLink(siteURL string, info *model.FileInfo) string
|
||||
GetActivePluginManifests() ([]*model.Manifest, *model.AppError)
|
||||
GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError)
|
||||
GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.AppError)
|
||||
GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError)
|
||||
GetAllPrivateTeams() ([]*model.Team, *model.AppError)
|
||||
GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||
GetAllPrivateTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError)
|
||||
GetAllPublicTeams() ([]*model.Team, *model.AppError)
|
||||
GetAllPublicTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||
GetAllPublicTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError)
|
||||
GetAllRoles() ([]*model.Role, *model.AppError)
|
||||
GetAllStatuses() map[string]*model.Status
|
||||
GetAllTeams() ([]*model.Team, *model.AppError)
|
||||
GetAllTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||
GetAllTeamsPageWithCount(offset int, limit int) (*model.TeamsWithCount, *model.AppError)
|
||||
GetAnalytics(name string, teamId string) (model.AnalyticsRows, *model.AppError)
|
||||
GetAudits(userId string, limit int) (model.Audits, *model.AppError)
|
||||
GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError)
|
||||
GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError)
|
||||
GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError)
|
||||
GetBotIconImage(botUserId string) ([]byte, *model.AppError)
|
||||
GetBots(options *model.BotGetOptions) (model.BotList, *model.AppError)
|
||||
GetBrandImage() ([]byte, *model.AppError)
|
||||
GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError)
|
||||
GetChannel(channelId string) (*model.Channel, *model.AppError)
|
||||
GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError)
|
||||
GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError)
|
||||
GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError)
|
||||
GetChannelGuestCount(channelId string) (int64, *model.AppError)
|
||||
GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError)
|
||||
GetChannelMemberCount(channelId string) (int64, *model.AppError)
|
||||
GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError)
|
||||
GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError)
|
||||
GetChannelMembersTimezones(channelId string) ([]string, *model.AppError)
|
||||
GetChannelPinnedPostCount(channelId string) (int64, *model.AppError)
|
||||
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
|
||||
GetChannelsByNames(channelNames []string, teamId string) ([]*model.Channel, *model.AppError)
|
||||
GetChannelsForScheme(scheme *model.Scheme, offset int, limit int) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForSchemePage(scheme *model.Scheme, page int, perPage int) (model.ChannelList, *model.AppError)
|
||||
GetChannelsForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
|
||||
GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetClusterId() string
|
||||
GetClusterPluginStatuses() (model.PluginStatuses, *model.AppError)
|
||||
GetClusterStatus() []*model.ClusterInfo
|
||||
GetCommand(commandId string) (*model.Command, *model.AppError)
|
||||
GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError)
|
||||
GetComplianceReport(reportId string) (*model.Compliance, *model.AppError)
|
||||
GetComplianceReports(page, perPage int) (model.Compliances, *model.AppError)
|
||||
GetConfigFile(name string) ([]byte, error)
|
||||
GetCookieDomain() string
|
||||
GetDataRetentionPolicy() (*model.DataRetentionPolicy, *model.AppError)
|
||||
GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError)
|
||||
GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError)
|
||||
GetEmoji(emojiId string) (*model.Emoji, *model.AppError)
|
||||
GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError)
|
||||
GetEmojiImage(emojiId string) ([]byte, string, *model.AppError)
|
||||
GetEmojiList(page, perPage int, sort string) ([]*model.Emoji, *model.AppError)
|
||||
GetEmojiStaticUrl(emojiName string) (string, *model.AppError)
|
||||
GetEnvironmentConfig() map[string]interface{}
|
||||
GetFile(fileId string) ([]byte, *model.AppError)
|
||||
GetFileInfo(fileId string) (*model.FileInfo, *model.AppError)
|
||||
GetFileInfosForPost(postId string, fromMaster bool) ([]*model.FileInfo, *model.AppError)
|
||||
GetFileInfosForPostWithMigration(postId string) ([]*model.FileInfo, *model.AppError)
|
||||
GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||
GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||
GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||
GetGroup(id string) (*model.Group, *model.AppError)
|
||||
GetGroupByName(name string) (*model.Group, *model.AppError)
|
||||
GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError)
|
||||
GetGroupChannel(userIds []string) (*model.Channel, *model.AppError)
|
||||
GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError)
|
||||
GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError)
|
||||
GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError)
|
||||
GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError)
|
||||
GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError)
|
||||
GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError)
|
||||
GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError)
|
||||
GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError)
|
||||
GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError)
|
||||
GetGroupsByUserId(userId string) ([]*model.Group, *model.AppError)
|
||||
GetHubForUserId(userId string) *Hub
|
||||
GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksForTeamPageByUser(teamId string, userId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksPageByUser(userId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetJob(id string) (*model.Job, *model.AppError)
|
||||
GetJobs(offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetLatestTermsOfService() (*model.TermsOfService, *model.AppError)
|
||||
GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError)
|
||||
GetLogs(page, perPage int) ([]string, *model.AppError)
|
||||
GetLogsSkipSend(page, perPage int) ([]string, *model.AppError)
|
||||
GetMarketplacePlugins(filter *model.MarketplacePluginFilter) ([]*model.MarketplacePlugin, *model.AppError)
|
||||
GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string
|
||||
GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError)
|
||||
GetNewUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetNextPostIdFromPostList(postList *model.PostList) string
|
||||
GetNotificationNameFormat(user *model.User) string
|
||||
GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError)
|
||||
GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError)
|
||||
GetOAuthAccessTokenForImplicitFlow(userId string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError)
|
||||
GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError)
|
||||
GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetOAuthCodeRedirect(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthImplicitRedirect(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, service, teamId, action, redirectTo, loginHint string) (string, *model.AppError)
|
||||
GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, service, teamId string) (string, *model.AppError)
|
||||
GetOAuthStateToken(token string) (*model.Token, *model.AppError)
|
||||
GetOpenGraphMetadata(requestURL string) *opengraph.OpenGraph
|
||||
GetOrCreateDirectChannel(userId, otherUserId string) (*model.Channel, *model.AppError)
|
||||
GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksForChannelPageByUser(channelId string, userId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksForTeamPageByUser(teamId string, userId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingWebhooksPageByUser(userId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError)
|
||||
GetPasswordRecoveryToken(token string) (*model.Token, *model.AppError)
|
||||
GetPermalinkPost(postId string, userId string) (*model.PostList, *model.AppError)
|
||||
GetPinnedPosts(channelId string) (*model.PostList, *model.AppError)
|
||||
GetPluginKey(pluginId string, key string) ([]byte, *model.AppError)
|
||||
GetPluginPublicKeyFiles() ([]string, *model.AppError)
|
||||
GetPluginStatus(id string) (*model.PluginStatus, *model.AppError)
|
||||
GetPluginStatuses() (model.PluginStatuses, *model.AppError)
|
||||
GetPlugins() (*model.PluginsResponse, *model.AppError)
|
||||
GetPluginsEnvironment() *plugin.Environment
|
||||
GetPostAfterTime(channelId string, time int64) (*model.Post, *model.AppError)
|
||||
GetPostIdAfterTime(channelId string, time int64) (string, *model.AppError)
|
||||
GetPostIdBeforeTime(channelId string, time int64) (string, *model.AppError)
|
||||
GetPostThread(postId string, skipFetchThreads bool) (*model.PostList, *model.AppError)
|
||||
GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError)
|
||||
GetPostsAfterPost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsAroundPost(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsBeforePost(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsEtag(channelId string) string
|
||||
GetPostsForChannelAroundLastUnread(channelId, userId string, limitBefore, limitAfter int, skipFetchThreads bool) (*model.PostList, *model.AppError)
|
||||
GetPostsPage(options model.GetPostsOptions) (*model.PostList, *model.AppError)
|
||||
GetPostsSince(options model.GetPostsSinceOptions) (*model.PostList, *model.AppError)
|
||||
GetPreferenceByCategoryAndNameForUser(userId string, category string, preferenceName string) (*model.Preference, *model.AppError)
|
||||
GetPreferenceByCategoryForUser(userId string, category string) (model.Preferences, *model.AppError)
|
||||
GetPreferencesForUser(userId string) (model.Preferences, *model.AppError)
|
||||
GetPrevPostIdFromPostList(postList *model.PostList) string
|
||||
GetProfileImage(user *model.User) ([]byte, bool, *model.AppError)
|
||||
GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError)
|
||||
GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError)
|
||||
GetPublicKey(name string) ([]byte, *model.AppError)
|
||||
GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError)
|
||||
GetRecentlyActiveUsersForTeam(teamId string) (map[string]*model.User, *model.AppError)
|
||||
GetRecentlyActiveUsersForTeamPage(teamId string, page, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetRole(id string) (*model.Role, *model.AppError)
|
||||
GetRoleByName(name string) (*model.Role, *model.AppError)
|
||||
GetRolesByNames(names []string) ([]*model.Role, *model.AppError)
|
||||
GetSamlCertificateStatus() *model.SamlCertificateStatus
|
||||
GetSamlMetadata() (string, *model.AppError)
|
||||
GetSamlMetadataFromIdp(idpMetadataUrl string) (*model.SamlMetadataResponse, *model.AppError)
|
||||
GetSanitizeOptions(asAdmin bool) map[string]bool
|
||||
GetSanitizedClientLicense() map[string]string
|
||||
GetSanitizedConfig() *model.Config
|
||||
GetScheme(id string) (*model.Scheme, *model.AppError)
|
||||
GetSchemeByName(name string) (*model.Scheme, *model.AppError)
|
||||
GetSchemeRolesForChannel(channelId string) (string, string, string, *model.AppError)
|
||||
GetSchemeRolesForTeam(teamId string) (string, string, string, *model.AppError)
|
||||
GetSchemes(scope string, offset int, limit int) ([]*model.Scheme, *model.AppError)
|
||||
GetSchemesPage(scope string, page int, perPage int) ([]*model.Scheme, *model.AppError)
|
||||
GetSession(token string) (*model.Session, *model.AppError)
|
||||
GetSessionById(sessionId string) (*model.Session, *model.AppError)
|
||||
GetSessions(userId string) ([]*model.Session, *model.AppError)
|
||||
GetSinglePost(postId string) (*model.Post, *model.AppError)
|
||||
GetSiteURL() string
|
||||
GetStatus(userId string) (*model.Status, *model.AppError)
|
||||
GetStatusFromCache(userId string) *model.Status
|
||||
GetStatusesByIds(userIds []string) (map[string]interface{}, *model.AppError)
|
||||
GetT() goi18n.TranslateFunc
|
||||
GetTeam(teamId string) (*model.Team, *model.AppError)
|
||||
GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||
GetTeamByName(name string) (*model.Team, *model.AppError)
|
||||
GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError)
|
||||
GetTeamIcon(team *model.Team) ([]byte, *model.AppError)
|
||||
GetTeamIdFromQuery(query url.Values) (string, *model.AppError)
|
||||
GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError)
|
||||
GetTeamMembers(teamId string, offset int, limit int, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersByIds(teamId string, userIds []string, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUser(userId string) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamMembersForUserWithPagination(userId string, page, perPage int) ([]*model.TeamMember, *model.AppError)
|
||||
GetTeamStats(teamId string, restrictions *model.ViewUsersRestrictions) (*model.TeamStats, *model.AppError)
|
||||
GetTeamUnread(teamId, userId string) (*model.TeamUnread, *model.AppError)
|
||||
GetTeamsForScheme(scheme *model.Scheme, offset int, limit int) ([]*model.Team, *model.AppError)
|
||||
GetTeamsForSchemePage(scheme *model.Scheme, page int, perPage int) ([]*model.Team, *model.AppError)
|
||||
GetTeamsForUser(userId string) ([]*model.Team, *model.AppError)
|
||||
GetTeamsUnreadForUser(excludeTeamId string, userId string) ([]*model.TeamUnread, *model.AppError)
|
||||
GetTermsOfService(id string) (*model.TermsOfService, *model.AppError)
|
||||
GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError)
|
||||
GetUser(userId string) (*model.User, *model.AppError)
|
||||
GetUserAccessToken(tokenId string, sanitize bool) (*model.UserAccessToken, *model.AppError)
|
||||
GetUserAccessTokens(page, perPage int) ([]*model.UserAccessToken, *model.AppError)
|
||||
GetUserAccessTokensForUser(userId string, page, perPage int) ([]*model.UserAccessToken, *model.AppError)
|
||||
GetUserByAuth(authData *string, authService string) (*model.User, *model.AppError)
|
||||
GetUserByEmail(email string) (*model.User, *model.AppError)
|
||||
GetUserByUsername(username string) (*model.User, *model.AppError)
|
||||
GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
|
||||
GetUserTermsOfService(userId string) (*model.UserTermsOfService, *model.AppError)
|
||||
GetUsers(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||
GetUsersByGroupChannelIds(channelIds []string, asAdmin bool) (map[string][]*model.User, *model.AppError)
|
||||
GetUsersByIds(userIds []string, options *store.UserGetByIdsOpts) ([]*model.User, *model.AppError)
|
||||
GetUsersByUsernames(usernames []string, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetUsersEtag(restrictionsHash string) string
|
||||
GetUsersInChannel(channelId string, offset int, limit int) ([]*model.User, *model.AppError)
|
||||
GetUsersInChannelByStatus(channelId string, offset int, limit int) ([]*model.User, *model.AppError)
|
||||
GetUsersInChannelMap(channelId string, offset int, limit int, asAdmin bool) (map[string]*model.User, *model.AppError)
|
||||
GetUsersInChannelPage(channelId string, page int, perPage int, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetUsersInChannelPageByStatus(channelId string, page int, perPage int, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetUsersInTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||
GetUsersInTeamEtag(teamId string, restrictionsHash string) string
|
||||
GetUsersInTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetUsersNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetUsersNotInChannelMap(teamId string, channelId string, groupConstrained bool, offset int, limit int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) (map[string]*model.User, *model.AppError)
|
||||
GetUsersNotInChannelPage(teamId string, channelId string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetUsersNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetUsersNotInTeamEtag(teamId string, restrictionsHash string) string
|
||||
GetUsersNotInTeamPage(teamId string, groupConstrained bool, page int, perPage int, asAdmin bool, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||
GetUsersPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetUsersWithoutTeam(options *model.UserGetOptions) ([]*model.User, *model.AppError)
|
||||
GetUsersWithoutTeamPage(options *model.UserGetOptions, asAdmin bool) ([]*model.User, *model.AppError)
|
||||
GetVerifyEmailToken(token string) (*model.Token, *model.AppError)
|
||||
GetViewUsersRestrictions(userId string) (*model.ViewUsersRestrictions, *model.AppError)
|
||||
GetViewUsersRestrictionsForTeam(userId string, teamId string) ([]string, *model.AppError)
|
||||
HTMLTemplates() *template.Template
|
||||
HTTPService() httpservice.HTTPService
|
||||
Handle404(w http.ResponseWriter, r *http.Request)
|
||||
HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError)
|
||||
HandleCommandResponsePost(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.Post, *model.AppError)
|
||||
HandleCommandWebhook(hookId string, response *model.CommandResponse) *model.AppError
|
||||
HandleImages(previewPathList []string, thumbnailPathList []string, fileData [][]byte)
|
||||
HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError
|
||||
HandleMessageExportConfig(cfg *model.Config, appCfg *model.Config)
|
||||
HasPermissionTo(askingUserId string, permission *model.Permission) bool
|
||||
HasPermissionToChannel(askingUserId string, channelId string, permission *model.Permission) bool
|
||||
HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool
|
||||
HasPermissionToTeam(askingUserId string, teamId string, permission *model.Permission) bool
|
||||
HasPermissionToUser(askingUserId string, userId string) bool
|
||||
HubRegister(webConn *WebConn)
|
||||
HubStart()
|
||||
HubStop()
|
||||
HubUnregister(webConn *WebConn)
|
||||
ImageProxy() *imageproxy.ImageProxy
|
||||
ImageProxyAdder() func(string) string
|
||||
ImageProxyRemover() func(string) string
|
||||
ImportPermissions(jsonl io.Reader) error
|
||||
InitPlugins(pluginDir, webappPluginDir string)
|
||||
InitPostMetadata()
|
||||
InstallMarketplacePlugin(request *model.InstallMarketplacePluginRequest) (*model.Manifest, *model.AppError)
|
||||
InstallPlugin(pluginFile io.ReadSeeker, replace bool) (*model.Manifest, *model.AppError)
|
||||
InstallPluginFromData(data model.PluginEventData)
|
||||
InstallPluginWithSignature(pluginFile, signature io.ReadSeeker) (*model.Manifest, *model.AppError)
|
||||
InvalidateAllCaches() *model.AppError
|
||||
InvalidateAllCachesSkipSend()
|
||||
InvalidateAllEmailInvites() *model.AppError
|
||||
InvalidateCacheForChannel(channel *model.Channel)
|
||||
InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string)
|
||||
InvalidateCacheForChannelMembers(channelId string)
|
||||
InvalidateCacheForChannelMembersNotifyProps(channelId string)
|
||||
InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId string)
|
||||
InvalidateCacheForChannelPosts(channelId string)
|
||||
InvalidateCacheForUser(userId string)
|
||||
InvalidateCacheForUserSkipClusterSend(userId string)
|
||||
InvalidateCacheForUserTeams(userId string)
|
||||
InvalidateCacheForUserTeamsSkipClusterSend(userId string)
|
||||
InvalidateCacheForWebhook(webhookId string)
|
||||
InvalidateWebConnSessionCacheForUser(userId string)
|
||||
InviteGuestsToChannels(teamId string, guestsInvite *model.GuestsInvite, senderId string) *model.AppError
|
||||
InviteGuestsToChannelsGracefully(teamId string, guestsInvite *model.GuestsInvite, senderId string) ([]*model.EmailInviteWithError, *model.AppError)
|
||||
InviteNewUsersToTeam(emailList []string, teamId, senderId string) *model.AppError
|
||||
InviteNewUsersToTeamGracefully(emailList []string, teamId, senderId string) ([]*model.EmailInviteWithError, *model.AppError)
|
||||
IpAddress() string
|
||||
IsESAutocompletionEnabled() bool
|
||||
IsESIndexingEnabled() bool
|
||||
IsESSearchEnabled() bool
|
||||
IsFirstUserAccount() bool
|
||||
IsLeader() bool
|
||||
IsPasswordValid(password string) *model.AppError
|
||||
IsPhase2MigrationCompleted() *model.AppError
|
||||
IsUserAway(lastActivityAt int64) bool
|
||||
IsUserSignUpAllowed() *model.AppError
|
||||
IsUsernameTaken(name string) bool
|
||||
JoinChannel(channel *model.Channel, userId string) *model.AppError
|
||||
JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError
|
||||
JoinUserToTeam(team *model.Team, user *model.User, userRequestorId string) *model.AppError
|
||||
Ldap() einterfaces.LdapInterface
|
||||
LeaveChannel(channelId string, userId string) *model.AppError
|
||||
LeaveTeam(team *model.Team, user *model.User, requestorId string) *model.AppError
|
||||
License() *model.License
|
||||
LimitedClientConfig() map[string]string
|
||||
LimitedClientConfigWithComputed() map[string]string
|
||||
ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError)
|
||||
ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError)
|
||||
ListDirectory(path string) ([]string, *model.AppError)
|
||||
ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError)
|
||||
ListTeamCommands(teamId string) ([]*model.Command, *model.AppError)
|
||||
LoadLicense()
|
||||
Log() *mlog.Logger
|
||||
LoginByOAuth(service string, userData io.Reader, teamId string) (*model.User, *model.AppError)
|
||||
MakePermissionError(permission *model.Permission) *model.AppError
|
||||
MarkChannelAsUnreadFromPost(postID string, userID string) (*model.ChannelUnreadAt, *model.AppError)
|
||||
MarkChannelsAsViewed(channelIds []string, userId string, currentSessionId string) (map[string]int64, *model.AppError)
|
||||
MaxPostSize() int
|
||||
MessageExport() einterfaces.MessageExportInterface
|
||||
Metrics() einterfaces.MetricsInterface
|
||||
MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo
|
||||
MoveChannel(team *model.Team, channel *model.Channel, user *model.User, removeDeactivatedMembers bool) *model.AppError
|
||||
MoveCommand(team *model.Team, command *model.Command) *model.AppError
|
||||
MoveFile(oldPath, newPath string) *model.AppError
|
||||
NewClusterDiscoveryService() *ClusterDiscoveryService
|
||||
NewEmailTemplate(name, locale string) *utils.HTMLTemplate
|
||||
NewPluginAPI(manifest *model.Manifest) plugin.API
|
||||
NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn
|
||||
NewWebHub() *Hub
|
||||
Notification() einterfaces.NotificationInterface
|
||||
NotificationsLog() *mlog.Logger
|
||||
OldImportChannel(channel *model.Channel, sChannel SlackChannel, users map[string]*model.User) *model.Channel
|
||||
OldImportFile(timestamp time.Time, file io.Reader, teamId string, channelId string, userId string, fileName string) (*model.FileInfo, error)
|
||||
OldImportIncomingWebhookPost(post *model.Post, props model.StringInterface) string
|
||||
OldImportPost(post *model.Post) string
|
||||
OldImportUser(team *model.Team, user *model.User) *model.User
|
||||
OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError
|
||||
OriginChecker() func(*http.Request) bool
|
||||
OverrideIconURLIfEmoji(post *model.Post)
|
||||
PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot, *model.AppError)
|
||||
PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userId string) (*model.Channel, *model.AppError)
|
||||
PatchPost(postId string, patch *model.PostPatch) (*model.Post, *model.AppError)
|
||||
PatchRole(role *model.Role, patch *model.RolePatch) (*model.Role, *model.AppError)
|
||||
PatchScheme(scheme *model.Scheme, patch *model.SchemePatch) (*model.Scheme, *model.AppError)
|
||||
PatchTeam(teamId string, patch *model.TeamPatch) (*model.Team, *model.AppError)
|
||||
PatchUser(userId string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError)
|
||||
Path() string
|
||||
PermanentDeleteAllUsers() *model.AppError
|
||||
PermanentDeleteBot(botUserId string) *model.AppError
|
||||
PermanentDeleteChannel(channel *model.Channel) *model.AppError
|
||||
PermanentDeleteTeam(team *model.Team) *model.AppError
|
||||
PermanentDeleteTeamId(teamId string) *model.AppError
|
||||
PermanentDeleteUser(user *model.User) *model.AppError
|
||||
PluginCommandsForTeam(teamId string) []*model.Command
|
||||
PluginContext() *plugin.Context
|
||||
PostActionCookieSecret() []byte
|
||||
PostAddToChannelMessage(user *model.User, addedUser *model.User, channel *model.Channel, postRootId string) *model.AppError
|
||||
PostPatchWithProxyRemovedFromImageURLs(patch *model.PostPatch) *model.PostPatch
|
||||
PostUpdateChannelDisplayNameMessage(userId string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError
|
||||
PostUpdateChannelHeaderMessage(userId string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError
|
||||
PostUpdateChannelPurposeMessage(userId string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError
|
||||
PostWithProxyAddedToImageURLs(post *model.Post) *model.Post
|
||||
PostWithProxyRemovedFromImageURLs(post *model.Post) *model.Post
|
||||
PreparePostForClient(originalPost *model.Post, isNewPost bool, isEditPost bool) *model.Post
|
||||
PreparePostListForClient(originalList *model.PostList) *model.PostList
|
||||
ProcessSlackAttachments(attachments []*model.SlackAttachment) []*model.SlackAttachment
|
||||
ProcessSlackText(text string) string
|
||||
PromoteGuestToUser(user *model.User, requestorId string) *model.AppError
|
||||
Publish(message *model.WebSocketEvent)
|
||||
PublishSkipClusterSend(message *model.WebSocketEvent)
|
||||
PurgeElasticsearchIndexes() *model.AppError
|
||||
ReadFile(path string) ([]byte, *model.AppError)
|
||||
RecycleDatabaseConnection()
|
||||
RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppError)
|
||||
RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
RegenerateTeamInviteId(teamId string) (*model.Team, *model.AppError)
|
||||
RegisterPluginCommand(pluginId string, command *model.Command) error
|
||||
ReloadConfig() error
|
||||
RemoveConfigListener(id string)
|
||||
RemoveFile(path string) *model.AppError
|
||||
RemoveLicense() *model.AppError
|
||||
RemoveLicenseListener(id string)
|
||||
RemovePlugin(id string) *model.AppError
|
||||
RemovePluginFromData(data model.PluginEventData)
|
||||
RemoveSamlIdpCertificate() *model.AppError
|
||||
RemoveSamlPrivateCertificate() *model.AppError
|
||||
RemoveSamlPublicCertificate() *model.AppError
|
||||
RemoveTeamIcon(teamId string) *model.AppError
|
||||
RemoveTeamMemberFromTeam(teamMember *model.TeamMember, requestorId string) *model.AppError
|
||||
RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError
|
||||
RemoveUserFromTeam(teamId string, userId string, requestorId string) *model.AppError
|
||||
RenameChannel(channel *model.Channel, newChannelName string, newDisplayName string) (*model.Channel, *model.AppError)
|
||||
RenameTeam(team *model.Team, newTeamName string, newDisplayName string) (*model.Team, *model.AppError)
|
||||
RequestId() string
|
||||
ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError
|
||||
ResetPermissionsSystem() *model.AppError
|
||||
RestoreChannel(channel *model.Channel, userId string) (*model.Channel, *model.AppError)
|
||||
RestoreTeam(teamId string) *model.AppError
|
||||
RestrictUsersGetByPermissions(userId string, options *model.UserGetOptions) (*model.UserGetOptions, *model.AppError)
|
||||
RestrictUsersSearchByPermissions(userId string, options *model.UserSearchOptions) (*model.UserSearchOptions, *model.AppError)
|
||||
RevokeAccessToken(token string) *model.AppError
|
||||
RevokeAllSessions(userId string) *model.AppError
|
||||
RevokeSession(session *model.Session) *model.AppError
|
||||
RevokeSessionById(sessionId string) *model.AppError
|
||||
RevokeSessionsForDeviceId(userId string, deviceId string, currentSessionId string) *model.AppError
|
||||
RevokeSessionsFromAllUsers() *model.AppError
|
||||
RevokeUserAccessToken(token *model.UserAccessToken) *model.AppError
|
||||
RolesGrantPermission(roleNames []string, permissionId string) bool
|
||||
Saml() einterfaces.SamlInterface
|
||||
SanitizeProfile(user *model.User, asAdmin bool)
|
||||
SanitizeTeam(session model.Session, team *model.Team) *model.Team
|
||||
SanitizeTeams(session model.Session, teams []*model.Team) []*model.Team
|
||||
SaveAndBroadcastStatus(status *model.Status)
|
||||
SaveBrandImage(imageData *multipart.FileHeader) *model.AppError
|
||||
SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError)
|
||||
SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError
|
||||
SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
||||
SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *model.AppError)
|
||||
SaveUserTermsOfService(userId, termsOfServiceId string, accepted bool) *model.AppError
|
||||
SchemesIterator(batchSize int) func() []*model.Scheme
|
||||
SearchAllChannels(term string, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, int64, *model.AppError)
|
||||
SearchAllTeams(searchOpts *model.TeamSearch) ([]*model.Team, int64, *model.AppError)
|
||||
SearchArchivedChannels(teamId string, term string, userId string) (*model.ChannelList, *model.AppError)
|
||||
SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
|
||||
SearchChannelsForUser(userId, teamId, term string) (*model.ChannelList, *model.AppError)
|
||||
SearchChannelsUserNotIn(teamId string, userId string, term string) (*model.ChannelList, *model.AppError)
|
||||
SearchEmoji(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError)
|
||||
SearchGroupChannels(userId, term string) (*model.ChannelList, *model.AppError)
|
||||
SearchPostsInTeam(teamId string, paramsList []*model.SearchParams) (*model.PostList, *model.AppError)
|
||||
SearchPostsInTeamForUser(terms string, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, timeZoneOffset int, page, perPage int) (*model.PostSearchResults, *model.AppError)
|
||||
SearchPrivateTeams(term string) ([]*model.Team, *model.AppError)
|
||||
SearchPublicTeams(term string) ([]*model.Team, *model.AppError)
|
||||
SearchUserAccessTokens(term string) ([]*model.UserAccessToken, *model.AppError)
|
||||
SearchUsers(props *model.UserSearch, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersInTeam(teamId, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SearchUsersWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError)
|
||||
SendAckToPushProxy(ack *model.PushNotificationAck) error
|
||||
SendAutoResponse(channel *model.Channel, receiver *model.User) (bool, *model.AppError)
|
||||
SendAutoResponseIfNecessary(channel *model.Channel, sender *model.User) (bool, *model.AppError)
|
||||
SendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError
|
||||
SendDailyDiagnostics()
|
||||
SendDeactivateAccountEmail(email string, locale, siteURL string) *model.AppError
|
||||
SendDiagnostic(event string, properties map[string]interface{})
|
||||
SendEmailChangeEmail(oldEmail, newEmail, locale, siteURL string) *model.AppError
|
||||
SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token string) *model.AppError
|
||||
SendEmailVerification(user *model.User, newEmail string) *model.AppError
|
||||
SendEphemeralPost(userId string, post *model.Post) *model.Post
|
||||
SendGuestInviteEmails(team *model.Team, channels []*model.Channel, senderName string, senderUserId string, invites []string, siteURL string, message string)
|
||||
SendInviteEmails(team *model.Team, senderName string, senderUserId string, invites []string, siteURL string)
|
||||
SendMail(to, subject, htmlBody string) *model.AppError
|
||||
SendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) *model.AppError
|
||||
SendMfaChangeEmail(email string, activated bool, locale, siteURL string) *model.AppError
|
||||
SendNotificationMail(to, subject, htmlBody string) *model.AppError
|
||||
SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList) ([]string, error)
|
||||
SendPasswordChangeEmail(email, method, locale, siteURL string) *model.AppError
|
||||
SendPasswordReset(email string, siteURL string) (bool, *model.AppError)
|
||||
SendPasswordResetEmail(email string, token *model.Token, locale, siteURL string) (bool, *model.AppError)
|
||||
SendSignInChangeEmail(email, method, locale, siteURL string) *model.AppError
|
||||
SendUserAccessTokenAddedEmail(email, locale, siteURL string) *model.AppError
|
||||
SendVerifyEmail(userEmail, locale, siteURL, token string) *model.AppError
|
||||
SendWelcomeEmail(userId string, email string, verified bool, locale, siteURL string) *model.AppError
|
||||
ServeInterPluginRequest(w http.ResponseWriter, r *http.Request, sourcePluginId, destinationPluginId string)
|
||||
ServePluginPublicRequest(w http.ResponseWriter, r *http.Request)
|
||||
ServePluginRequest(w http.ResponseWriter, r *http.Request)
|
||||
ServerBusyStateChanged(sbs *model.ServerBusyState)
|
||||
Session() *model.Session
|
||||
SessionCacheLength() int
|
||||
SessionHasPermissionTo(session model.Session, permission *model.Permission) bool
|
||||
SessionHasPermissionToChannel(session model.Session, channelId string, permission *model.Permission) bool
|
||||
SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool
|
||||
SessionHasPermissionToManageBot(session model.Session, botUserId string) *model.AppError
|
||||
SessionHasPermissionToTeam(session model.Session, teamId string, permission *model.Permission) bool
|
||||
SessionHasPermissionToUser(session model.Session, userId string) bool
|
||||
SessionHasPermissionToUserOrBot(session model.Session, userId string) bool
|
||||
SetAcceptLanguage(s string)
|
||||
SetActiveChannel(userId string, channelId string) *model.AppError
|
||||
SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap)
|
||||
SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppError
|
||||
SetBotIconImageFromMultiPartFile(botUserId string, imageData *multipart.FileHeader) *model.AppError
|
||||
SetClientLicense(m map[string]string)
|
||||
SetContext(c context.Context)
|
||||
SetDefaultProfileImage(user *model.User) *model.AppError
|
||||
SetDiagnosticId(id string)
|
||||
SetIpAddress(s string)
|
||||
SetLicense(license *model.License) bool
|
||||
SetLog(l *mlog.Logger)
|
||||
SetPath(s string)
|
||||
SetPhase2PermissionsMigrationStatus(isComplete bool) error
|
||||
SetPluginKey(pluginId string, key string, value []byte) *model.AppError
|
||||
SetPluginKeyWithExpiry(pluginId string, key string, value []byte, expireInSeconds int64) *model.AppError
|
||||
SetPluginKeyWithOptions(pluginId string, key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
|
||||
SetPluginsEnvironment(pluginsEnvironment *plugin.Environment)
|
||||
SetProfileImage(userId string, imageData *multipart.FileHeader) *model.AppError
|
||||
SetProfileImageFromFile(userId string, file io.Reader) *model.AppError
|
||||
SetProfileImageFromMultiPartFile(userId string, file multipart.File) *model.AppError
|
||||
SetRequestId(s string)
|
||||
SetSamlIdpCertificateFromMetadata(data []byte) *model.AppError
|
||||
SetServer(srv *Server)
|
||||
SetSession(s *model.Session)
|
||||
SetStatusAwayIfNeeded(userId string, manual bool)
|
||||
SetStatusDoNotDisturb(userId string)
|
||||
SetStatusLastActivityAt(userId string, activityAt int64)
|
||||
SetStatusOffline(userId string, manual bool)
|
||||
SetStatusOnline(userId string, manual bool)
|
||||
SetStatusOutOfOffice(userId string)
|
||||
SetT(t goi18n.TranslateFunc)
|
||||
SetTeamIcon(teamId string, imageData *multipart.FileHeader) *model.AppError
|
||||
SetTeamIconFromFile(team *model.Team, file io.Reader) *model.AppError
|
||||
SetTeamIconFromMultiPartFile(teamId string, file multipart.File) *model.AppError
|
||||
SetUserAgent(s string)
|
||||
SetupInviteEmailRateLimiting() error
|
||||
ShutDownPlugins()
|
||||
Shutdown()
|
||||
SlackAddBotUser(teamId string, log *bytes.Buffer) *model.User
|
||||
SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel
|
||||
SlackAddPosts(teamId string, channel *model.Channel, posts []SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User)
|
||||
SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *bytes.Buffer) map[string]*model.User
|
||||
SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer)
|
||||
SlackUploadFile(slackPostFile *SlackFile, uploads map[string]*zip.File, teamId string, channelId string, userId string, slackTimestamp string) (*model.FileInfo, bool)
|
||||
SoftDeleteTeam(teamId string) *model.AppError
|
||||
Srv() *Server
|
||||
StartPushNotificationsHubWorkers()
|
||||
StopPushNotificationsHubWorkers()
|
||||
SubmitInteractiveDialog(request model.SubmitDialogRequest) (*model.SubmitDialogResponse, *model.AppError)
|
||||
SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError)
|
||||
SwitchEmailToOAuth(w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError)
|
||||
SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (string, *model.AppError)
|
||||
SwitchOAuthToEmail(email, password, requesterId string) (string, *model.AppError)
|
||||
SyncLdap()
|
||||
SyncPlugins() *model.AppError
|
||||
SyncPluginsActiveState()
|
||||
SyncRolesAndMembership(syncableID string, syncableType model.GroupSyncableType)
|
||||
SyncSyncableRoles(syncableID string, syncableType model.GroupSyncableType) *model.AppError
|
||||
T(translationID string, args ...interface{}) string
|
||||
TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError)
|
||||
TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError)
|
||||
TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError)
|
||||
TestElasticsearch(cfg *model.Config) *model.AppError
|
||||
TestEmail(userId string, cfg *model.Config) *model.AppError
|
||||
TestLdap() *model.AppError
|
||||
TestSiteURL(siteURL string) *model.AppError
|
||||
Timezones() *timezones.Timezones
|
||||
ToggleMuteChannel(channelId string, userId string) *model.ChannelMember
|
||||
TotalWebsocketConnections() int
|
||||
TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel)
|
||||
UnregisterPluginCommand(pluginId, teamId, trigger string)
|
||||
UnregisterPluginCommands(pluginId string)
|
||||
UpdateActive(user *model.User, active bool) (*model.User, *model.AppError)
|
||||
UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError)
|
||||
UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.AppError)
|
||||
UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError
|
||||
UpdateChannelMemberNotifyProps(data map[string]string, channelId string, userId string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelMemberSchemeRoles(channelId string, userId string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.ChannelMember, *model.AppError)
|
||||
UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError)
|
||||
UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||
UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError)
|
||||
UpdateConfig(f func(*model.Config))
|
||||
UpdateEphemeralPost(userId string, post *model.Post) *model.Post
|
||||
UpdateGroup(group *model.Group) (*model.Group, *model.AppError)
|
||||
UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
UpdateLastActivityAtIfNeeded(session model.Session)
|
||||
UpdateMfa(activate bool, userId, token string) *model.AppError
|
||||
UpdateMobileAppBadge(userId string)
|
||||
UpdateMobileAppBadgeSync(userId string) *model.AppError
|
||||
UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OauthProvider, service string) *model.AppError
|
||||
UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
UpdatePassword(user *model.User, newPassword string) *model.AppError
|
||||
UpdatePasswordAsUser(userId, currentPassword, newPassword string) *model.AppError
|
||||
UpdatePasswordByUserIdSendEmail(userId, newPassword, method string) *model.AppError
|
||||
UpdatePasswordSendEmail(user *model.User, newPassword, method string) *model.AppError
|
||||
UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError)
|
||||
UpdatePreferences(userId string, preferences model.Preferences) *model.AppError
|
||||
UpdateRole(role *model.Role) (*model.Role, *model.AppError)
|
||||
UpdateScheme(scheme *model.Scheme) (*model.Scheme, *model.AppError)
|
||||
UpdateSessionsIsGuest(userId string, isGuest bool)
|
||||
UpdateTeam(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateTeamMemberRoles(teamId string, userId string, newRoles string) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamMemberSchemeRoles(teamId string, userId string, isSchemeGuest bool, isSchemeUser bool, isSchemeAdmin bool) (*model.TeamMember, *model.AppError)
|
||||
UpdateTeamPrivacy(teamId string, teamType string, allowOpenInvite bool) *model.AppError
|
||||
UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
UpdateUserActive(userId string, active bool) *model.AppError
|
||||
UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError)
|
||||
UpdateUserAuth(userId string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError)
|
||||
UpdateUserNotifyProps(userId string, props map[string]string) (*model.User, *model.AppError)
|
||||
UpdateUserRoles(userId string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError)
|
||||
UpdateWebConnUserActivity(session model.Session, activityAt int64)
|
||||
UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError
|
||||
UploadFile(data []byte, channelId string, filename string) (*model.FileInfo, *model.AppError)
|
||||
UploadFileX(channelId, name string, input io.Reader, opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError)
|
||||
UploadFiles(teamId string, channelId string, userId string, files []io.ReadCloser, filenames []string, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||
UploadMultipartFiles(teamId string, channelId string, userId string, fileHeaders []*multipart.FileHeader, clientIds []string, now time.Time) (*model.FileUploadResponse, *model.AppError)
|
||||
UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError)
|
||||
UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError)
|
||||
UserAgent() string
|
||||
UserCanSeeOtherUser(userId string, otherUserId string) (bool, *model.AppError)
|
||||
UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError)
|
||||
ValidateAndSetLicenseBytes(b []byte)
|
||||
VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError
|
||||
VerifyPlugin(plugin, signature io.ReadSeeker) *model.AppError
|
||||
VerifyUserEmail(userId, email string) *model.AppError
|
||||
ViewChannel(view *model.ChannelView, userId string, currentSessionId string) (map[string]int64, *model.AppError)
|
||||
WaitForChannelMembership(channelId string, userId string)
|
||||
WriteFile(fr io.Reader, path string) (int64, *model.AppError)
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) GetAudits(userId string, limit int) (model.Audits, *model.AppError) {
|
||||
return a.Srv.Store.Audit().Get(userId, 0, limit)
|
||||
return a.Srv().Store.Audit().Get(userId, 0, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetAuditsPage(userId string, page int, perPage int) (model.Audits, *model.AppError) {
|
||||
return a.Srv.Store.Audit().Get(userId, page*perPage, perPage)
|
||||
return a.Srv().Store.Audit().Get(userId, page*perPage, perPage)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||
}
|
||||
|
||||
if err := a.checkUserPassword(user, password); err != nil {
|
||||
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
return passErr
|
||||
}
|
||||
return err
|
||||
|
|
@ -61,14 +61,14 @@ func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfa
|
|||
// If the mfaToken is not set, we assume the client used this as a pre-flight request to query the server
|
||||
// about the MFA state of the user in question
|
||||
if mfaToken != "" {
|
||||
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
return passErr
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||
return passErr
|
||||
}
|
||||
|
||||
|
|
@ -86,13 +86,13 @@ func (a *App) DoubleCheckPassword(user *model.User, password string) *model.AppE
|
|||
}
|
||||
|
||||
if err := a.checkUserPassword(user, password); err != nil {
|
||||
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); passErr != nil {
|
||||
return passErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if passErr := a.Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||
if passErr := a.Srv().Store.User().UpdateFailedPasswordAttempts(user.Id, 0); passErr != nil {
|
||||
return passErr
|
||||
}
|
||||
|
||||
|
|
@ -108,12 +108,12 @@ func (a *App) checkUserPassword(user *model.User, password string) *model.AppErr
|
|||
}
|
||||
|
||||
func (a *App) checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) {
|
||||
if a.Ldap == nil || ldapId == nil {
|
||||
if a.Ldap() == nil || ldapId == nil {
|
||||
err := model.NewAppError("doLdapAuthentication", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ldapUser, err := a.Ldap.DoLogin(*ldapId, password)
|
||||
ldapUser, err := a.Ldap().DoLogin(*ldapId, password)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusUnauthorized
|
||||
return nil, err
|
||||
|
|
@ -172,7 +172,7 @@ func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
mfaService := mfa.New(a, a.Srv.Store)
|
||||
mfaService := mfa.New(a, a.Srv().Store)
|
||||
ok, err := mfaService.ValidateToken(user.MfaSecret, token)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -209,7 +209,7 @@ func checkUserNotBot(user *model.User) *model.AppError {
|
|||
|
||||
func (a *App) authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
|
||||
license := a.License()
|
||||
ldapAvailable := *a.Config().LdapSettings.Enable && a.Ldap != nil && license != nil && *license.Features.LDAP
|
||||
ldapAvailable := *a.Config().LdapSettings.Enable && a.Ldap() != nil && license != nil && *license.Features.LDAP
|
||||
|
||||
if user.AuthService == model.USER_AUTH_SERVICE_LDAP {
|
||||
if !ldapAvailable {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) MakePermissionError(permission *model.Permission) *model.AppError {
|
||||
return model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+a.Session.UserId+", "+"permission="+permission.Id, http.StatusForbidden)
|
||||
return model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+a.Session().UserId+", "+"permission="+permission.Id, http.StatusForbidden)
|
||||
}
|
||||
|
||||
func (a *App) SessionHasPermissionTo(session model.Session, permission *model.Permission) bool {
|
||||
|
|
@ -39,7 +39,7 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||
return false
|
||||
}
|
||||
|
||||
ids, err := a.Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true, true)
|
||||
ids, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(session.UserId, true, true)
|
||||
|
||||
var channelRoles []string
|
||||
if err == nil {
|
||||
|
|
@ -64,14 +64,14 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
|
|||
}
|
||||
|
||||
func (a *App) SessionHasPermissionToChannelByPost(session model.Session, postId string, permission *model.Permission) bool {
|
||||
if channelMember, err := a.Srv.Store.Channel().GetMemberForPost(postId, session.UserId); err == nil {
|
||||
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postId, session.UserId); err == nil {
|
||||
|
||||
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if channel, err := a.Srv.Store.Channel().GetForPost(postId); err == nil {
|
||||
if channel, err := a.Srv().Store.Channel().GetForPost(postId); err == nil {
|
||||
if channel.TeamId != "" {
|
||||
return a.SessionHasPermissionToTeam(session, channel.TeamId, permission)
|
||||
}
|
||||
|
|
@ -161,13 +161,13 @@ func (a *App) HasPermissionToChannel(askingUserId string, channelId string, perm
|
|||
}
|
||||
|
||||
func (a *App) HasPermissionToChannelByPost(askingUserId string, postId string, permission *model.Permission) bool {
|
||||
if channelMember, err := a.Srv.Store.Channel().GetMemberForPost(postId, askingUserId); err == nil {
|
||||
if channelMember, err := a.Srv().Store.Channel().GetMemberForPost(postId, askingUserId); err == nil {
|
||||
if a.RolesGrantPermission(channelMember.GetRoles(), permission.Id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if channel, err := a.Srv.Store.Channel().GetForPost(postId); err == nil {
|
||||
if channel, err := a.Srv().Store.Channel().GetForPost(postId); err == nil {
|
||||
return a.HasPermissionToTeam(askingUserId, channel.TeamId, permission)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ func (a *App) CreateBasicUser(client *model.Client4) *model.AppError {
|
|||
if resp.Error != nil {
|
||||
return resp.Error
|
||||
}
|
||||
_, err := a.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err := a.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = a.Srv.Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam); err != nil {
|
||||
if _, err = a.Srv().Store.Team().SaveMember(&model.TeamMember{TeamId: basicteam.Id, UserId: ruser.Id}, *a.Config().TeamSettings.MaxUsersPerTeam); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -81,13 +81,13 @@ func (cfg *AutoUserCreator) createRandomUser() (*model.User, bool) {
|
|||
}
|
||||
|
||||
status := &model.Status{UserId: ruser.Id, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||
if err := cfg.app.Srv.Store.Status().SaveOrUpdate(status); err != nil {
|
||||
if err := cfg.app.Srv().Store.Status().SaveOrUpdate(status); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// We need to cheat to verify the user's email
|
||||
_, err := cfg.app.Srv.Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
_, err := cfg.app.Srv().Store.User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
|
|
|
|||
42
app/bot.go
42
app/bot.go
|
|
@ -17,20 +17,20 @@ import (
|
|||
|
||||
// CreateBot creates the given bot and corresponding user.
|
||||
func (a *App) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
||||
user, err := a.Srv.Store.User().Save(model.UserFromBot(bot))
|
||||
user, err := a.Srv().Store.User().Save(model.UserFromBot(bot))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bot.UserId = user.Id
|
||||
|
||||
savedBot, err := a.Srv.Store.Bot().Save(bot)
|
||||
savedBot, err := a.Srv().Store.Bot().Save(bot)
|
||||
if err != nil {
|
||||
a.Srv.Store.User().PermanentDelete(bot.UserId)
|
||||
a.Srv().Store.User().PermanentDelete(bot.UserId)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get the owner of the bot, if one exists. If not, don't send a message
|
||||
ownerUser, err := a.Srv.Store.User().Get(bot.OwnerId)
|
||||
ownerUser, err := a.Srv().Store.User().Get(bot.OwnerId)
|
||||
if err != nil && err.Id != store.MISSING_ACCOUNT_ERROR {
|
||||
mlog.Error(err.Error())
|
||||
return nil, err
|
||||
|
|
@ -50,7 +50,7 @@ func (a *App) CreateBot(bot *model.Bot) (*model.Bot, *model.AppError) {
|
|||
Message: T("api.bot.teams_channels.add_message_mobile"),
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostAsUser(botAddPost, a.Session.Id); err != nil {
|
||||
if _, err := a.CreatePostAsUser(botAddPost, a.Session().Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot,
|
|||
|
||||
bot.Patch(botPatch)
|
||||
|
||||
user, err := a.Srv.Store.User().Get(botUserId)
|
||||
user, err := a.Srv().Store.User().Get(botUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot,
|
|||
user.Email = patchedUser.Email
|
||||
user.FirstName = patchedUser.FirstName
|
||||
|
||||
userUpdate, err := a.Srv.Store.User().Update(user, true)
|
||||
userUpdate, err := a.Srv().Store.User().Update(user, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -86,22 +86,22 @@ func (a *App) PatchBot(botUserId string, botPatch *model.BotPatch) (*model.Bot,
|
|||
ruser := userUpdate.New
|
||||
a.sendUpdatedUserEvent(*ruser)
|
||||
|
||||
return a.Srv.Store.Bot().Update(bot)
|
||||
return a.Srv().Store.Bot().Update(bot)
|
||||
}
|
||||
|
||||
// GetBot returns the given bot.
|
||||
func (a *App) GetBot(botUserId string, includeDeleted bool) (*model.Bot, *model.AppError) {
|
||||
return a.Srv.Store.Bot().Get(botUserId, includeDeleted)
|
||||
return a.Srv().Store.Bot().Get(botUserId, includeDeleted)
|
||||
}
|
||||
|
||||
// GetBots returns the requested page of bots.
|
||||
func (a *App) GetBots(options *model.BotGetOptions) (model.BotList, *model.AppError) {
|
||||
return a.Srv.Store.Bot().GetAll(options)
|
||||
return a.Srv().Store.Bot().GetAll(options)
|
||||
}
|
||||
|
||||
// UpdateBotActive marks a bot as active or inactive, along with its corresponding user.
|
||||
func (a *App) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) {
|
||||
user, err := a.Srv.Store.User().Get(botUserId)
|
||||
user, err := a.Srv().Store.User().Get(botUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func (a *App) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model
|
|||
return nil, err
|
||||
}
|
||||
|
||||
bot, err := a.Srv.Store.Bot().Get(botUserId, true)
|
||||
bot, err := a.Srv().Store.Bot().Get(botUserId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ func (a *App) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model
|
|||
}
|
||||
|
||||
if changed {
|
||||
bot, err = a.Srv.Store.Bot().Update(bot)
|
||||
bot, err = a.Srv().Store.Bot().Update(bot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -136,11 +136,11 @@ func (a *App) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model
|
|||
|
||||
// PermanentDeleteBot permanently deletes a bot and its corresponding user.
|
||||
func (a *App) PermanentDeleteBot(botUserId string) *model.AppError {
|
||||
if err := a.Srv.Store.Bot().PermanentDelete(botUserId); err != nil {
|
||||
if err := a.Srv().Store.Bot().PermanentDelete(botUserId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.User().PermanentDelete(botUserId); err != nil {
|
||||
if err := a.Srv().Store.User().PermanentDelete(botUserId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -149,14 +149,14 @@ func (a *App) PermanentDeleteBot(botUserId string) *model.AppError {
|
|||
|
||||
// UpdateBotOwner changes a bot's owner to the given value.
|
||||
func (a *App) UpdateBotOwner(botUserId, newOwnerId string) (*model.Bot, *model.AppError) {
|
||||
bot, err := a.Srv.Store.Bot().Get(botUserId, true)
|
||||
bot, err := a.Srv().Store.Bot().Get(botUserId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bot.OwnerId = newOwnerId
|
||||
|
||||
bot, err = a.Srv.Store.Bot().Update(bot)
|
||||
bot, err = a.Srv().Store.Bot().Update(bot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ func (a *App) getDisableBotSysadminMessage(user *model.User, userBots model.BotL
|
|||
|
||||
// ConvertUserToBot converts a user to bot.
|
||||
func (a *App) ConvertUserToBot(user *model.User) (*model.Bot, *model.AppError) {
|
||||
return a.Srv.Store.Bot().Save(model.BotFromUser(user))
|
||||
return a.Srv().Store.Bot().Save(model.BotFromUser(user))
|
||||
}
|
||||
|
||||
// SetBotIconImageFromMultiPartFile sets LHS icon for a bot.
|
||||
|
|
@ -344,7 +344,7 @@ func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppEr
|
|||
}
|
||||
|
||||
bot.LastIconUpdate = model.GetMillis()
|
||||
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||
if _, err = a.Srv().Store.Bot().Update(bot); err != nil {
|
||||
return err
|
||||
}
|
||||
a.invalidateUserCacheAndPublish(botUserId)
|
||||
|
|
@ -364,12 +364,12 @@ func (a *App) DeleteBotIconImage(botUserId string) *model.AppError {
|
|||
return model.NewAppError("DeleteBotIconImage", "api.bot.delete_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err = a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||
if err = a.Srv().Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
bot.LastIconUpdate = int64(0)
|
||||
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||
if _, err = a.Srv().Store.Bot().Update(bot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
260
app/channel.go
260
app/channel.go
|
|
@ -66,7 +66,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
|||
var requestor *model.User
|
||||
if userRequestorId != "" {
|
||||
var err *model.AppError
|
||||
requestor, err = a.Srv.Store.User().Get(userRequestorId)
|
||||
requestor, err = a.Srv().Store.User().Get(userRequestorId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
|||
|
||||
var err *model.AppError
|
||||
for _, channelName := range a.DefaultChannelNames() {
|
||||
channel, channelErr := a.Srv.Store.Channel().GetByName(teamId, channelName, true)
|
||||
channel, channelErr := a.Srv().Store.Channel().GetByName(teamId, channelName, true)
|
||||
if channelErr != nil {
|
||||
err = channelErr
|
||||
continue
|
||||
|
|
@ -93,8 +93,8 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
|||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
}
|
||||
|
||||
_, err = a.Srv.Store.Channel().SaveMember(cm)
|
||||
if histErr := a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil {
|
||||
_, err = a.Srv().Store.Channel().SaveMember(cm)
|
||||
if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(histErr))
|
||||
return histErr
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
|||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err = a.indexUser(user); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod
|
|||
a.Publish(message)
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.indexUser(user); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -226,13 +226,13 @@ func (a *App) RenameChannel(channel *model.Channel, newChannelName string, newDi
|
|||
func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
|
||||
channel.DisplayName = strings.TrimSpace(channel.DisplayName)
|
||||
|
||||
sc, err := a.Srv.Store.Channel().Save(channel, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||
sc, err := a.Srv().Store.Channel().Save(channel, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if addMember {
|
||||
user, err := a.Srv.Store.User().Get(channel.CreatorId)
|
||||
user, err := a.Srv().Store.User().Get(channel.CreatorId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -246,10 +246,10 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
|||
NotifyProps: model.GetDefaultChannelNotifyProps(),
|
||||
}
|
||||
|
||||
if _, err := a.Srv.Store.Channel().SaveMember(cm); err != nil {
|
||||
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := a.Srv.Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil {
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -258,7 +258,7 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
|||
}
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ChannelHasBeenCreated(pluginContext, sc)
|
||||
|
|
@ -269,14 +269,14 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
|||
|
||||
if a.IsESIndexingEnabled() {
|
||||
if sc.Type == model.CHANNEL_OPEN {
|
||||
a.Srv.Go(func() {
|
||||
if err := a.Elasticsearch.IndexChannel(sc); err != nil {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Elasticsearch().IndexChannel(sc); err != nil {
|
||||
mlog.Error("Encountered error indexing channel", mlog.String("channel_id", sc.Id), mlog.Err(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
if addMember {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.indexUserFromId(channel.CreatorId); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", channel.CreatorId), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
|||
}
|
||||
|
||||
func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Channel, *model.AppError) {
|
||||
channel, err := a.Srv.Store.Channel().GetByName("", model.GetDMNameFromIds(userId, otherUserId), true)
|
||||
channel, err := a.Srv().Store.Channel().GetByName("", model.GetDMNameFromIds(userId, otherUserId), true)
|
||||
if err != nil {
|
||||
if err.Id == store.MISSING_CHANNEL_ERROR {
|
||||
channel, err = a.createDirectChannel(userId, otherUserId)
|
||||
|
|
@ -305,7 +305,7 @@ func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Chann
|
|||
a.InvalidateCacheForUser(otherUserId)
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.ChannelHasBeenCreated(pluginContext, channel)
|
||||
|
|
@ -315,7 +315,7 @@ func (a *App) GetOrCreateDirectChannel(userId, otherUserId string) (*model.Chann
|
|||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
for _, id := range []string{userId, otherUserId} {
|
||||
if indexUserErr := a.indexUserFromId(id); indexUserErr != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", id), mlog.Err(indexUserErr))
|
||||
|
|
@ -339,12 +339,12 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||
uc1 := make(chan store.StoreResult, 1)
|
||||
uc2 := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
uc1 <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc1)
|
||||
}()
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(otherUserId)
|
||||
user, err := a.Srv().Store.User().Get(otherUserId)
|
||||
uc2 <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc2)
|
||||
}()
|
||||
|
|
@ -361,7 +361,7 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||
}
|
||||
otherUser := result.Data.(*model.User)
|
||||
|
||||
channel, err := a.Srv.Store.Channel().CreateDirectChannel(user, otherUser)
|
||||
channel, err := a.Srv().Store.Channel().CreateDirectChannel(user, otherUser)
|
||||
if err != nil {
|
||||
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||
return channel, err
|
||||
|
|
@ -369,12 +369,12 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err = a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); err != nil {
|
||||
if err = a.Srv().Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
if userId != otherUserId {
|
||||
if err = a.Srv.Store.ChannelMemberHistory().LogJoinEvent(otherUserId, channel.Id, model.GetMillis()); err != nil {
|
||||
if err = a.Srv().Store.ChannelMemberHistory().LogJoinEvent(otherUserId, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -394,7 +394,7 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
|||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
_, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
_, err := a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
|
||||
// If the membership was found then return
|
||||
if err == nil {
|
||||
|
|
@ -432,7 +432,7 @@ func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||
a.Publish(message)
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
for _, id := range userIds {
|
||||
if err := a.indexUserFromId(id); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", id), mlog.Err(err))
|
||||
|
|
@ -449,7 +449,7 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
users, err := a.Srv.Store.User().GetProfileByIds(userIds, nil, true)
|
||||
users, err := a.Srv().Store.User().GetProfileByIds(userIds, nil, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -464,7 +464,7 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||
Type: model.CHANNEL_GROUP,
|
||||
}
|
||||
|
||||
channel, err := a.Srv.Store.Channel().Save(group, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||
channel, err := a.Srv().Store.Channel().Save(group, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||
if err != nil {
|
||||
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||
return channel, err
|
||||
|
|
@ -481,10 +481,10 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||
SchemeUser: !user.IsGuest(),
|
||||
}
|
||||
|
||||
if _, err := a.Srv.Store.Channel().SaveMember(cm); err != nil {
|
||||
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -498,7 +498,7 @@ func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError
|
|||
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
users, err := a.Srv.Store.User().GetProfileByIds(userIds, nil, true)
|
||||
users, err := a.Srv().Store.User().GetProfileByIds(userIds, nil, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -525,7 +525,7 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
|
|||
return nil, model.NewAppError("UpdateChannel", "api.channel.update_channel.invalid_character.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
_, err := a.Srv.Store.Channel().Update(channel)
|
||||
_, err := a.Srv().Store.Channel().Update(channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -537,8 +537,8 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
|
|||
a.Publish(messageWs)
|
||||
|
||||
if a.IsESIndexingEnabled() && channel.Type == model.CHANNEL_OPEN {
|
||||
a.Srv.Go(func() {
|
||||
if err := a.Elasticsearch.IndexChannel(channel); err != nil {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Elasticsearch().IndexChannel(channel); err != nil {
|
||||
mlog.Error("Encountered error indexing channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
|
@ -617,7 +617,7 @@ func (a *App) RestoreChannel(channel *model.Channel, userId string) (*model.Chan
|
|||
return nil, model.NewAppError("restoreChannel", "api.channel.restore_channel.restored.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Channel().Restore(channel.Id, model.GetMillis()); err != nil {
|
||||
if err := a.Srv().Store.Channel().Restore(channel.Id, model.GetMillis()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channel.DeleteAt = 0
|
||||
|
|
@ -627,7 +627,7 @@ func (a *App) RestoreChannel(channel *model.Channel, userId string) (*model.Chan
|
|||
message.Add("channel_id", channel.Id)
|
||||
a.Publish(message)
|
||||
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -772,7 +772,7 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userId string, newRoles
|
|||
|
||||
member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
|
||||
|
||||
member, err = a.Srv.Store.Channel().UpdateMember(member)
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -800,7 +800,7 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userId string, is
|
|||
member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_GUEST_ROLE_ID, model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles)
|
||||
}
|
||||
|
||||
member, err = a.Srv.Store.Channel().UpdateMember(member)
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -842,7 +842,7 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
|||
member.NotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] = ignoreChannelMentions
|
||||
}
|
||||
|
||||
member, err = a.Srv.Store.Channel().UpdateMember(member)
|
||||
member, err = a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -861,13 +861,13 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
|||
ohc := make(chan store.StoreResult, 1)
|
||||
|
||||
go func() {
|
||||
webhooks, err := a.Srv.Store.Webhook().GetIncomingByChannel(channel.Id)
|
||||
webhooks, err := a.Srv().Store.Webhook().GetIncomingByChannel(channel.Id)
|
||||
ihc <- store.StoreResult{Data: webhooks, Err: err}
|
||||
close(ihc)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
outgoingHooks, err := a.Srv.Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||
outgoingHooks, err := a.Srv().Store.Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||
ohc <- store.StoreResult{Data: outgoingHooks, Err: err}
|
||||
close(ohc)
|
||||
}()
|
||||
|
|
@ -875,7 +875,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
|||
var user *model.User
|
||||
if userId != "" {
|
||||
var err *model.AppError
|
||||
user, err = a.Srv.Store.User().Get(userId)
|
||||
user, err = a.Srv().Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -924,21 +924,21 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
|||
|
||||
now := model.GetMillis()
|
||||
for _, hook := range incomingHooks {
|
||||
if err := a.Srv.Store.Webhook().DeleteIncoming(hook.Id, now); err != nil {
|
||||
if err := a.Srv().Store.Webhook().DeleteIncoming(hook.Id, now); err != nil {
|
||||
mlog.Error("Encountered error deleting incoming webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||
}
|
||||
a.InvalidateCacheForWebhook(hook.Id)
|
||||
}
|
||||
|
||||
for _, hook := range outgoingHooks {
|
||||
if err := a.Srv.Store.Webhook().DeleteOutgoing(hook.Id, now); err != nil {
|
||||
if err := a.Srv().Store.Webhook().DeleteOutgoing(hook.Id, now); err != nil {
|
||||
mlog.Error("Encountered error deleting outgoing webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
deleteAt := model.GetMillis()
|
||||
|
||||
if err := a.Srv.Store.Channel().Delete(channel.Id, deleteAt); err != nil {
|
||||
if err := a.Srv().Store.Channel().Delete(channel.Id, deleteAt); err != nil {
|
||||
return err
|
||||
}
|
||||
a.InvalidateCacheForChannel(channel)
|
||||
|
|
@ -956,7 +956,7 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
|||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channelMember, err := a.Srv.Store.Channel().GetMember(channel.Id, user.Id)
|
||||
channelMember, err := a.Srv().Store.Channel().GetMember(channel.Id, user.Id)
|
||||
if err != nil {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, err
|
||||
|
|
@ -992,13 +992,13 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
|||
newMember.SchemeAdmin = userShouldBeAdmin
|
||||
}
|
||||
|
||||
if _, err = a.Srv.Store.Channel().SaveMember(newMember); err != nil {
|
||||
if _, err = a.Srv().Store.Channel().SaveMember(newMember); err != nil {
|
||||
mlog.Error("Failed to add member", mlog.String("user_id", user.Id), mlog.String("channel_id", channel.Id), mlog.Err(err))
|
||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
a.WaitForChannelMembership(channel.Id, user.Id)
|
||||
|
||||
if err = a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
if err = a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
|
||||
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1010,7 +1010,7 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
|
|||
}
|
||||
|
||||
func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
|
||||
teamMember, err := a.Srv.Store.Team().GetMember(channel.TeamId, user.Id)
|
||||
teamMember, err := a.Srv().Store.Team().GetMember(channel.TeamId, user.Id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -1033,7 +1033,7 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
|||
}
|
||||
|
||||
func (a *App) AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError) {
|
||||
if member, err := a.Srv.Store.Channel().GetMember(channel.Id, userId); err != nil {
|
||||
if member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId); err != nil {
|
||||
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1061,7 +1061,7 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
|
|||
}
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasJoinedChannel(pluginContext, cm, userRequestor)
|
||||
|
|
@ -1071,7 +1071,7 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
|
|||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.indexUser(user); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -1081,7 +1081,7 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
|
|||
if userRequestorId == "" || userId == userRequestorId {
|
||||
a.postJoinChannelMessage(user, channel)
|
||||
} else {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
a.PostAddToChannelMessage(userRequestor, user, channel, postRootId)
|
||||
})
|
||||
}
|
||||
|
|
@ -1092,7 +1092,7 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
|
|||
func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError {
|
||||
var profiles []*model.User
|
||||
options := &model.UserGetOptions{InTeamId: teamId, Page: 0, PerPage: 100}
|
||||
profiles, err := a.Srv.Store.User().GetProfiles(options)
|
||||
profiles, err := a.Srv().Store.User().GetProfiles(options)
|
||||
if err != nil {
|
||||
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": err.Error()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
|
@ -1118,7 +1118,7 @@ func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError
|
|||
}
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": err.Error()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
|
@ -1126,7 +1126,7 @@ func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError
|
|||
}
|
||||
|
||||
func (a *App) PostUpdateChannelHeaderMessage(userId string, channel *model.Channel, oldChannelHeader, newChannelHeader string) *model.AppError {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelHeaderMessage", "api.channel.post_update_channel_header_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1160,7 +1160,7 @@ func (a *App) PostUpdateChannelHeaderMessage(userId string, channel *model.Chann
|
|||
}
|
||||
|
||||
func (a *App) PostUpdateChannelPurposeMessage(userId string, channel *model.Channel, oldChannelPurpose string, newChannelPurpose string) *model.AppError {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1193,7 +1193,7 @@ func (a *App) PostUpdateChannelPurposeMessage(userId string, channel *model.Chan
|
|||
}
|
||||
|
||||
func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.Channel, oldChannelDisplayName, newChannelDisplayName string) *model.AppError {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
if err != nil {
|
||||
return model.NewAppError("PostUpdateChannelDisplayNameMessage", "api.channel.post_update_channel_displayname_message_and_forget.retrieve_user.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1220,7 +1220,7 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
|
|||
}
|
||||
|
||||
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
||||
channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
|
||||
channel, errCh := a.Srv().Store.Channel().Get(channelId, true)
|
||||
if errCh != nil {
|
||||
if errCh.Id == "store.sql_channel.get.existing.app_error" {
|
||||
errCh.StatusCode = http.StatusNotFound
|
||||
|
|
@ -1237,9 +1237,9 @@ func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool)
|
|||
var err *model.AppError
|
||||
|
||||
if includeDeleted {
|
||||
channel, err = a.Srv.Store.Channel().GetByNameIncludeDeleted(teamId, channelName, false)
|
||||
channel, err = a.Srv().Store.Channel().GetByNameIncludeDeleted(teamId, channelName, false)
|
||||
} else {
|
||||
channel, err = a.Srv.Store.Channel().GetByName(teamId, channelName, false)
|
||||
channel, err = a.Srv().Store.Channel().GetByName(teamId, channelName, false)
|
||||
}
|
||||
|
||||
if err != nil && err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||
|
|
@ -1256,7 +1256,7 @@ func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool)
|
|||
}
|
||||
|
||||
func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model.Channel, *model.AppError) {
|
||||
channels, err := a.Srv.Store.Channel().GetByNames(teamId, channelNames, true)
|
||||
channels, err := a.Srv().Store.Channel().GetByNames(teamId, channelNames, true)
|
||||
if err != nil {
|
||||
if err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
|
|
@ -1271,7 +1271,7 @@ func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model
|
|||
func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
var team *model.Team
|
||||
|
||||
team, err := a.Srv.Store.Team().GetByName(teamName)
|
||||
team, err := a.Srv().Store.Team().GetByName(teamName)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
|
|
@ -1280,9 +1280,9 @@ func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeD
|
|||
var result *model.Channel
|
||||
|
||||
if includeDeleted {
|
||||
result, err = a.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false)
|
||||
result, err = a.Srv().Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false)
|
||||
} else {
|
||||
result, err = a.Srv.Store.Channel().GetByName(team.Id, channelName, false)
|
||||
result, err = a.Srv().Store.Channel().GetByName(team.Id, channelName, false)
|
||||
}
|
||||
|
||||
if err != nil && err.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||
|
|
@ -1299,7 +1299,7 @@ func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeD
|
|||
}
|
||||
|
||||
func (a *App) GetChannelsForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetChannels(teamId, userId, includeDeleted)
|
||||
return a.Srv().Store.Channel().GetChannels(teamId, userId, includeDeleted)
|
||||
}
|
||||
|
||||
func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) {
|
||||
|
|
@ -1311,7 +1311,7 @@ func (a *App) GetAllChannels(page, perPage int, opts model.ChannelSearchOpts) (*
|
|||
NotAssociatedToGroup: opts.NotAssociatedToGroup,
|
||||
IncludeDeleted: opts.IncludeDeleted,
|
||||
}
|
||||
return a.Srv.Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts)
|
||||
return a.Srv().Store.Channel().GetAllChannels(page*perPage, perPage, storeOpts)
|
||||
}
|
||||
|
||||
func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.AppError) {
|
||||
|
|
@ -1323,35 +1323,35 @@ func (a *App) GetAllChannelsCount(opts model.ChannelSearchOpts) (int64, *model.A
|
|||
NotAssociatedToGroup: opts.NotAssociatedToGroup,
|
||||
IncludeDeleted: opts.IncludeDeleted,
|
||||
}
|
||||
return a.Srv.Store.Channel().GetAllChannelsCount(storeOpts)
|
||||
return a.Srv().Store.Channel().GetAllChannelsCount(storeOpts)
|
||||
}
|
||||
|
||||
func (a *App) GetDeletedChannels(teamId string, offset int, limit int, userId string) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetDeleted(teamId, offset, limit, userId)
|
||||
return a.Srv().Store.Channel().GetDeleted(teamId, offset, limit, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMoreChannels(teamId, userId, offset, limit)
|
||||
return a.Srv().Store.Channel().GetMoreChannels(teamId, userId, offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
||||
return a.Srv().Store.Channel().GetPublicChannelsByIdsForTeam(teamId, channelIds)
|
||||
}
|
||||
|
||||
func (a *App) GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
return a.Srv().Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
return a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMembers(channelId, page*perPage, perPage)
|
||||
return a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) {
|
||||
membersTimezones, err := a.Srv.Store.Channel().GetChannelMembersTimezones(channelId)
|
||||
membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1368,15 +1368,15 @@ func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.App
|
|||
}
|
||||
|
||||
func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMembersByIds(channelId, userIds)
|
||||
return a.Srv().Store.Channel().GetMembersByIds(channelId, userIds)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMembersForUser(teamId, userId)
|
||||
return a.Srv().Store.Channel().GetMembersForUser(teamId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
|
||||
m, err := a.Srv.Store.Channel().GetMembersForUserWithPagination(teamId, userId, page, perPage)
|
||||
m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(teamId, userId, page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1391,23 +1391,23 @@ func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page
|
|||
}
|
||||
|
||||
func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetMemberCount(channelId, true)
|
||||
return a.Srv().Store.Channel().GetMemberCount(channelId, true)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetGuestCount(channelId, true)
|
||||
return a.Srv().Store.Channel().GetGuestCount(channelId, true)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetPinnedPostCount(channelId, true)
|
||||
return a.Srv().Store.Channel().GetPinnedPostCount(channelId, true)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetChannelCounts(teamId, userId)
|
||||
return a.Srv().Store.Channel().GetChannelCounts(teamId, userId)
|
||||
}
|
||||
|
||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||
channelUnread, err := a.Srv.Store.Channel().GetChannelUnread(channelId, userId)
|
||||
channelUnread, err := a.Srv().Store.Channel().GetChannelUnread(channelId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1423,12 +1423,12 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
|
|||
userChan := make(chan store.StoreResult, 1)
|
||||
memberChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
go func() {
|
||||
member, err := a.Srv.Store.Channel().GetMember(channel.Id, userId)
|
||||
member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId)
|
||||
memberChan <- store.StoreResult{Data: member, Err: err}
|
||||
close(memberChan)
|
||||
}()
|
||||
|
|
@ -1456,7 +1456,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
|
|||
}
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasJoinedChannel(pluginContext, cm, nil)
|
||||
|
|
@ -1466,7 +1466,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
|
|||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.indexUser(user); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -1527,21 +1527,21 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
|
|||
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||
sc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv.Store.Channel().Get(channelId, true)
|
||||
channel, err := a.Srv().Store.Channel().Get(channelId, true)
|
||||
sc <- store.StoreResult{Data: channel, Err: err}
|
||||
close(sc)
|
||||
}()
|
||||
|
||||
uc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(userId)
|
||||
user, err := a.Srv().Store.User().Get(userId)
|
||||
uc <- store.StoreResult{Data: user, Err: err}
|
||||
close(uc)
|
||||
}()
|
||||
|
||||
mcc := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.Channel().GetMemberCount(channelId, false)
|
||||
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, false)
|
||||
mcc <- store.StoreResult{Data: count, Err: err}
|
||||
close(mcc)
|
||||
}()
|
||||
|
|
@ -1581,7 +1581,7 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
a.postLeaveChannelMessage(user, channel)
|
||||
})
|
||||
|
||||
|
|
@ -1684,7 +1684,7 @@ func (a *App) postRemoveFromChannelMessage(removerUserId string, removedUser *mo
|
|||
}
|
||||
|
||||
func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string, channel *model.Channel) *model.AppError {
|
||||
user, err := a.Srv.Store.User().Get(userIdToRemove)
|
||||
user, err := a.Srv().Store.User().Get(userIdToRemove)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1711,10 +1711,10 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
|||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Channel().RemoveMember(channel.Id, userIdToRemove); err != nil {
|
||||
if err := a.Srv().Store.Channel().RemoveMember(channel.Id, userIdToRemove); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.Srv.Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil {
|
||||
if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -1744,7 +1744,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
|||
actorUser, _ = a.GetUser(removerUserId)
|
||||
}
|
||||
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLeftChannel(pluginContext, cm, actorUser)
|
||||
|
|
@ -1754,7 +1754,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
|
|||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.indexUserFromId(userIdToRemove); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", userIdToRemove), mlog.Err(err))
|
||||
}
|
||||
|
|
@ -1790,7 +1790,7 @@ func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string,
|
|||
if userIdToRemove == removerUserId {
|
||||
a.postLeaveChannelMessage(user, channel)
|
||||
} else {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
a.postRemoveFromChannelMessage(removerUserId, user, channel)
|
||||
})
|
||||
}
|
||||
|
|
@ -1800,7 +1800,7 @@ func (a *App) RemoveUserFromChannel(userIdToRemove string, removerUserId string,
|
|||
|
||||
func (a *App) GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) {
|
||||
// Get total number of channels on current team
|
||||
list, err := a.Srv.Store.Channel().GetTeamChannels(teamId)
|
||||
list, err := a.Srv().Store.Channel().GetTeamChannels(teamId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -1833,7 +1833,7 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError
|
|||
}
|
||||
|
||||
func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError {
|
||||
if _, err := a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil {
|
||||
if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -1865,7 +1865,7 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string) (*model.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
channelUnread, updateErr := a.Srv.Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions)
|
||||
channelUnread, updateErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions)
|
||||
if updateErr != nil {
|
||||
return channelUnread, updateErr
|
||||
}
|
||||
|
|
@ -1883,14 +1883,14 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string) (*model.
|
|||
}
|
||||
|
||||
func (a *App) esAutocompleteChannels(teamId, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
|
||||
channelIds, err := a.Elasticsearch.SearchChannels(teamId, term)
|
||||
channelIds, err := a.Elasticsearch().SearchChannels(teamId, term)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
channelList := model.ChannelList{}
|
||||
if len(channelIds) > 0 {
|
||||
channels, err := a.Srv.Store.Channel().GetChannelsByIds(channelIds)
|
||||
channels, err := a.Srv().Store.Channel().GetChannelsByIds(channelIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1919,7 +1919,7 @@ func (a *App) AutocompleteChannels(teamId string, term string) (*model.ChannelLi
|
|||
}
|
||||
|
||||
if !a.IsESAutocompletionEnabled() || err != nil {
|
||||
channelList, err = a.Srv.Store.Channel().AutocompleteInTeam(teamId, term, includeDeleted)
|
||||
channelList, err = a.Srv().Store.Channel().AutocompleteInTeam(teamId, term, includeDeleted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1933,7 +1933,7 @@ func (a *App) AutocompleteChannelsForSearch(teamId string, userId string, term s
|
|||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
||||
return a.Srv().Store.Channel().AutocompleteInTeamForSearch(teamId, userId, term, includeDeleted)
|
||||
}
|
||||
|
||||
// SearchAllChannels returns a list of channels, the total count of the results of the search (if the paginate search option is true), and an error.
|
||||
|
|
@ -1952,7 +1952,7 @@ func (a *App) SearchAllChannels(term string, opts model.ChannelSearchOpts) (*mod
|
|||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().SearchAllChannels(term, storeOpts)
|
||||
return a.Srv().Store.Channel().SearchAllChannels(term, storeOpts)
|
||||
}
|
||||
|
||||
func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
|
||||
|
|
@ -1960,13 +1960,13 @@ func (a *App) SearchChannels(teamId string, term string) (*model.ChannelList, *m
|
|||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().SearchInTeam(teamId, term, includeDeleted)
|
||||
return a.Srv().Store.Channel().SearchInTeam(teamId, term, includeDeleted)
|
||||
}
|
||||
|
||||
func (a *App) SearchArchivedChannels(teamId string, term string, userId string) (*model.ChannelList, *model.AppError) {
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().SearchArchivedInTeam(teamId, term, userId)
|
||||
return a.Srv().Store.Channel().SearchArchivedInTeam(teamId, term, userId)
|
||||
}
|
||||
|
||||
func (a *App) SearchChannelsForUser(userId, teamId, term string) (*model.ChannelList, *model.AppError) {
|
||||
|
|
@ -1974,7 +1974,7 @@ func (a *App) SearchChannelsForUser(userId, teamId, term string) (*model.Channel
|
|||
|
||||
term = strings.TrimSpace(term)
|
||||
|
||||
return a.Srv.Store.Channel().SearchForUserInTeam(userId, teamId, term, includeDeleted)
|
||||
return a.Srv().Store.Channel().SearchForUserInTeam(userId, teamId, term, includeDeleted)
|
||||
}
|
||||
|
||||
func (a *App) SearchGroupChannels(userId, term string) (*model.ChannelList, *model.AppError) {
|
||||
|
|
@ -1982,7 +1982,7 @@ func (a *App) SearchGroupChannels(userId, term string) (*model.ChannelList, *mod
|
|||
return &model.ChannelList{}, nil
|
||||
}
|
||||
|
||||
channelList, err := a.Srv.Store.Channel().SearchGroupChannels(userId, term)
|
||||
channelList, err := a.Srv().Store.Channel().SearchGroupChannels(userId, term)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1991,7 +1991,7 @@ func (a *App) SearchGroupChannels(userId, term string) (*model.ChannelList, *mod
|
|||
|
||||
func (a *App) SearchChannelsUserNotIn(teamId string, userId string, term string) (*model.ChannelList, *model.AppError) {
|
||||
term = strings.TrimSpace(term)
|
||||
return a.Srv.Store.Channel().SearchMore(userId, teamId, term)
|
||||
return a.Srv().Store.Channel().SearchMore(userId, teamId, term)
|
||||
}
|
||||
|
||||
func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSessionId string) (map[string]int64, *model.AppError) {
|
||||
|
|
@ -1999,13 +1999,13 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
|||
channelsToClearPushNotifications := []string{}
|
||||
if *a.Config().EmailSettings.SendPushNotifications {
|
||||
for _, channelId := range channelIds {
|
||||
channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
|
||||
channel, errCh := a.Srv().Store.Channel().Get(channelId, true)
|
||||
if errCh != nil {
|
||||
mlog.Warn("Failed to get channel", mlog.Err(errCh))
|
||||
continue
|
||||
}
|
||||
|
||||
member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
member, err := a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to get membership", mlog.Err(err))
|
||||
continue
|
||||
|
|
@ -2017,13 +2017,13 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
|||
notify = user.NotifyProps[model.PUSH_NOTIFY_PROP]
|
||||
}
|
||||
if notify == model.USER_NOTIFY_ALL {
|
||||
if count, err := a.Srv.Store.User().GetAnyUnreadPostCountForChannel(userId, channelId); err == nil {
|
||||
if count, err := a.Srv().Store.User().GetAnyUnreadPostCountForChannel(userId, channelId); err == nil {
|
||||
if count > 0 {
|
||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
||||
}
|
||||
}
|
||||
} else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT {
|
||||
if count, err := a.Srv.Store.User().GetUnreadCountForChannel(userId, channelId); err == nil {
|
||||
if count, err := a.Srv().Store.User().GetUnreadCountForChannel(userId, channelId); err == nil {
|
||||
if count > 0 {
|
||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
||||
}
|
||||
|
|
@ -2031,7 +2031,7 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
|||
}
|
||||
}
|
||||
}
|
||||
times, err := a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId)
|
||||
times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -2072,33 +2072,33 @@ func (a *App) ViewChannel(view *model.ChannelView, userId string, currentSession
|
|||
}
|
||||
|
||||
func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
||||
profiles, err := a.Srv.Store.User().GetAllProfilesInChannel(channel.Id, false)
|
||||
profiles, err := a.Srv().Store.User().GetAllProfilesInChannel(channel.Id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Post().PermanentDeleteByChannel(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Post().PermanentDeleteByChannel(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Webhook().PermanentDeleteOutgoingByChannel(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Channel().PermanentDelete(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Channel().PermanentDelete(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if a.IsESIndexingEnabled() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
for _, user := range profiles {
|
||||
if err := a.indexUser(user); err != nil {
|
||||
mlog.Error("Encountered error indexing user", mlog.String("user_id", user.Id), mlog.Err(err))
|
||||
|
|
@ -2106,8 +2106,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
|||
}
|
||||
})
|
||||
if channel.Type == model.CHANNEL_OPEN {
|
||||
a.Srv.Go(func() {
|
||||
if err := a.Elasticsearch.DeleteChannel(channel); err != nil {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Elasticsearch().DeleteChannel(channel); err != nil {
|
||||
mlog.Error("Encountered error deleting channel", mlog.String("channel_id", channel.Id), mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
|
@ -2121,7 +2121,7 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
|
|||
// is in progress, and therefore should not be used from the API without first fixing this potential race condition.
|
||||
func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.User, removeDeactivatedMembers bool) *model.AppError {
|
||||
if removeDeactivatedMembers {
|
||||
if err := a.Srv.Store.Channel().RemoveAllDeactivatedMembers(channel.Id); err != nil {
|
||||
if err := a.Srv().Store.Channel().RemoveAllDeactivatedMembers(channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -2149,13 +2149,13 @@ func (a *App) MoveChannel(team *model.Team, channel *model.Channel, user *model.
|
|||
}
|
||||
|
||||
// keep instance of the previous team
|
||||
previousTeam, err := a.Srv.Store.Team().Get(channel.TeamId)
|
||||
previousTeam, err := a.Srv().Store.Team().Get(channel.TeamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
channel.TeamId = team.Id
|
||||
if _, err := a.Srv.Store.Channel().Update(channel); err != nil {
|
||||
if _, err := a.Srv().Store.Channel().Update(channel); err != nil {
|
||||
return err
|
||||
}
|
||||
a.postChannelMoveMessage(user, channel, previousTeam)
|
||||
|
|
@ -2183,11 +2183,11 @@ func (a *App) postChannelMoveMessage(user *model.User, channel *model.Channel, p
|
|||
}
|
||||
|
||||
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||
return a.Srv.Store.Channel().GetPinnedPosts(channelId)
|
||||
return a.Srv().Store.Channel().GetPinnedPosts(channelId)
|
||||
}
|
||||
|
||||
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {
|
||||
member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
|
||||
member, err := a.Srv().Store.Channel().GetMember(channelId, userId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2198,7 +2198,7 @@ func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelM
|
|||
member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
|
||||
}
|
||||
|
||||
a.Srv.Store.Channel().UpdateMember(member)
|
||||
a.Srv().Store.Channel().UpdateMember(member)
|
||||
return member
|
||||
}
|
||||
|
||||
|
|
@ -2271,9 +2271,9 @@ func (a *App) ClearChannelMembersCache(channelID string) {
|
|||
page := 0
|
||||
|
||||
for {
|
||||
channelMembers, err := a.Srv.Store.Channel().GetMembers(channelID, page, perPage)
|
||||
channelMembers, err := a.Srv().Store.Channel().GetMembers(channelID, page, perPage)
|
||||
if err != nil {
|
||||
a.Log.Warn("error clearing cache for channel members", mlog.String("channel_id", channelID))
|
||||
a.Log().Warn("error clearing cache for channel members", mlog.String("channel_id", channelID))
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,10 +146,10 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi
|
|||
defer th.TearDown()
|
||||
|
||||
// figure out the initial number of users in town square
|
||||
channel, err := th.App.Srv.Store.Channel().GetByName(th.BasicTeam.Id, "town-square", true)
|
||||
channel, err := th.App.Srv().Store.Channel().GetByName(th.BasicTeam.Id, "town-square", true)
|
||||
require.Nil(t, err)
|
||||
townSquareChannelId := channel.Id
|
||||
users, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
users, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, err)
|
||||
initialNumTownSquareUsers := len(users)
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordTownSquare(t *testi
|
|||
th.App.JoinDefaultChannels(th.BasicTeam.Id, user, false, "")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, townSquareChannelId)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, initialNumTownSquareUsers+1)
|
||||
|
||||
|
|
@ -177,10 +177,10 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing
|
|||
defer th.TearDown()
|
||||
|
||||
// figure out the initial number of users in off-topic
|
||||
channel, err := th.App.Srv.Store.Channel().GetByName(th.BasicTeam.Id, "off-topic", true)
|
||||
channel, err := th.App.Srv().Store.Channel().GetByName(th.BasicTeam.Id, "off-topic", true)
|
||||
require.Nil(t, err)
|
||||
offTopicChannelId := channel.Id
|
||||
users, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
users, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, err)
|
||||
initialNumTownSquareUsers := len(users)
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ func TestJoinDefaultChannelsCreatesChannelMemberHistoryRecordOffTopic(t *testing
|
|||
th.App.JoinDefaultChannels(th.BasicTeam.Id, user, false, "")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, offTopicChannelId)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, initialNumTownSquareUsers+1)
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ func TestCreateChannelPublicCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
publicChannel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 1)
|
||||
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
|
||||
|
|
@ -248,7 +248,7 @@ func TestCreateChannelPrivateCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
privateChannel := th.createChannel(th.BasicTeam, model.CHANNEL_PRIVATE)
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, privateChannel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, privateChannel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 1)
|
||||
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
|
||||
|
|
@ -291,7 +291,7 @@ func TestCreateGroupChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
channel, err := th.App.CreateGroupChannel(groupUserIds, th.BasicUser.Id)
|
||||
|
||||
require.Nil(t, err, "Failed to create group channel.")
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 3)
|
||||
|
||||
|
|
@ -316,7 +316,7 @@ func TestCreateDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
channel, err := th.App.GetOrCreateDirectChannel(user1.Id, user2.Id)
|
||||
require.Nil(t, err, "Failed to create direct channel.")
|
||||
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 2)
|
||||
|
||||
|
|
@ -344,7 +344,7 @@ func TestGetDirectChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
require.Nil(t, err, "Failed to create direct channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for both users
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 2)
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
require.Nil(t, err, "Failed to add user to channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 2)
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
|
|
@ -396,7 +396,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
|
||||
// a user creates a channel
|
||||
publicChannel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 1)
|
||||
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
|
||||
|
|
@ -407,7 +407,7 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
|
|||
if err := th.App.LeaveChannel(publicChannel.Id, th.BasicUser.Id); err != nil {
|
||||
t.Fatal("Failed to remove user from channel. Error: " + err.Message)
|
||||
}
|
||||
histories = store.Must(th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)).([]*model.ChannelMemberHistoryResult)
|
||||
histories = store.Must(th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)).([]*model.ChannelMemberHistoryResult)
|
||||
assert.Len(t, histories, 1)
|
||||
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
|
||||
assert.Equal(t, publicChannel.Id, histories[0].ChannelId)
|
||||
|
|
@ -492,7 +492,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
|||
require.Nil(t, err, "Failed to add user to channel.")
|
||||
|
||||
// there should be a ChannelMemberHistory record for the user
|
||||
histories, err := th.App.Srv.Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, channel.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Len(t, histories, 2)
|
||||
channelMemberHistoryUserIds := make([]string, 0)
|
||||
|
|
@ -502,7 +502,7 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
|
|||
}
|
||||
assert.Equal(t, groupUserIds, channelMemberHistoryUserIds)
|
||||
|
||||
postList, err := th.App.Srv.Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channel.Id, Page: 0, PerPage: 1}, false)
|
||||
postList, err := th.App.Srv().Store.Post().GetPosts(model.GetPostsOptions{ChannelId: channel.Id, Page: 0, PerPage: 1}, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
if assert.Len(t, postList.Order, 1) {
|
||||
|
|
|
|||
|
|
@ -31,23 +31,23 @@ func (a *App) NewClusterDiscoveryService() *ClusterDiscoveryService {
|
|||
}
|
||||
|
||||
func (me *ClusterDiscoveryService) Start() {
|
||||
err := me.app.Srv.Store.ClusterDiscovery().Cleanup()
|
||||
err := me.app.Srv().Store.ClusterDiscovery().Cleanup()
|
||||
if err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to cleanup the outdated cluster discovery information", mlog.Err(err))
|
||||
}
|
||||
|
||||
exists, err := me.app.Srv.Store.ClusterDiscovery().Exists(&me.ClusterDiscovery)
|
||||
exists, err := me.app.Srv().Store.ClusterDiscovery().Exists(&me.ClusterDiscovery)
|
||||
if err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to check if row exists", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()), mlog.Err(err))
|
||||
} else {
|
||||
if exists {
|
||||
if _, err := me.app.Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); err != nil {
|
||||
if _, err := me.app.Srv().Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to start clean", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := me.app.Srv.Store.ClusterDiscovery().Save(&me.ClusterDiscovery); err != nil {
|
||||
if err := me.app.Srv().Store.ClusterDiscovery().Save(&me.ClusterDiscovery); err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to save", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()), mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ func (me *ClusterDiscoveryService) Start() {
|
|||
ticker := time.NewTicker(DISCOVERY_SERVICE_WRITE_PING)
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
if _, err := me.app.Srv.Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); err != nil {
|
||||
if _, err := me.app.Srv().Store.ClusterDiscovery().Delete(&me.ClusterDiscovery); err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to cleanup", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()), mlog.Err(err))
|
||||
}
|
||||
mlog.Debug("ClusterDiscoveryService ping writer stopped", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()))
|
||||
|
|
@ -66,7 +66,7 @@ func (me *ClusterDiscoveryService) Start() {
|
|||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if err := me.app.Srv.Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); err != nil {
|
||||
if err := me.app.Srv().Store.ClusterDiscovery().SetLastPingAt(&me.ClusterDiscovery); err != nil {
|
||||
mlog.Error("ClusterDiscoveryService failed to write ping", mlog.String("ClusterDiscovery", me.ClusterDiscovery.ToJson()), mlog.Err(err))
|
||||
}
|
||||
case <-me.stop:
|
||||
|
|
@ -81,16 +81,16 @@ func (me *ClusterDiscoveryService) Stop() {
|
|||
}
|
||||
|
||||
func (a *App) IsLeader() bool {
|
||||
if a.License() != nil && *a.Config().ClusterSettings.Enable && a.Cluster != nil {
|
||||
return a.Cluster.IsLeader()
|
||||
if a.License() != nil && *a.Config().ClusterSettings.Enable && a.Cluster() != nil {
|
||||
return a.Cluster().IsLeader()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *App) GetClusterId() string {
|
||||
if a.Cluster == nil {
|
||||
if a.Cluster() == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return a.Cluster.GetClusterId()
|
||||
return a.Cluster().GetClusterId()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@ import (
|
|||
// NewLocalCacheLayer. Be careful to not have duplicated handlers here and
|
||||
// there.
|
||||
func (a *App) registerAllClusterMessageHandlers() {
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.clusterPublishHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.clusterUpdateStatusHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.clusterInvalidateAllCachesHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.clusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.clusterInvalidateCacheForChannelByNameHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.clusterInvalidateCacheForUserHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER_TEAMS, a.clusterInvalidateCacheForUserTeamsHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, a.clusterClearSessionCacheForUserHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_ALL_USERS, a.clusterClearSessionCacheForAllUsersHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INSTALL_PLUGIN, a.clusterInstallPluginHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_REMOVE_PLUGIN, a.clusterRemovePluginHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_BUSY_STATE_CHANGED, a.clusterBusyStateChgHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.clusterPublishHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.clusterUpdateStatusHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.clusterInvalidateAllCachesHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.clusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.clusterInvalidateCacheForChannelByNameHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.clusterInvalidateCacheForUserHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER_TEAMS, a.clusterInvalidateCacheForUserTeamsHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, a.clusterClearSessionCacheForUserHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_ALL_USERS, a.clusterClearSessionCacheForAllUsersHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INSTALL_PLUGIN, a.clusterInstallPluginHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_REMOVE_PLUGIN, a.clusterRemovePluginHandler)
|
||||
a.Cluster().RegisterClusterMessageHandler(model.CLUSTER_EVENT_BUSY_STATE_CHANGED, a.clusterBusyStateChgHandler)
|
||||
}
|
||||
|
||||
func (a *App) clusterPublishHandler(msg *model.ClusterMessage) {
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
|
|||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableCommands {
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func (a *App) ListTeamCommands(teamId string) ([]*model.Command, *model.AppError
|
|||
return nil, model.NewAppError("ListTeamCommands", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Command().GetByTeam(teamId)
|
||||
return a.Srv().Store.Command().GetByTeam(teamId)
|
||||
}
|
||||
|
||||
func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
|
|
@ -138,7 +138,7 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
|
|||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableCommands {
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -217,26 +217,26 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
|||
|
||||
chanChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv.Store.Channel().Get(args.ChannelId, true)
|
||||
channel, err := a.Srv().Store.Channel().Get(args.ChannelId, true)
|
||||
chanChan <- store.StoreResult{Data: channel, Err: err}
|
||||
close(chanChan)
|
||||
}()
|
||||
|
||||
teamChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
team, err := a.Srv.Store.Team().Get(args.TeamId)
|
||||
team, err := a.Srv().Store.Team().Get(args.TeamId)
|
||||
teamChan <- store.StoreResult{Data: team, Err: err}
|
||||
close(teamChan)
|
||||
}()
|
||||
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(args.UserId)
|
||||
user, err := a.Srv().Store.User().Get(args.UserId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(args.TeamId)
|
||||
teamCmds, err := a.Srv().Store.Command().GetByTeam(args.TeamId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
@ -327,7 +327,7 @@ func (a *App) doCommandRequest(cmd *model.Command, p url.Values) (*model.Command
|
|||
}
|
||||
|
||||
// Send the request
|
||||
resp, err := a.HTTPService.MakeClient(false).Do(req)
|
||||
resp, err := a.HTTPService().MakeClient(false).Do(req)
|
||||
if err != nil {
|
||||
return cmd, nil, model.NewAppError("command", "api.command.execute_command.failed.app_error", map[string]interface{}{"Trigger": cmd.Trigger}, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
|
@ -454,7 +454,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
|||
|
||||
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
||||
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(cmd.TeamId)
|
||||
teamCmds, err := a.Srv().Store.Command().GetByTeam(cmd.TeamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -472,7 +472,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
|||
}
|
||||
}
|
||||
|
||||
return a.Srv.Store.Command().Save(cmd)
|
||||
return a.Srv().Store.Command().Save(cmd)
|
||||
}
|
||||
|
||||
func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
|
||||
|
|
@ -480,7 +480,7 @@ func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
|
|||
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
cmd, err := a.Srv.Store.Command().Get(commandId)
|
||||
cmd, err := a.Srv().Store.Command().Get(commandId)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
|
|
@ -503,13 +503,13 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
|
|||
updatedCmd.CreatorId = oldCmd.CreatorId
|
||||
updatedCmd.TeamId = oldCmd.TeamId
|
||||
|
||||
return a.Srv.Store.Command().Update(updatedCmd)
|
||||
return a.Srv().Store.Command().Update(updatedCmd)
|
||||
}
|
||||
|
||||
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
|
||||
command.TeamId = team.Id
|
||||
|
||||
_, err := a.Srv.Store.Command().Update(command)
|
||||
_, err := a.Srv().Store.Command().Update(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -524,7 +524,7 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
|
|||
|
||||
cmd.Token = model.NewId()
|
||||
|
||||
return a.Srv.Store.Command().Update(cmd)
|
||||
return a.Srv().Store.Command().Update(cmd)
|
||||
}
|
||||
|
||||
func (a *App) DeleteCommand(commandId string) *model.AppError {
|
||||
|
|
@ -532,5 +532,5 @@ func (a *App) DeleteCommand(commandId string) *model.AppError {
|
|||
return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Command().Delete(commandId, model.GetMillis())
|
||||
return a.Srv().Store.Command().Delete(commandId, model.GetMillis())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func (me *EchoProvider) DoCommand(a *App, args *model.CommandArgs, message strin
|
|||
}
|
||||
|
||||
echoSem <- true
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
defer func() { <-echoSem }()
|
||||
post := &model.Post{}
|
||||
post.ChannelId = args.ChannelId
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func (a *App) setCollapsePreference(args *model.CommandArgs, isCollapse bool) *m
|
|||
Value: strconv.FormatBool(isCollapse),
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Preference().Save(&model.Preferences{pref}); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&model.Preferences{pref}); err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_expand_collapse.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func (me *groupmsgProvider) DoCommand(a *App, args *model.CommandArgs, message s
|
|||
for _, username := range users {
|
||||
username = strings.TrimSpace(username)
|
||||
username = strings.TrimPrefix(username, "@")
|
||||
targetUser, err := a.Srv.Store.User().GetByUsername(username)
|
||||
targetUser, err := a.Srv().Store.User().GetByUsername(username)
|
||||
if err != nil {
|
||||
invalidUsernames = append(invalidUsernames, username)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func (me *InviteProvider) DoCommand(a *App, args *model.CommandArgs, message str
|
|||
targetUsername := splitMessage[0]
|
||||
targetUsername = strings.TrimPrefix(targetUsername, "@")
|
||||
|
||||
userProfile, err := a.Srv.Store.User().GetByUsername(targetUsername)
|
||||
userProfile, err := a.Srv().Store.User().GetByUsername(targetUsername)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func (me *JoinProvider) DoCommand(a *App, args *model.CommandArgs, message strin
|
|||
channelName = message[1:]
|
||||
}
|
||||
|
||||
channel, err := a.Srv.Store.Channel().GetByName(args.TeamId, channelName, true)
|
||||
channel, err := a.Srv().Store.Channel().GetByName(args.TeamId, channelName, true)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ func (me *LoadTestProvider) SetupCommand(a *App, args *model.CommandArgs, messag
|
|||
}
|
||||
}
|
||||
} else {
|
||||
team, err := a.Srv.Store.Team().Get(args.TeamId)
|
||||
team, err := a.Srv().Store.Team().Get(args.TeamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ func (me *LoadTestProvider) UsersCommand(a *App, args *model.CommandArgs, messag
|
|||
usersr = utils.Range{Begin: 2, End: 5}
|
||||
}
|
||||
|
||||
team, err := a.Srv.Store.Team().Get(args.TeamId)
|
||||
team, err := a.Srv().Store.Team().Get(args.TeamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
|
|||
channelsr = utils.Range{Begin: 2, End: 5}
|
||||
}
|
||||
|
||||
team, err := a.Srv.Store.Team().Get(args.TeamId)
|
||||
team, err := a.Srv().Store.Team().Get(args.TeamId)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ func (me *LoadTestProvider) ChannelsCommand(a *App, args *model.CommandArgs, mes
|
|||
func (me *LoadTestProvider) ThreadedPostCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
var usernames []string
|
||||
options := &model.UserGetOptions{InTeamId: args.TeamId, Page: 0, PerPage: 1000}
|
||||
if profileUsers, err := a.Srv.Store.User().GetProfiles(options); err == nil {
|
||||
if profileUsers, err := a.Srv().Store.User().GetProfiles(options); err == nil {
|
||||
usernames = make([]string, len(profileUsers))
|
||||
i := 0
|
||||
for _, userprof := range profileUsers {
|
||||
|
|
@ -360,7 +360,7 @@ func (me *LoadTestProvider) PostsCommand(a *App, args *model.CommandArgs, messag
|
|||
|
||||
var usernames []string
|
||||
options := &model.UserGetOptions{InTeamId: args.TeamId, Page: 0, PerPage: 1000}
|
||||
if profileUsers, err := a.Srv.Store.User().GetProfiles(options); err == nil {
|
||||
if profileUsers, err := a.Srv().Store.User().GetProfiles(options); err == nil {
|
||||
usernames = make([]string, len(profileUsers))
|
||||
i := 0
|
||||
for _, userprof := range profileUsers {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string
|
|||
targetUsername = strings.SplitN(message, " ", 2)[0]
|
||||
targetUsername = strings.TrimPrefix(targetUsername, "@")
|
||||
|
||||
userProfile, err := a.Srv.Store.User().GetByUsername(targetUsername)
|
||||
userProfile, err := a.Srv().Store.User().GetByUsername(targetUsername)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.missing.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
|
|
@ -71,7 +71,7 @@ func (me *msgProvider) DoCommand(a *App, args *model.CommandArgs, message string
|
|||
channelName := model.GetDMNameFromIds(args.UserId, userProfile.Id)
|
||||
|
||||
targetChannelId := ""
|
||||
if channel, channelErr := a.Srv.Store.Channel().GetByName(args.TeamId, channelName, true); channelErr != nil {
|
||||
if channel, channelErr := a.Srv().Store.Channel().GetByName(args.TeamId, channelName, true); channelErr != nil {
|
||||
if channelErr.Id == "store.sql_channel.get_by_name.missing.app_error" {
|
||||
if !a.SessionHasPermissionTo(args.Session, model.PERMISSION_CREATE_DIRECT_CHANNEL) {
|
||||
return &model.CommandResponse{Text: args.T("api.command_msg.permission.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func (me *MuteProvider) DoCommand(a *App, args *model.CommandArgs, message strin
|
|||
}
|
||||
|
||||
if len(channelName) > 0 && len(message) > 0 {
|
||||
channel, _ = a.Srv.Store.Channel().GetByName(channel.TeamId, channelName, true)
|
||||
channel, _ = a.Srv().Store.Channel().GetByName(channel.TeamId, channelName, true)
|
||||
|
||||
if channel == nil {
|
||||
return &model.CommandResponse{Text: args.T("api.command_mute.error", map[string]interface{}{"Channel": channelName}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
|
|
@ -66,7 +66,7 @@ func (me *MuteProvider) DoCommand(a *App, args *model.CommandArgs, message strin
|
|||
}
|
||||
|
||||
// Invalidate cache to allow cache lookups while sending notifications
|
||||
a.Srv.Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channel.Id)
|
||||
a.Srv().Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channel.Id)
|
||||
|
||||
// Direct and Group messages won't have a nice channel title, omit it
|
||||
if channel.Type == model.CHANNEL_DIRECT || channel.Type == model.CHANNEL_GROUP {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func doCommand(a *App, args *model.CommandArgs, message string) *model.CommandRe
|
|||
targetUsername = strings.SplitN(message, " ", 2)[0]
|
||||
targetUsername = strings.TrimPrefix(targetUsername, "@")
|
||||
|
||||
userProfile, err := a.Srv.Store.User().GetByUsername(targetUsername)
|
||||
userProfile, err := a.Srv().Store.User().GetByUsername(targetUsername)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{
|
||||
|
|
|
|||
|
|
@ -376,9 +376,9 @@ func TestDoCommandRequest(t *testing.T) {
|
|||
}))
|
||||
defer server.Close()
|
||||
|
||||
th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = 100 * time.Millisecond
|
||||
th.App.HTTPService().(*httpservice.HTTPServiceImpl).RequestTimeout = 100 * time.Millisecond
|
||||
defer func() {
|
||||
th.App.HTTPService.(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout
|
||||
th.App.HTTPService().(*httpservice.HTTPServiceImpl).RequestTimeout = httpservice.RequestTimeout
|
||||
}()
|
||||
|
||||
_, _, err := th.App.doCommandRequest(&model.Command{URL: server.URL}, url.Values{})
|
||||
|
|
|
|||
|
|
@ -16,34 +16,34 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model
|
|||
return nil, model.NewAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Compliance().GetAll(page*perPage, perPage)
|
||||
return a.Srv().Store.Compliance().GetAll(page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
|
||||
if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance == nil {
|
||||
if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance() == nil {
|
||||
return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
job.Type = model.COMPLIANCE_TYPE_ADHOC
|
||||
|
||||
job, err := a.Srv.Store.Compliance().Save(job)
|
||||
job, err := a.Srv().Store.Compliance().Save(job)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a.Srv.Go(func() {
|
||||
a.Compliance.RunComplianceJob(job)
|
||||
a.Srv().Go(func() {
|
||||
a.Compliance().RunComplianceJob(job)
|
||||
})
|
||||
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
|
||||
if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance == nil {
|
||||
if license := a.License(); !*a.Config().ComplianceSettings.Enable || license == nil || !*license.Features.Compliance || a.Compliance() == nil {
|
||||
return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Compliance().Get(reportId)
|
||||
return a.Srv().Store.Compliance().Get(reportId)
|
||||
}
|
||||
|
||||
func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func (s *Server) Config() *model.Config {
|
|||
}
|
||||
|
||||
func (a *App) Config() *model.Config {
|
||||
return a.Srv.Config()
|
||||
return a.Srv().Config()
|
||||
}
|
||||
|
||||
func (s *Server) EnvironmentConfig() map[string]interface{} {
|
||||
|
|
@ -43,7 +43,7 @@ func (s *Server) EnvironmentConfig() map[string]interface{} {
|
|||
}
|
||||
|
||||
func (a *App) EnvironmentConfig() map[string]interface{} {
|
||||
return a.Srv.EnvironmentConfig()
|
||||
return a.Srv().EnvironmentConfig()
|
||||
}
|
||||
|
||||
func (s *Server) UpdateConfig(f func(*model.Config)) {
|
||||
|
|
@ -56,7 +56,7 @@ func (s *Server) UpdateConfig(f func(*model.Config)) {
|
|||
}
|
||||
|
||||
func (a *App) UpdateConfig(f func(*model.Config)) {
|
||||
a.Srv.UpdateConfig(f)
|
||||
a.Srv().UpdateConfig(f)
|
||||
}
|
||||
|
||||
func (s *Server) ReloadConfig() error {
|
||||
|
|
@ -68,19 +68,19 @@ func (s *Server) ReloadConfig() error {
|
|||
}
|
||||
|
||||
func (a *App) ReloadConfig() error {
|
||||
return a.Srv.ReloadConfig()
|
||||
return a.Srv().ReloadConfig()
|
||||
}
|
||||
|
||||
func (a *App) ClientConfig() map[string]string {
|
||||
return a.Srv.clientConfig
|
||||
return a.Srv().clientConfig
|
||||
}
|
||||
|
||||
func (a *App) ClientConfigHash() string {
|
||||
return a.Srv.clientConfigHash
|
||||
return a.Srv().clientConfigHash
|
||||
}
|
||||
|
||||
func (a *App) LimitedClientConfig() map[string]string {
|
||||
return a.Srv.limitedClientConfig
|
||||
return a.Srv().limitedClientConfig
|
||||
}
|
||||
|
||||
// Registers a function with a given listener to be called when the config is reloaded and may have changed. The function
|
||||
|
|
@ -91,7 +91,7 @@ func (s *Server) AddConfigListener(listener func(*model.Config, *model.Config))
|
|||
}
|
||||
|
||||
func (a *App) AddConfigListener(listener func(*model.Config, *model.Config)) string {
|
||||
return a.Srv.AddConfigListener(listener)
|
||||
return a.Srv().AddConfigListener(listener)
|
||||
}
|
||||
|
||||
// Removes a listener function by the unique ID returned when AddConfigListener was called
|
||||
|
|
@ -100,20 +100,20 @@ func (s *Server) RemoveConfigListener(id string) {
|
|||
}
|
||||
|
||||
func (a *App) RemoveConfigListener(id string) {
|
||||
a.Srv.RemoveConfigListener(id)
|
||||
a.Srv().RemoveConfigListener(id)
|
||||
}
|
||||
|
||||
// ensurePostActionCookieSecret ensures that the key for encrypting PostActionCookie exists
|
||||
// and future calls to PostActionCookieSecret will always return a valid key, same on all
|
||||
// servers in the cluster
|
||||
func (a *App) ensurePostActionCookieSecret() error {
|
||||
if a.Srv.postActionCookieSecret != nil {
|
||||
if a.Srv().postActionCookieSecret != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var secret *model.SystemPostActionCookieSecret
|
||||
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &secret); err != nil {
|
||||
return err
|
||||
|
|
@ -139,7 +139,7 @@ func (a *App) ensurePostActionCookieSecret() error {
|
|||
}
|
||||
system.Value = string(v)
|
||||
// If we were able to save the key, use it, otherwise log the error.
|
||||
if appErr := a.Srv.Store.System().Save(system); appErr != nil {
|
||||
if appErr := a.Srv().Store.System().Save(system); appErr != nil {
|
||||
mlog.Error("Failed to save PostActionCookieSecret", mlog.Err(appErr))
|
||||
} else {
|
||||
secret = newSecret
|
||||
|
|
@ -149,7 +149,7 @@ func (a *App) ensurePostActionCookieSecret() error {
|
|||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if secret == nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -159,20 +159,20 @@ func (a *App) ensurePostActionCookieSecret() error {
|
|||
}
|
||||
}
|
||||
|
||||
a.Srv.postActionCookieSecret = secret.Secret
|
||||
a.Srv().postActionCookieSecret = secret.Secret
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureAsymmetricSigningKey ensures that an asymmetric signing key exists and future calls to
|
||||
// AsymmetricSigningKey will always return a valid signing key.
|
||||
func (a *App) ensureAsymmetricSigningKey() error {
|
||||
if a.Srv.asymmetricSigningKey != nil {
|
||||
if a.Srv().asymmetricSigningKey != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var key *model.SystemAsymmetricSigningKey
|
||||
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &key); err != nil {
|
||||
return err
|
||||
|
|
@ -202,7 +202,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
|||
}
|
||||
system.Value = string(v)
|
||||
// If we were able to save the key, use it, otherwise log the error.
|
||||
if appErr := a.Srv.Store.System().Save(system); appErr != nil {
|
||||
if appErr := a.Srv().Store.System().Save(system); appErr != nil {
|
||||
mlog.Error("Failed to save AsymmetricSigningKey", mlog.Err(appErr))
|
||||
} else {
|
||||
key = newKey
|
||||
|
|
@ -212,7 +212,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
|||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if key == nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
value, err := a.Srv().Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
|||
default:
|
||||
return fmt.Errorf("unknown curve: " + key.ECDSAKey.Curve)
|
||||
}
|
||||
a.Srv.asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
a.Srv().asymmetricSigningKey = &ecdsa.PrivateKey{
|
||||
PublicKey: ecdsa.PublicKey{
|
||||
Curve: curve,
|
||||
X: key.ECDSAKey.X,
|
||||
|
|
@ -247,7 +247,7 @@ func (a *App) ensureInstallationDate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
installDate, err := a.Srv.Store.User().InferSystemInstallDate()
|
||||
installDate, err := a.Srv().Store.User().InferSystemInstallDate()
|
||||
var installationDate int64
|
||||
if err == nil && installDate > 0 {
|
||||
installationDate = installDate
|
||||
|
|
@ -255,7 +255,7 @@ func (a *App) ensureInstallationDate() error {
|
|||
installationDate = utils.MillisFromTime(time.Now())
|
||||
}
|
||||
|
||||
err = a.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
err = a.Srv().Store.System().SaveOrUpdate(&model.System{
|
||||
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
||||
Value: strconv.FormatInt(installationDate, 10),
|
||||
})
|
||||
|
|
@ -271,7 +271,7 @@ func (s *Server) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
|||
}
|
||||
|
||||
func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey {
|
||||
return a.Srv.AsymmetricSigningKey()
|
||||
return a.Srv().AsymmetricSigningKey()
|
||||
}
|
||||
|
||||
func (s *Server) PostActionCookieSecret() []byte {
|
||||
|
|
@ -279,7 +279,7 @@ func (s *Server) PostActionCookieSecret() []byte {
|
|||
}
|
||||
|
||||
func (a *App) PostActionCookieSecret() []byte {
|
||||
return a.Srv.PostActionCookieSecret()
|
||||
return a.Srv().PostActionCookieSecret()
|
||||
}
|
||||
|
||||
func (a *App) regenerateClientConfig() {
|
||||
|
|
@ -303,9 +303,9 @@ func (a *App) regenerateClientConfig() {
|
|||
}
|
||||
|
||||
clientConfigJSON, _ := json.Marshal(clientConfig)
|
||||
a.Srv.clientConfig = clientConfig
|
||||
a.Srv.limitedClientConfig = limitedClientConfig
|
||||
a.Srv.clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
a.Srv().clientConfig = clientConfig
|
||||
a.Srv().limitedClientConfig = limitedClientConfig
|
||||
a.Srv().clientConfigHash = fmt.Sprintf("%x", md5.Sum(clientConfigJSON))
|
||||
}
|
||||
|
||||
func (a *App) GetCookieDomain() string {
|
||||
|
|
@ -356,7 +356,7 @@ func (a *App) LimitedClientConfigWithComputed() map[string]string {
|
|||
|
||||
// GetConfigFile proxies access to the given configuration file to the underlying config store.
|
||||
func (a *App) GetConfigFile(name string) ([]byte, error) {
|
||||
data, err := a.Srv.configStore.GetFile(name)
|
||||
data, err := a.Srv().configStore.GetFile(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get config file %s", name)
|
||||
}
|
||||
|
|
@ -379,25 +379,25 @@ func (a *App) GetEnvironmentConfig() map[string]interface{} {
|
|||
|
||||
// SaveConfig replaces the active configuration, optionally notifying cluster peers.
|
||||
func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
|
||||
oldCfg, err := a.Srv.configStore.Set(newCfg)
|
||||
oldCfg, err := a.Srv().configStore.Set(newCfg)
|
||||
if errors.Cause(err) == config.ErrReadOnlyConfiguration {
|
||||
return model.NewAppError("saveConfig", "ent.cluster.save_config.error", nil, err.Error(), http.StatusForbidden)
|
||||
} else if err != nil {
|
||||
return model.NewAppError("saveConfig", "app.save_config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if a.Metrics != nil {
|
||||
if a.Metrics() != nil {
|
||||
if *a.Config().MetricsSettings.Enable {
|
||||
a.Metrics.StartServer()
|
||||
a.Metrics().StartServer()
|
||||
} else {
|
||||
a.Metrics.StopServer()
|
||||
a.Metrics().StopServer()
|
||||
}
|
||||
}
|
||||
|
||||
if a.Cluster != nil {
|
||||
newCfg = a.Srv.configStore.RemoveEnvironmentOverrides(newCfg)
|
||||
oldCfg = a.Srv.configStore.RemoveEnvironmentOverrides(oldCfg)
|
||||
err := a.Cluster.ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
|
||||
if a.Cluster() != nil {
|
||||
newCfg = a.Srv().configStore.RemoveEnvironmentOverrides(newCfg)
|
||||
oldCfg = a.Srv().configStore.RemoveEnvironmentOverrides(oldCfg)
|
||||
err := a.Cluster().ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -407,17 +407,17 @@ func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bo
|
|||
}
|
||||
|
||||
func (a *App) IsESIndexingEnabled() bool {
|
||||
return a.Elasticsearch != nil && *a.Config().ElasticsearchSettings.EnableIndexing
|
||||
return a.Elasticsearch() != nil && *a.Config().ElasticsearchSettings.EnableIndexing
|
||||
}
|
||||
|
||||
func (a *App) IsESSearchEnabled() bool {
|
||||
esInterface := a.Elasticsearch
|
||||
esInterface := a.Elasticsearch()
|
||||
license := a.License()
|
||||
return esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && license != nil && *license.Features.Elasticsearch
|
||||
}
|
||||
|
||||
func (a *App) IsESAutocompletionEnabled() bool {
|
||||
esInterface := a.Elasticsearch
|
||||
esInterface := a.Elasticsearch()
|
||||
license := a.License()
|
||||
return esInterface != nil && *a.Config().ElasticsearchSettings.EnableAutocomplete && license != nil && *license.Features.Elasticsearch
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ func TestEnsureInstallationDate(t *testing.T) {
|
|||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
sqlStore := th.App.Srv.Store.User().(*sqlstore.SqlUserStore)
|
||||
sqlStore := th.App.Srv().Store.User().(*sqlstore.SqlUserStore)
|
||||
sqlStore.GetMaster().Exec("DELETE FROM Users")
|
||||
|
||||
for _, createAt := range tc.UsersCreationDates {
|
||||
|
|
@ -122,9 +122,9 @@ func TestEnsureInstallationDate(t *testing.T) {
|
|||
}
|
||||
|
||||
if tc.PrevInstallationDate == nil {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
} else {
|
||||
th.App.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
th.App.Srv().Store.System().SaveOrUpdate(&model.System{
|
||||
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
||||
Value: strconv.FormatInt(*tc.PrevInstallationDate, 10),
|
||||
})
|
||||
|
|
@ -137,7 +137,7 @@ func TestEnsureInstallationDate(t *testing.T) {
|
|||
} else {
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, err := th.App.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
data, err := th.App.Srv().Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
assert.Nil(t, err)
|
||||
value, _ := strconv.ParseInt(data.Value, 10, 64)
|
||||
assert.True(t, *tc.ExpectedInstallationDate <= value && *tc.ExpectedInstallationDate+1000 >= value)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) GetDataRetentionPolicy() (*model.DataRetentionPolicy, *model.AppError) {
|
||||
if a.DataRetention == nil {
|
||||
if a.DataRetention() == nil {
|
||||
return nil, model.NewAppError("App.GetDataRetentionPolicy", "ent.data_retention.generic.license.error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.DataRetention.GetPolicy()
|
||||
return a.DataRetention().GetPolicy()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (a *App) SendDailyDiagnostics() {
|
|||
|
||||
func (a *App) sendDailyDiagnostics(override bool) {
|
||||
if *a.Config().LogSettings.EnableDiagnostics && a.IsLeader() && (!strings.Contains(SEGMENT_KEY, "placeholder") || override) {
|
||||
a.Srv.initDiagnostics("")
|
||||
a.Srv().initDiagnostics("")
|
||||
a.trackActivity()
|
||||
a.trackConfig()
|
||||
a.trackLicense()
|
||||
|
|
@ -80,7 +80,7 @@ func (a *App) sendDailyDiagnostics(override bool) {
|
|||
}
|
||||
|
||||
func (a *App) SendDiagnostic(event string, properties map[string]interface{}) {
|
||||
a.Srv.diagnosticClient.Enqueue(analytics.Track{
|
||||
a.Srv().diagnosticClient.Enqueue(analytics.Track{
|
||||
Event: event,
|
||||
UserId: a.DiagnosticId(),
|
||||
Properties: properties,
|
||||
|
|
@ -137,78 +137,78 @@ func (a *App) trackActivity() {
|
|||
|
||||
activeUsersDailyCountChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
count, err := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
activeUsersDailyCountChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(activeUsersDailyCountChan)
|
||||
}()
|
||||
|
||||
activeUsersMonthlyCountChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
count, err := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
count, err := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
|
||||
activeUsersMonthlyCountChan <- store.StoreResult{Data: count, Err: err}
|
||||
close(activeUsersMonthlyCountChan)
|
||||
}()
|
||||
|
||||
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
||||
if count, err := a.Srv().Store.User().Count(model.UserCountOptions{IncludeDeleted: true}); err == nil {
|
||||
userCount = count
|
||||
}
|
||||
|
||||
if count, err := a.Srv.Store.User().Count(model.UserCountOptions{IncludeBotAccounts: true, ExcludeRegularUsers: true}); err == nil {
|
||||
if count, err := a.Srv().Store.User().Count(model.UserCountOptions{IncludeBotAccounts: true, ExcludeRegularUsers: true}); err == nil {
|
||||
botAccountsCount = count
|
||||
}
|
||||
|
||||
if iucr, err := a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); err == nil {
|
||||
if iucr, err := a.Srv().Store.User().AnalyticsGetInactiveUsersCount(); err == nil {
|
||||
inactiveUserCount = iucr
|
||||
}
|
||||
|
||||
teamCount, err := a.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
teamCount, err := a.Srv().Store.Team().AnalyticsTeamCount(false)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
if ucc, err := a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); err == nil {
|
||||
if ucc, err := a.Srv().Store.Channel().AnalyticsTypeCount("", "O"); err == nil {
|
||||
publicChannelCount = ucc
|
||||
}
|
||||
|
||||
if pcc, err := a.Srv.Store.Channel().AnalyticsTypeCount("", "P"); err == nil {
|
||||
if pcc, err := a.Srv().Store.Channel().AnalyticsTypeCount("", "P"); err == nil {
|
||||
privateChannelCount = pcc
|
||||
}
|
||||
|
||||
if dcc, err := a.Srv.Store.Channel().AnalyticsTypeCount("", "D"); err == nil {
|
||||
if dcc, err := a.Srv().Store.Channel().AnalyticsTypeCount("", "D"); err == nil {
|
||||
directChannelCount = dcc
|
||||
}
|
||||
|
||||
if duccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); err == nil {
|
||||
if duccr, err := a.Srv().Store.Channel().AnalyticsDeletedTypeCount("", "O"); err == nil {
|
||||
deletedPublicChannelCount = duccr
|
||||
}
|
||||
|
||||
if dpccr, err := a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); err == nil {
|
||||
if dpccr, err := a.Srv().Store.Channel().AnalyticsDeletedTypeCount("", "P"); err == nil {
|
||||
deletedPrivateChannelCount = dpccr
|
||||
}
|
||||
|
||||
postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||
postsCount, _ = a.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
|
||||
postCountsOptions := &model.AnalyticsPostCountsOptions{TeamId: "", BotsOnly: false, YesterdayOnly: true}
|
||||
postCountsYesterday, _ := a.Srv.Store.Post().AnalyticsPostCountsByDay(postCountsOptions)
|
||||
postCountsYesterday, _ := a.Srv().Store.Post().AnalyticsPostCountsByDay(postCountsOptions)
|
||||
postsCountPreviousDay = 0
|
||||
if len(postCountsYesterday) > 0 {
|
||||
postsCountPreviousDay = int64(postCountsYesterday[0].Value)
|
||||
}
|
||||
|
||||
postCountsOptions = &model.AnalyticsPostCountsOptions{TeamId: "", BotsOnly: true, YesterdayOnly: true}
|
||||
botPostCountsYesterday, _ := a.Srv.Store.Post().AnalyticsPostCountsByDay(postCountsOptions)
|
||||
botPostCountsYesterday, _ := a.Srv().Store.Post().AnalyticsPostCountsByDay(postCountsOptions)
|
||||
botPostsCountPreviousDay = 0
|
||||
if len(botPostCountsYesterday) > 0 {
|
||||
botPostsCountPreviousDay = int64(botPostCountsYesterday[0].Value)
|
||||
}
|
||||
|
||||
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")
|
||||
slashCommandsCount, _ = a.Srv().Store.Command().AnalyticsCommandCount("")
|
||||
|
||||
if c, err := a.Srv.Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||
if c, err := a.Srv().Store.Webhook().AnalyticsIncomingCount(""); err == nil {
|
||||
incomingWebhooksCount = c
|
||||
}
|
||||
|
||||
outgoingWebhooksCount, _ = a.Srv.Store.Webhook().AnalyticsOutgoingCount("")
|
||||
outgoingWebhooksCount, _ = a.Srv().Store.Webhook().AnalyticsOutgoingCount("")
|
||||
|
||||
var activeUsersDailyCount int64
|
||||
if r := <-activeUsersDailyCountChan; r.Err == nil {
|
||||
|
|
@ -788,7 +788,7 @@ func (a *App) trackServer() {
|
|||
"operating_system": runtime.GOOS,
|
||||
}
|
||||
|
||||
if scr, err := a.Srv.Store.User().AnalyticsGetSystemAdminCount(); err == nil {
|
||||
if scr, err := a.Srv().Store.User().AnalyticsGetSystemAdminCount(); err == nil {
|
||||
data["system_admins"] = scr
|
||||
}
|
||||
|
||||
|
|
@ -797,12 +797,12 @@ func (a *App) trackServer() {
|
|||
|
||||
func (a *App) trackPermissions() {
|
||||
phase1Complete := false
|
||||
if _, err := a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); err == nil {
|
||||
if _, err := a.Srv().Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); err == nil {
|
||||
phase1Complete = true
|
||||
}
|
||||
|
||||
phase2Complete := false
|
||||
if _, err := a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); err == nil {
|
||||
if _, err := a.Srv().Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); err == nil {
|
||||
phase2Complete = true
|
||||
}
|
||||
|
||||
|
|
@ -894,7 +894,7 @@ func (a *App) trackPermissions() {
|
|||
channelGuestPermissions = strings.Join(role.Permissions, " ")
|
||||
}
|
||||
|
||||
count, _ := a.Srv.Store.Team().AnalyticsGetTeamCountForScheme(scheme.Id)
|
||||
count, _ := a.Srv().Store.Team().AnalyticsGetTeamCountForScheme(scheme.Id)
|
||||
|
||||
a.SendDiagnostic(TRACK_PERMISSIONS_TEAM_SCHEMES, map[string]interface{}{
|
||||
"scheme_id": scheme.Id,
|
||||
|
|
@ -913,45 +913,45 @@ func (a *App) trackPermissions() {
|
|||
func (a *App) trackElasticsearch() {
|
||||
data := map[string]interface{}{}
|
||||
|
||||
if a.Elasticsearch != nil && a.Elasticsearch.GetVersion() != 0 {
|
||||
data["elasticsearch_server_version"] = a.Elasticsearch.GetVersion()
|
||||
if a.Elasticsearch() != nil && a.Elasticsearch().GetVersion() != 0 {
|
||||
data["elasticsearch_server_version"] = a.Elasticsearch().GetVersion()
|
||||
}
|
||||
|
||||
a.SendDiagnostic(TRACK_ELASTICSEARCH, data)
|
||||
}
|
||||
|
||||
func (a *App) trackGroups() {
|
||||
groupCount, err := a.Srv.Store.Group().GroupCount()
|
||||
groupCount, err := a.Srv().Store.Group().GroupCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
groupTeamCount, err := a.Srv.Store.Group().GroupTeamCount()
|
||||
groupTeamCount, err := a.Srv().Store.Group().GroupTeamCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
groupChannelCount, err := a.Srv.Store.Group().GroupChannelCount()
|
||||
groupChannelCount, err := a.Srv().Store.Group().GroupChannelCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
groupSyncedTeamCount, err := a.Srv.Store.Team().GroupSyncedTeamCount()
|
||||
groupSyncedTeamCount, err := a.Srv().Store.Team().GroupSyncedTeamCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
groupSyncedChannelCount, err := a.Srv.Store.Channel().GroupSyncedChannelCount()
|
||||
groupSyncedChannelCount, err := a.Srv().Store.Channel().GroupSyncedChannelCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
groupMemberCount, err := a.Srv.Store.Group().GroupMemberCount()
|
||||
groupMemberCount, err := a.Srv().Store.Group().GroupMemberCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
distinctGroupMemberCount, err := a.Srv.Store.Group().DistinctGroupMemberCount()
|
||||
distinctGroupMemberCount, err := a.Srv().Store.Group().DistinctGroupMemberCount()
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func (a *App) DownloadFromURL(downloadURL string) ([]byte, error) {
|
|||
return nil, errors.Errorf("insecure url not allowed %s", downloadURL)
|
||||
}
|
||||
|
||||
client := a.HTTPService.MakeClient(true)
|
||||
client := a.HTTPService().MakeClient(true)
|
||||
client.Timeout = HTTP_REQUEST_TIMEOUT
|
||||
|
||||
resp, err := client.Get(downloadURL)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
|
|||
}
|
||||
}
|
||||
|
||||
esI := a.Elasticsearch
|
||||
esI := a.Elasticsearch()
|
||||
if esI == nil {
|
||||
err := model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
|
||||
return err
|
||||
|
|
@ -31,7 +31,7 @@ func (a *App) TestElasticsearch(cfg *model.Config) *model.AppError {
|
|||
}
|
||||
|
||||
func (a *App) PurgeElasticsearchIndexes() *model.AppError {
|
||||
esI := a.Elasticsearch
|
||||
esI := a.Elasticsearch()
|
||||
if esI == nil {
|
||||
err := model.NewAppError("PurgeElasticsearchIndexes", "ent.elasticsearch.test_config.license.error", nil, "", http.StatusNotImplemented)
|
||||
return err
|
||||
|
|
|
|||
30
app/email.go
30
app/email.go
|
|
@ -55,7 +55,7 @@ func (a *App) SetupInviteEmailRateLimiting() error {
|
|||
return errors.Wrap(err, "Unable to setup email rate limiting GCRA rate limiter.")
|
||||
}
|
||||
|
||||
a.Srv.EmailRateLimiter = rateLimiter
|
||||
a.Srv().EmailRateLimiter = rateLimiter
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -302,18 +302,18 @@ func (a *App) SendMfaChangeEmail(email string, activated bool, locale, siteURL s
|
|||
}
|
||||
|
||||
func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId string, invites []string, siteURL string) {
|
||||
if a.Srv.EmailRateLimiter == nil {
|
||||
a.Log.Error("Email invite not sent, rate limiting could not be setup.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id))
|
||||
if a.Srv().EmailRateLimiter == nil {
|
||||
a.Log().Error("Email invite not sent, rate limiting could not be setup.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id))
|
||||
return
|
||||
}
|
||||
rateLimited, result, err := a.Srv.EmailRateLimiter.RateLimit(senderUserId, len(invites))
|
||||
rateLimited, result, err := a.Srv().EmailRateLimiter.RateLimit(senderUserId, len(invites))
|
||||
if err != nil {
|
||||
a.Log.Error("Error rate limiting invite email.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(err))
|
||||
a.Log().Error("Error rate limiting invite email.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
if rateLimited {
|
||||
a.Log.Error("Invite emails rate limited.",
|
||||
a.Log().Error("Invite emails rate limited.",
|
||||
mlog.String("user_id", senderUserId),
|
||||
mlog.String("team_id", team.Id),
|
||||
mlog.String("retry_after", result.RetryAfter.String()),
|
||||
|
|
@ -349,7 +349,7 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
|
|||
props["name"] = team.Name
|
||||
data := model.MapToJson(props)
|
||||
|
||||
if err := a.Srv.Store.Token().Save(token); err != nil {
|
||||
if err := a.Srv().Store.Token().Save(token); err != nil {
|
||||
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
|
@ -363,29 +363,29 @@ func (a *App) SendInviteEmails(team *model.Team, senderName string, senderUserId
|
|||
}
|
||||
|
||||
func (a *App) SendGuestInviteEmails(team *model.Team, channels []*model.Channel, senderName string, senderUserId string, invites []string, siteURL string, message string) {
|
||||
if a.Srv.EmailRateLimiter == nil {
|
||||
a.Log.Error("Email invite not sent, rate limiting could not be setup.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id))
|
||||
if a.Srv().EmailRateLimiter == nil {
|
||||
a.Log().Error("Email invite not sent, rate limiting could not be setup.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id))
|
||||
return
|
||||
}
|
||||
rateLimited, result, err := a.Srv.EmailRateLimiter.RateLimit(senderUserId, len(invites))
|
||||
rateLimited, result, err := a.Srv().EmailRateLimiter.RateLimit(senderUserId, len(invites))
|
||||
if err != nil {
|
||||
a.Log.Error("Error rate limiting invite email.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(err))
|
||||
a.Log().Error("Error rate limiting invite email.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
sender, appErr := a.GetUser(senderUserId)
|
||||
if appErr != nil {
|
||||
a.Log.Error("Email invite not sent, unable to find the sender user.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(appErr))
|
||||
a.Log().Error("Email invite not sent, unable to find the sender user.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
senderProfileImage, _, appErr := a.GetProfileImage(sender)
|
||||
if appErr != nil {
|
||||
a.Log.Warn("Unable to get the sender user profile image.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(appErr))
|
||||
a.Log().Warn("Unable to get the sender user profile image.", mlog.String("user_id", senderUserId), mlog.String("team_id", team.Id), mlog.Err(appErr))
|
||||
}
|
||||
|
||||
if rateLimited {
|
||||
a.Log.Error("Invite emails rate limited.",
|
||||
a.Log().Error("Invite emails rate limited.",
|
||||
mlog.String("user_id", senderUserId),
|
||||
mlog.String("team_id", team.Id),
|
||||
mlog.String("retry_after", result.RetryAfter.String()),
|
||||
|
|
@ -437,7 +437,7 @@ func (a *App) SendGuestInviteEmails(team *model.Team, channels []*model.Channel,
|
|||
props["name"] = team.Name
|
||||
data := model.MapToJson(props)
|
||||
|
||||
if err := a.Srv.Store.Token().Save(token); err != nil {
|
||||
if err := a.Srv().Store.Token().Save(token); err != nil {
|
||||
mlog.Error("Failed to send invite email successfully ", mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func (a *App) AddNotificationEmailToBatch(user *model.User, post *model.Post, te
|
|||
return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if !a.Srv.EmailBatching.Add(user, post, team) {
|
||||
if !a.Srv().EmailBatching.Add(user, post, team) {
|
||||
mlog.Error("Email batching job's receiving channel was full. Please increase the EmailBatchingBufferSize.")
|
||||
return model.NewAppError("AddNotificationEmailToBatch", "api.email_batching.add_notification_email_to_batch.channel_full.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,13 +88,13 @@ func TestCheckPendingNotifications(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999999
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
|
||||
err = th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
err = th.App.Srv().Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
|
|
@ -109,10 +109,10 @@ func TestCheckPendingNotifications(t *testing.T) {
|
|||
require.Len(t, job.pendingNotifications[th.BasicUser.Id], 1, "shouldn't have sent queued post")
|
||||
|
||||
// test that notifications are cleared if the user has acted
|
||||
channelMember, err = th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err = th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 10001000
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
|
||||
job.checkPendingNotifications(time.Unix(10002, 0), func(string, []*batchedNotification) {})
|
||||
|
|
@ -186,10 +186,10 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
|||
job := NewEmailBatchingJob(th.Server, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
|
|
@ -224,14 +224,14 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
|||
job := NewEmailBatchingJob(th.Server, 128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember, err := th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
channelMember, err := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
_, err = th.App.Srv.Store.Channel().UpdateMember(channelMember)
|
||||
_, err = th.App.Srv().Store.Channel().UpdateMember(channelMember)
|
||||
require.Nil(t, err)
|
||||
|
||||
// preference value is not an integer, so we'll fall back to the default 15min value
|
||||
err = th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
err = th.App.Srv().Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
|
|
|
|||
22
app/emoji.go
22
app/emoji.go
|
|
@ -54,7 +54,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
|||
return nil, model.NewAppError("createEmoji", "api.emoji.create.other_user.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if existingEmoji, err := a.Srv.Store.Emoji().GetByName(emoji.Name, true); err == nil && existingEmoji != nil {
|
||||
if existingEmoji, err := a.Srv().Store.Emoji().GetByName(emoji.Name, true); err == nil && existingEmoji != nil {
|
||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
|||
return nil, err
|
||||
}
|
||||
|
||||
emoji, err := a.Srv.Store.Emoji().Save(emoji)
|
||||
emoji, err := a.Srv().Store.Emoji().Save(emoji)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
|||
}
|
||||
|
||||
func (a *App) GetEmojiList(page, perPage int, sort string) ([]*model.Emoji, *model.AppError) {
|
||||
return a.Srv.Store.Emoji().GetList(page*perPage, perPage, sort)
|
||||
return a.Srv().Store.Emoji().GetList(page*perPage, perPage, sort)
|
||||
}
|
||||
|
||||
func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError {
|
||||
|
|
@ -157,7 +157,7 @@ func (a *App) UploadEmojiImage(id string, imageData *multipart.FileHeader) *mode
|
|||
}
|
||||
|
||||
func (a *App) DeleteEmoji(emoji *model.Emoji) *model.AppError {
|
||||
if err := a.Srv.Store.Emoji().Delete(emoji, model.GetMillis()); err != nil {
|
||||
if err := a.Srv().Store.Emoji().Delete(emoji, model.GetMillis()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) {
|
|||
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Emoji().Get(emojiId, false)
|
||||
return a.Srv().Store.Emoji().Get(emojiId, false)
|
||||
}
|
||||
|
||||
func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
|
||||
|
|
@ -187,7 +187,7 @@ func (a *App) GetEmojiByName(emojiName string) (*model.Emoji, *model.AppError) {
|
|||
return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Emoji().GetByName(emojiName, true)
|
||||
return a.Srv().Store.Emoji().GetByName(emojiName, true)
|
||||
}
|
||||
|
||||
func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.AppError) {
|
||||
|
|
@ -195,11 +195,11 @@ func (a *App) GetMultipleEmojiByName(names []string) ([]*model.Emoji, *model.App
|
|||
return nil, model.NewAppError("GetMultipleEmojiByName", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Emoji().GetMultipleByName(names)
|
||||
return a.Srv().Store.Emoji().GetMultipleByName(names)
|
||||
}
|
||||
|
||||
func (a *App) GetEmojiImage(emojiId string) ([]byte, string, *model.AppError) {
|
||||
_, storeErr := a.Srv.Store.Emoji().Get(emojiId, true)
|
||||
_, storeErr := a.Srv().Store.Emoji().Get(emojiId, true)
|
||||
if storeErr != nil {
|
||||
return nil, "", storeErr
|
||||
}
|
||||
|
|
@ -222,7 +222,7 @@ func (a *App) SearchEmoji(name string, prefixOnly bool, limit int) ([]*model.Emo
|
|||
return nil, model.NewAppError("SearchEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
return a.Srv.Store.Emoji().Search(name, prefixOnly, limit)
|
||||
return a.Srv().Store.Emoji().Search(name, prefixOnly, limit)
|
||||
}
|
||||
|
||||
// GetEmojiStaticUrl returns a relative static URL for system default emojis,
|
||||
|
|
@ -234,7 +234,7 @@ func (a *App) GetEmojiStaticUrl(emojiName string) (string, *model.AppError) {
|
|||
return path.Join(subPath, "/static/emoji", id+".png"), nil
|
||||
}
|
||||
|
||||
if emoji, err := a.Srv.Store.Emoji().GetByName(emojiName, true); err == nil {
|
||||
if emoji, err := a.Srv().Store.Emoji().GetByName(emojiName, true); err == nil {
|
||||
return path.Join(subPath, "/api/v4/emoji", emoji.Id, "image"), nil
|
||||
} else {
|
||||
return "", err
|
||||
|
|
@ -289,7 +289,7 @@ func (a *App) deleteEmojiImage(id string) {
|
|||
}
|
||||
|
||||
func (a *App) deleteReactionsForEmoji(emojiName string) {
|
||||
if err := a.Srv.Store.Reaction().DeleteAllWithEmojiName(emojiName); err != nil {
|
||||
if err := a.Srv().Store.Reaction().DeleteAllWithEmojiName(emojiName); err != nil {
|
||||
mlog.Warn("Unable to delete reactions when deleting emoji", mlog.String("emoji_name", emojiName), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,10 +104,10 @@ func TestSAMLSettings(t *testing.T) {
|
|||
|
||||
th.Server.initEnterprise()
|
||||
if tc.isNil {
|
||||
assert.Nil(t, th.App.Srv.Saml)
|
||||
assert.Nil(t, th.App.Srv().Saml)
|
||||
} else {
|
||||
assert.NotNil(t, th.App.Srv.Saml)
|
||||
metadata, err := th.App.Srv.Saml.GetMetadata()
|
||||
assert.NotNil(t, th.App.Srv().Saml)
|
||||
metadata, err := th.App.Srv().Saml.GetMetadata()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.metadata, metadata)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ func (a *App) ExportVersion(writer io.Writer) *model.AppError {
|
|||
func (a *App) ExportAllTeams(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
teams, err := a.Srv.Store.Team().GetAllForExportAfter(1000, afterId)
|
||||
teams, err := a.Srv().Store.Team().GetAllForExportAfter(1000, afterId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -154,7 +154,7 @@ func (a *App) ExportAllTeams(writer io.Writer) *model.AppError {
|
|||
func (a *App) ExportAllChannels(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
channels, err := a.Srv.Store.Channel().GetAllChannelsForExportAfter(1000, afterId)
|
||||
channels, err := a.Srv().Store.Channel().GetAllChannelsForExportAfter(1000, afterId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -185,7 +185,7 @@ func (a *App) ExportAllChannels(writer io.Writer) *model.AppError {
|
|||
func (a *App) ExportAllUsers(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
users, err := a.Srv.Store.User().GetAllAfter(1000, afterId)
|
||||
users, err := a.Srv().Store.User().GetAllAfter(1000, afterId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -260,7 +260,7 @@ func (a *App) ExportAllUsers(writer io.Writer) *model.AppError {
|
|||
func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImportData, *model.AppError) {
|
||||
var memberships []UserTeamImportData
|
||||
|
||||
members, err := a.Srv.Store.Team().GetTeamMembersForExport(userId)
|
||||
members, err := a.Srv().Store.Team().GetTeamMembersForExport(userId)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -281,7 +281,7 @@ func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImpo
|
|||
}
|
||||
|
||||
// Get the user theme
|
||||
themePreference, err := a.Srv.Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId)
|
||||
themePreference, err := a.Srv().Store.Preference().Get(member.UserId, model.PREFERENCE_CATEGORY_THEME, member.TeamId)
|
||||
if err == nil {
|
||||
memberData.Theme = &themePreference.Value
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ func (a *App) buildUserTeamAndChannelMemberships(userId string) (*[]UserTeamImpo
|
|||
func (a *App) buildUserChannelMemberships(userId string, teamId string) (*[]UserChannelImportData, *model.AppError) {
|
||||
var memberships []UserChannelImportData
|
||||
|
||||
members, err := a.Srv.Store.Channel().GetChannelMembersForExport(userId, teamId)
|
||||
members, err := a.Srv().Store.Channel().GetChannelMembersForExport(userId, teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -339,7 +339,7 @@ func (a *App) ExportAllPosts(writer io.Writer) *model.AppError {
|
|||
afterId := strings.Repeat("0", 26)
|
||||
|
||||
for {
|
||||
posts, err := a.Srv.Store.Post().GetParentsForExportAfter(1000, afterId)
|
||||
posts, err := a.Srv().Store.Post().GetParentsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -381,7 +381,7 @@ func (a *App) ExportAllPosts(writer io.Writer) *model.AppError {
|
|||
func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppError) {
|
||||
var replies []ReplyImportData
|
||||
|
||||
replyPosts, err := a.Srv.Store.Post().GetRepliesForExport(postId)
|
||||
replyPosts, err := a.Srv().Store.Post().GetRepliesForExport(postId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -403,14 +403,14 @@ func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppErr
|
|||
func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
||||
var reactionsOfPost []ReactionImportData
|
||||
|
||||
reactions, err := a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
reactions, err := a.Srv().Store.Reaction().GetForPost(postId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, reaction := range reactions {
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().Get(reaction.UserId)
|
||||
user, err = a.Srv().Store.User().Get(reaction.UserId)
|
||||
if err != nil {
|
||||
if err.Id == store.MISSING_ACCOUNT_ERROR { // this is a valid case, the user that reacted might've been deleted by now
|
||||
mlog.Info("Skipping reactions by user since the entity doesn't exist anymore", mlog.String("user_id", reaction.UserId))
|
||||
|
|
@ -515,7 +515,7 @@ func (a *App) copyEmojiImages(emojiId string, emojiImagePath string, pathToDir s
|
|||
func (a *App) ExportAllDirectChannels(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
channels, err := a.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, afterId)
|
||||
channels, err := a.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -545,7 +545,7 @@ func (a *App) ExportAllDirectChannels(writer io.Writer) *model.AppError {
|
|||
func (a *App) ExportAllDirectPosts(writer io.Writer) *model.AppError {
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
posts, err := a.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, afterId)
|
||||
posts, err := a.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, afterId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func TestExportUserChannels(t *testing.T) {
|
|||
}
|
||||
var preferences model.Preferences
|
||||
preferences = append(preferences, preference)
|
||||
err := th.App.Srv.Store.Preference().Save(&preferences)
|
||||
err := th.App.Srv().Store.Preference().Save(&preferences)
|
||||
require.Nil(t, err)
|
||||
|
||||
th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id)
|
||||
|
|
@ -231,7 +231,7 @@ func TestExportDMChannel(t *testing.T) {
|
|||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ func TestExportDMChannel(t *testing.T) {
|
|||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ func TestExportDMChannel(t *testing.T) {
|
|||
assert.Equal(t, 0, i)
|
||||
|
||||
// Ensure the Members of the imported DM channel is the same was from the exported
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
assert.ElementsMatch(t, []string{th1.BasicUser.Username, th1.BasicUser2.Username}, *channels[0].Members)
|
||||
|
|
@ -267,14 +267,14 @@ func TestExportDMChannelToSelf(t *testing.T) {
|
|||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
|
|
@ -283,7 +283,7 @@ func TestExportDMChannelToSelf(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
assert.Equal(t, 1, len((*channels[0].Members)))
|
||||
|
|
@ -305,7 +305,7 @@ func TestExportGMChannel(t *testing.T) {
|
|||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(channels))
|
||||
|
||||
|
|
@ -314,7 +314,7 @@ func TestExportGMChannel(t *testing.T) {
|
|||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ func TestExportGMandDMChannels(t *testing.T) {
|
|||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
channels, err := th1.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err := th1.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 2, len(channels))
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ func TestExportGMandDMChannels(t *testing.T) {
|
|||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(channels))
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ func TestExportGMandDMChannels(t *testing.T) {
|
|||
assert.Equal(t, 0, i)
|
||||
|
||||
// Ensure the Members of the imported GM channel is the same was from the exported
|
||||
channels, err = th2.App.Srv.Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
channels, err = th2.App.Srv().Store.Channel().GetAllDirectChannelsForExportAfter(1000, "00000000")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Adding some deteminism so its possible to assert on slice index
|
||||
|
|
@ -412,7 +412,7 @@ func TestExportDMandGMPost(t *testing.T) {
|
|||
}
|
||||
th1.App.CreatePost(p4, gmChannel, false)
|
||||
|
||||
posts, err := th1.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 4, len(posts))
|
||||
|
||||
|
|
@ -425,7 +425,7 @@ func TestExportDMandGMPost(t *testing.T) {
|
|||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(posts))
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ func TestExportDMandGMPost(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
|
||||
// Adding some deteminism so its possible to assert on slice index
|
||||
|
|
@ -458,7 +458,7 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
|||
err := th1.App.BulkExport(&b, "somefile", "somePath", "someDir")
|
||||
require.Nil(t, err)
|
||||
|
||||
posts, err := th1.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err := th1.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(posts))
|
||||
|
||||
|
|
@ -467,7 +467,7 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
|||
th2 := Setup(t)
|
||||
defer th2.TearDown()
|
||||
|
||||
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 0, len(posts))
|
||||
|
||||
|
|
@ -476,7 +476,7 @@ func TestExportDMPostWithSelf(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, i)
|
||||
|
||||
posts, err = th2.App.Srv.Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
posts, err = th2.App.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, "0000000")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(posts))
|
||||
assert.Equal(t, 1, len((*posts[0].ChannelMembers)))
|
||||
|
|
|
|||
68
app/file.go
68
app/file.go
|
|
@ -185,7 +185,7 @@ func (a *App) findTeamIdForFilename(post *model.Post, id, filename string) strin
|
|||
name, _ := url.QueryUnescape(filename)
|
||||
|
||||
// This post is in a direct channel so we need to figure out what team the files are stored under.
|
||||
teams, err := a.Srv.Store.Team().GetTeamsByUserId(post.UserId)
|
||||
teams, err := a.Srv().Store.Team().GetTeamsByUserId(post.UserId)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get teams when migrating post to use FileInfo", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return ""
|
||||
|
|
@ -237,7 +237,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||
return []*model.FileInfo{}
|
||||
}
|
||||
|
||||
channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
channel, errCh := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
// There's a weird bug that rarely happens where a post ends up with duplicate Filenames so remove those
|
||||
filenames := utils.RemoveDuplicatesFromStringArray(post.Filenames)
|
||||
if errCh != nil {
|
||||
|
|
@ -290,7 +290,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||
fileMigrationLock.Lock()
|
||||
defer fileMigrationLock.Unlock()
|
||||
|
||||
result, err := a.Srv.Store.Post().Get(post.Id, false)
|
||||
result, err := a.Srv().Store.Post().Get(post.Id, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get post when migrating post to use FileInfos", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
|
|
@ -299,7 +299,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||
if newPost := result.Posts[post.Id]; len(newPost.Filenames) != len(post.Filenames) {
|
||||
// Another thread has already created FileInfos for this post, so just return those
|
||||
var fileInfos []*model.FileInfo
|
||||
fileInfos, err = a.Srv.Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
fileInfos, err = a.Srv().Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get FileInfos for migrated post", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
|
|
@ -314,7 +314,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||
savedInfos := make([]*model.FileInfo, 0, len(infos))
|
||||
fileIds := make([]string, 0, len(filenames))
|
||||
for _, info := range infos {
|
||||
if _, err = a.Srv.Store.FileInfo().Save(info); err != nil {
|
||||
if _, err = a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
mlog.Error(
|
||||
"Unable to save file info when migrating post to use FileInfos",
|
||||
mlog.String("post_id", post.Id),
|
||||
|
|
@ -337,7 +337,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
|||
newPost.FileIds = fileIds
|
||||
|
||||
// Update Posts to clear Filenames and set FileIds
|
||||
if _, err = a.Srv.Store.Post().Update(newPost, post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Update(newPost, post); err != nil {
|
||||
mlog.Error(
|
||||
"Unable to save migrated post when migrating to use FileInfos",
|
||||
mlog.String("new_file_ids", strings.Join(newPost.FileIds, ",")),
|
||||
|
|
@ -457,43 +457,43 @@ func (a *App) DoUploadFile(now time.Time, rawTeamId string, rawChannelId string,
|
|||
return info, err
|
||||
}
|
||||
|
||||
func UploadFileSetTeamId(teamId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetTeamId(teamId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.TeamId = filepath.Base(teamId)
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetUserId(userId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetUserId(userId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.UserId = filepath.Base(userId)
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetTimestamp(timestamp time.Time) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetTimestamp(timestamp time.Time) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.Timestamp = timestamp
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetContentLength(contentLength int64) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetContentLength(contentLength int64) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.ContentLength = contentLength
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetClientId(clientId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetClientId(clientId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.ClientId = clientId
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetRaw() func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetRaw() func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.Raw = true
|
||||
}
|
||||
}
|
||||
|
||||
type uploadFileTask struct {
|
||||
type UploadFileTask struct {
|
||||
// File name.
|
||||
Name string
|
||||
|
||||
|
|
@ -539,7 +539,7 @@ type uploadFileTask struct {
|
|||
saveToDatabase func(*model.FileInfo) (*model.FileInfo, *model.AppError)
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) init(a *App) {
|
||||
func (t *UploadFileTask) init(a *App) {
|
||||
t.buf = &bytes.Buffer{}
|
||||
t.maxFileSize = *a.Config().FileSettings.MaxFileSize
|
||||
t.limit = *a.Config().FileSettings.MaxFileSize
|
||||
|
|
@ -571,7 +571,7 @@ func (t *uploadFileTask) init(a *App) {
|
|||
|
||||
t.pluginsEnvironment = a.GetPluginsEnvironment()
|
||||
t.writeFile = a.WriteFile
|
||||
t.saveToDatabase = a.Srv.Store.FileInfo().Save
|
||||
t.saveToDatabase = a.Srv().Store.FileInfo().Save
|
||||
}
|
||||
|
||||
// UploadFileX uploads a single file as specified in t. It applies the upload
|
||||
|
|
@ -580,9 +580,9 @@ func (t *uploadFileTask) init(a *App) {
|
|||
// upload, returning a rejection error. In this case FileInfo would have
|
||||
// contained the last "good" FileInfo before the execution of that plugin.
|
||||
func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
||||
opts ...func(*uploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
|
||||
t := &uploadFileTask{
|
||||
t := &UploadFileTask{
|
||||
ChannelId: filepath.Base(channelId),
|
||||
Name: filepath.Base(name),
|
||||
Input: input,
|
||||
|
|
@ -644,7 +644,7 @@ func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
|||
return t.fileinfo, nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) readAll() *model.AppError {
|
||||
func (t *UploadFileTask) readAll() *model.AppError {
|
||||
_, err := t.buf.ReadFrom(t.limitedInput)
|
||||
if err != nil {
|
||||
// Ugly hack: the error is not exported from net/http.
|
||||
|
|
@ -666,7 +666,7 @@ func (t *uploadFileTask) readAll() *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) runPlugins() *model.AppError {
|
||||
func (t *UploadFileTask) runPlugins() *model.AppError {
|
||||
if t.pluginsEnvironment == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -703,7 +703,7 @@ func (t *uploadFileTask) runPlugins() *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) preprocessImage() *model.AppError {
|
||||
func (t *UploadFileTask) preprocessImage() *model.AppError {
|
||||
// If SVG, attempt to extract dimensions and then return
|
||||
if t.fileinfo.MimeType == "image/svg+xml" {
|
||||
svgInfo, err := parseSVG(t.newReader())
|
||||
|
|
@ -767,7 +767,7 @@ func (t *uploadFileTask) preprocessImage() *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) postprocessImage() {
|
||||
func (t *UploadFileTask) postprocessImage() {
|
||||
// don't try to process SVG files
|
||||
if t.fileinfo.MimeType == "image/svg+xml" {
|
||||
return
|
||||
|
|
@ -845,7 +845,7 @@ func (t *uploadFileTask) postprocessImage() {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func (t uploadFileTask) newReader() io.Reader {
|
||||
func (t UploadFileTask) newReader() io.Reader {
|
||||
if t.teeInput != nil {
|
||||
return io.MultiReader(bytes.NewReader(t.buf.Bytes()), t.teeInput)
|
||||
} else {
|
||||
|
|
@ -853,7 +853,7 @@ func (t uploadFileTask) newReader() io.Reader {
|
|||
}
|
||||
}
|
||||
|
||||
func (t uploadFileTask) pathPrefix() string {
|
||||
func (t UploadFileTask) pathPrefix() string {
|
||||
return t.Timestamp.Format("20060102") +
|
||||
"/teams/" + t.TeamId +
|
||||
"/channels/" + t.ChannelId +
|
||||
|
|
@ -861,7 +861,7 @@ func (t uploadFileTask) pathPrefix() string {
|
|||
"/" + t.fileinfo.Id + "/"
|
||||
}
|
||||
|
||||
func (t uploadFileTask) newAppError(id string, details interface{}, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
func (t UploadFileTask) newAppError(id string, details interface{}, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
params := map[string]interface{}{
|
||||
"Name": t.Name,
|
||||
"Filename": t.Name,
|
||||
|
|
@ -950,7 +950,7 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra
|
|||
return nil, data, err
|
||||
}
|
||||
|
||||
if _, err := a.Srv.Store.FileInfo().Save(info); err != nil {
|
||||
if _, err := a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
return nil, data, err
|
||||
}
|
||||
|
||||
|
|
@ -1094,7 +1094,7 @@ func (a *App) generatePreviewImage(img image.Image, previewPath string, width in
|
|||
}
|
||||
|
||||
func (a *App) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
return a.Srv.Store.FileInfo().Get(fileId)
|
||||
return a.Srv().Store.FileInfo().Get(fileId)
|
||||
}
|
||||
|
||||
func (a *App) GetFile(fileId string) ([]byte, *model.AppError) {
|
||||
|
|
@ -1117,7 +1117,7 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
|||
now := model.GetMillis()
|
||||
|
||||
for _, fileId := range fileIds {
|
||||
fileInfo, err := a.Srv.Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -1128,7 +1128,7 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
|||
fileInfo.UpdateAt = now
|
||||
fileInfo.PostId = ""
|
||||
|
||||
if _, err := a.Srv.Store.FileInfo().Save(fileInfo); err != nil {
|
||||
if _, err := a.Srv().Store.FileInfo().Save(fileInfo); err != nil {
|
||||
return newFileIds, err
|
||||
}
|
||||
|
||||
|
|
|
|||
1139
app/file.go.orig
Normal file
1139
app/file.go.orig
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -60,7 +60,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
th := Setup(b).InitBasic()
|
||||
defer th.TearDown()
|
||||
// disable logging in the benchmark, as best we can
|
||||
th.App.Log.SetConsoleLevel(mlog.LevelError)
|
||||
th.App.Log().SetConsoleLevel(mlog.LevelError)
|
||||
teamId := model.NewId()
|
||||
channelId := model.NewId()
|
||||
userId := model.NewId()
|
||||
|
|
@ -91,7 +91,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
|
||||
},
|
||||
|
|
@ -110,7 +110,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if aerr != nil {
|
||||
b.Fatal(aerr)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.RemoveFile(info.Path)
|
||||
},
|
||||
},
|
||||
|
|
@ -128,7 +128,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if aerr != nil {
|
||||
b.Fatal(aerr)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.RemoveFile(info.Path)
|
||||
},
|
||||
},
|
||||
|
|
@ -143,7 +143,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(resp.FileInfos[0].Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(resp.FileInfos[0].Id)
|
||||
th.App.RemoveFile(resp.FileInfos[0].Path)
|
||||
},
|
||||
},
|
||||
|
|
@ -160,7 +160,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if aerr != nil {
|
||||
b.Fatal(aerr)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.RemoveFile(info.Path)
|
||||
},
|
||||
},
|
||||
|
|
@ -177,7 +177,7 @@ func BenchmarkUploadFile(b *testing.B) {
|
|||
if aerr != nil {
|
||||
b.Fatal(aerr)
|
||||
}
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info.Id)
|
||||
th.App.RemoveFile(info.Path)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func TestDoUploadFile(t *testing.T) {
|
|||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ func TestDoUploadFile(t *testing.T) {
|
|||
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.RemoveFile(info2.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ func TestDoUploadFile(t *testing.T) {
|
|||
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info3.Id)
|
||||
th.App.RemoveFile(info3.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ func TestDoUploadFile(t *testing.T) {
|
|||
info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamId, "../../"+channelId, "../../"+userId, "../../"+filename, data)
|
||||
require.Nil(t, err, "DoUploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info4.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info4.Id)
|
||||
th.App.RemoveFile(info4.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ func TestUploadFile(t *testing.T) {
|
|||
info1, err := th.App.UploadFile(data, channelId, filename)
|
||||
require.Nil(t, err, "UploadFile should succeed with valid data")
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ func TestCopyFileInfos(t *testing.T) {
|
|||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info1.Id)
|
||||
th.App.RemoveFile(info1.Path)
|
||||
}()
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ func TestCopyFileInfos(t *testing.T) {
|
|||
info2, err := th.App.GetFileInfo(infoIds[0])
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.Srv().Store.FileInfo().PermanentDelete(info2.Id)
|
||||
th.App.RemoveFile(info2.Path)
|
||||
}()
|
||||
|
||||
|
|
|
|||
76
app/group.go
76
app/group.go
|
|
@ -8,48 +8,48 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) GetGroup(id string) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().Get(id)
|
||||
return a.Srv().Store.Group().Get(id)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupByName(name string) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetByName(name)
|
||||
return a.Srv().Store.Group().GetByName(name)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupByRemoteID(remoteID string, groupSource model.GroupSource) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetByRemoteID(remoteID, groupSource)
|
||||
return a.Srv().Store.Group().GetByRemoteID(remoteID, groupSource)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupsBySource(groupSource model.GroupSource) ([]*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetAllBySource(groupSource)
|
||||
return a.Srv().Store.Group().GetAllBySource(groupSource)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupsByUserId(userId string) ([]*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetByUser(userId)
|
||||
return a.Srv().Store.Group().GetByUser(userId)
|
||||
}
|
||||
|
||||
func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().Create(group)
|
||||
return a.Srv().Store.Group().Create(group)
|
||||
}
|
||||
|
||||
func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().Update(group)
|
||||
return a.Srv().Store.Group().Update(group)
|
||||
}
|
||||
|
||||
func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().Delete(groupID)
|
||||
return a.Srv().Store.Group().Delete(groupID)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetMemberUsers(groupID)
|
||||
return a.Srv().Store.Group().GetMemberUsers(groupID)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]*model.User, int, *model.AppError) {
|
||||
members, err := a.Srv.Store.Group().GetMemberUsersPage(groupID, page, perPage)
|
||||
members, err := a.Srv().Store.Group().GetMemberUsersPage(groupID, page, perPage)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
count, err := a.Srv.Store.Group().GetMemberCount(groupID)
|
||||
count, err := a.Srv().Store.Group().GetMemberCount(groupID)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -57,26 +57,26 @@ func (a *App) GetGroupMemberUsersPage(groupID string, page int, perPage int) ([]
|
|||
}
|
||||
|
||||
func (a *App) UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
return a.Srv.Store.Group().UpsertMember(groupID, userID)
|
||||
return a.Srv().Store.Group().UpsertMember(groupID, userID)
|
||||
}
|
||||
|
||||
func (a *App) DeleteGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) {
|
||||
return a.Srv.Store.Group().DeleteMember(groupID, userID)
|
||||
return a.Srv().Store.Group().DeleteMember(groupID, userID)
|
||||
}
|
||||
|
||||
func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
gs, err := a.Srv.Store.Group().GetGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
||||
gs, err := a.Srv().Store.Group().GetGroupSyncable(groupSyncable.GroupId, groupSyncable.SyncableId, groupSyncable.Type)
|
||||
if err != nil && err.Id != "store.sql_group.no_rows" {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if gs == nil {
|
||||
gs, err = a.Srv.Store.Group().CreateGroupSyncable(groupSyncable)
|
||||
gs, err = a.Srv().Store.Group().CreateGroupSyncable(groupSyncable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
gs, err = a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
gs, err = a.Srv().Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
|||
|
||||
// if the type is channel, then upsert the associated GroupTeam [MM-14675]
|
||||
if gs.Type == model.GroupSyncableTypeChannel {
|
||||
channel, err := a.Srv.Store.Channel().Get(gs.SyncableId, true)
|
||||
channel, err := a.Srv().Store.Channel().Get(gs.SyncableId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -103,11 +103,11 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
|||
}
|
||||
|
||||
func (a *App) GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
|
||||
return a.Srv().Store.Group().GetGroupSyncable(groupID, syncableID, syncableType)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupSyncables(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
|
||||
return a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(groupID, syncableType)
|
||||
}
|
||||
|
||||
func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) {
|
||||
|
|
@ -116,7 +116,7 @@ func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
|||
|
||||
if groupSyncable.DeleteAt == 0 {
|
||||
// updating a *deleted* GroupSyncable, so no need to ensure the GroupTeam is present (as done in the upsert)
|
||||
gs, err = a.Srv.Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
gs, err = a.Srv().Store.Group().UpdateGroupSyncable(groupSyncable)
|
||||
} else {
|
||||
// do an upsert to ensure that there's an associated GroupTeam
|
||||
gs, err = a.UpsertGroupSyncable(groupSyncable)
|
||||
|
|
@ -129,20 +129,20 @@ func (a *App) UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
|||
}
|
||||
|
||||
func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) {
|
||||
gs, err := a.Srv.Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
|
||||
gs, err := a.Srv().Store.Group().DeleteGroupSyncable(groupID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// if a GroupTeam is being deleted delete all associated GroupChannels
|
||||
if gs.Type == model.GroupSyncableTypeTeam {
|
||||
allGroupChannels, err := a.Srv.Store.Group().GetAllGroupSyncablesByGroupId(gs.GroupId, model.GroupSyncableTypeChannel)
|
||||
allGroupChannels, err := a.Srv().Store.Group().GetAllGroupSyncablesByGroupId(gs.GroupId, model.GroupSyncableTypeChannel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, groupChannel := range allGroupChannels {
|
||||
_, err = a.Srv.Store.Group().DeleteGroupSyncable(groupChannel.GroupId, groupChannel.SyncableId, groupChannel.Type)
|
||||
_, err = a.Srv().Store.Group().DeleteGroupSyncable(groupChannel.GroupId, groupChannel.SyncableId, groupChannel.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -153,28 +153,28 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp
|
|||
}
|
||||
|
||||
func (a *App) TeamMembersToAdd(since int64, teamID *string) ([]*model.UserTeamIDPair, *model.AppError) {
|
||||
return a.Srv.Store.Group().TeamMembersToAdd(since, teamID)
|
||||
return a.Srv().Store.Group().TeamMembersToAdd(since, teamID)
|
||||
}
|
||||
|
||||
func (a *App) ChannelMembersToAdd(since int64, channelID *string) ([]*model.UserChannelIDPair, *model.AppError) {
|
||||
return a.Srv.Store.Group().ChannelMembersToAdd(since, channelID)
|
||||
return a.Srv().Store.Group().ChannelMembersToAdd(since, channelID)
|
||||
}
|
||||
|
||||
func (a *App) TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError) {
|
||||
return a.Srv.Store.Group().TeamMembersToRemove(teamID)
|
||||
return a.Srv().Store.Group().TeamMembersToRemove(teamID)
|
||||
}
|
||||
|
||||
func (a *App) ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError) {
|
||||
return a.Srv.Store.Group().ChannelMembersToRemove(teamID)
|
||||
return a.Srv().Store.Group().ChannelMembersToRemove(teamID)
|
||||
}
|
||||
|
||||
func (a *App) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) {
|
||||
groups, err := a.Srv.Store.Group().GetGroupsByChannel(channelId, opts)
|
||||
groups, err := a.Srv().Store.Group().GetGroupsByChannel(channelId, opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
count, err := a.Srv.Store.Group().CountGroupsByChannel(channelId, opts)
|
||||
count, err := a.Srv().Store.Group().CountGroupsByChannel(channelId, opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -183,12 +183,12 @@ func (a *App) GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) (
|
|||
}
|
||||
|
||||
func (a *App) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.GroupWithSchemeAdmin, int, *model.AppError) {
|
||||
groups, err := a.Srv.Store.Group().GetGroupsByTeam(teamId, opts)
|
||||
groups, err := a.Srv().Store.Group().GetGroupsByTeam(teamId, opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
count, err := a.Srv.Store.Group().CountGroupsByTeam(teamId, opts)
|
||||
count, err := a.Srv().Store.Group().CountGroupsByTeam(teamId, opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ func (a *App) GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*mod
|
|||
}
|
||||
|
||||
func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetGroups(page, perPage, opts)
|
||||
return a.Srv().Store.Group().GetGroups(page, perPage, opts)
|
||||
}
|
||||
|
||||
// TeamMembersMinusGroupMembers returns the set of users on the given team minus the set of users in the given
|
||||
|
|
@ -206,7 +206,7 @@ func (a *App) GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model
|
|||
// The result can be used, for example, to determine the set of users who would be removed from a team if the team
|
||||
// were group-constrained with the given groups.
|
||||
func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) {
|
||||
users, err := a.Srv.Store.Group().TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage)
|
||||
users, err := a.Srv().Store.Group().TeamMembersMinusGroupMembers(teamID, groupIDs, page, perPage)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag
|
|||
}
|
||||
}
|
||||
|
||||
totalCount, err := a.Srv.Store.Group().CountTeamMembersMinusGroupMembers(teamID, groupIDs)
|
||||
totalCount, err := a.Srv().Store.Group().CountTeamMembersMinusGroupMembers(teamID, groupIDs)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -256,7 +256,7 @@ func (a *App) TeamMembersMinusGroupMembers(teamID string, groupIDs []string, pag
|
|||
}
|
||||
|
||||
func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError) {
|
||||
return a.Srv.Store.Group().GetByIDs(groupIDs)
|
||||
return a.Srv().Store.Group().GetByIDs(groupIDs)
|
||||
}
|
||||
|
||||
// ChannelMembersMinusGroupMembers returns the set of users in the given channel minus the set of users in the given
|
||||
|
|
@ -265,7 +265,7 @@ func (a *App) GetGroupsByIDs(groupIDs []string) ([]*model.Group, *model.AppError
|
|||
// The result can be used, for example, to determine the set of users who would be removed from a channel if the
|
||||
// channel were group-constrained with the given groups.
|
||||
func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, int64, *model.AppError) {
|
||||
users, err := a.Srv.Store.Group().ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage)
|
||||
users, err := a.Srv().Store.Group().ChannelMembersMinusGroupMembers(channelID, groupIDs, page, perPage)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -307,7 +307,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin
|
|||
}
|
||||
}
|
||||
|
||||
totalCount, err := a.Srv.Store.Group().CountChannelMembersMinusGroupMembers(channelID, groupIDs)
|
||||
totalCount, err := a.Srv().Store.Group().CountChannelMembersMinusGroupMembers(channelID, groupIDs)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -317,7 +317,7 @@ func (a *App) ChannelMembersMinusGroupMembers(channelID string, groupIDs []strin
|
|||
// UserIsInAdminRoleGroup returns true at least one of the user's groups are configured to set the members as
|
||||
// admins in the given syncable.
|
||||
func (a *App) UserIsInAdminRoleGroup(userID, syncableID string, syncableType model.GroupSyncableType) (bool, *model.AppError) {
|
||||
groupIDs, err := a.Srv.Store.Group().AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType)
|
||||
groupIDs, err := a.Srv().Store.Group().AdminRoleGroupsForSyncableMember(userID, syncableID, syncableType)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func setupTestHelper(enterprise bool, tb testing.TB) *TestHelper {
|
|||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
|
||||
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
th.App.Srv().Store.MarkSystemRanUnitTests()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
|
||||
|
||||
|
|
@ -204,7 +204,7 @@ func (me *TestHelper) CreateBot() *model.Bot {
|
|||
OwnerId: me.BasicUser.Id,
|
||||
}
|
||||
|
||||
me.App.Log.SetConsoleLevel(mlog.LevelError)
|
||||
me.App.Log().SetConsoleLevel(mlog.LevelError)
|
||||
bot, err := me.App.CreateBot(bot)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
|
|
@ -212,7 +212,7 @@ func (me *TestHelper) CreateBot() *model.Bot {
|
|||
time.Sleep(time.Second)
|
||||
panic(err)
|
||||
}
|
||||
me.App.Log.SetConsoleLevel(mlog.LevelDebug)
|
||||
me.App.Log().SetConsoleLevel(mlog.LevelDebug)
|
||||
return bot
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +431,7 @@ func (me *TestHelper) CreateGroup() *model.Group {
|
|||
func (me *TestHelper) CreateEmoji() *model.Emoji {
|
||||
utils.DisableDebugLogForTest()
|
||||
|
||||
emoji, err := me.App.Srv.Store.Emoji().Save(&model.Emoji{
|
||||
emoji, err := me.App.Srv().Store.Emoji().Save(&model.Emoji{
|
||||
CreatorId: me.BasicUser.Id,
|
||||
Name: model.NewRandomString(10),
|
||||
})
|
||||
|
|
@ -522,13 +522,13 @@ func (me *TestHelper) ResetEmojisMigration() {
|
|||
}
|
||||
|
||||
func (me *TestHelper) CheckTeamCount(t *testing.T, expected int64) {
|
||||
teamCount, err := me.App.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
teamCount, err := me.App.Srv().Store.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
require.Equalf(t, teamCount, expected, "Unexpected number of teams. Expected: %v, found: %v", expected, teamCount)
|
||||
}
|
||||
|
||||
func (me *TestHelper) CheckChannelsCount(t *testing.T, expected int64) {
|
||||
count, err := me.App.Srv.Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
count, err := me.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
require.Nilf(t, err, "Failed to get channel count.")
|
||||
require.Equalf(t, count, expected, "Unexpected number of channels. Expected: %v, found: %v", expected, count)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ func (a *App) BulkImport(fileReader io.Reader, dryRun bool, workers int) (*model
|
|||
scanner := bufio.NewScanner(fileReader)
|
||||
lineNumber := 0
|
||||
|
||||
a.Srv.Store.LockToMaster()
|
||||
defer a.Srv.Store.UnlockFromMaster()
|
||||
a.Srv().Store.LockToMaster()
|
||||
defer a.Srv().Store.UnlockFromMaster()
|
||||
|
||||
errorsChan := make(chan LineImportWorkerError, (2*workers)+1) // size chosen to ensure it never gets filled up completely.
|
||||
var wg sync.WaitGroup
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ func (a *App) importTeam(data *TeamImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
|
||||
var team *model.Team
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Name)
|
||||
team, err := a.Srv().Store.Team().GetByName(*data.Name)
|
||||
|
||||
if err != nil {
|
||||
team = &model.Team{}
|
||||
|
|
@ -221,13 +221,13 @@ func (a *App) importChannel(data *ChannelImportData, dryRun bool) *model.AppErro
|
|||
return nil
|
||||
}
|
||||
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Team)
|
||||
team, err := a.Srv().Store.Team().GetByName(*data.Team)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_channel.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var channel *model.Channel
|
||||
if result, err := a.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, *data.Name, true); err == nil {
|
||||
if result, err := a.Srv().Store.Channel().GetByNameIncludeDeleted(team.Id, *data.Name, true); err == nil {
|
||||
channel = result
|
||||
} else {
|
||||
channel = &model.Channel{}
|
||||
|
|
@ -295,7 +295,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||
|
||||
var user *model.User
|
||||
var err *model.AppError
|
||||
user, err = a.Srv.Store.User().GetByUsername(*data.Username)
|
||||
user, err = a.Srv().Store.User().GetByUsername(*data.Username)
|
||||
if err != nil {
|
||||
user = &model.User{}
|
||||
user.MakeNonNil()
|
||||
|
|
@ -499,7 +499,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
} else {
|
||||
if hasUserAuthDataChanged {
|
||||
if _, err = a.Srv.Store.User().UpdateAuthData(user.Id, authService, authData, user.Email, false); err != nil {
|
||||
if _, err = a.Srv().Store.User().UpdateAuthData(user.Id, authService, authData, user.Email, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -721,7 +721,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
|
|||
}
|
||||
|
||||
if len(teamThemePreferences) > 0 {
|
||||
if err := a.Srv.Store.Preference().Save(&teamThemePreferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&teamThemePreferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -818,7 +818,7 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
|
|||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_user_channels.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -833,7 +833,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun
|
|||
}
|
||||
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(*data.User)
|
||||
user, err = a.Srv().Store.User().GetByUsername(*data.User)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]interface{}{"Username": data.User}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -844,7 +844,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun
|
|||
EmojiName: *data.EmojiName,
|
||||
CreateAt: *data.CreateAt,
|
||||
}
|
||||
if _, err = a.Srv.Store.Reaction().Save(reaction); err != nil {
|
||||
if _, err = a.Srv().Store.Reaction().Save(reaction); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -858,13 +858,13 @@ func (a *App) importReply(data *ReplyImportData, post *model.Post, teamId string
|
|||
}
|
||||
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(*data.User)
|
||||
user, err = a.Srv().Store.User().GetByUsername(*data.User)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]interface{}{"Username": data.User}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check if this post already exists.
|
||||
replies, err := a.Srv.Store.Post().GetPostsCreatedAt(post.ChannelId, *data.CreateAt)
|
||||
replies, err := a.Srv().Store.Post().GetPostsCreatedAt(post.ChannelId, *data.CreateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -893,7 +893,7 @@ func (a *App) importReply(data *ReplyImportData, post *model.Post, teamId string
|
|||
}
|
||||
for _, fileID := range reply.FileIds {
|
||||
if _, ok := fileIds[fileID]; !ok {
|
||||
a.Srv.Store.FileInfo().PermanentDelete(fileID)
|
||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||
}
|
||||
}
|
||||
reply.FileIds = make([]string, 0)
|
||||
|
|
@ -902,11 +902,11 @@ func (a *App) importReply(data *ReplyImportData, post *model.Post, teamId string
|
|||
}
|
||||
|
||||
if reply.Id == "" {
|
||||
if _, err := a.Srv.Store.Post().Save(reply); err != nil {
|
||||
if _, err := a.Srv().Store.Post().Save(reply); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := a.Srv.Store.Post().Overwrite(reply); err != nil {
|
||||
if _, err := a.Srv().Store.Post().Overwrite(reply); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -971,24 +971,24 @@ func (a *App) importPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||
return nil
|
||||
}
|
||||
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Team)
|
||||
team, err := a.Srv().Store.Team().GetByName(*data.Team)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, err := a.Srv.Store.Channel().GetByName(team.Id, *data.Channel, false)
|
||||
channel, err := a.Srv().Store.Channel().GetByName(team.Id, *data.Channel, false)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]interface{}{"ChannelName": *data.Channel}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(*data.User)
|
||||
user, err = a.Srv().Store.User().GetByUsername(*data.User)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]interface{}{"Username": *data.User}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check if this post already exists.
|
||||
posts, err := a.Srv.Store.Post().GetPostsCreatedAt(channel.Id, *data.CreateAt)
|
||||
posts, err := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *data.CreateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1018,7 +1018,7 @@ func (a *App) importPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
for _, fileID := range post.FileIds {
|
||||
if _, ok := fileIds[fileID]; !ok {
|
||||
a.Srv.Store.FileInfo().PermanentDelete(fileID)
|
||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||
}
|
||||
}
|
||||
post.FileIds = make([]string, 0)
|
||||
|
|
@ -1027,11 +1027,11 @@ func (a *App) importPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
|
||||
if post.Id == "" {
|
||||
if _, err = a.Srv.Store.Post().Save(post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Save(post); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err = a.Srv.Store.Post().Overwrite(post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1041,7 +1041,7 @@ func (a *App) importPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||
|
||||
for _, username := range *data.FlaggedBy {
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(username)
|
||||
user, err = a.Srv().Store.User().GetByUsername(username)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.user_not_found.error", map[string]interface{}{"Username": username}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1055,7 +1055,7 @@ func (a *App) importPost(data *PostImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -1099,7 +1099,7 @@ func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model
|
|||
|
||||
func (a *App) updateFileInfoWithPostId(post *model.Post) {
|
||||
for _, fileId := range post.FileIds {
|
||||
if err := a.Srv.Store.FileInfo().AttachToPost(fileId, post.Id, post.UserId); err != nil {
|
||||
if err := a.Srv().Store.FileInfo().AttachToPost(fileId, post.Id, post.UserId); err != nil {
|
||||
mlog.Error("Error attaching files to post.", mlog.String("post_id", post.Id), mlog.Any("post_file_ids", post.FileIds), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
|
@ -1119,7 +1119,7 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
|||
userMap := make(map[string]string)
|
||||
for _, username := range *data.Members {
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(username)
|
||||
user, err = a.Srv().Store.User().GetByUsername(username)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_channel.member_not_found.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1165,14 +1165,14 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
|||
}
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return err
|
||||
}
|
||||
|
||||
if data.Header != nil {
|
||||
channel.Header = *data.Header
|
||||
if _, appErr := a.Srv.Store.Channel().Update(channel); appErr != nil {
|
||||
if _, appErr := a.Srv().Store.Channel().Update(channel); appErr != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, appErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
|
@ -1194,7 +1194,7 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
var userIds []string
|
||||
for _, username := range *data.ChannelMembers {
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(username)
|
||||
user, err = a.Srv().Store.User().GetByUsername(username)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.channel_member_not_found.error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1218,13 +1218,13 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
}
|
||||
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(*data.User)
|
||||
user, err = a.Srv().Store.User().GetByUsername(*data.User)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.user_not_found.error", map[string]interface{}{"Username": *data.User}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// Check if this post already exists.
|
||||
posts, err := a.Srv.Store.Post().GetPostsCreatedAt(channel.Id, *data.CreateAt)
|
||||
posts, err := a.Srv().Store.Post().GetPostsCreatedAt(channel.Id, *data.CreateAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1254,7 +1254,7 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
}
|
||||
for _, fileID := range post.FileIds {
|
||||
if _, ok := fileIds[fileID]; !ok {
|
||||
a.Srv.Store.FileInfo().PermanentDelete(fileID)
|
||||
a.Srv().Store.FileInfo().PermanentDelete(fileID)
|
||||
}
|
||||
}
|
||||
post.FileIds = make([]string, 0)
|
||||
|
|
@ -1263,11 +1263,11 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
}
|
||||
|
||||
if post.Id == "" {
|
||||
if _, err = a.Srv.Store.Post().Save(post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Save(post); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err = a.Srv.Store.Post().Overwrite(post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Overwrite(post); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -1277,7 +1277,7 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
|
||||
for _, username := range *data.FlaggedBy {
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().GetByUsername(username)
|
||||
user, err = a.Srv().Store.User().GetByUsername(username)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.user_not_found.error", map[string]interface{}{"Username": username}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
|
@ -1291,7 +1291,7 @@ func (a *App) importDirectPost(data *DirectPostImportData, dryRun bool) *model.A
|
|||
}
|
||||
|
||||
if len(preferences) > 0 {
|
||||
if err := a.Srv.Store.Preference().Save(&preferences); err != nil {
|
||||
if err := a.Srv().Store.Preference().Save(&preferences); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_direct_post.save_preferences.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -1329,7 +1329,7 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
|
|||
|
||||
var emoji *model.Emoji
|
||||
|
||||
emoji, appError := a.Srv.Store.Emoji().GetByName(*data.Name, true)
|
||||
emoji, appError := a.Srv().Store.Emoji().GetByName(*data.Name, true)
|
||||
if appError != nil && appError.StatusCode != http.StatusNotFound {
|
||||
return appError
|
||||
}
|
||||
|
|
@ -1353,7 +1353,7 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
|
|||
}
|
||||
|
||||
if !alreadyExists {
|
||||
if _, err := a.Srv.Store.Emoji().Save(emoji); err != nil {
|
||||
if _, err := a.Srv().Store.Emoji().Save(emoji); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ func TestImportImportScheme(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv().Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
// Try importing an invalid scheme in dryRun mode.
|
||||
|
|
@ -64,7 +64,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err := th.App.importScheme(&data, true)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing a valid scheme in dryRun mode.
|
||||
|
|
@ -73,7 +73,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err = th.App.importScheme(&data, true)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing an invalid scheme.
|
||||
|
|
@ -82,7 +82,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing a valid scheme with all params set.
|
||||
|
|
@ -91,7 +91,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
scheme, err := th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err := th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -99,42 +99,42 @@ func TestImportImportScheme(t *testing.T) {
|
|||
assert.Equal(t, *data.Description, scheme.Description)
|
||||
assert.Equal(t, *data.Scope, scheme.Scope)
|
||||
|
||||
role, err := th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
role, err := th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamGuestRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelGuestRole.DisplayName, role.DisplayName)
|
||||
|
|
@ -148,7 +148,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.Nil(t, err, "Should have succeeded: %v", err)
|
||||
|
||||
scheme, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -156,42 +156,42 @@ func TestImportImportScheme(t *testing.T) {
|
|||
assert.Equal(t, *data.Description, scheme.Description)
|
||||
assert.Equal(t, *data.Scope, scheme.Scope)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamGuestRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelGuestRole.DisplayName, role.DisplayName)
|
||||
|
|
@ -204,7 +204,7 @@ func TestImportImportScheme(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
scheme, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -219,10 +219,10 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv().Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
// Try importing an invalid scheme in dryRun mode.
|
||||
|
|
@ -251,7 +251,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err := th.App.importScheme(&data, true)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing a valid scheme in dryRun mode.
|
||||
|
|
@ -260,7 +260,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err = th.App.importScheme(&data, true)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing an invalid scheme.
|
||||
|
|
@ -269,7 +269,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
_, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.NotNil(t, err, "Scheme should not have imported.")
|
||||
|
||||
// Try importing a valid scheme with all params set.
|
||||
|
|
@ -278,7 +278,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
scheme, err := th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err := th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -286,42 +286,42 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
assert.Equal(t, *data.Description, scheme.Description)
|
||||
assert.Equal(t, *data.Scope, scheme.Scope)
|
||||
|
||||
role, err := th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
role, err := th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamGuestRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelGuestRole.DisplayName, role.DisplayName)
|
||||
|
|
@ -335,7 +335,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.Nil(t, err, "Should have succeeded: %v", err)
|
||||
|
||||
scheme, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -343,42 +343,42 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
assert.Equal(t, *data.Description, scheme.Description)
|
||||
assert.Equal(t, *data.Scope, scheme.Scope)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultTeamGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultTeamGuestRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelAdminRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelAdminRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelUserRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelUserRole.DisplayName, role.DisplayName)
|
||||
assert.False(t, role.BuiltIn)
|
||||
assert.True(t, role.SchemeManaged)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(scheme.DefaultChannelGuestRole)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.DefaultChannelGuestRole.DisplayName, role.DisplayName)
|
||||
|
|
@ -391,7 +391,7 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
|||
err = th.App.importScheme(&data, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
scheme, err = th.App.Srv.Store.Scheme().GetByName(*data.Name)
|
||||
scheme, err = th.App.Srv().Store.Scheme().GetByName(*data.Name)
|
||||
require.Nil(t, err, "Failed to import scheme: %v", err)
|
||||
|
||||
assert.Equal(t, *data.Name, scheme.Name)
|
||||
|
|
@ -413,7 +413,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err := th.App.importRole(&data, true, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Role().GetByName(rid1)
|
||||
_, err = th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
// Try importing the valid role in dryRun mode.
|
||||
|
|
@ -422,7 +422,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err = th.App.importRole(&data, true, false)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
_, err = th.App.Srv.Store.Role().GetByName(rid1)
|
||||
_, err = th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.NotNil(t, err, "Role should not have imported as we are in dry run mode.")
|
||||
|
||||
// Try importing an invalid role.
|
||||
|
|
@ -431,7 +431,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err = th.App.importRole(&data, false, false)
|
||||
require.NotNil(t, err, "Should have failed to import.")
|
||||
|
||||
_, err = th.App.Srv.Store.Role().GetByName(rid1)
|
||||
_, err = th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.NotNil(t, err, "Role should not have imported.")
|
||||
|
||||
// Try importing a valid role with all params set.
|
||||
|
|
@ -442,7 +442,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err = th.App.importRole(&data, false, false)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
role, err := th.App.Srv.Store.Role().GetByName(rid1)
|
||||
role, err := th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.Name, role.Name)
|
||||
|
|
@ -460,7 +460,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err = th.App.importRole(&data, false, true)
|
||||
require.Nil(t, err, "Should have succeeded. %v", err)
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(rid1)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data.Name, role.Name)
|
||||
|
|
@ -479,7 +479,7 @@ func TestImportImportRole(t *testing.T) {
|
|||
err = th.App.importRole(&data2, false, false)
|
||||
require.Nil(t, err, "Should have succeeded.")
|
||||
|
||||
role, err = th.App.Srv.Store.Role().GetByName(rid1)
|
||||
role, err = th.App.Srv().Store.Role().GetByName(rid1)
|
||||
require.Nil(t, err, "Should have found the imported role.")
|
||||
|
||||
assert.Equal(t, *data2.Name, role.Name)
|
||||
|
|
@ -495,17 +495,17 @@ func TestImportImportTeam(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv().Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
scheme1 := th.SetupTeamScheme()
|
||||
scheme2 := th.SetupTeamScheme()
|
||||
|
||||
// Check how many teams are in the database.
|
||||
teamsCount, err := th.App.Srv.Store.Team().AnalyticsTeamCount(false)
|
||||
teamsCount, err := th.App.Srv().Store.Team().AnalyticsTeamCount(false)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
|
||||
data := TeamImportData{
|
||||
|
|
@ -585,10 +585,10 @@ func TestImportImportChannel(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv().Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
scheme1 := th.SetupChannelScheme()
|
||||
|
|
@ -605,7 +605,7 @@ func TestImportImportChannel(t *testing.T) {
|
|||
require.Nil(t, err, "Failed to get team from database.")
|
||||
|
||||
// Check how many channels are in the database.
|
||||
channelCount, err := th.App.Srv.Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
channelCount, err := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
|
||||
require.Nil(t, err, "Failed to get team count.")
|
||||
|
||||
// Do an invalid channel in dry-run mode.
|
||||
|
|
@ -705,7 +705,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Check how many users are in the database.
|
||||
userCount, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -719,7 +719,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
require.NotNil(t, err, "Should have failed to import invalid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
userCount2, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount2, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -735,7 +735,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
require.Nil(t, err, "Should have succeeded to import valid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
userCount3, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount3, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -750,7 +750,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
require.NotNil(t, err, "Should have failed to import invalid user.")
|
||||
|
||||
// Check that no more users are in the DB.
|
||||
userCount4, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount4, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -773,7 +773,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
require.Nil(t, err, "Should have succeeded to import valid user.")
|
||||
|
||||
// Check that one more user is in the DB.
|
||||
userCount5, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount5, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -816,7 +816,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
require.Nil(t, err, "Should have succeeded to update valid user %v", err)
|
||||
|
||||
// Check user count the same.
|
||||
userCount6, err := th.App.Srv.Store.User().Count(model.UserCountOptions{
|
||||
userCount6, err := th.App.Srv().Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
IncludeBotAccounts: false,
|
||||
})
|
||||
|
|
@ -1334,10 +1334,10 @@ func TestImportImportUser(t *testing.T) {
|
|||
// to the appropriate scheme-managed-role booleans.
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv().Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv().Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
teamSchemeData := &SchemeImportData{
|
||||
|
|
@ -1374,7 +1374,7 @@ func TestImportImportUser(t *testing.T) {
|
|||
err = th.App.importScheme(teamSchemeData, false)
|
||||
assert.Nil(t, err)
|
||||
|
||||
teamScheme, err := th.App.Srv.Store.Scheme().GetByName(*teamSchemeData.Name)
|
||||
teamScheme, err := th.App.Srv().Store.Scheme().GetByName(*teamSchemeData.Name)
|
||||
require.Nil(t, err, "Failed to import scheme")
|
||||
|
||||
teamData := &TeamImportData{
|
||||
|
|
@ -1600,7 +1600,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
require.Nil(t, err, "Failed to get user from database.")
|
||||
|
||||
// Count the number of posts in the testing team.
|
||||
initialPostCount, err := th.App.Srv.Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
initialPostCount, err := th.App.Srv().Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Try adding an invalid post in dry run mode.
|
||||
|
|
@ -1686,7 +1686,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1708,7 +1708,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, time)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1755,7 +1755,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, team.Id)
|
||||
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1794,7 +1794,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 5, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, flagsTime)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1827,7 +1827,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 6, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, reactionPostTime)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1836,7 +1836,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
postBool = post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != user.Id || !post.HasReactions
|
||||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
reactions, err := th.App.Srv.Store.Reaction().GetForPost(post.Id, false)
|
||||
reactions, err := th.App.Srv().Store.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, err, "Can't get reaction")
|
||||
|
||||
require.Len(t, reactions, 1, "Invalid number of reactions")
|
||||
|
|
@ -1862,7 +1862,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 8, team.Id)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyPostTime)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, posts, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1872,7 +1872,7 @@ func TestImportImportPost(t *testing.T) {
|
|||
require.False(t, postBool, "Post properties not as expected")
|
||||
|
||||
// Check the reply values.
|
||||
replies, err := th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
replies, err := th.App.Srv().Store.Post().GetPostsCreatedAt(channel.Id, replyTime)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, replies, 1, "Unexpected number of posts found.")
|
||||
|
|
@ -1943,10 +1943,10 @@ func TestImportImportDirectChannel(t *testing.T) {
|
|||
defer th.TearDown()
|
||||
|
||||
// Check how many channels are in the database.
|
||||
directChannelCount, err := th.App.Srv.Store.Channel().AnalyticsTypeCount("", model.CHANNEL_DIRECT)
|
||||
directChannelCount, err := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_DIRECT)
|
||||
require.Nil(t, err, "Failed to get direct channel count.")
|
||||
|
||||
groupChannelCount, err := th.App.Srv.Store.Channel().AnalyticsTypeCount("", model.CHANNEL_GROUP)
|
||||
groupChannelCount, err := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_GROUP)
|
||||
require.Nil(t, err, "Failed to get group channel count.")
|
||||
|
||||
// Do an invalid channel in dry-run mode.
|
||||
|
|
@ -2128,7 +2128,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
directChannel = channel
|
||||
|
||||
// Get the number of posts in the system.
|
||||
result, err := th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||
result, err := th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, err)
|
||||
initialPostCount := result
|
||||
|
||||
|
|
@ -2188,7 +2188,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err := th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2203,7 +2203,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2231,7 +2231,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
|
||||
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2260,7 +2260,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2294,7 +2294,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
groupChannel = channel
|
||||
|
||||
// Get the number of posts in the system.
|
||||
result, err = th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||
result, err = th.App.Srv().Store.Post().AnalyticsPostCount("", false, false)
|
||||
require.Nil(t, err)
|
||||
initialPostCount = result
|
||||
|
||||
|
|
@ -2359,7 +2359,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2374,7 +2374,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2402,7 +2402,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
|
||||
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2432,7 +2432,7 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
|
||||
// Check the post values.
|
||||
posts, err = th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
posts, err = th.App.Srv().Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, posts, 1)
|
||||
|
||||
|
|
@ -2455,7 +2455,7 @@ func TestImportImportEmoji(t *testing.T) {
|
|||
err := th.App.importEmoji(&data, true)
|
||||
assert.NotNil(t, err, "Invalid emoji should have failed dry run")
|
||||
|
||||
emoji, err := th.App.Srv.Store.Emoji().GetByName(*data.Name, true)
|
||||
emoji, err := th.App.Srv().Store.Emoji().GetByName(*data.Name, true)
|
||||
assert.Nil(t, emoji, "Emoji should not have been imported")
|
||||
assert.NotNil(t, err)
|
||||
|
||||
|
|
@ -2475,7 +2475,7 @@ func TestImportImportEmoji(t *testing.T) {
|
|||
err = th.App.importEmoji(&data, false)
|
||||
assert.Nil(t, err, "Valid emoji should have succeeded apply mode")
|
||||
|
||||
emoji, err = th.App.Srv.Store.Emoji().GetByName(*data.Name, true)
|
||||
emoji, err = th.App.Srv().Store.Emoji().GetByName(*data.Name, true)
|
||||
assert.NotNil(t, emoji, "Emoji should have been imported")
|
||||
assert.Nil(t, err, "Emoji should have been imported without any error")
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func ptrBool(b bool) *bool {
|
|||
}
|
||||
|
||||
func checkPreference(t *testing.T, a *App, userId string, category string, name string, value string) {
|
||||
preferences, err := a.Srv.Store.Preference().GetCategory(userId, category)
|
||||
preferences, err := a.Srv().Store.Preference().GetCategory(userId, category)
|
||||
require.Nilf(t, err, "Failed to get preferences for user %v with category %v", userId, category)
|
||||
found := false
|
||||
for _, preference := range preferences {
|
||||
|
|
@ -61,13 +61,13 @@ func checkNoError(t *testing.T, err *model.AppError) {
|
|||
}
|
||||
|
||||
func AssertAllPostsCount(t *testing.T, a *App, initialCount int64, change int64, teamName string) {
|
||||
result, err := a.Srv.Store.Post().AnalyticsPostCount(teamName, false, false)
|
||||
result, err := a.Srv().Store.Post().AnalyticsPostCount(teamName, false, false)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, initialCount+change, result, "Did not find the expected number of posts.")
|
||||
}
|
||||
|
||||
func AssertChannelCount(t *testing.T, a *App, channelType string, expectedCount int64) {
|
||||
count, err := a.Srv.Store.Channel().AnalyticsTypeCount("", channelType)
|
||||
count, err := a.Srv().Store.Channel().AnalyticsTypeCount("", channelType)
|
||||
require.Equalf(t, expectedCount, count, "Channel count of type: %v. Expected: %v, Got: %v", channelType, expectedCount, count)
|
||||
require.Nil(t, err, "Failed to get channel count.")
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
|||
}
|
||||
|
||||
func GetAttachments(userId string, th *TestHelper, t *testing.T) []*model.FileInfo {
|
||||
fileInfos, err := th.App.Srv.Store.FileInfo().GetForUser(userId)
|
||||
fileInfos, err := th.App.Srv().Store.FileInfo().GetForUser(userId)
|
||||
require.Nil(t, err)
|
||||
return fileInfos
|
||||
}
|
||||
|
|
@ -228,7 +228,7 @@ func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T)
|
|||
postId := files[0].PostId
|
||||
assert.NotNil(t, postId)
|
||||
|
||||
posts, err := th.App.Srv.Store.Post().GetPostsByIds([]string{postId})
|
||||
posts, err := th.App.Srv().Store.Post().GetPostsByIds([]string{postId})
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, len(posts), 1)
|
||||
|
|
|
|||
|
|
@ -67,21 +67,21 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||
// Start all queries here for parallel execution
|
||||
pchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
post, err := a.Srv.Store.Post().GetSingle(postId)
|
||||
post, err := a.Srv().Store.Post().GetSingle(postId)
|
||||
pchan <- store.StoreResult{Data: post, Err: err}
|
||||
close(pchan)
|
||||
}()
|
||||
|
||||
cchan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
channel, err := a.Srv.Store.Channel().GetForPost(postId)
|
||||
channel, err := a.Srv().Store.Channel().GetForPost(postId)
|
||||
cchan <- store.StoreResult{Data: channel, Err: err}
|
||||
close(cchan)
|
||||
}()
|
||||
|
||||
userChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
user, err := a.Srv.Store.User().Get(upstreamRequest.UserId)
|
||||
user, err := a.Srv().Store.User().Get(upstreamRequest.UserId)
|
||||
userChan <- store.StoreResult{Data: user, Err: err}
|
||||
close(userChan)
|
||||
}()
|
||||
|
|
@ -99,7 +99,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||
return "", model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "postId doesn't match", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, err := a.Srv.Store.Channel().Get(cookie.ChannelId, true)
|
||||
channel, err := a.Srv().Store.Channel().Get(cookie.ChannelId, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -168,7 +168,7 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||
return
|
||||
}
|
||||
|
||||
team, err := a.Srv.Store.Team().Get(upstreamRequest.TeamId)
|
||||
team, err := a.Srv().Store.Team().Get(upstreamRequest.TeamId)
|
||||
teamChan <- store.StoreResult{Data: team, Err: err}
|
||||
}()
|
||||
|
||||
|
|
@ -279,10 +279,10 @@ func (a *App) DoActionRequest(rawURL string, body []byte) (*http.Response, *mode
|
|||
subpath, _ := utils.GetSubpathFromConfig(a.Config())
|
||||
siteURL, _ := url.Parse(*a.Config().ServiceSettings.SiteURL)
|
||||
if (inURL.Hostname() == "localhost" || inURL.Hostname() == "127.0.0.1" || inURL.Hostname() == siteURL.Hostname()) && strings.HasPrefix(inURL.Path, path.Join(subpath, "plugins")) {
|
||||
req.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session.Token)
|
||||
httpClient = a.HTTPService.MakeClient(true)
|
||||
req.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session().Token)
|
||||
httpClient = a.HTTPService().MakeClient(true)
|
||||
} else {
|
||||
httpClient = a.HTTPService.MakeClient(false)
|
||||
httpClient = a.HTTPService().MakeClient(false)
|
||||
}
|
||||
|
||||
resp, httpErr := httpClient.Do(req)
|
||||
|
|
@ -342,8 +342,8 @@ func (a *App) DoLocalRequest(rawURL string, body []byte) (*http.Response, *model
|
|||
if err != nil {
|
||||
return nil, model.NewAppError("DoActionRequest", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
r.Header.Set("Mattermost-User-Id", a.Session.UserId)
|
||||
r.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session.Token)
|
||||
r.Header.Set("Mattermost-User-Id", a.Session().UserId)
|
||||
r.Header.Set(model.HEADER_AUTH, "Bearer "+a.Session().Token)
|
||||
params := make(map[string]string)
|
||||
params["plugin_id"] = pluginId
|
||||
r = mux.SetURLVars(r, params)
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ func TestPostActionProps(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
assert.True(t, len(clientTriggerId) == 26)
|
||||
|
||||
newPost, err := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||
newPost, err := th.App.Srv().Store.Post().GetSingle(post.Id)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.True(t, newPost.IsPinned)
|
||||
|
|
|
|||
10
app/job.go
10
app/job.go
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
return a.Srv.Store.Job().Get(id)
|
||||
return a.Srv().Store.Job().Get(id)
|
||||
}
|
||||
|
||||
func (a *App) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
|
|
@ -16,7 +16,7 @@ func (a *App) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError)
|
|||
}
|
||||
|
||||
func (a *App) GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
return a.Srv.Store.Job().GetAllPage(offset, limit)
|
||||
return a.Srv().Store.Job().GetAllPage(offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
|
|
@ -24,13 +24,13 @@ func (a *App) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model
|
|||
}
|
||||
|
||||
func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
return a.Srv.Store.Job().GetAllByTypePage(jobType, offset, limit)
|
||||
return a.Srv().Store.Job().GetAllByTypePage(jobType, offset, limit)
|
||||
}
|
||||
|
||||
func (a *App) CreateJob(job *model.Job) (*model.Job, *model.AppError) {
|
||||
return a.Srv.Jobs.CreateJob(job.Type, job.Data)
|
||||
return a.Srv().Jobs.CreateJob(job.Type, job.Data)
|
||||
}
|
||||
|
||||
func (a *App) CancelJob(jobId string) *model.AppError {
|
||||
return a.Srv.Jobs.RequestCancellation(jobId)
|
||||
return a.Srv().Jobs.RequestCancellation(jobId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ func TestGetJob(t *testing.T) {
|
|||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
_, err := th.App.Srv.Store.Job().Save(status)
|
||||
_, err := th.App.Srv().Store.Job().Save(status)
|
||||
require.Nil(t, err)
|
||||
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(status.Id)
|
||||
|
||||
received, err := th.App.GetJob(status.Id)
|
||||
require.Nil(t, err)
|
||||
|
|
@ -53,9 +53,9 @@ func TestGetJobByType(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
_, err := th.App.Srv.Store.Job().Save(status)
|
||||
_, err := th.App.Srv().Store.Job().Save(status)
|
||||
require.Nil(t, err)
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
defer th.App.Srv().Store.Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
received, err := th.App.GetJobsByType(jobType, 0, 2)
|
||||
|
|
|
|||
12
app/layer_generators/app_iface.go.tmpl
Normal file
12
app/layer_generators/app_iface.go.tmpl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make store-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
|
||||
// AppIface is extracted from App struct and contains all it's exported methods. It's provided to allow partial interface passing and app layers creation.
|
||||
type AppIface interface {
|
||||
{{.Content}}
|
||||
}
|
||||
22
app/ldap.go
22
app/ldap.go
|
|
@ -12,10 +12,10 @@ import (
|
|||
)
|
||||
|
||||
func (a *App) SyncLdap() {
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
|
||||
if license := a.License(); license != nil && *license.Features.LDAP && *a.Config().LdapSettings.EnableSync {
|
||||
if ldapI := a.Ldap; ldapI != nil {
|
||||
if ldapI := a.Ldap(); ldapI != nil {
|
||||
ldapI.StartSynchronizeJob(false)
|
||||
} else {
|
||||
mlog.Error("Not executing ldap sync because ldap is not available")
|
||||
|
|
@ -26,7 +26,7 @@ func (a *App) SyncLdap() {
|
|||
|
||||
func (a *App) TestLdap() *model.AppError {
|
||||
license := a.License()
|
||||
if ldapI := a.Ldap; ldapI != nil && license != nil && *license.Features.LDAP && (*a.Config().LdapSettings.Enable || *a.Config().LdapSettings.EnableSync) {
|
||||
if ldapI := a.Ldap(); ldapI != nil && license != nil && *license.Features.LDAP && (*a.Config().LdapSettings.Enable || *a.Config().LdapSettings.EnableSync) {
|
||||
if err := ldapI.RunTest(); err != nil {
|
||||
err.StatusCode = 500
|
||||
return err
|
||||
|
|
@ -43,9 +43,9 @@ func (a *App) TestLdap() *model.AppError {
|
|||
func (a *App) GetLdapGroup(ldapGroupID string) (*model.Group, *model.AppError) {
|
||||
var group *model.Group
|
||||
|
||||
if a.Ldap != nil {
|
||||
if a.Ldap() != nil {
|
||||
var err *model.AppError
|
||||
group, err = a.Ldap.GetGroup(ldapGroupID)
|
||||
group, err = a.Ldap().GetGroup(ldapGroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -64,9 +64,9 @@ func (a *App) GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSe
|
|||
var groups []*model.Group
|
||||
var total int
|
||||
|
||||
if a.Ldap != nil {
|
||||
if a.Ldap() != nil {
|
||||
var err *model.AppError
|
||||
groups, total, err = a.Ldap.GetAllGroupsPage(page, perPage, opts)
|
||||
groups, total, err = a.Ldap().GetAllGroupsPage(page, perPage, opts)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword
|
|||
return "", err
|
||||
}
|
||||
|
||||
ldapInterface := a.Ldap
|
||||
ldapInterface := a.Ldap()
|
||||
if ldapInterface == nil {
|
||||
return "", model.NewAppError("SwitchEmailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword
|
|||
return "", err
|
||||
}
|
||||
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.SendSignInChangeEmail(user.Email, "AD/LDAP", user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
|||
return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_ldap_account.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
ldapInterface := a.Ldap
|
||||
ldapInterface := a.Ldap()
|
||||
if ldapInterface == nil || user.AuthData == nil {
|
||||
return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
|||
|
||||
T := utils.GetUserTranslations(user.Locale)
|
||||
|
||||
a.Srv.Go(func() {
|
||||
a.Srv().Go(func() {
|
||||
if err := a.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue