MM-45194: Switch app/user and api4/user to logger context (#20674)

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-07-28 10:04:21 +05:30
коммит произвёл GitHub
родитель 90c6350410
Коммит d4b710b3ab
34 изменённых файлов: 354 добавлений и 353 удалений

Просмотреть файл

@@ -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, "")