From d4b710b3ab9c08083595e7edae2e2594d3c2642b Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Thu, 28 Jul 2022 10:04:21 +0530 Subject: [PATCH] MM-45194: Switch app/user and api4/user to logger context (#20674) ```release-note NONE ``` Co-authored-by: Mattermod --- api4/apitestlib.go | 8 +- api4/bot.go | 2 +- api4/bot_test.go | 80 +++++------ api4/post_test.go | 8 +- api4/remote_cluster.go | 2 +- api4/resolver_user_test.go | 2 +- api4/shared_channel_test.go | 6 +- api4/status.go | 6 +- api4/system_test.go | 2 +- api4/user.go | 68 +++++----- api4/user_test.go | 58 ++++---- app/app_iface.go | 52 ++++---- app/auto_responder.go | 4 +- app/auto_responder_test.go | 24 ++-- app/bot_test.go | 4 +- app/channel_test.go | 6 +- app/helper_test.go | 2 +- app/import_functions.go | 6 +- app/login.go | 2 +- app/notification_test.go | 8 +- app/opentracing/opentracing_layer.go | 90 ++++++------- app/plugin_api.go | 8 +- app/slashcommands/command_custom_status.go | 4 +- app/slashcommands/helper_test.go | 2 +- app/status.go | 11 +- app/status_test.go | 8 +- app/syncables_test.go | 2 +- app/team.go | 2 +- app/user.go | 148 ++++++++++----------- app/user_test.go | 62 ++++----- app/user_viewmembers_test.go | 10 +- einterfaces/ldap.go | 2 +- einterfaces/mocks/LdapInterface.go | 6 +- product/api.go | 2 +- 34 files changed, 354 insertions(+), 353 deletions(-) diff --git a/api4/apitestlib.go b/api4/apitestlib.go index e40bd255fd..9168983bbf 100644 --- a/api4/apitestlib.go +++ b/api4/apitestlib.go @@ -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() diff --git a/api4/bot.go b/api4/bot.go index fad11c8114..15acae8cf6 100644 --- a/api4/bot.go +++ b/api4/bot.go @@ -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 diff --git a/api4/bot_test.go b/api4/bot_test.go index b01dca609e..c5b7bc1413 100644 --- a/api4/bot_test.go +++ b/api4/bot_test.go @@ -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 }) diff --git a/api4/post_test.go b/api4/post_test.go index a7550edffc..e90ed309f9 100644 --- a/api4/post_test.go +++ b/api4/post_test.go @@ -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() diff --git a/api4/remote_cluster.go b/api4/remote_cluster.go index a919beadb4..9b34fcc7c5 100644 --- a/api4/remote_cluster.go +++ b/api4/remote_cluster.go @@ -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 } diff --git a/api4/resolver_user_test.go b/api4/resolver_user_test.go index c10176be2c..6328aec631 100644 --- a/api4/resolver_user_test.go +++ b/api4/resolver_user_test.go @@ -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", diff --git a/api4/shared_channel_test.go b/api4/shared_channel_test.go index e26732d8f7..16796c73ac 100644 --- a/api4/shared_channel_test.go +++ b/api4/shared_channel_test.go @@ -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) diff --git a/api4/status.go b/api4/status.go index e9fd83b2d8..7dc865572b 100644 --- a/api4/status.go +++ b/api4/status.go @@ -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 } diff --git a/api4/system_test.go b/api4/system_test.go index 5058e89acd..13eced3f1f 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -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() diff --git a/api4/user.go b/api4/user.go index 60145829fc..5749c145c0 100644 --- a/api4/user.go +++ b/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)) } } diff --git a/api4/user_test.go b/api4/user_test.go index 658ebf4d4b..733f6e0e27 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -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, "") diff --git a/app/app_iface.go b/app/app_iface.go index 3049aaa3de..5176813a34 100644 --- a/app/app_iface.go +++ b/app/app_iface.go @@ -80,7 +80,7 @@ type AppIface interface { // Use GetLastAccessiblePostTime() to access the result. ComputeLastAccessiblePostTime() error // ConvertBotToUser converts a bot to user. - ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) + ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) // ConvertUserToBot converts a user to bot. ConvertUserToBot(user *model.User) (*model.Bot, *model.AppError) // CreateBot creates the given bot and corresponding user. @@ -94,10 +94,10 @@ type AppIface interface { CreateDefaultMemberships(c *request.Context, since int64, includeRemovedMembers bool) error // CreateGuest creates a guest and sets several fields of the returned User struct to // their zero values. - CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError) + CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError) // CreateUser creates a user and sets several fields of the returned User struct to // their zero values. - CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError) + CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError) // Creates and stores FileInfos for a post created before the FileInfos table existed. MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo // DefaultChannelNames returns the list of system-wide default channel names. @@ -496,10 +496,10 @@ type AppIface interface { CreateTermsOfService(text, userID string) (*model.TermsOfService, *model.AppError) CreateUploadSession(c request.CTX, us *model.UploadSession) (*model.UploadSession, *model.AppError) CreateUserAccessToken(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) - CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) - CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) - CreateUserWithInviteId(c *request.Context, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) - CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError) + CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) + CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) + CreateUserWithInviteId(c request.CTX, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) + CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError) CreateWebhookPost(c request.CTX, userID string, channel *model.Channel, text, overrideUsername, overrideIconURL, overrideIconEmoji string, props model.StringInterface, postType string, postRootId string) (*model.Post, *model.AppError) DBHealthCheckDelete() error DBHealthCheckWrite() error @@ -533,7 +533,7 @@ type AppIface interface { DeleteSharedChannelRemote(id string) (bool, error) DeleteSidebarCategory(c request.CTX, userID, teamID, categoryId string) *model.AppError DeleteToken(token *model.Token) *model.AppError - DisableAutoResponder(userID string, asAdmin bool) *model.AppError + DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError DisableUserAccessToken(token *model.UserAccessToken) *model.AppError DoAppMigrations() DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command, *model.CommandResponse, *model.AppError) @@ -870,7 +870,7 @@ type AppIface interface { IsUserSignUpAllowed() *model.AppError JoinChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError JoinDefaultChannels(c request.CTX, teamID string, user *model.User, shouldBeAdmin bool, userRequestorId string) *model.AppError - JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) + JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) Ldap() einterfaces.LdapInterface LeaveChannel(c request.CTX, channelID string, userID string) *model.AppError LeaveTeam(c *request.Context, team *model.Team, user *model.User, requestorId string) *model.AppError @@ -908,7 +908,7 @@ type AppIface interface { 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) + PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) PermanentDeleteAllUsers(c *request.Context) *model.AppError PermanentDeleteChannel(c request.CTX, channel *model.Channel) *model.AppError PermanentDeleteTeam(c request.CTX, team *model.Team) *model.AppError @@ -942,7 +942,7 @@ type AppIface interface { RemoveAllDeactivatedMembersFromChannel(c request.CTX, channel *model.Channel) *model.AppError RemoveChannelsFromRetentionPolicy(policyID string, channelIDs []string) *model.AppError RemoveConfigListener(id string) - RemoveCustomStatus(userID string) *model.AppError + RemoveCustomStatus(c request.CTX, userID string) *model.AppError RemoveDirectory(path string) *model.AppError RemoveFile(path string) *model.AppError RemoveLdapPrivateCertificate() *model.AppError @@ -957,7 +957,7 @@ type AppIface interface { RemoveUserFromTeam(c *request.Context, teamID string, userID string, requestorId string) *model.AppError RemoveUsersFromChannelNotMemberOfTeam(c request.CTX, remover *model.User, channel *model.Channel, team *model.Team) *model.AppError RequestLicenseAndAckWarnMetric(c *request.Context, warnMetricId string, isBot bool) *model.AppError - ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError + ResetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string) *model.AppError ResetPermissionsSystem() *model.AppError ResetSamlAuthDataToEmail(includeDeleted bool, dryRun bool, userIDs []string) (numAffected int, appErr *model.AppError) RestoreChannel(c request.CTX, channel *model.Channel, userID string) (*model.Channel, *model.AppError) @@ -1032,16 +1032,16 @@ type AppIface interface { SetActiveChannel(c request.CTX, userID string, channelID string) *model.AppError SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap) SetChannels(ch *Channels) - SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError - SetDefaultProfileImage(user *model.User) *model.AppError + SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError + SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError 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) SetPostReminder(postID, userID string, targetTime int64) *model.AppError - SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError - SetProfileImageFromFile(userID string, file io.Reader) *model.AppError - SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError + SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError + SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError + SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError SetRemoteClusterLastPingAt(remoteClusterId string) *model.AppError SetSamlIdpCertificateFromMetadata(data []byte) *model.AppError SetSearchEngine(se *searchengine.Broker) @@ -1091,15 +1091,15 @@ type AppIface interface { UpdateHashedPasswordByUserId(userID, newHashedPassword string) *model.AppError UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) UpdateLastActivityAtIfNeeded(session model.Session) - UpdateMfa(activate bool, userID, token string) *model.AppError + UpdateMfa(c request.CTX, activate bool, userID, token string) *model.AppError UpdateMobileAppBadge(userID string) UpdateOAuthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError UpdateOutgoingWebhook(c request.CTX, 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 + UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPassword string) *model.AppError + UpdatePasswordByUserIdSendEmail(c request.CTX, userID, newPassword, method string) *model.AppError + UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword, method string) *model.AppError UpdatePost(c *request.Context, post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) UpdatePreferences(userID string, preferences model.Preferences) *model.AppError UpdateRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster, *model.AppError) @@ -1120,19 +1120,19 @@ type AppIface interface { UpdateThreadReadForUser(c request.CTX, currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError) UpdateThreadReadForUserByPost(c request.CTX, currentSessionId, userID, teamID, threadID, postID string) (*model.ThreadResponse, *model.AppError) UpdateThreadsReadForUser(userID, teamID string) *model.AppError - UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) + UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) UpdateUserActive(c *request.Context, userID string, active bool) *model.AppError - UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError) + UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError) UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError) - UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) - UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) + UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) + UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) UploadData(c *request.Context, us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError) UploadEmojiImage(id string, imageData *multipart.FileHeader) *model.AppError UpsertGroupMember(groupID string, userID string) (*model.GroupMember, *model.AppError) UpsertGroupMembers(groupID string, userIDs []string) ([]*model.GroupMember, *model.AppError) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) UserCanSeeOtherUser(userID string, otherUserId string) (bool, *model.AppError) - VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError + VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError VerifyUserEmail(userID, email string) *model.AppError ViewChannel(c request.CTX, view *model.ChannelView, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) WriteFile(fr io.Reader, path string) (int64, *model.AppError) diff --git a/app/auto_responder.go b/app/auto_responder.go index 90411ef419..9c5ffc5d75 100644 --- a/app/auto_responder.go +++ b/app/auto_responder.go @@ -98,7 +98,7 @@ func (a *App) SetAutoResponderStatus(user *model.User, oldNotifyProps model.Stri } } -func (a *App) DisableAutoResponder(userID string, asAdmin bool) *model.AppError { +func (a *App) DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError { user, err := a.GetUser(userID) if err != nil { return err @@ -111,7 +111,7 @@ func (a *App) DisableAutoResponder(userID string, asAdmin bool) *model.AppError patch.NotifyProps = user.NotifyProps patch.NotifyProps[model.AutoResponderActiveNotifyProp] = "false" - _, err := a.PatchUser(userID, patch, asAdmin) + _, err := a.PatchUser(c, userID, patch, asAdmin) if err != nil { return err } diff --git a/app/auto_responder_test.go b/app/auto_responder_test.go index 5593d11c4c..a7acc6eca1 100644 --- a/app/auto_responder_test.go +++ b/app/auto_responder_test.go @@ -27,7 +27,7 @@ func TestSetAutoResponderStatus(t *testing.T) { patch.NotifyProps["auto_responder_active"] = "true" patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - userUpdated1, _ := th.App.PatchUser(user.Id, patch, true) + userUpdated1, _ := th.App.PatchUser(th.Context, user.Id, patch, true) // autoResponder is enabled, status should be OOO th.App.SetAutoResponderStatus(userUpdated1, user.NotifyProps) @@ -41,7 +41,7 @@ func TestSetAutoResponderStatus(t *testing.T) { patch2.NotifyProps["auto_responder_active"] = "false" patch2.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - userUpdated2, _ := th.App.PatchUser(user.Id, patch2, true) + userUpdated2, _ := th.App.PatchUser(th.Context, user.Id, patch2, true) // autoResponder is disabled, status should be ONLINE th.App.SetAutoResponderStatus(userUpdated2, userUpdated1.NotifyProps) @@ -66,15 +66,15 @@ func TestDisableAutoResponder(t *testing.T) { patch.NotifyProps["auto_responder_active"] = "true" patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - th.App.PatchUser(user.Id, patch, true) + th.App.PatchUser(th.Context, user.Id, patch, true) - th.App.DisableAutoResponder(user.Id, true) + th.App.DisableAutoResponder(th.Context, user.Id, true) userUpdated1, err := th.App.GetUser(user.Id) require.Nil(t, err) assert.Equal(t, userUpdated1.NotifyProps["auto_responder_active"], "false") - th.App.DisableAutoResponder(user.Id, true) + th.App.DisableAutoResponder(th.Context, user.Id, true) userUpdated2, err := th.App.GetUser(user.Id) require.Nil(t, err) @@ -94,7 +94,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { "auto_responder_message": "Hello, I'm unavailable today.", }, } - receiver, err := th.App.PatchUser(receiver.Id, patch, true) + receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true) require.Nil(t, err) channel := th.CreateDmChannel(receiver) @@ -124,7 +124,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { "auto_responder_message": "Hello, I'm unavailable today.", }, } - receiver, err := th.App.PatchUser(receiver.Id, patch, true) + receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true) require.Nil(t, err) channel := th.CreateDmChannel(receiver) @@ -171,7 +171,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { "auto_responder_message": "Hello, I'm unavailable today.", }, } - receiver, err := th.App.PatchUser(receiver.Id, patch, true) + receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true) require.Nil(t, err) channel := th.CreateDmChannel(receiver) @@ -211,7 +211,7 @@ func TestSendAutoResponseIfNecessary(t *testing.T) { "auto_responder_message": "Hello, I'm unavailable today.", }, } - receiver, err := th.App.PatchUser(receiver.Id, patch, true) + receiver, err := th.App.PatchUser(th.Context, receiver.Id, patch, true) require.Nil(t, err) channel := th.CreateDmChannel(receiver) @@ -252,7 +252,7 @@ func TestSendAutoResponseSuccess(t *testing.T) { patch.NotifyProps["auto_responder_active"] = "true" patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - userUpdated1, err := th.App.PatchUser(user.Id, patch, true) + userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true) require.Nil(t, err) savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ @@ -292,7 +292,7 @@ func TestSendAutoResponseSuccessOnThread(t *testing.T) { patch.NotifyProps["auto_responder_active"] = "true" patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - userUpdated1, err := th.App.PatchUser(user.Id, patch, true) + userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true) require.Nil(t, err) parentPost, _ := th.App.CreatePost(th.Context, &model.Post{ @@ -341,7 +341,7 @@ func TestSendAutoResponseFailure(t *testing.T) { patch.NotifyProps["auto_responder_active"] = "false" patch.NotifyProps["auto_responder_message"] = "Hello, I'm unavailable today." - userUpdated1, err := th.App.PatchUser(user.Id, patch, true) + userUpdated1, err := th.App.PatchUser(th.Context, user.Id, patch, true) require.Nil(t, err) savedPost, _ := th.App.CreatePost(th.Context, &model.Post{ diff --git a/app/bot_test.go b/app/bot_test.go index c491f9aca8..6b77b08fa0 100644 --- a/app/bot_test.go +++ b/app/bot_test.go @@ -606,7 +606,7 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId} _, err := th.App.CreateUser(th.Context, &sysadmin1) require.Nil(t, err, "failed to create user") - th.App.UpdateUserRoles(sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) sysadmin2 := model.User{ Email: "sys2@example.com", @@ -616,7 +616,7 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) { Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId} _, err = th.App.CreateUser(th.Context, &sysadmin2) require.Nil(t, err, "failed to create user") - th.App.UpdateUserRoles(sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) // create user to be disabled user1, err := th.App.CreateUser(th.Context, &model.User{ diff --git a/app/channel_test.go b/app/channel_test.go index d42d608f3c..50a6768ffe 100644 --- a/app/channel_test.go +++ b/app/channel_test.go @@ -1004,18 +1004,18 @@ func TestGetChannelMembersTimezones(t *testing.T) { user := th.BasicUser user.Timezone["useAutomaticTimezone"] = "false" user.Timezone["manualTimezone"] = "XOXO/BLABLA" - th.App.UpdateUser(user, false) + th.App.UpdateUser(th.Context, user, false) user2 := th.BasicUser2 user2.Timezone["automaticTimezone"] = "NoWhere/Island" - th.App.UpdateUser(user2, false) + th.App.UpdateUser(th.Context, user2, false) user3 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""} ruser, _ := th.App.CreateUser(th.Context, &user3) th.App.AddUserToChannel(th.Context, ruser, th.BasicChannel, false) ruser.Timezone["automaticTimezone"] = "NoWhere/Island" - th.App.UpdateUser(ruser, false) + th.App.UpdateUser(th.Context, ruser, false) user4 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""} ruser, _ = th.App.CreateUser(th.Context, &user4) diff --git a/app/helper_test.go b/app/helper_test.go index bb6b1cdee4..cafec901cf 100644 --- a/app/helper_test.go +++ b/app/helper_test.go @@ -222,7 +222,7 @@ func (th *TestHelper) InitBasic() *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() diff --git a/app/import_functions.go b/app/import_functions.go index 7ab16c3e50..75ec8ad364 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -527,12 +527,12 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode } else { var appErr *model.AppError if hasUserChanged { - if savedUser, appErr = a.UpdateUser(user, false); appErr != nil { + if savedUser, appErr = a.UpdateUser(c, user, false); appErr != nil { return appErr } } if hasUserRolesChanged { - if savedUser, appErr = a.UpdateUserRoles(user.Id, roles, false); appErr != nil { + if savedUser, appErr = a.UpdateUserRoles(c, user.Id, roles, false); appErr != nil { return appErr } } @@ -590,7 +590,7 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil { return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest) } - if err := a.SetProfileImageFromFile(savedUser.Id, file); err != nil { + if err := a.SetProfileImageFromFile(c, savedUser.Id, file); err != nil { mlog.Warn("Unable to set the profile image from a file.", mlog.Err(err)) } } diff --git a/app/login.go b/app/login.go index 25d3ede871..375d50d914 100644 --- a/app/login.go +++ b/app/login.go @@ -222,7 +222,7 @@ func (a *App) DoLogin(c *request.Context, w http.ResponseWriter, r *http.Request userVal := *user sessionVal := *session a.Srv().Go(func() { - a.Ldap().UpdateProfilePictureIfNecessary(userVal, sessionVal) + a.Ldap().UpdateProfilePictureIfNecessary(c, userVal, sessionVal) }) } diff --git a/app/notification_test.go b/app/notification_test.go index 4d482d9bba..4929244bb7 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -149,14 +149,14 @@ func TestSendNotifications(t *testing.T) { } th.BasicUser.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny - th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false) + th.BasicUser, appErr = th.App.UpdateUser(th.Context, th.BasicUser, false) require.Nil(t, appErr) t.Run("user wants notifications on all comments", func(t *testing.T) { testUserNotNotified(t, th.BasicUser) }) th.BasicUser.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyRoot - th.BasicUser, appErr = th.App.UpdateUser(th.BasicUser, false) + th.BasicUser, appErr = th.App.UpdateUser(th.Context, th.BasicUser, false) require.Nil(t, appErr) t.Run("user wants notifications on root comment", func(t *testing.T) { testUserNotNotified(t, th.BasicUser) @@ -2723,13 +2723,13 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) { oldValue := th.BasicUser2.NotifyProps[model.CommentsNotifyProp] newNotifyProps := th.BasicUser2.NotifyProps newNotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny - u2, appErr := th.App.PatchUser(th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false) + u2, appErr := th.App.PatchUser(th.Context, th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false) require.Nil(t, appErr) require.Equal(t, model.CommentsNotifyAny, u2.NotifyProps[model.CommentsNotifyProp]) defer func() { newNotifyProps := th.BasicUser2.NotifyProps newNotifyProps[model.CommentsNotifyProp] = oldValue - _, nAppErr := th.App.PatchUser(th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false) + _, nAppErr := th.App.PatchUser(th.Context, th.BasicUser2.Id, &model.UserPatch{NotifyProps: newNotifyProps}, false) require.Nil(t, nAppErr) }() diff --git a/app/opentracing/opentracing_layer.go b/app/opentracing/opentracing_layer.go index b71e18b9e5..193d739f40 100644 --- a/app/opentracing/opentracing_layer.go +++ b/app/opentracing/opentracing_layer.go @@ -1791,7 +1791,7 @@ func (a *OpenTracingAppLayer) Config() *model.Config { return resultVar0 } -func (a *OpenTracingAppLayer) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ConvertBotToUser") @@ -1803,7 +1803,7 @@ func (a *OpenTracingAppLayer) ConvertBotToUser(bot *model.Bot, userPatch *model. }() defer span.Finish() - resultVar0, resultVar1 := a.app.ConvertBotToUser(bot, userPatch, sysadmin) + resultVar0, resultVar1 := a.app.ConvertBotToUser(c, bot, userPatch, sysadmin) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -2125,7 +2125,7 @@ func (a *OpenTracingAppLayer) CreateGroupWithUserIds(group *model.GroupWithUserI return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateGuest") @@ -2565,7 +2565,7 @@ func (a *OpenTracingAppLayer) CreateUploadSession(c request.CTX, us *model.Uploa return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUser") @@ -2609,7 +2609,7 @@ func (a *OpenTracingAppLayer) CreateUserAccessToken(token *model.UserAccessToken return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserAsAdmin") @@ -2631,7 +2631,7 @@ func (a *OpenTracingAppLayer) CreateUserAsAdmin(c *request.Context, user *model. return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserFromSignup") @@ -2653,7 +2653,7 @@ func (a *OpenTracingAppLayer) CreateUserFromSignup(c *request.Context, user *mod return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateUserWithInviteId(c *request.Context, user *model.User, inviteId string, redirect string) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateUserWithInviteId(c request.CTX, user *model.User, inviteId string, redirect string) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserWithInviteId") @@ -2675,7 +2675,7 @@ func (a *OpenTracingAppLayer) CreateUserWithInviteId(c *request.Context, user *m return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateUserWithToken") @@ -3521,7 +3521,7 @@ func (a *OpenTracingAppLayer) DemoteUserToGuest(c request.CTX, user *model.User) return resultVar0 } -func (a *OpenTracingAppLayer) DisableAutoResponder(userID string, asAdmin bool) *model.AppError { +func (a *OpenTracingAppLayer) DisableAutoResponder(c request.CTX, userID string, asAdmin bool) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.DisableAutoResponder") @@ -3533,7 +3533,7 @@ func (a *OpenTracingAppLayer) DisableAutoResponder(userID string, asAdmin bool) }() defer span.Finish() - resultVar0 := a.app.DisableAutoResponder(userID, asAdmin) + resultVar0 := a.app.DisableAutoResponder(c, userID, asAdmin) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -11687,7 +11687,7 @@ func (a *OpenTracingAppLayer) JoinDefaultChannels(c request.CTX, teamID string, return resultVar0 } -func (a *OpenTracingAppLayer) JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) { +func (a *OpenTracingAppLayer) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.JoinUserToTeam") @@ -12635,7 +12635,7 @@ func (a *OpenTracingAppLayer) PatchTeam(teamID string, patch *model.TeamPatch) ( return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PatchUser") @@ -12647,7 +12647,7 @@ func (a *OpenTracingAppLayer) PatchUser(userID string, patch *model.UserPatch, a }() defer span.Finish() - resultVar0, resultVar1 := a.app.PatchUser(userID, patch, asAdmin) + resultVar0, resultVar1 := a.app.PatchUser(c, userID, patch, asAdmin) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -13422,7 +13422,7 @@ func (a *OpenTracingAppLayer) RemoveConfigListener(id string) { a.app.RemoveConfigListener(id) } -func (a *OpenTracingAppLayer) RemoveCustomStatus(userID string) *model.AppError { +func (a *OpenTracingAppLayer) RemoveCustomStatus(c request.CTX, userID string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.RemoveCustomStatus") @@ -13434,7 +13434,7 @@ func (a *OpenTracingAppLayer) RemoveCustomStatus(userID string) *model.AppError }() defer span.Finish() - resultVar0 := a.app.RemoveCustomStatus(userID) + resultVar0 := a.app.RemoveCustomStatus(c, userID) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -13796,7 +13796,7 @@ func (a *OpenTracingAppLayer) RequestLicenseAndAckWarnMetric(c *request.Context, return resultVar0 } -func (a *OpenTracingAppLayer) ResetPasswordFromToken(userSuppliedTokenString string, newPassword string) *model.AppError { +func (a *OpenTracingAppLayer) ResetPasswordFromToken(c request.CTX, userSuppliedTokenString string, newPassword string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.ResetPasswordFromToken") @@ -13808,7 +13808,7 @@ func (a *OpenTracingAppLayer) ResetPasswordFromToken(userSuppliedTokenString str }() defer span.Finish() - resultVar0 := a.app.ResetPasswordFromToken(userSuppliedTokenString, newPassword) + resultVar0 := a.app.ResetPasswordFromToken(c, userSuppliedTokenString, newPassword) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -15475,7 +15475,7 @@ func (a *OpenTracingAppLayer) SetChannels(ch *app.Channels) { a.app.SetChannels(ch) } -func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError { +func (a *OpenTracingAppLayer) SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetCustomStatus") @@ -15487,7 +15487,7 @@ func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomSta }() defer span.Finish() - resultVar0 := a.app.SetCustomStatus(userID, cs) + resultVar0 := a.app.SetCustomStatus(c, userID, cs) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -15497,7 +15497,7 @@ func (a *OpenTracingAppLayer) SetCustomStatus(userID string, cs *model.CustomSta return resultVar0 } -func (a *OpenTracingAppLayer) SetDefaultProfileImage(user *model.User) *model.AppError { +func (a *OpenTracingAppLayer) SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetDefaultProfileImage") @@ -15509,7 +15509,7 @@ func (a *OpenTracingAppLayer) SetDefaultProfileImage(user *model.User) *model.Ap }() defer span.Finish() - resultVar0 := a.app.SetDefaultProfileImage(user) + resultVar0 := a.app.SetDefaultProfileImage(c, user) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -15629,7 +15629,7 @@ func (a *OpenTracingAppLayer) SetPostReminder(postID string, userID string, targ return resultVar0 } -func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError { +func (a *OpenTracingAppLayer) SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImage") @@ -15641,7 +15641,7 @@ func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipar }() defer span.Finish() - resultVar0 := a.app.SetProfileImage(userID, imageData) + resultVar0 := a.app.SetProfileImage(c, userID, imageData) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -15651,7 +15651,7 @@ func (a *OpenTracingAppLayer) SetProfileImage(userID string, imageData *multipar return resultVar0 } -func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Reader) *model.AppError { +func (a *OpenTracingAppLayer) SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImageFromFile") @@ -15663,7 +15663,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Rea }() defer span.Finish() - resultVar0 := a.app.SetProfileImageFromFile(userID, file) + resultVar0 := a.app.SetProfileImageFromFile(c, userID, file) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -15673,7 +15673,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromFile(userID string, file io.Rea return resultVar0 } -func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError { +func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SetProfileImageFromMultiPartFile") @@ -15685,7 +15685,7 @@ func (a *OpenTracingAppLayer) SetProfileImageFromMultiPartFile(userID string, fi }() defer span.Finish() - resultVar0 := a.app.SetProfileImageFromMultiPartFile(userID, file) + resultVar0 := a.app.SetProfileImageFromMultiPartFile(c, userID, file) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -16888,7 +16888,7 @@ func (a *OpenTracingAppLayer) UpdateLastActivityAtIfNeeded(session model.Session a.app.UpdateLastActivityAtIfNeeded(session) } -func (a *OpenTracingAppLayer) UpdateMfa(activate bool, userID string, token string) *model.AppError { +func (a *OpenTracingAppLayer) UpdateMfa(c request.CTX, activate bool, userID string, token string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateMfa") @@ -16900,7 +16900,7 @@ func (a *OpenTracingAppLayer) UpdateMfa(activate bool, userID string, token stri }() defer span.Finish() - resultVar0 := a.app.UpdateMfa(activate, userID, token) + resultVar0 := a.app.UpdateMfa(c, activate, userID, token) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -17013,7 +17013,7 @@ func (a *OpenTracingAppLayer) UpdatePassword(user *model.User, newPassword strin return resultVar0 } -func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPassword string, newPassword string) *model.AppError { +func (a *OpenTracingAppLayer) UpdatePasswordAsUser(c request.CTX, userID string, currentPassword string, newPassword string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordAsUser") @@ -17025,7 +17025,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPasswor }() defer span.Finish() - resultVar0 := a.app.UpdatePasswordAsUser(userID, currentPassword, newPassword) + resultVar0 := a.app.UpdatePasswordAsUser(c, userID, currentPassword, newPassword) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -17035,7 +17035,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordAsUser(userID string, currentPasswor return resultVar0 } -func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, newPassword string, method string) *model.AppError { +func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(c request.CTX, userID string, newPassword string, method string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordByUserIdSendEmail") @@ -17047,7 +17047,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, new }() defer span.Finish() - resultVar0 := a.app.UpdatePasswordByUserIdSendEmail(userID, newPassword, method) + resultVar0 := a.app.UpdatePasswordByUserIdSendEmail(c, userID, newPassword, method) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -17057,7 +17057,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordByUserIdSendEmail(userID string, new return resultVar0 } -func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(user *model.User, newPassword string, method string) *model.AppError { +func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword string, method string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdatePasswordSendEmail") @@ -17069,7 +17069,7 @@ func (a *OpenTracingAppLayer) UpdatePasswordSendEmail(user *model.User, newPassw }() defer span.Finish() - resultVar0 := a.app.UpdatePasswordSendEmail(user, newPassword, method) + resultVar0 := a.app.UpdatePasswordSendEmail(c, user, newPassword, method) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) @@ -17541,7 +17541,7 @@ func (a *OpenTracingAppLayer) UpdateThreadsReadForUser(userID string, teamID str return resultVar0 } -func (a *OpenTracingAppLayer) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUser") @@ -17553,7 +17553,7 @@ func (a *OpenTracingAppLayer) UpdateUser(user *model.User, sendNotifications boo }() defer span.Finish() - resultVar0, resultVar1 := a.app.UpdateUser(user, sendNotifications) + resultVar0, resultVar1 := a.app.UpdateUser(c, user, sendNotifications) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -17585,7 +17585,7 @@ func (a *OpenTracingAppLayer) UpdateUserActive(c *request.Context, userID string return resultVar0 } -func (a *OpenTracingAppLayer) UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserAsUser") @@ -17597,7 +17597,7 @@ func (a *OpenTracingAppLayer) UpdateUserAsUser(user *model.User, asAdmin bool) ( }() defer span.Finish() - resultVar0, resultVar1 := a.app.UpdateUserAsUser(user, asAdmin) + resultVar0, resultVar1 := a.app.UpdateUserAsUser(c, user, asAdmin) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -17629,7 +17629,7 @@ func (a *OpenTracingAppLayer) UpdateUserAuth(userID string, userAuth *model.User return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserRoles") @@ -17641,7 +17641,7 @@ func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, se }() defer span.Finish() - resultVar0, resultVar1 := a.app.UpdateUserRoles(userID, newRoles, sendWebSocketEvent) + resultVar0, resultVar1 := a.app.UpdateUserRoles(c, userID, newRoles, sendWebSocketEvent) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -17651,7 +17651,7 @@ func (a *OpenTracingAppLayer) UpdateUserRoles(userID string, newRoles string, se return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { +func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateUserRolesWithUser") @@ -17663,7 +17663,7 @@ func (a *OpenTracingAppLayer) UpdateUserRolesWithUser(user *model.User, newRoles }() defer span.Finish() - resultVar0, resultVar1 := a.app.UpdateUserRolesWithUser(user, newRoles, sendWebSocketEvent) + resultVar0, resultVar1 := a.app.UpdateUserRolesWithUser(c, user, newRoles, sendWebSocketEvent) if resultVar1 != nil { span.LogFields(spanlog.Error(resultVar1)) @@ -17923,7 +17923,7 @@ func (a *OpenTracingAppLayer) UserIsInAdminRoleGroup(userID string, syncableID s return resultVar0, resultVar1 } -func (a *OpenTracingAppLayer) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError { +func (a *OpenTracingAppLayer) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError { origCtx := a.ctx span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.VerifyEmailFromToken") @@ -17935,7 +17935,7 @@ func (a *OpenTracingAppLayer) VerifyEmailFromToken(userSuppliedTokenString strin }() defer span.Finish() - resultVar0 := a.app.VerifyEmailFromToken(userSuppliedTokenString) + resultVar0 := a.app.VerifyEmailFromToken(c, userSuppliedTokenString) if resultVar0 != nil { span.LogFields(spanlog.Error(resultVar0)) diff --git a/app/plugin_api.go b/app/plugin_api.go index 0b1187d250..d42d08613d 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -318,7 +318,7 @@ func (api *PluginAPI) RevokeUserAccessToken(tokenID string) *model.AppError { } func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) { - return api.app.UpdateUser(user, true) + return api.app.UpdateUser(api.ctx, user, true) } func (api *PluginAPI) UpdateUserActive(userID string, active bool) *model.AppError { @@ -359,11 +359,11 @@ func (api *PluginAPI) SetUserStatusTimedDND(userID string, endTime int64) (*mode } func (api *PluginAPI) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError { - return api.app.SetCustomStatus(userID, customStatus) + return api.app.SetCustomStatus(api.ctx, userID, customStatus) } func (api *PluginAPI) RemoveUserCustomStatus(userID string) *model.AppError { - return api.app.RemoveCustomStatus(userID) + return api.app.RemoveCustomStatus(api.ctx, userID) } func (api *PluginAPI) GetUserCustomStatus(userID string) (*model.CustomStatus, *model.AppError) { @@ -738,7 +738,7 @@ func (api *PluginAPI) SetProfileImage(userID string, data []byte) *model.AppErro return err } - return api.app.SetProfileImageFromFile(userID, bytes.NewReader(data)) + return api.app.SetProfileImageFromFile(api.ctx, userID, bytes.NewReader(data)) } func (api *PluginAPI) GetEmojiList(sortBy string, page, perPage int) ([]*model.Emoji, *model.AppError) { diff --git a/app/slashcommands/command_custom_status.go b/app/slashcommands/command_custom_status.go index 4f50614c8d..74749b5f85 100644 --- a/app/slashcommands/command_custom_status.go +++ b/app/slashcommands/command_custom_status.go @@ -48,7 +48,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *mod message = strings.TrimSpace(message) if message == CmdCustomStatusClear { - if err := a.RemoveCustomStatus(args.UserId); err != nil { + if err := a.RemoveCustomStatus(c, args.UserId); err != nil { mlog.Debug(err.Error()) return &model.CommandResponse{Text: args.T("api.command_custom_status.clear.app_error"), ResponseType: model.CommandResponseTypeEphemeral} } @@ -61,7 +61,7 @@ func (*CustomStatusProvider) DoCommand(a *app.App, c *request.Context, args *mod customStatus := GetCustomStatus(message) customStatus.PreSave() - if err := a.SetCustomStatus(args.UserId, customStatus); err != nil { + if err := a.SetCustomStatus(c, args.UserId, customStatus); err != nil { mlog.Debug(err.Error()) return &model.CommandResponse{Text: args.T("api.command_custom_status.app_error"), ResponseType: model.CommandResponseTypeEphemeral} } diff --git a/app/slashcommands/helper_test.go b/app/slashcommands/helper_test.go index 2435c71feb..32d9d4c4ce 100644 --- a/app/slashcommands/helper_test.go +++ b/app/slashcommands/helper_test.go @@ -165,7 +165,7 @@ func (th *TestHelper) initBasic() *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() diff --git a/app/status.go b/app/status.go index 7ec9c304f5..374e3477de 100644 --- a/app/status.go +++ b/app/status.go @@ -8,6 +8,7 @@ import ( "errors" "net/http" + "github.com/mattermost/mattermost-server/v6/app/request" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/mattermost/mattermost-server/v6/store" @@ -405,7 +406,7 @@ func (a *App) UpdateDNDStatusOfUsers() { } } -func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError { +func (a *App) SetCustomStatus(c request.CTX, userID string, cs *model.CustomStatus) *model.AppError { if cs == nil || (cs.Emoji == "" && cs.Text == "") { return model.NewAppError("SetCustomStatus", "api.custom_status.set_custom_statuses.update.app_error", nil, "", http.StatusBadRequest) } @@ -416,26 +417,26 @@ func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppE } user.SetCustomStatus(cs) - _, updateErr := a.UpdateUser(user, true) + _, updateErr := a.UpdateUser(c, user, true) if updateErr != nil { return updateErr } if err := a.addRecentCustomStatus(userID, cs); err != nil { - a.Log().Error("Can't add recent custom status for", mlog.String("userID", userID), mlog.Err(err)) + c.Logger().Error("Can't add recent custom status for", mlog.String("userID", userID), mlog.Err(err)) } return nil } -func (a *App) RemoveCustomStatus(userID string) *model.AppError { +func (a *App) RemoveCustomStatus(c request.CTX, userID string) *model.AppError { user, err := a.GetUser(userID) if err != nil { return err } user.ClearCustomStatus() - _, updateErr := a.UpdateUser(user, true) + _, updateErr := a.UpdateUser(c, user, true) if updateErr != nil { return updateErr } diff --git a/app/status_test.go b/app/status_test.go index 74d82f5153..e56ef60728 100644 --- a/app/status_test.go +++ b/app/status_test.go @@ -53,14 +53,14 @@ func TestCustomStatus(t *testing.T) { Text: "honk!", } - err := th.App.SetCustomStatus(user.Id, cs) + err := th.App.SetCustomStatus(th.Context, user.Id, cs) require.Nil(t, err, "failed to set custom status %v", err) csSaved, err := th.App.GetCustomStatus(user.Id) require.Nil(t, err, "failed to get custom status after save %v", err) require.Equal(t, cs, csSaved) - err = th.App.RemoveCustomStatus(user.Id) + err = th.App.RemoveCustomStatus(th.Context, user.Id) require.Nil(t, err, "failed to to clear custom status %v", err) var csClear *model.CustomStatus @@ -117,9 +117,9 @@ func TestCustomStatusErrors(t *testing.T) { var appErr *model.AppError switch tc.customStatus { case "set": - appErr = th.App.SetCustomStatus(fakeUserID, cs) + appErr = th.App.SetCustomStatus(th.Context, fakeUserID, cs) case "remove": - appErr = th.App.RemoveCustomStatus(fakeUserID) + appErr = th.App.RemoveCustomStatus(th.Context, fakeUserID) } require.NotNil(t, appErr) diff --git a/app/syncables_test.go b/app/syncables_test.go index c996546f80..6947af7342 100644 --- a/app/syncables_test.go +++ b/app/syncables_test.go @@ -337,7 +337,7 @@ func TestCreateDefaultMemberships(t *testing.T) { t.Run("Team with restricted domains skips over members that do not match the allowed domains", func(t *testing.T) { restrictedUser := th.CreateUser() restrictedUser.Email = "restricted@mattermost.org" - _, err = th.App.UpdateUser(restrictedUser, false) + _, err = th.App.UpdateUser(th.Context, restrictedUser, false) require.Nil(t, err) _, err = th.App.UpsertGroupMember(scienceGroup.Id, restrictedUser.Id) require.Nil(t, err) diff --git a/app/team.go b/app/team.go index 94c25aae79..6240f4b932 100644 --- a/app/team.go +++ b/app/team.go @@ -763,7 +763,7 @@ func (a *App) AddUserToTeamByInviteId(c *request.Context, inviteId string, userI return team, teamMember, nil } -func (a *App) JoinUserToTeam(c *request.Context, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) { +func (a *App) JoinUserToTeam(c request.CTX, team *model.Team, user *model.User, userRequestorId string) (*model.TeamMember, *model.AppError) { teamMember, alreadyAdded, err := a.ch.srv.teamService.JoinUserToTeam(team, user) if err != nil { var appErr *model.AppError diff --git a/app/user.go b/app/user.go index 89dabb2f82..edeef970ff 100644 --- a/app/user.go +++ b/app/user.go @@ -43,7 +43,7 @@ const ( ImageProfilePixelDimension = 128 ) -func (a *App) CreateUserWithToken(c *request.Context, user *model.User, token *model.Token) (*model.User, *model.AppError) { +func (a *App) CreateUserWithToken(c request.CTX, user *model.User, token *model.Token) (*model.User, *model.AppError) { if err := a.IsUserSignUpAllowed(); err != nil { return nil, err } @@ -104,19 +104,19 @@ func (a *App) CreateUserWithToken(c *request.Context, user *model.User, token *m for _, channel := range channels { _, err := a.AddChannelMember(c, ruser.Id, channel, ChannelMemberOpts{}) if err != nil { - mlog.Warn("Failed to add channel member", mlog.Err(err)) + c.Logger().Warn("Failed to add channel member", mlog.Err(err)) } } } if err := a.DeleteToken(token); err != nil { - mlog.Warn("Error while deleting token", mlog.Err(err)) + c.Logger().Warn("Error while deleting token", mlog.Err(err)) } return ruser, nil } -func (a *App) CreateUserWithInviteId(c *request.Context, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) { +func (a *App) CreateUserWithInviteId(c request.CTX, user *model.User, inviteId, redirect string) (*model.User, *model.AppError) { if err := a.IsUserSignUpAllowed(); err != nil { return nil, err } @@ -154,26 +154,26 @@ func (a *App) CreateUserWithInviteId(c *request.Context, user *model.User, invit a.AddDirectChannels(c, team.Id, ruser) if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil { - mlog.Warn("Failed to send welcome email on create user with inviteId", mlog.Err(err)) + c.Logger().Warn("Failed to send welcome email on create user with inviteId", mlog.Err(err)) } return ruser, nil } -func (a *App) CreateUserAsAdmin(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) { +func (a *App) CreateUserAsAdmin(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) { ruser, err := a.CreateUser(c, user) if err != nil { return nil, err } if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil { - mlog.Warn("Failed to send welcome email to the new user, created by system admin", mlog.Err(err)) + c.Logger().Warn("Failed to send welcome email to the new user, created by system admin", mlog.Err(err)) } return ruser, nil } -func (a *App) CreateUserFromSignup(c *request.Context, user *model.User, redirect string) (*model.User, *model.AppError) { +func (a *App) CreateUserFromSignup(c request.CTX, user *model.User, redirect string) (*model.User, *model.AppError) { if err := a.IsUserSignUpAllowed(); err != nil { return nil, err } @@ -191,7 +191,7 @@ func (a *App) CreateUserFromSignup(c *request.Context, user *model.User, redirec } if err := a.Srv().EmailService.SendWelcomeEmail(ruser.Id, ruser.Email, ruser.EmailVerified, ruser.DisableWelcomeEmail, ruser.Locale, a.GetSiteURL(), redirect); err != nil { - mlog.Warn("Failed to send welcome email on create user from signup", mlog.Err(err)) + c.Logger().Warn("Failed to send welcome email on create user from signup", mlog.Err(err)) } return ruser, nil @@ -211,17 +211,17 @@ func (a *App) IsFirstUserAccount() bool { // CreateUser creates a user and sets several fields of the returned User struct to // their zero values. -func (a *App) CreateUser(c *request.Context, user *model.User) (*model.User, *model.AppError) { +func (a *App) CreateUser(c request.CTX, user *model.User) (*model.User, *model.AppError) { return a.createUserOrGuest(c, user, false) } // CreateGuest creates a guest and sets several fields of the returned User struct to // their zero values. -func (a *App) CreateGuest(c *request.Context, user *model.User) (*model.User, *model.AppError) { +func (a *App) CreateGuest(c request.CTX, user *model.User) (*model.User, *model.AppError) { return a.createUserOrGuest(c, user, true) } -func (a *App) createUserOrGuest(c *request.Context, user *model.User, guest bool) (*model.User, *model.AppError) { +func (a *App) createUserOrGuest(c request.CTX, user *model.User, guest bool) (*model.User, *model.AppError) { if err := a.isUniqueToGroupNames(user.Username); err != nil { err.Where = "createUserOrGuest" return nil, err @@ -285,7 +285,7 @@ func (a *App) createUserOrGuest(c *request.Context, user *model.User, guest bool } if err := a.Srv().Store.Preference().Save(preferences); err != nil { - mlog.Warn("Encountered error saving user preferences", mlog.Err(err)) + c.Logger().Warn("Encountered error saving user preferences", mlog.Err(err)) } go a.UpdateViewedProductNoticesForNewUser(ruser.Id) @@ -347,7 +347,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re if provider.IsSameUser(userByEmail, user) { if _, err := a.Srv().Store.User().UpdateAuthData(userByEmail.Id, user.AuthService, user.AuthData, "", false); err != nil { // if the user is not updated, write a warning to the log, but don't prevent user login - mlog.Warn("Error attempting to update user AuthData", mlog.Err(err)) + c.Logger().Warn("Error attempting to update user AuthData", mlog.Err(err)) } return userByEmail, nil } @@ -369,7 +369,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re err = a.AddDirectChannels(c, teamID, user) if err != nil { - mlog.Warn("Failed to add direct channels", mlog.Err(err)) + c.Logger().Warn("Failed to add direct channels", mlog.Err(err)) } } @@ -759,7 +759,7 @@ func (a *App) GetDefaultProfileImage(user *model.User) ([]byte, *model.AppError) return a.ch.srv.GetDefaultProfileImage(user) } -func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError { +func (a *App) SetDefaultProfileImage(c request.CTX, user *model.User) *model.AppError { img, appErr := a.GetDefaultProfileImage(user) if appErr != nil { return appErr @@ -771,14 +771,14 @@ func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError { } if err := a.Srv().Store.User().ResetLastPictureUpdate(user.Id); err != nil { - mlog.Warn("Failed to reset last picture update", mlog.Err(err)) + c.Logger().Warn("Failed to reset last picture update", mlog.Err(err)) } a.InvalidateCacheForUser(user.Id) updatedUser, appErr := a.GetUser(user.Id) if appErr != nil { - mlog.Warn("Error in getting users profile forcing logout", mlog.String("user_id", user.Id), mlog.Err(appErr)) + c.Logger().Warn("Error in getting users profile forcing logout", mlog.String("user_id", user.Id), mlog.Err(appErr)) return nil } @@ -792,21 +792,21 @@ func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError { return nil } -func (a *App) SetProfileImage(userID string, imageData *multipart.FileHeader) *model.AppError { +func (a *App) SetProfileImage(c request.CTX, userID string, imageData *multipart.FileHeader) *model.AppError { file, err := imageData.Open() if err != nil { return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.open.app_error", nil, err.Error(), http.StatusBadRequest) } defer file.Close() - return a.SetProfileImageFromMultiPartFile(userID, file) + return a.SetProfileImageFromMultiPartFile(c, userID, file) } -func (a *App) SetProfileImageFromMultiPartFile(userID string, file multipart.File) *model.AppError { +func (a *App) SetProfileImageFromMultiPartFile(c request.CTX, userID string, file multipart.File) *model.AppError { if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil { return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest) } - return a.SetProfileImageFromFile(userID, file) + return a.SetProfileImageFromFile(c, userID, file) } func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) { @@ -831,7 +831,7 @@ func (a *App) AdjustImage(file io.Reader) (*bytes.Buffer, *model.AppError) { return buf, nil } -func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppError { +func (a *App) SetProfileImageFromFile(c request.CTX, userID string, file io.Reader) *model.AppError { buf, err := a.AdjustImage(file) if err != nil { return err @@ -847,7 +847,7 @@ func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppE } if err := a.Srv().Store.User().UpdateLastPictureUpdate(userID); err != nil { - mlog.Warn("Error with updating last picture update", mlog.Err(err)) + c.Logger().Warn("Error with updating last picture update", mlog.Err(err)) } a.invalidateUserCacheAndPublish(userID) a.onUserProfileChange(userID) @@ -855,7 +855,7 @@ func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppE return nil } -func (a *App) UpdatePasswordAsUser(userID, currentPassword, newPassword string) *model.AppError { +func (a *App) UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPassword string) *model.AppError { user, err := a.GetUser(userID) if err != nil { return err @@ -880,7 +880,7 @@ func (a *App) UpdatePasswordAsUser(userID, currentPassword, newPassword string) T := i18n.GetUserTranslations(user.Locale) - return a.UpdatePasswordSendEmail(user, newPassword, T("api.user.update_password.menu")) + return a.UpdatePasswordSendEmail(c, user, newPassword, T("api.user.update_password.menu")) } func (a *App) userDeactivated(c *request.Context, userID string) *model.AppError { @@ -999,8 +999,8 @@ func (a *App) SanitizeProfile(user *model.User, asAdmin bool) { user.SanitizeProfile(options) } -func (a *App) UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError) { - updatedUser, err := a.UpdateUser(user, true) +func (a *App) UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*model.User, *model.AppError) { + updatedUser, err := a.UpdateUser(c, user, true) if err != nil { return nil, err } @@ -1039,7 +1039,7 @@ func (a *App) CheckProviderAttributes(user *model.User, patch *model.UserPatch) return conflictField } -func (a *App) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) { +func (a *App) PatchUser(c request.CTX, userID string, patch *model.UserPatch, asAdmin bool) (*model.User, *model.AppError) { user, err := a.GetUser(userID) if err != nil { return nil, err @@ -1047,7 +1047,7 @@ func (a *App) PatchUser(userID string, patch *model.UserPatch, asAdmin bool) (*m user.Patch(patch) - updatedUser, err := a.UpdateUser(user, true) + updatedUser, err := a.UpdateUser(c, user, true) if err != nil { return nil, err } @@ -1112,7 +1112,7 @@ func (a *App) isUniqueToGroupNames(val string) *model.AppError { return nil } -func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) { +func (a *App) UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) { prev, err := a.ch.srv.userService.GetUser(user.Id) if err != nil { var nfErr *store.ErrNotFound @@ -1192,13 +1192,13 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, if *a.Config().EmailSettings.RequireEmailVerification { a.Srv().Go(func() { if err := a.SendEmailVerification(userUpdate.New, newEmail, ""); err != nil { - mlog.Error("Failed to send email verification", mlog.Err(err)) + c.Logger().Error("Failed to send email verification", mlog.Err(err)) } }) } else { a.Srv().Go(func() { if err := a.Srv().EmailService.SendEmailChangeEmail(userUpdate.Old.Email, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil { - mlog.Error("Failed to send email change email", mlog.Err(err)) + c.Logger().Error("Failed to send email change email", mlog.Err(err)) } }) } @@ -1207,7 +1207,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User, if userUpdate.New.Username != userUpdate.Old.Username { a.Srv().Go(func() { if err := a.Srv().EmailService.SendChangeUsernameEmail(userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil { - mlog.Error("Failed to send change username email", mlog.Err(err)) + c.Logger().Error("Failed to send change username email", mlog.Err(err)) } }) } @@ -1251,7 +1251,7 @@ func (a *App) updateUserNotifyProps(userID string, props map[string]string) *mod return nil } -func (a *App) UpdateMfa(activate bool, userID, token string) *model.AppError { +func (a *App) UpdateMfa(c request.CTX, activate bool, userID, token string) *model.AppError { if activate { if err := a.ActivateMfa(userID, token); err != nil { return err @@ -1265,25 +1265,25 @@ func (a *App) UpdateMfa(activate bool, userID, token string) *model.AppError { a.Srv().Go(func() { user, err := a.GetUser(userID) if err != nil { - mlog.Error("Failed to get user", mlog.Err(err)) + c.Logger().Error("Failed to get user", mlog.Err(err)) return } if err := a.Srv().EmailService.SendMfaChangeEmail(user.Email, activate, user.Locale, a.GetSiteURL()); err != nil { - mlog.Error("Failed to send mfa change email", mlog.Err(err)) + c.Logger().Error("Failed to send mfa change email", mlog.Err(err)) } }) return nil } -func (a *App) UpdatePasswordByUserIdSendEmail(userID, newPassword, method string) *model.AppError { +func (a *App) UpdatePasswordByUserIdSendEmail(c request.CTX, userID, newPassword, method string) *model.AppError { user, err := a.GetUser(userID) if err != nil { return err } - return a.UpdatePasswordSendEmail(user, newPassword, method) + return a.UpdatePasswordSendEmail(c, user, newPassword, method) } func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppError { @@ -1302,14 +1302,14 @@ func (a *App) UpdatePassword(user *model.User, newPassword string) *model.AppErr return nil } -func (a *App) UpdatePasswordSendEmail(user *model.User, newPassword, method string) *model.AppError { +func (a *App) UpdatePasswordSendEmail(c request.CTX, user *model.User, newPassword, method string) *model.AppError { if err := a.UpdatePassword(user, newPassword); err != nil { return err } a.Srv().Go(func() { if err := a.Srv().EmailService.SendPasswordChangeEmail(user.Email, method, user.Locale, a.GetSiteURL()); err != nil { - mlog.Error("Failed to send password change email", mlog.Err(err)) + c.Logger().Error("Failed to send password change email", mlog.Err(err)) } }) @@ -1335,11 +1335,11 @@ func (a *App) UpdateHashedPassword(user *model.User, newHashedPassword string) * return nil } -func (a *App) ResetPasswordFromToken(userSuppliedTokenString, newPassword string) *model.AppError { - return a.resetPasswordFromToken(userSuppliedTokenString, newPassword, model.GetMillis()) +func (a *App) ResetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string) *model.AppError { + return a.resetPasswordFromToken(c, userSuppliedTokenString, newPassword, model.GetMillis()) } -func (a *App) resetPasswordFromToken(userSuppliedTokenString, newPassword string, nowMilli int64) *model.AppError { +func (a *App) resetPasswordFromToken(c request.CTX, userSuppliedTokenString, newPassword string, nowMilli int64) *model.AppError { token, err := a.GetPasswordRecoveryToken(userSuppliedTokenString) if err != nil { return err @@ -1373,12 +1373,12 @@ func (a *App) resetPasswordFromToken(userSuppliedTokenString, newPassword string T := i18n.GetUserTranslations(user.Locale) - if err := a.UpdatePasswordSendEmail(user, newPassword, T("api.user.reset_password.method")); err != nil { + if err := a.UpdatePasswordSendEmail(c, user, newPassword, T("api.user.reset_password.method")); err != nil { return err } if err := a.DeleteToken(token); err != nil { - mlog.Warn("Failed to delete token", mlog.Err(err)) + c.Logger().Warn("Failed to delete token", mlog.Err(err)) } return nil @@ -1474,17 +1474,17 @@ func (a *App) DeleteToken(token *model.Token) *model.AppError { return nil } -func (a *App) UpdateUserRoles(userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { +func (a *App) UpdateUserRoles(c request.CTX, userID string, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { user, err := a.GetUser(userID) if err != nil { err.StatusCode = http.StatusBadRequest return nil, err } - return a.UpdateUserRolesWithUser(user, newRoles, sendWebSocketEvent) + return a.UpdateUserRolesWithUser(c, user, newRoles, sendWebSocketEvent) } -func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { +func (a *App) UpdateUserRolesWithUser(c request.CTX, user *model.User, newRoles string, sendWebSocketEvent bool) (*model.User, *model.AppError) { if err := a.CheckRolesExist(strings.Fields(newRoles)); err != nil { return nil, err @@ -1522,7 +1522,7 @@ func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWeb if result := <-schan; result.NErr != nil { // soft error since the user roles were still updated - mlog.Warn("Failed during updating user roles", mlog.Err(result.NErr)) + c.Logger().Warn("Failed during updating user roles", mlog.Err(result.NErr)) } a.InvalidateCacheForUser(user.Id) @@ -1539,9 +1539,9 @@ func (a *App) UpdateUserRolesWithUser(user *model.User, newRoles string, sendWeb } func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.AppError { - mlog.Warn("Attempting to permanently delete account", mlog.String("user_id", user.Id), mlog.String("user_email", user.Email)) + c.Logger().Warn("Attempting to permanently delete account", mlog.String("user_id", user.Id), mlog.String("user_email", user.Email)) if user.IsInRole(model.SystemAdminRoleId) { - mlog.Warn("You are deleting a user that is a system administrator. You may need to set another account as the system administrator using the command line tools.", mlog.String("user_email", user.Email)) + c.Logger().Warn("You are deleting a user that is a system administrator. You may need to set another account as the system administrator using the command line tools.", mlog.String("user_email", user.Email)) } if _, err := a.UpdateActive(c, user, false); err != nil { @@ -1600,13 +1600,13 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A infos, err := a.Srv().Store.FileInfo().GetForUser(user.Id) if err != nil { - mlog.Warn("Error getting file list for user from FileInfoStore", mlog.Err(err)) + c.Logger().Warn("Error getting file list for user from FileInfoStore", mlog.Err(err)) } for _, info := range infos { res, err := a.FileExists(info.Path) if err != nil { - mlog.Warn( + c.Logger().Warn( "Error checking existence of file", mlog.String("path", info.Path), mlog.Err(err), @@ -1615,14 +1615,14 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A } if !res { - mlog.Warn("File not found", mlog.String("path", info.Path)) + c.Logger().Warn("File not found", mlog.String("path", info.Path)) continue } err = a.RemoveFile(info.Path) if err != nil { - mlog.Warn( + c.Logger().Warn( "Unable to remove file", mlog.String("path", info.Path), mlog.Err(err), @@ -1646,7 +1646,7 @@ func (a *App) PermanentDeleteUser(c *request.Context, user *model.User) *model.A return model.NewAppError("PermanentDeleteUser", "app.team.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError) } - mlog.Warn("Permanently deleted account", mlog.String("user_email", user.Email), mlog.String("user_id", user.Id)) + c.Logger().Warn("Permanently deleted account", mlog.String("user_email", user.Email), mlog.String("user_id", user.Id)) return nil } @@ -1693,7 +1693,7 @@ func (a *App) SendEmailVerification(user *model.User, newEmail, redirect string) return nil } -func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppError { +func (a *App) VerifyEmailFromToken(c request.CTX, userSuppliedTokenString string) *model.AppError { token, err := a.GetVerifyEmailToken(userSuppliedTokenString) if err != nil { return err @@ -1731,7 +1731,7 @@ func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppErr } if err := a.DeleteToken(token); err != nil { - mlog.Warn("Failed to delete token", mlog.Err(err)) + c.Logger().Warn("Failed to delete token", mlog.Err(err)) } return nil @@ -2163,23 +2163,23 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor for _, team := range userTeams { // Soft error if there is an issue joining the default channels if err := a.JoinDefaultChannels(c, team.Id, user, false, requestorId); err != nil { - mlog.Warn("Failed to join default channels", mlog.String("user_id", user.Id), mlog.String("team_id", team.Id), mlog.String("requestor_id", requestorId), mlog.Err(err)) + c.Logger().Warn("Failed to join default channels", mlog.String("user_id", user.Id), mlog.String("team_id", team.Id), mlog.String("requestor_id", requestorId), mlog.Err(err)) } } promotedUser, err := a.GetUser(user.Id) if err != nil { - mlog.Warn("Failed to get user on promote guest to user", mlog.Err(err)) + c.Logger().Warn("Failed to get user on promote guest to user", mlog.Err(err)) } else { a.sendUpdatedUserEvent(*promotedUser) if uErr := a.ch.srv.userService.UpdateSessionsIsGuest(promotedUser.Id, promotedUser.IsGuest()); uErr != nil { - mlog.Warn("Unable to update user sessions", mlog.String("user_id", promotedUser.Id), mlog.Err(uErr)) + c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", promotedUser.Id), mlog.Err(uErr)) } } teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true) if err != nil { - mlog.Warn("Failed to get team members for user on promote guest to user", mlog.Err(err)) + c.Logger().Warn("Failed to get team members for user on promote guest to user", mlog.Err(err)) } for _, member := range teamMembers { @@ -2187,7 +2187,7 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id) if err != nil { - mlog.Warn("Failed to get channel members for user on promote guest to user", mlog.Err(err)) + c.Logger().Warn("Failed to get channel members for user on promote guest to user", mlog.Err(err)) } for _, member := range channelMembers { @@ -2196,7 +2196,7 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil) memberJSON, jsonErr := json.Marshal(member) if jsonErr != nil { - mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr)) + c.Logger().Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr)) } evt.Add("channelMember", string(memberJSON)) a.Publish(evt) @@ -2218,12 +2218,12 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError a.sendUpdatedUserEvent(*demotedUser) if uErr := a.ch.srv.userService.UpdateSessionsIsGuest(demotedUser.Id, demotedUser.IsGuest()); uErr != nil { - mlog.Warn("Unable to update user sessions", mlog.String("user_id", demotedUser.Id), mlog.Err(uErr)) + c.Logger().Warn("Unable to update user sessions", mlog.String("user_id", demotedUser.Id), mlog.Err(uErr)) } teamMembers, err := a.GetTeamMembersForUser(user.Id, "", true) if err != nil { - mlog.Warn("Failed to get team members for users on demote user to guest", mlog.Err(err)) + c.Logger().Warn("Failed to get team members for users on demote user to guest", mlog.Err(err)) } for _, member := range teamMembers { @@ -2231,7 +2231,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id) if err != nil { - mlog.Warn("Failed to get channel members for users on demote user to guest", mlog.Err(err)) + c.Logger().Warn("Failed to get channel members for users on demote user to guest", mlog.Err(err)) continue } @@ -2241,7 +2241,7 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", user.Id, nil) memberJSON, jsonErr := json.Marshal(member) if jsonErr != nil { - mlog.Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr)) + c.Logger().Warn("Failed to encode channel member to JSON", mlog.Err(jsonErr)) } evt.Add("channelMember", string(memberJSON)) a.Publish(evt) @@ -2295,8 +2295,8 @@ func (a *App) GetKnownUsers(userID string) ([]string, *model.AppError) { } // ConvertBotToUser converts a bot to user. -func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) { - user, nErr := a.Srv().Store.User().Get(context.Background(), bot.UserId) +func (a *App) ConvertBotToUser(c request.CTX, bot *model.Bot, userPatch *model.UserPatch, sysadmin bool) (*model.User, *model.AppError) { + user, nErr := a.Srv().Store.User().Get(c.Context(), bot.UserId) if nErr != nil { var nfErr *store.ErrNotFound switch { @@ -2308,7 +2308,7 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad } if sysadmin && !user.IsInRole(model.SystemAdminRoleId) { - _, appErr := a.UpdateUserRoles( + _, appErr := a.UpdateUserRoles(c, user.Id, fmt.Sprintf("%s %s", user.Roles, model.SystemAdminRoleId), false) @@ -2319,7 +2319,7 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad user.Patch(userPatch) - user, err := a.UpdateUser(user, false) + user, err := a.UpdateUser(c, user, false) if err != nil { return nil, err } @@ -2518,7 +2518,7 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(c request.CTX, userID, tea payload, jsonErr := json.Marshal(userThread) if jsonErr != nil { - mlog.Warn("Failed to encode thread to JSON") + c.Logger().Warn("Failed to encode thread to JSON") } message.Add("thread", string(payload)) message.Add("previous_unread_replies", int64(0)) diff --git a/app/user_test.go b/app/user_test.go index ad4786e52c..4d545f894f 100644 --- a/app/user_test.go +++ b/app/user_test.go @@ -88,7 +88,7 @@ func TestSetDefaultProfileImage(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - err := th.App.SetDefaultProfileImage(&model.User{ + err := th.App.SetDefaultProfileImage(th.Context, &model.User{ Id: model.NewId(), Username: "notvaliduser", }) @@ -97,7 +97,7 @@ func TestSetDefaultProfileImage(t *testing.T) { user := th.BasicUser - err = th.App.SetDefaultProfileImage(user) + err = th.App.SetDefaultProfileImage(th.Context, user) require.Nil(t, err) user = getUserFromDB(th.App, user.Id, t) @@ -140,11 +140,11 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) { *cfg.TeamSettings.RestrictCreationToDomains = "foo.com" }) - _, err := th.App.UpdateUser(user, false) + _, err := th.App.UpdateUser(th.Context, user, false) assert.Nil(t, err) user.Email = "asdf@ghjk.l" - _, err = th.App.UpdateUser(user, false) + _, err = th.App.UpdateUser(th.Context, user, false) assert.NotNil(t, err) t.Run("Restricted Domains must be ignored for guest users", func(t *testing.T) { @@ -156,7 +156,7 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) { }) guest.Email = "asdf@bar.com" - updatedGuest, err := th.App.UpdateUser(guest, false) + updatedGuest, err := th.App.UpdateUser(th.Context, guest, false) require.Nil(t, err) require.Equal(t, guest.Email, updatedGuest.Email) }) @@ -170,11 +170,11 @@ func TestUpdateUserToRestrictedDomain(t *testing.T) { }) guest.Email = "asdf@bar.com" - _, err := th.App.UpdateUser(guest, false) + _, err := th.App.UpdateUser(th.Context, guest, false) require.NotNil(t, err) guest.Email = "asdf@foo.com" - updatedGuest, err := th.App.UpdateUser(guest, false) + updatedGuest, err := th.App.UpdateUser(th.Context, guest, false) require.Nil(t, err) require.Equal(t, guest.Email, updatedGuest.Email) }) @@ -189,7 +189,7 @@ func TestUpdateUser(t *testing.T) { t.Run("fails if the username matches a group name", func(t *testing.T) { user.Username = *group.Name - u, err := th.App.UpdateUser(user, false) + u, err := th.App.UpdateUser(th.Context, user, false) require.NotNil(t, err) require.Equal(t, "app.user.group_name_conflict", err.Id) require.Nil(t, u) @@ -215,7 +215,7 @@ func TestUpdateUserMissingFields(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - _, err := th.App.UpdateUser(tc.input, false) + _, err := th.App.UpdateUser(th.Context, tc.input, false) if name == "no missing fields" { assert.Nil(t, err) @@ -517,7 +517,7 @@ func TestUpdateUserEmail(t *testing.T) { newEmail := th.MakeEmail() user.Email = newEmail - user2, appErr := th.App.UpdateUser(user, false) + user2, appErr := th.App.UpdateUser(th.Context, user, false) assert.Nil(t, appErr) assert.Equal(t, currentEmail, user2.Email) assert.True(t, user2.EmailVerified) @@ -525,7 +525,7 @@ func TestUpdateUserEmail(t *testing.T) { token, err := th.App.Srv().EmailService.CreateVerifyEmailToken(user2.Id, newEmail) assert.NoError(t, err) - appErr = th.App.VerifyEmailFromToken(token.Token) + appErr = th.App.VerifyEmailFromToken(th.Context, token.Token) assert.Nil(t, appErr) user2, appErr = th.App.GetUser(user2.Id) @@ -544,7 +544,7 @@ func TestUpdateUserEmail(t *testing.T) { newBotEmail := th.MakeEmail() botuser.Email = newBotEmail - botuser2, appErr := th.App.UpdateUser(&botuser, false) + botuser2, appErr := th.App.UpdateUser(th.Context, &botuser, false) assert.Nil(t, appErr) assert.Equal(t, botuser2.Email, newBotEmail) @@ -559,7 +559,7 @@ func TestUpdateUserEmail(t *testing.T) { newEmail := user2.Email user.Email = newEmail - user3, err := th.App.UpdateUser(user, false) + user3, err := th.App.UpdateUser(th.Context, user, false) require.NotNil(t, err) assert.Equal(t, err.Id, "app.user.save.email_exists.app_error") assert.Nil(t, user3) @@ -573,7 +573,7 @@ func TestUpdateUserEmail(t *testing.T) { newEmail := th.MakeEmail() user.Email = newEmail - user2, err := th.App.UpdateUser(user, false) + user2, err := th.App.UpdateUser(th.Context, user, false) assert.Nil(t, err) assert.Equal(t, newEmail, user2.Email) @@ -588,7 +588,7 @@ func TestUpdateUserEmail(t *testing.T) { newBotEmail := th.MakeEmail() botuser.Email = newBotEmail - botuser2, err := th.App.UpdateUser(&botuser, false) + botuser2, err := th.App.UpdateUser(th.Context, &botuser, false) assert.Nil(t, err) assert.Equal(t, botuser2.Email, newBotEmail) }) @@ -602,7 +602,7 @@ func TestUpdateUserEmail(t *testing.T) { newEmail := user2.Email user.Email = newEmail - user3, err := th.App.UpdateUser(user, false) + user3, err := th.App.UpdateUser(th.Context, user, false) require.NotNil(t, err) assert.Equal(t, err.Id, "app.user.save.email_exists.app_error") assert.Nil(t, user3) @@ -616,7 +616,7 @@ func TestUpdateUserEmail(t *testing.T) { // we update the email a first time and update. The first // token is sent with the email user.Email = th.MakeEmail() - _, appErr := th.App.UpdateUser(user, true) + _, appErr := th.App.UpdateUser(th.Context, user, true) require.Nil(t, appErr) tokens := []*model.Token{} @@ -632,7 +632,7 @@ func TestUpdateUserEmail(t *testing.T) { // time and another token gets sent. The first one should not // work anymore and the second should work properly user.Email = th.MakeEmail() - _, appErr = th.App.UpdateUser(user, true) + _, appErr = th.App.UpdateUser(th.Context, user, true) require.Nil(t, appErr) require.Eventually(t, func() bool { @@ -649,9 +649,9 @@ func TestUpdateUserEmail(t *testing.T) { _, err := th.App.Srv().Store.Token().GetByToken(firstToken.Token) require.Error(t, err) - require.NotNil(t, th.App.VerifyEmailFromToken(firstToken.Token)) - require.Nil(t, th.App.VerifyEmailFromToken(secondToken.Token)) - require.NotNil(t, th.App.VerifyEmailFromToken(firstToken.Token)) + require.NotNil(t, th.App.VerifyEmailFromToken(th.Context, firstToken.Token)) + require.Nil(t, th.App.VerifyEmailFromToken(th.Context, secondToken.Token)) + require.NotNil(t, th.App.VerifyEmailFromToken(th.Context, firstToken.Token)) }) } @@ -1096,7 +1096,7 @@ func TestPasswordRecovery(t *testing.T) { assert.Equal(t, th.BasicUser.Id, tokenData.UserId) assert.Equal(t, th.BasicUser.Email, tokenData.Email) - err = th.App.ResetPasswordFromToken(token.Token, "abcdefgh") + err = th.App.ResetPasswordFromToken(th.Context, token.Token, "abcdefgh") assert.Nil(t, err) }) @@ -1109,10 +1109,10 @@ func TestPasswordRecovery(t *testing.T) { }) th.BasicUser.Email = th.MakeEmail() - _, err = th.App.UpdateUser(th.BasicUser, false) + _, err = th.App.UpdateUser(th.Context, th.BasicUser, false) assert.Nil(t, err) - err = th.App.ResetPasswordFromToken(token.Token, "abcdefgh") + err = th.App.ResetPasswordFromToken(th.Context, token.Token, "abcdefgh") assert.NotNil(t, err) }) @@ -1120,7 +1120,7 @@ func TestPasswordRecovery(t *testing.T) { token, err := th.App.CreatePasswordRecoveryToken(th.BasicUser.Id, th.BasicUser.Email) assert.Nil(t, err) - err = th.App.resetPasswordFromToken(token.Token, "abcdefgh", model.GetMillis()) + err = th.App.resetPasswordFromToken(th.Context, token.Token, "abcdefgh", model.GetMillis()) assert.Nil(t, err) }) @@ -1128,7 +1128,7 @@ func TestPasswordRecovery(t *testing.T) { token, err := th.App.CreatePasswordRecoveryToken(th.BasicUser.Id, th.BasicUser.Email) assert.Nil(t, err) - err = th.App.resetPasswordFromToken(token.Token, "abcdefgh", model.GetMillisForTime(time.Now().Add(25*time.Hour))) + err = th.App.resetPasswordFromToken(th.Context, token.Token, "abcdefgh", model.GetMillisForTime(time.Now().Add(25*time.Hour))) assert.NotNil(t, err) }) @@ -1604,12 +1604,12 @@ func TestUpdateUserRolesWithUser(t *testing.T) { assert.Equal(t, user.Roles, model.SystemUserRoleId) // Upgrade to sysadmin. - user, err := th.App.UpdateUserRolesWithUser(user, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + user, err := th.App.UpdateUserRolesWithUser(th.Context, user, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) require.Nil(t, err) assert.Equal(t, user.Roles, model.SystemUserRoleId+" "+model.SystemAdminRoleId) // Test bad role. - _, err = th.App.UpdateUserRolesWithUser(user, "does not exist", false) + _, err = th.App.UpdateUserRolesWithUser(th.Context, user, "does not exist", false) require.NotNil(t, err) } @@ -1636,7 +1636,7 @@ func TestPatchUser(t *testing.T) { defer th.App.PermanentDeleteUser(th.Context, testUser) t.Run("Patch with a username already exists", func(t *testing.T) { - _, err := th.App.PatchUser(testUser.Id, &model.UserPatch{ + _, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{ Username: model.NewString(th.BasicUser.Username), }, true) @@ -1645,7 +1645,7 @@ func TestPatchUser(t *testing.T) { }) t.Run("Patch with a email already exists", func(t *testing.T) { - _, err := th.App.PatchUser(testUser.Id, &model.UserPatch{ + _, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{ Email: model.NewString(th.BasicUser.Email), }, true) @@ -1654,7 +1654,7 @@ func TestPatchUser(t *testing.T) { }) t.Run("Patch username with a new username", func(t *testing.T) { - _, err := th.App.PatchUser(testUser.Id, &model.UserPatch{ + _, err := th.App.PatchUser(th.Context, testUser.Id, &model.UserPatch{ Username: model.NewString(model.NewId()), }, true) diff --git a/app/user_viewmembers_test.go b/app/user_viewmembers_test.go index 1c3e4309aa..055151b95a 100644 --- a/app/user_viewmembers_test.go +++ b/app/user_viewmembers_test.go @@ -20,23 +20,23 @@ func TestRestrictedViewMembers(t *testing.T) { user1 := th.CreateUser() user1.Nickname = "test user1" user1.Username = "test-user-1" - th.App.UpdateUser(user1, false) + th.App.UpdateUser(th.Context, user1, false) user2 := th.CreateUser() user2.Username = "test-user-2" user2.Nickname = "test user2" - th.App.UpdateUser(user2, false) + th.App.UpdateUser(th.Context, user2, false) user3 := th.CreateUser() user3.Username = "test-user-3" user3.Nickname = "test user3" - th.App.UpdateUser(user3, false) + th.App.UpdateUser(th.Context, user3, false) user4 := th.CreateUser() user4.Username = "test-user-4" user4.Nickname = "test user4" - th.App.UpdateUser(user4, false) + th.App.UpdateUser(th.Context, user4, false) user5 := th.CreateUser() user5.Username = "test-user-5" user5.Nickname = "test user5" - th.App.UpdateUser(user5, false) + th.App.UpdateUser(th.Context, user5, false) // user1 is member of all the channels and teams because is the creator th.BasicUser = user1 diff --git a/einterfaces/ldap.go b/einterfaces/ldap.go index 990a4fd98a..23e38405af 100644 --- a/einterfaces/ldap.go +++ b/einterfaces/ldap.go @@ -23,7 +23,7 @@ type LdapInterface interface { GetGroup(groupUID string) (*model.Group, *model.AppError) GetAllGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError) FirstLoginSync(c *request.Context, user *model.User, userAuthService, userAuthData, email string) *model.AppError - UpdateProfilePictureIfNecessary(model.User, model.Session) + UpdateProfilePictureIfNecessary(request.CTX, model.User, model.Session) GetADLdapIdFromSAMLId(authData string) string GetSAMLIdFromADLdapId(authData string) string GetVendorNameAndVendorVersion() (string, string) diff --git a/einterfaces/mocks/LdapInterface.go b/einterfaces/mocks/LdapInterface.go index cb3a3850a8..6c4b1ad25a 100644 --- a/einterfaces/mocks/LdapInterface.go +++ b/einterfaces/mocks/LdapInterface.go @@ -354,7 +354,7 @@ func (_m *LdapInterface) SwitchToLdap(userID string, ldapID string, ldapPassword return r0 } -// UpdateProfilePictureIfNecessary provides a mock function with given fields: _a0, _a1 -func (_m *LdapInterface) UpdateProfilePictureIfNecessary(_a0 model.User, _a1 model.Session) { - _m.Called(_a0, _a1) +// UpdateProfilePictureIfNecessary provides a mock function with given fields: _a0, _a1, _a2 +func (_m *LdapInterface) UpdateProfilePictureIfNecessary(_a0 request.CTX, _a1 model.User, _a2 model.Session) { + _m.Called(_a0, _a1, _a2) } diff --git a/product/api.go b/product/api.go index 539b497a31..33da6c5899 100644 --- a/product/api.go +++ b/product/api.go @@ -80,7 +80,7 @@ type LicenseService interface { // The service shall be registered via app.UserKey service key. type UserService interface { GetUser(userID string) (*model.User, *model.AppError) - UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError) + UpdateUser(c request.CTX, user *model.User, sendNotifications bool) (*model.User, *model.AppError) GetUserByEmail(email string) (*model.User, *model.AppError) GetUserByUsername(username string) (*model.User, *model.AppError) GetUsersFromProfiles(options *model.UserGetOptions) ([]*model.User, *model.AppError)