MM-45194: Switch app/user and api4/user to logger context (#20674)
```release-note NONE ``` Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
90c6350410
Коммит
d4b710b3ab
@@ -401,17 +401,17 @@ func (th *TestHelper) InitLogin() *TestHelper {
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
th.SystemAdminUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.SystemAdminUser.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||
th.SystemAdminUser, _ = th.App.GetUser(th.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = th.SystemAdminUser.DeepCopy()
|
||||
|
||||
th.SystemManagerUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.SystemManagerUser.Id, model.SystemUserRoleId+" "+model.SystemManagerRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.SystemManagerUser.Id, model.SystemUserRoleId+" "+model.SystemManagerRoleId, false)
|
||||
th.SystemManagerUser, _ = th.App.GetUser(th.SystemManagerUser.Id)
|
||||
userCache.SystemManagerUser = th.SystemManagerUser.DeepCopy()
|
||||
|
||||
th.TeamAdminUser = th.CreateUser()
|
||||
th.App.UpdateUserRoles(th.TeamAdminUser.Id, model.SystemUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.TeamAdminUser.Id, model.SystemUserRoleId, false)
|
||||
th.TeamAdminUser, _ = th.App.GetUser(th.TeamAdminUser.Id)
|
||||
userCache.TeamAdminUser = th.TeamAdminUser.DeepCopy()
|
||||
|
||||
@@ -476,7 +476,7 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicPrivateChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicDeletedChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicDeletedChannel, false)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId, false)
|
||||
th.Client.DeleteChannel(th.BasicDeletedChannel.Id)
|
||||
th.LoginBasic()
|
||||
th.Group = th.CreateGroup()
|
||||
|
||||
@@ -304,7 +304,7 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.ConvertBotToUser(bot, &userPatch, systemAdmin)
|
||||
user, err := c.App.ConvertBotToUser(c.AppContext, bot, &userPatch, systemAdmin)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestCreateBot(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.Config().ServiceSettings.EnableBotAccountCreation = model.NewBool(false)
|
||||
|
||||
_, _, err := th.Client.CreateBot(&model.Bot{
|
||||
@@ -55,7 +55,7 @@ func TestCreateBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -81,7 +81,7 @@ func TestCreateBot(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -106,7 +106,7 @@ func TestCreateBot(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -116,7 +116,7 @@ func TestCreateBot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
th.App.UpdateUserRoles(bot.UserId, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, bot.UserId, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
rtoken, _, err := th.Client.CreateUserAccessToken(bot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -152,7 +152,7 @@ func TestPatchBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -234,7 +234,7 @@ func TestPatchBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -258,7 +258,7 @@ func TestPatchBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -291,7 +291,7 @@ func TestPatchBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageRoles.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
resp, err = th.Client.UpdateUserRoles(createdBot.UserId, model.SystemUserRoleId)
|
||||
require.NoError(t, err)
|
||||
@@ -310,7 +310,7 @@ func TestPatchBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -341,7 +341,7 @@ func TestPatchBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -372,7 +372,7 @@ func TestPatchBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -408,7 +408,7 @@ func TestPatchBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -444,7 +444,7 @@ func TestPatchBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -513,7 +513,7 @@ func TestGetBot(t *testing.T) {
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -533,7 +533,7 @@ func TestGetBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, resp, err := th.Client.GetBot(model.NewId(), "")
|
||||
require.Error(t, err)
|
||||
@@ -545,7 +545,7 @@ func TestGetBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBot(bot1.UserId, "")
|
||||
require.NoError(t, err)
|
||||
@@ -561,7 +561,7 @@ func TestGetBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBot(bot2.UserId, "")
|
||||
require.NoError(t, err)
|
||||
@@ -579,7 +579,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBot(bot1.UserId, "")
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
@@ -591,7 +591,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBot(myBot.UserId, "")
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
@@ -602,7 +602,7 @@ func TestGetBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, resp, err := th.Client.GetBot(deletedBot.UserId, "")
|
||||
require.Error(t, err)
|
||||
@@ -614,7 +614,7 @@ func TestGetBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBotIncludeDeleted(deletedBot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
@@ -687,7 +687,7 @@ func TestGetBots(t *testing.T) {
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser2.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser2.Id, model.TeamUserRoleId, false)
|
||||
th.LoginBasic2()
|
||||
orphanedBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -710,7 +710,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot1, bot2, bot3, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -730,7 +730,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot1}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -750,7 +750,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot3, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -770,7 +770,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -790,7 +790,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot1, deletedBot1, bot2, bot3, deletedBot2, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -810,7 +810,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot1}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -830,7 +830,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{bot2, bot3}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -850,7 +850,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{deletedBot2, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -870,7 +870,7 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
expectedBotList := []*model.Bot{orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
@@ -891,7 +891,7 @@ func TestGetBots(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBots(0, 10, "")
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
@@ -916,7 +916,7 @@ func TestDisableBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -942,7 +942,7 @@ func TestDisableBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -968,7 +968,7 @@ func TestDisableBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -1021,7 +1021,7 @@ func TestEnableBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -1051,7 +1051,7 @@ func TestEnableBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -1081,7 +1081,7 @@ func TestEnableBot(t *testing.T) {
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -1288,7 +1288,7 @@ func TestConvertBotToUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
@@ -448,7 +448,7 @@ func TestCreatePostPublic(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.App.UpdateUserRoles(ruser.Id, model.SystemUserRoleId+" "+model.SystemPostAllPublicRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, ruser.Id, model.SystemUserRoleId+" "+model.SystemPostAllPublicRoleId, false)
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
|
||||
client.Login(user.Email, user.Password)
|
||||
@@ -461,7 +461,7 @@ func TestCreatePostPublic(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.App.UpdateUserRoles(ruser.Id, model.SystemUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, ruser.Id, model.SystemUserRoleId, false)
|
||||
th.App.JoinUserToTeam(th.Context, th.BasicTeam, ruser, "")
|
||||
th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.TeamUserRoleId+" "+model.TeamPostAllPublicRoleId)
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
@@ -498,7 +498,7 @@ func TestCreatePostAll(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.App.UpdateUserRoles(ruser.Id, model.SystemUserRoleId+" "+model.SystemPostAllRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, ruser.Id, model.SystemUserRoleId+" "+model.SystemPostAllRoleId, false)
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
|
||||
client.Login(user.Email, user.Password)
|
||||
@@ -514,7 +514,7 @@ func TestCreatePostAll(t *testing.T) {
|
||||
_, _, err = client.CreatePost(post)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.UpdateUserRoles(ruser.Id, model.SystemUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, ruser.Id, model.SystemUserRoleId, false)
|
||||
th.App.JoinUserToTeam(th.Context, th.BasicTeam, ruser, "")
|
||||
th.App.UpdateTeamMemberRoles(th.BasicTeam.Id, ruser.Id, model.TeamUserRoleId+" "+model.TeamPostAllRoleId)
|
||||
th.App.Srv().InvalidateAllCaches()
|
||||
|
||||
@@ -269,7 +269,7 @@ func remoteSetProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("user", user)
|
||||
|
||||
imageData := imageArray[0]
|
||||
if err := c.App.SetProfileImage(c.Params.UserId, imageData); err != nil {
|
||||
if err := c.App.SetProfileImage(c.AppContext, c.Params.UserId, imageData); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func TestGraphQLUser(t *testing.T) {
|
||||
|
||||
t.Run("Update", func(t *testing.T) {
|
||||
th.BasicUser.Props = map[string]string{"testpropkey": "testpropvalue"}
|
||||
th.App.UpdateUser(th.BasicUser, false)
|
||||
th.App.UpdateUser(th.Context, th.BasicUser, false)
|
||||
|
||||
input := graphQLInput{
|
||||
OperationName: "user",
|
||||
|
||||
@@ -163,7 +163,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
localUser := th.BasicUser
|
||||
remoteUser := th.CreateUser()
|
||||
remoteUser.RemoteId = model.NewString(model.NewId())
|
||||
remoteUser, appErr := th.App.UpdateUser(remoteUser, false)
|
||||
remoteUser, appErr := th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(localUser.Id, remoteUser.Id)
|
||||
@@ -194,7 +194,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
remoteUser.RemoteId = model.NewString(rc.RemoteId)
|
||||
remoteUser, appErr = th.App.UpdateUser(remoteUser, false)
|
||||
remoteUser, appErr = th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(localUser.Id, remoteUser.Id)
|
||||
@@ -227,7 +227,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
remoteUser.RemoteId = model.NewString(rc.RemoteId)
|
||||
remoteUser, appErr = th.App.UpdateUser(remoteUser, false)
|
||||
remoteUser, appErr = th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(remoteUser.Id, localUser.Id)
|
||||
|
||||
@@ -103,7 +103,7 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
currentStatus, err := c.App.GetStatus(c.Params.UserId)
|
||||
if err == nil && currentStatus.Status == model.StatusOutOfOffice && status.Status != model.StatusOutOfOffice {
|
||||
c.App.DisableAutoResponder(c.Params.UserId, c.IsSystemAdmin())
|
||||
c.App.DisableAutoResponder(c.AppContext, c.Params.UserId, c.IsSystemAdmin())
|
||||
}
|
||||
|
||||
switch status.Status {
|
||||
@@ -147,7 +147,7 @@ func updateUserCustomStatus(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
customStatus.PreSave()
|
||||
err := c.App.SetCustomStatus(c.Params.UserId, &customStatus)
|
||||
err := c.App.SetCustomStatus(c.AppContext, c.Params.UserId, &customStatus)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -172,7 +172,7 @@ func removeUserCustomStatus(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.RemoveCustomStatus(c.Params.UserId); err != nil {
|
||||
if err := c.App.RemoveCustomStatus(c.AppContext, c.Params.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -967,7 +967,7 @@ func TestGetAppliedSchemaMigrations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("as a system manager role", func(t *testing.T) {
|
||||
_, appErr := th.App.UpdateUserRoles(th.BasicUser2.Id, model.SystemManagerRoleId, false)
|
||||
_, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser2.Id, model.SystemManagerRoleId, false)
|
||||
require.Nil(t, appErr)
|
||||
th.LoginBasic2()
|
||||
|
||||
|
||||
68
api4/user.go
68
api4/user.go
@@ -167,7 +167,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
if err := json.NewEncoder(w).Encode(ruser); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.AppContext.Session())
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.App.SanitizeProfile(user, c.IsSystemAdmin())
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
imageData := imageArray[0]
|
||||
if err := c.App.SetProfileImage(c.Params.UserId, imageData); err != nil {
|
||||
if err := c.App.SetProfileImage(c.AppContext, c.Params.UserId, imageData); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -517,7 +517,7 @@ func setDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
auditRec.AddMeta("user", user)
|
||||
|
||||
if err := c.App.SetDefaultProfileImage(user); err != nil {
|
||||
if err := c.App.SetDefaultProfileImage(c.AppContext, user); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -546,7 +546,7 @@ func getTotalUsersStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(stats); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +610,7 @@ func getFilteredUsersStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(stats); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1156,7 +1156,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(autocomplete); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1227,7 +1227,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
ruser, err := c.App.UpdateUserAsUser(&user, c.IsSystemAdmin())
|
||||
ruser, err := c.App.UpdateUserAsUser(c.AppContext, &user, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1238,7 +1238,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
|
||||
if err := json.NewEncoder(w).Encode(ruser); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,7 +1306,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
ruser, err := c.App.PatchUser(c.Params.UserId, &patch, c.IsSystemAdmin())
|
||||
ruser, err := c.App.PatchUser(c.AppContext, c.Params.UserId, &patch, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1319,7 +1319,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("")
|
||||
|
||||
if err := json.NewEncoder(w).Encode(ruser); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1413,7 +1413,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.UpdateUserRoles(c.Params.UserId, newRoles, true)
|
||||
user, err := c.App.UpdateUserRoles(c.AppContext, c.Params.UserId, newRoles, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1542,7 +1542,7 @@ func updateUserAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit(fmt.Sprintf("updated user %s auth to service=%v", c.Params.UserId, user.AuthService))
|
||||
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1588,7 +1588,7 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("attempt")
|
||||
|
||||
if err := c.App.UpdateMfa(activate, c.Params.UserId, code); err != nil {
|
||||
if err := c.App.UpdateMfa(c.AppContext, activate, c.Params.UserId, code); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -1627,7 +1627,7 @@ func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Pragma", "no-cache")
|
||||
w.Header().Set("Expires", "0")
|
||||
if err := json.NewEncoder(w).Encode(secret); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1675,9 +1675,9 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.UpdatePasswordAsUser(c.Params.UserId, currentPassword, newPassword)
|
||||
err = c.App.UpdatePasswordAsUser(c.AppContext, c.Params.UserId, currentPassword, newPassword)
|
||||
} else if canUpdatePassword {
|
||||
err = c.App.UpdatePasswordByUserIdSendEmail(c.Params.UserId, newPassword, c.AppContext.T("api.user.reset_password.method"))
|
||||
err = c.App.UpdatePasswordByUserIdSendEmail(c.AppContext, c.Params.UserId, newPassword, c.AppContext.T("api.user.reset_password.method"))
|
||||
} else {
|
||||
err = model.NewAppError("updatePassword", "api.user.update_password.context.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -1711,7 +1711,7 @@ func resetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("token", token)
|
||||
c.LogAudit("attempt - token=" + token)
|
||||
|
||||
if err := c.App.ResetPasswordFromToken(token, newPassword); err != nil {
|
||||
if err := c.App.ResetPasswordFromToken(c.AppContext, token, newPassword); err != nil {
|
||||
c.LogAudit("fail - token=" + token)
|
||||
c.Err = err
|
||||
return
|
||||
@@ -1827,7 +1827,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
certPem, certSubject, certEmail := c.App.CheckForClientSideCert(r)
|
||||
mlog.Debug("Client Cert", mlog.String("cert_subject", certSubject), mlog.String("cert_email", certEmail))
|
||||
c.Logger.Debug("Client Cert", mlog.String("cert_subject", certSubject), mlog.String("cert_email", certEmail))
|
||||
|
||||
if certPem == "" || certEmail == "" {
|
||||
c.Err = model.NewAppError("ClientSideCertMissing", "api.user.login.client_side_cert.certificate.app_error", nil, "", http.StatusBadRequest)
|
||||
@@ -1895,7 +1895,7 @@ func login(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.Success()
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2170,7 +2170,7 @@ func getUserAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("audits_per_page", c.Params.LogsPerPage)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(audits); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2186,7 +2186,7 @@ func verifyUserEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("verifyUserEmail", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
if err := c.App.VerifyEmailFromToken(token); err != nil {
|
||||
if err := c.App.VerifyEmailFromToken(c.AppContext, token); err != nil {
|
||||
c.Err = model.NewAppError("verifyUserEmail", "api.user.verify_email.bad_link.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -2332,7 +2332,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("success - token_id=" + token.Id)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(token); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2443,7 +2443,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(accessToken); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2628,7 +2628,7 @@ func getUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(result); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2781,7 +2781,7 @@ func verifyUserEmailWithoutToken(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
c.LogAudit("user verified")
|
||||
|
||||
if err := json.NewEncoder(w).Encode(user); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2871,7 +2871,7 @@ func getChannelMembersForUser(c *Context, w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(members); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3014,7 +3014,7 @@ func getThreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(thread); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3085,7 +3085,7 @@ func getThreadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(threads); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3113,7 +3113,7 @@ func updateReadStateThreadByUser(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(thread); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
@@ -3149,7 +3149,7 @@ func setUnreadThreadByPostId(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(thread); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
|
||||
auditRec.Success()
|
||||
@@ -3285,6 +3285,6 @@ func getRecentSearches(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := json.NewEncoder(w).Encode(searchParams); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ func TestGetUser(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
user.Props = map[string]string{"testpropkey": "testpropvalue"}
|
||||
|
||||
th.App.UpdateUser(user, false)
|
||||
th.App.UpdateUser(th.Context, user, false)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
ruser, resp, err := client.GetUser(user.Id, "")
|
||||
@@ -699,7 +699,7 @@ func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) {
|
||||
|
||||
tos, _ := th.App.CreateTermsOfService("Dummy TOS", user.Id)
|
||||
|
||||
th.App.UpdateUser(user, false)
|
||||
th.App.UpdateUser(th.Context, user, false)
|
||||
|
||||
ruser, _, err := th.Client.GetUser(user.Id, "")
|
||||
require.NoError(t, err)
|
||||
@@ -785,7 +785,7 @@ func TestGetBotUser(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.TeamUserRoleId, false)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
@@ -4038,7 +4038,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = false })
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
@@ -4052,7 +4052,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
rtoken, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4117,7 +4117,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4159,7 +4159,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4219,7 +4219,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4239,7 +4239,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4264,7 +4264,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4312,7 +4312,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionReadUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4355,7 +4355,7 @@ func TestGetUserAccessTokensForUser(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
_, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4380,7 +4380,7 @@ func TestGetUserAccessTokensForUser(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
_, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4407,7 +4407,7 @@ func TestGetUserAccessTokens(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
_, resp, err := th.Client.GetUserAccessTokens(0, 100)
|
||||
require.Error(t, err)
|
||||
@@ -4420,7 +4420,7 @@ func TestGetUserAccessTokens(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
_, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token 2")
|
||||
require.NoError(t, err)
|
||||
@@ -4440,7 +4440,7 @@ func TestGetUserAccessTokens(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
_, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token 2")
|
||||
require.NoError(t, err)
|
||||
@@ -4463,7 +4463,7 @@ func TestSearchUserAccessToken(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4499,7 +4499,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
token, _, err := client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4537,7 +4537,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4581,7 +4581,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4620,7 +4620,7 @@ func TestDisableUserAccessToken(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
assertToken(t, th, token, th.BasicUser.Id)
|
||||
@@ -4656,7 +4656,7 @@ func TestDisableUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4700,7 +4700,7 @@ func TestDisableUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4739,7 +4739,7 @@ func TestEnableUserAccessToken(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, "test token")
|
||||
require.NoError(t, err)
|
||||
assertToken(t, th, token, th.BasicUser.Id)
|
||||
@@ -4783,7 +4783,7 @@ func TestEnableUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4830,7 +4830,7 @@ func TestEnableUserAccessToken(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
@@ -4873,7 +4873,7 @@ func TestUserAccessTokenInactiveUser(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -4896,7 +4896,7 @@ func TestUserAccessTokenDisableConfig(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
token, _, err := th.Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -5267,7 +5267,7 @@ func TestPromoteGuestToUser(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
user := th.BasicUser
|
||||
th.App.UpdateUserRoles(user.Id, model.SystemGuestRoleId, false)
|
||||
th.App.UpdateUserRoles(th.Context, user.Id, model.SystemGuestRoleId, false)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, _, err := c.GetUser(user.Id, "")
|
||||
|
||||
Ссылка в новой задаче
Block a user