[GH-25494] add request context to public methods in bot go (#26408)
Этот коммит содержится в:
@@ -485,9 +485,9 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
}
|
||||
|
||||
func (th *TestHelper) DeleteBots() *TestHelper {
|
||||
preexistingBots, _ := th.App.GetBots(&model.BotGetOptions{Page: 0, PerPage: 100})
|
||||
preexistingBots, _ := th.App.GetBots(th.Context, &model.BotGetOptions{Page: 0, PerPage: 100})
|
||||
for _, bot := range preexistingBots {
|
||||
th.App.PermanentDeleteBot(bot.UserId)
|
||||
th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
}
|
||||
return th
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameter(auditRec, "id", botUserId)
|
||||
audit.AddEventParameterAuditable(auditRec, "bot", botPatch)
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.AppContext.Session(), botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.AppContext, *c.AppContext.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func getBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
includeDeleted, _ := strconv.ParseBool(r.URL.Query().Get("include_deleted"))
|
||||
|
||||
bot, appErr := c.App.GetBot(botUserId, includeDeleted)
|
||||
bot, appErr := c.App.GetBot(c.AppContext, botUserId, includeDeleted)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
@@ -170,7 +170,7 @@ func getBots(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
bots, appErr := c.App.GetBots(&model.BotGetOptions{
|
||||
bots, appErr := c.App.GetBots(c.AppContext, &model.BotGetOptions{
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
OwnerId: OwnerId,
|
||||
@@ -211,7 +211,7 @@ func updateBotActive(c *Context, w http.ResponseWriter, active bool) {
|
||||
audit.AddEventParameter(auditRec, "id", botUserId)
|
||||
audit.AddEventParameter(auditRec, "enable", active)
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.AppContext.Session(), botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.AppContext, *c.AppContext.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func assignBot(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
audit.AddEventParameter(auditRec, "id", botUserId)
|
||||
audit.AddEventParameter(auditRec, "user_id", userId)
|
||||
|
||||
if err := c.App.SessionHasPermissionToManageBot(*c.AppContext.Session(), botUserId); err != nil {
|
||||
if err := c.App.SessionHasPermissionToManageBot(c.AppContext, *c.AppContext.Session(), botUserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func assignBot(c *Context, w http.ResponseWriter, _ *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
bot, err := c.App.UpdateBotOwner(botUserId, userId)
|
||||
bot, err := c.App.UpdateBotOwner(c.AppContext, botUserId, userId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -278,7 +278,7 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
bot, err := c.App.GetBot(c.Params.BotUserId, false)
|
||||
bot, err := c.App.GetBot(c.AppContext, c.Params.BotUserId, false)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestCreateBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
require.Equal(t, bot.Username, createdBot.Username)
|
||||
require.Equal(t, bot.DisplayName, createdBot.DisplayName)
|
||||
require.Equal(t, bot.Description, createdBot.Description)
|
||||
@@ -117,7 +117,7 @@ func TestCreateBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
th.App.UpdateUserRoles(th.Context, bot.UserId, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
rtoken, _, err := th.Client.CreateUserAccessToken(context.Background(), bot.UserId, "test token")
|
||||
@@ -183,7 +183,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
botPatch := &model.BotPatch{
|
||||
@@ -207,7 +207,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBotSystemAdmin.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBotSystemAdmin.UserId)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
botPatch := &model.BotPatch{
|
||||
@@ -241,7 +241,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, &model.BotPatch{})
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
@@ -265,7 +265,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, &model.BotPatch{})
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
@@ -289,7 +289,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botPatch := &model.BotPatch{
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
@@ -340,7 +340,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botPatch := &model.BotPatch{
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
@@ -371,7 +371,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botPatch := &model.BotPatch{
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
@@ -402,7 +402,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botPatch := &model.BotPatch{
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
@@ -440,7 +440,7 @@ func TestPatchBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botPatch := &model.BotPatch{
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
@@ -474,7 +474,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
r, err := th.Client.DoAPIPut(context.Background(), "/bots/"+createdBot.UserId, `{"creator_id":"`+th.BasicUser2.Id+`"}`)
|
||||
require.NoError(t, err)
|
||||
@@ -511,7 +511,7 @@ func TestPatchBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
var botPatch *model.BotPatch
|
||||
|
||||
@@ -536,7 +536,7 @@ func TestGetBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot1.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
||||
|
||||
bot2, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -545,7 +545,7 @@ func TestGetBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
||||
|
||||
deletedBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -553,7 +553,7 @@ func TestGetBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot.UserId)
|
||||
deletedBot, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
@@ -571,7 +571,7 @@ func TestGetBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(myBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, myBot.UserId)
|
||||
th.RemovePermissionFromRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
|
||||
t.Run("get unknown bot", func(t *testing.T) {
|
||||
@@ -690,7 +690,7 @@ func TestGetBots(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot1.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
||||
|
||||
deletedBot1, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -698,7 +698,7 @@ func TestGetBots(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot1.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot1.UserId)
|
||||
deletedBot1, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot1.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
@@ -710,7 +710,7 @@ func TestGetBots(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
||||
|
||||
bot3, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -719,7 +719,7 @@ func TestGetBots(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot3.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot3.UserId)
|
||||
|
||||
deletedBot2, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -727,7 +727,7 @@ func TestGetBots(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot2.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot2.UserId)
|
||||
deletedBot2, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot2.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
@@ -742,7 +742,7 @@ func TestGetBots(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
th.LoginBasic()
|
||||
defer th.App.PermanentDeleteBot(orphanedBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, orphanedBot.UserId)
|
||||
// Automatic deactivation disabled
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.DisableBotsWhenOwnerIsDeactivated = false
|
||||
@@ -975,7 +975,7 @@ func TestDisableBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.DisableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
@@ -1001,7 +1001,7 @@ func TestDisableBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.DisableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
@@ -1026,7 +1026,7 @@ func TestDisableBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
disabledBot, resp, err := client.DisableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
@@ -1080,7 +1080,7 @@ func TestEnableBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), createdBot.UserId)
|
||||
require.NoError(t, err)
|
||||
@@ -1110,7 +1110,7 @@ func TestEnableBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), createdBot.UserId)
|
||||
require.NoError(t, err)
|
||||
@@ -1139,7 +1139,7 @@ func TestEnableBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
@@ -1195,7 +1195,7 @@ func TestAssignBot(t *testing.T) {
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
before, resp, err := th.Client.GetBot(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
@@ -1244,7 +1244,7 @@ func TestAssignBot(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
@@ -1276,7 +1276,7 @@ func TestAssignBot(t *testing.T) {
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
// Simulate custom role by just changing the system user role
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.SystemUserRoleId)
|
||||
@@ -1312,7 +1312,7 @@ func TestAssignBot(t *testing.T) {
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
bot2, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
@@ -1321,7 +1321,7 @@ func TestAssignBot(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
||||
|
||||
_, _, err = th.Client.AssignBot(context.Background(), bot.UserId, bot2.UserId)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
@@ -1345,7 +1345,7 @@ func TestConvertBotToUser(t *testing.T) {
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||
|
||||
_, resp, err = th.Client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{}, false)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -430,7 +430,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -501,7 +501,7 @@ func setDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -1260,7 +1260,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), user.Id) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), user.Id) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -1337,7 +1337,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameterAuditable(auditRec, "user_patch", &patch)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -1417,7 +1417,7 @@ func deleteUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameter(auditRec, "permanent", permanent)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), userId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), userId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2458,7 +2458,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2550,7 +2550,7 @@ func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), c.Params.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), c.Params.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2587,7 +2587,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2625,7 +2625,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameterAuditable(auditRec, "user", user)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2670,7 +2670,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
audit.AddEventParameterAuditable(auditRec, "user", user)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2715,7 +2715,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameterAuditable(auditRec, "user", user)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToUserOrBot(*c.AppContext.Session(), accessToken.UserId) {
|
||||
if !c.App.SessionHasPermissionToUserOrBot(c.AppContext, *c.AppContext.Session(), accessToken.UserId) {
|
||||
c.SetPermissionError(model.PermissionEditOtherUsers)
|
||||
return
|
||||
}
|
||||
@@ -2965,7 +2965,7 @@ func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
bot, appErr := c.App.ConvertUserToBot(user)
|
||||
bot, appErr := c.App.ConvertUserToBot(c.AppContext, user)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
|
||||
@@ -916,7 +916,7 @@ func TestGetBotUser(t *testing.T) {
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
botUser, _, err := th.Client.GetUser(context.Background(), createdBot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
@@ -4556,7 +4556,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
t.Run("without MANAGE_BOT permission", func(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PermissionManageBots.Id, model.TeamUserRoleId)
|
||||
@@ -4598,7 +4598,7 @@ func TestCreateUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
t.Run("only having MANAGE_BOTS permission", func(t *testing.T) {
|
||||
_, resp, err = th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
@@ -4703,7 +4703,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4751,7 +4751,7 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -4976,7 +4976,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -5020,7 +5020,7 @@ func TestRevokeUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -5095,7 +5095,7 @@ func TestDisableUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -5139,7 +5139,7 @@ func TestDisableUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -5222,7 +5222,7 @@ func TestEnableUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
@@ -5269,7 +5269,7 @@ func TestEnableUserAccessToken(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||
|
||||
token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user