Merge branch 'master' into MM-45118_my_top_dms

Этот коммит содержится в:
Mattermod
2022-07-29 10:46:32 +03:00
коммит произвёл GitHub
родитель f84a6ae7ac 887bc0173e
Коммит 8a532c0b8c
95 изменённых файлов: 1097 добавлений и 999 удалений

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

@@ -322,8 +322,8 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper {
return th
}
func SetupEnterpriseWithStoreMock(tb testing.TB, options ...app.Option) *TestHelper {
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, true, false, nil, options)
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, true, false, nil, nil)
statusMock := mocks.StatusStore{}
statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil)
statusMock.On("Get", "user1").Return(&model.Status{UserId: "user1", Status: model.StatusOnline}, nil)
@@ -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()

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

@@ -28,7 +28,7 @@ func createBot(c *Context, w http.ResponseWriter, r *http.Request) {
var botPatch *model.BotPatch
err := json.NewDecoder(r.Body).Decode(&botPatch)
if err != nil {
c.SetInvalidParam("bot")
c.SetInvalidParamWithErr("bot", err)
return
}
@@ -70,7 +70,7 @@ func createBot(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(createdBot); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -84,7 +84,7 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
var botPatch *model.BotPatch
err := json.NewDecoder(r.Body).Decode(&botPatch)
if err != nil {
c.SetInvalidParam("bot")
c.SetInvalidParamWithErr("bot", err)
return
}
@@ -109,7 +109,7 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddEventObjectType("bot")
if err := json.NewEncoder(w).Encode(updatedBot); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -150,7 +150,7 @@ func getBot(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(bot); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -268,7 +268,7 @@ func assignBot(c *Context, w http.ResponseWriter, _ *http.Request) {
auditRec.AddEventObjectType("bot")
if err := json.NewEncoder(w).Encode(bot); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -287,7 +287,7 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
var userPatch model.UserPatch
jsonErr := json.NewDecoder(r.Body).Decode(&userPatch)
if jsonErr != nil || userPatch.Password == nil || *userPatch.Password == "" {
c.SetInvalidParam("userPatch")
c.SetInvalidParamWithErr("userPatch", jsonErr)
return
}
@@ -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
@@ -315,6 +315,6 @@ func convertBotToUser(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddEventObjectType("user")
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))
}
}

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

@@ -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
})

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

@@ -82,7 +82,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
err := json.NewDecoder(r.Body).Decode(&channel)
if err != nil {
c.SetInvalidParam("channel")
c.SetInvalidParamWithErr("channel", err)
return
}
@@ -126,7 +126,7 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
err := json.NewDecoder(r.Body).Decode(&channel)
if err != nil {
c.SetInvalidParam("channel")
c.SetInvalidParamWithErr("channel", err)
return
}
@@ -303,7 +303,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var patch *model.ChannelPatch
err := json.NewDecoder(r.Body).Decode(&patch)
if err != nil {
c.SetInvalidParam("channel")
c.SetInvalidParamWithErr("channel", err)
return
}
@@ -482,7 +482,7 @@ func searchGroupChannels(c *Context, w http.ResponseWriter, r *http.Request) {
var props *model.ChannelSearch
err := json.NewDecoder(r.Body).Decode(&props)
if err != nil {
c.SetInvalidParam("channel_search")
c.SetInvalidParamWithErr("channel_search", err)
return
}
@@ -1057,7 +1057,7 @@ func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var props *model.ChannelSearch
err := json.NewDecoder(r.Body).Decode(&props)
if err != nil {
c.SetInvalidParam("channel_search")
c.SetInvalidParamWithErr("channel_search", err)
return
}
@@ -1096,7 +1096,7 @@ func searchArchivedChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Re
var props *model.ChannelSearch
err := json.NewDecoder(r.Body).Decode(&props)
if err != nil {
c.SetInvalidParam("channel_search")
c.SetInvalidParamWithErr("channel_search", err)
return
}
@@ -1130,7 +1130,7 @@ func searchAllChannels(c *Context, w http.ResponseWriter, r *http.Request) {
var props *model.ChannelSearch
err := json.NewDecoder(r.Body).Decode(&props)
if err != nil {
c.SetInvalidParam("channel_search")
c.SetInvalidParamWithErr("channel_search", err)
return
}
@@ -1470,7 +1470,7 @@ func viewChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var view model.ChannelView
if jsonErr := json.NewDecoder(r.Body).Decode(&view); jsonErr != nil {
c.SetInvalidParam("channel_view")
c.SetInvalidParamWithErr("channel_view", jsonErr)
return
}
@@ -1547,7 +1547,7 @@ func updateChannelMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.R
var schemeRoles model.SchemeRoles
if jsonErr := json.NewDecoder(r.Body).Decode(&schemeRoles); jsonErr != nil {
c.SetInvalidParam("scheme_roles")
c.SetInvalidParamWithErr("scheme_roles", jsonErr)
return
}
@@ -1810,7 +1810,7 @@ func updateChannelScheme(c *Context, w http.ResponseWriter, r *http.Request) {
var p model.SchemeIDPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&p); jsonErr != nil || p.SchemeID == nil || !model.IsValidId(*p.SchemeID) {
c.SetInvalidParam("scheme_id")
c.SetInvalidParamWithErr("scheme_id", jsonErr)
return
}
schemeID := p.SchemeID
@@ -2013,7 +2013,7 @@ func patchChannelModerations(c *Context, w http.ResponseWriter, r *http.Request)
var channelModerationsPatch []*model.ChannelModerationPatch
err := json.NewDecoder(r.Body).Decode(&channelModerationsPatch)
if err != nil {
c.Err = model.NewAppError("Api4.patchChannelModerations", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("Api4.patchChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
return
}

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

@@ -55,7 +55,7 @@ func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
var categoryCreateRequest model.SidebarCategoryWithChannels
err := json.NewDecoder(r.Body).Decode(&categoryCreateRequest)
if err != nil || c.Params.UserId != categoryCreateRequest.UserId || c.Params.TeamId != categoryCreateRequest.TeamId {
c.SetInvalidParam("category")
c.SetInvalidParamWithErr("category", err)
return
}
@@ -177,7 +177,7 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
var categoriesUpdateRequest []*model.SidebarCategoryWithChannels
err := json.NewDecoder(r.Body).Decode(&categoriesUpdateRequest)
if err != nil {
c.SetInvalidParam("category")
c.SetInvalidParamWithErr("category", err)
return
}
@@ -278,7 +278,7 @@ func updateCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
var categoryUpdateRequest model.SidebarCategoryWithChannels
err := json.NewDecoder(r.Body).Decode(&categoryUpdateRequest)
if err != nil || categoryUpdateRequest.TeamId != c.Params.TeamId || categoryUpdateRequest.UserId != c.Params.UserId {
c.SetInvalidParam("category")
c.SetInvalidParamWithErr("category", err)
return
}

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

@@ -41,7 +41,7 @@ func localCreateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var channel *model.Channel
err := json.NewDecoder(r.Body).Decode(&channel)
if err != nil {
c.SetInvalidParam("channel")
c.SetInvalidParamWithErr("channel", err)
return
}
@@ -284,7 +284,7 @@ func localPatchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var patch *model.ChannelPatch
err := json.NewDecoder(r.Body).Decode(&patch)
if err != nil {
c.SetInvalidParam("channel")
c.SetInvalidParamWithErr("channel", err)
return
}

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

@@ -14,6 +14,7 @@ import (
"github.com/mattermost/mattermost-server/v6/audit"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
func (api *API) InitCloud() {
@@ -57,7 +58,7 @@ func handleNotifyAdminToUpgrade(c *Context, w http.ResponseWriter, r *http.Reque
var notifyAdminRequest *model.NotifyAdminToUpgradeRequest
err := json.NewDecoder(r.Body).Decode(&notifyAdminRequest)
if err != nil {
c.SetInvalidParam("notifyAdminRequest")
c.SetInvalidParamWithErr("notifyAdminRequest", err)
return
}
@@ -232,12 +233,19 @@ func validateBusinessEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
errValidatingEmail := c.App.Cloud().ValidateBusinessEmail(user.Id, emailToValidate.Email)
if errValidatingEmail != nil {
c.Err = model.NewAppError("Api4.valiateBusinessEmail", "api.cloud.request_error", nil, errValidatingEmail.Error(), http.StatusInternalServerError)
emailErr := c.App.Cloud().ValidateBusinessEmail(user.Id, emailToValidate.Email)
if emailErr != nil {
c.Err = model.NewAppError("Api4.validateBusinessEmail", "api.cloud.request_error", nil, emailErr.Error(), http.StatusForbidden)
emailResp := model.ValidateBusinessEmailResponse{IsValid: false}
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
return
}
ReturnStatusOK(w)
emailResp := model.ValidateBusinessEmailResponse{IsValid: true}
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
}
func validateWorkspaceBusinessEmail(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -263,20 +271,27 @@ func validateWorkspaceBusinessEmail(c *Context, w http.ResponseWriter, r *http.R
c.Err = model.NewAppError("Api4.validateWorkspaceBusinessEmail", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
return
}
errValidatingSystemEmail := c.App.Cloud().ValidateBusinessEmail(user.Id, cloudCustomer.Email)
emailErr := c.App.Cloud().ValidateBusinessEmail(user.Id, cloudCustomer.Email)
// if the current workspace email is not a valid business email
if errValidatingSystemEmail != nil {
if emailErr != nil {
// grab the current admin email and validate it
errValidatingAdminEmail := c.App.Cloud().ValidateBusinessEmail(user.Id, user.Email)
if errValidatingAdminEmail != nil {
c.Err = model.NewAppError("Api4.validateWorkspaceBusinessEmail", "api.cloud.request_error", nil, errValidatingAdminEmail.Error(), http.StatusInternalServerError)
c.Err = model.NewAppError("Api4.validateWorkspaceBusinessEmail", "api.cloud.request_error", nil, errValidatingAdminEmail.Error(), http.StatusForbidden)
emailResp := model.ValidateBusinessEmailResponse{IsValid: false}
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
return
}
}
// if any of the emails is valid, return ok
ReturnStatusOK(w)
emailResp := model.ValidateBusinessEmailResponse{IsValid: true}
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
}
}
func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {

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

@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
@@ -401,21 +400,19 @@ func TestNotifyAdminToUpgrade(t *testing.T) {
})
}
func Test_validateBusinessEmail(t *testing.T) {
t.Run("Initial request has invalid email", func(t *testing.T) {
t.Run("Returns forbidden for non admin executors", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
validateBusinessEmail := model.ValidateBusinessEmailRequest{Email: ""}
invalidEmail := model.ValidateBusinessEmailRequest{Email: "invalid@gmail.com"}
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
cloud := mocks.CloudInterface{}
resp := httptest.NewRecorder()
cloud.Mock.On("ValidateBusinessEmail", mock.Anything).Return(resp, nil)
cloud.Mock.On("ValidateBusinessEmail", th.SystemAdminUser.Id, invalidEmail.Email).Return(errors.New("invalid email"))
cloudImpl := th.App.Srv().Cloud
defer func() {
@@ -423,8 +420,59 @@ func Test_validateBusinessEmail(t *testing.T) {
}()
th.App.Srv().Cloud = &cloud
_, err := th.Client.ValidateBusinessEmail(&validateBusinessEmail)
res, err := th.Client.ValidateBusinessEmail(&invalidEmail)
require.Error(t, err)
require.Equal(t, http.StatusForbidden, res.StatusCode, "403")
})
t.Run("Returns forbidden for invalid business email", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
validBusinessEmail := model.ValidateBusinessEmailRequest{Email: "invalid@slacker.com"}
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
cloud := mocks.CloudInterface{}
cloud.Mock.On("ValidateBusinessEmail", th.SystemAdminUser.Id, validBusinessEmail.Email).Return(errors.New("invalid email"))
cloudImpl := th.App.Srv().Cloud
defer func() {
th.App.Srv().Cloud = cloudImpl
}()
th.App.Srv().Cloud = &cloud
res, err := th.SystemAdminClient.ValidateBusinessEmail(&validBusinessEmail)
require.Error(t, err)
require.Equal(t, http.StatusForbidden, res.StatusCode, "403")
})
t.Run("Validate business email for admin", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
validBusinessEmail := model.ValidateBusinessEmailRequest{Email: "valid@mattermost.com"}
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
cloud := mocks.CloudInterface{}
cloud.Mock.On("ValidateBusinessEmail", th.SystemAdminUser.Id, validBusinessEmail.Email).Return(nil)
cloudImpl := th.App.Srv().Cloud
defer func() {
th.App.Srv().Cloud = cloudImpl
}()
th.App.Srv().Cloud = &cloud
res, err := th.SystemAdminClient.ValidateBusinessEmail(&validBusinessEmail)
require.NoError(t, err)
require.Equal(t, http.StatusOK, res.StatusCode, "200")
})
}

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

@@ -32,7 +32,7 @@ func (api *API) InitCommand() {
func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
var cmd model.Command
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil {
c.SetInvalidParam("command")
c.SetInvalidParamWithErr("command", jsonErr)
return
}
@@ -62,7 +62,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rcmd); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -74,7 +74,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
var cmd model.Command
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil || cmd.Id != c.Params.CommandId {
c.SetInvalidParam("command")
c.SetInvalidParamWithErr("command", jsonErr)
return
}
@@ -122,7 +122,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(rcmd); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -134,7 +134,7 @@ func moveCommand(c *Context, w http.ResponseWriter, r *http.Request) {
var cmr model.CommandMoveRequest
if jsonErr := json.NewDecoder(r.Body).Decode(&cmr); jsonErr != nil {
c.SetInvalidParam("team_id")
c.SetInvalidParamWithErr("team_id", jsonErr)
return
}
@@ -274,7 +274,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(commands); err != nil {
mlog.Warn("Error writing response", mlog.Err(err))
c.Logger.Warn("Error writing response", mlog.Err(err))
}
}
@@ -305,14 +305,14 @@ func getCommand(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := json.NewEncoder(w).Encode(cmd); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
var commandArgs model.CommandArgs
if jsonErr := json.NewDecoder(r.Body).Decode(&commandArgs); jsonErr != nil {
c.SetInvalidParam("command_args")
c.SetInvalidParamWithErr("command_args", jsonErr)
return
}
@@ -368,7 +368,7 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(response); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -390,7 +390,7 @@ func listAutocompleteCommands(c *Context, w http.ResponseWriter, r *http.Request
}
if err := json.NewEncoder(w).Encode(commands); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -25,7 +25,7 @@ func (api *API) InitCommandLocal() {
func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
var cmd model.Command
if jsonErr := json.NewDecoder(r.Body).Decode(&cmd); jsonErr != nil {
c.SetInvalidParam("command")
c.SetInvalidParamWithErr("command", jsonErr)
return
}
@@ -47,6 +47,6 @@ func localCreateCommand(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rcmd); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -646,7 +646,7 @@ func TestExecuteInvalidCommand(t *testing.T) {
rc := &model.CommandResponse{}
if err := json.NewEncoder(w).Encode(rc); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -732,7 +732,7 @@ func TestExecuteGetCommand(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -792,7 +792,7 @@ func TestExecutePostCommand(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -846,7 +846,7 @@ func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -898,7 +898,7 @@ func TestExecuteCommandAgainstChannelUserIsNotIn(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -958,7 +958,7 @@ func TestExecuteCommandInDirectMessageChannel(t *testing.T) {
require.Equal(t, http.MethodPost, r.Method)
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()
@@ -1025,7 +1025,7 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(expectedCommandResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
th.TestLogger.Warn("Error while writing response", mlog.Err(err))
}
}))
defer ts.Close()

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

@@ -25,7 +25,7 @@ func (api *API) InitCompliance() {
func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
var job model.Compliance
if jsonErr := json.NewDecoder(r.Body).Decode(&job); jsonErr != nil {
c.SetInvalidParam("compliance")
c.SetInvalidParamWithErr("compliance", jsonErr)
return
}
@@ -55,7 +55,7 @@ func createComplianceReport(c *Context, w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rjob); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -76,7 +76,7 @@ func getComplianceReports(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(crs); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -106,7 +106,7 @@ func getComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddMeta("compliance_desc", job.Desc)
if err := json.NewEncoder(w).Encode(job); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -78,7 +78,7 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := json.NewEncoder(w).Encode(cfg); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -220,7 +220,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(cfg); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -370,7 +370,7 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(cfg); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -30,7 +30,7 @@ func localGetConfig(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if err := json.NewEncoder(w).Encode(cfg); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -82,7 +82,7 @@ func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if err := json.NewEncoder(w).Encode(newCfg); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -137,7 +137,7 @@ func localPatchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if err := json.NewEncoder(w).Encode(c.App.GetSanitizedConfig()); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -111,7 +111,7 @@ func getPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
func createPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var policy model.RetentionPolicyWithTeamAndChannelIDs
if jsonErr := json.NewDecoder(r.Body).Decode(&policy); jsonErr != nil {
c.SetInvalidParam("policy")
c.SetInvalidParamWithErr("policy", jsonErr)
return
}
auditRec := c.MakeAuditRecord("createPolicy", audit.Fail)
@@ -144,7 +144,7 @@ func createPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
func patchPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var patch model.RetentionPolicyWithTeamAndChannelIDs
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
c.SetInvalidParam("policy")
c.SetInvalidParamWithErr("policy", jsonErr)
return
}
c.RequirePolicyId()
@@ -233,7 +233,7 @@ func searchTeamsInPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var props model.TeamSearch
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
c.SetInvalidParam("team_search")
c.SetInvalidParamWithErr("team_search", jsonErr)
return
}
@@ -261,7 +261,7 @@ func addTeamsToPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var teamIDs []string
jsonErr := json.NewDecoder(r.Body).Decode(&teamIDs)
if jsonErr != nil {
c.SetInvalidParam("team_ids")
c.SetInvalidParamWithErr("team_ids", jsonErr)
return
}
auditRec := c.MakeAuditRecord("addTeamsToPolicy", audit.Fail)
@@ -289,7 +289,7 @@ func removeTeamsFromPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var teamIDs []string
jsonErr := json.NewDecoder(r.Body).Decode(&teamIDs)
if jsonErr != nil {
c.SetInvalidParam("team_ids")
c.SetInvalidParamWithErr("team_ids", jsonErr)
return
}
auditRec := c.MakeAuditRecord("removeTeamsFromPolicy", audit.Fail)
@@ -342,7 +342,7 @@ func searchChannelsInPolicy(c *Context, w http.ResponseWriter, r *http.Request)
var props *model.ChannelSearch
err := json.NewDecoder(r.Body).Decode(&props)
if err != nil {
c.SetInvalidParam("channel_search")
c.SetInvalidParamWithErr("channel_search", err)
return
}
@@ -382,7 +382,7 @@ func addChannelsToPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
var channelIDs []string
jsonErr := json.NewDecoder(r.Body).Decode(&channelIDs)
if jsonErr != nil {
c.SetInvalidParam("channel_ids")
c.SetInvalidParamWithErr("channel_ids", jsonErr)
return
}
auditRec := c.MakeAuditRecord("addChannelsToPolicy", audit.Fail)
@@ -411,7 +411,7 @@ func removeChannelsFromPolicy(c *Context, w http.ResponseWriter, r *http.Request
var channelIDs []string
jsonErr := json.NewDecoder(r.Body).Decode(&channelIDs)
if jsonErr != nil {
c.SetInvalidParam("channel_ids")
c.SetInvalidParamWithErr("channel_ids", jsonErr)
return
}
auditRec := c.MakeAuditRecord("removeChannelsFromPolicy", audit.Fail)

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

@@ -98,7 +98,7 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(newEmoji); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -121,7 +121,7 @@ func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(listEmoji); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -211,7 +211,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(emoji); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -228,7 +228,7 @@ func getEmojiByName(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(emoji); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -257,7 +257,7 @@ func getEmojiImage(c *Context, w http.ResponseWriter, r *http.Request) {
func searchEmojis(c *Context, w http.ResponseWriter, r *http.Request) {
var emojiSearch model.EmojiSearch
if jsonErr := json.NewDecoder(r.Body).Decode(&emojiSearch); jsonErr != nil {
c.SetInvalidParam("term")
c.SetInvalidParamWithErr("term", jsonErr)
return
}
@@ -273,7 +273,7 @@ func searchEmojis(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(emojis); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -292,6 +292,6 @@ func autocompleteEmojis(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(emojis); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -150,7 +150,7 @@ func uploadFileStream(c *Context, w http.ResponseWriter, r *http.Request) {
// Write the response values to the output upon return
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(fileUploadResponse); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -632,7 +632,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=2592000, private")
if err := json.NewEncoder(w).Encode(info); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -759,7 +759,7 @@ func searchFiles(c *Context, w http.ResponseWriter, r *http.Request, teamID stri
var params model.SearchParameter
jsonErr := json.NewDecoder(r.Body).Decode(&params)
if jsonErr != nil {
c.Err = model.NewAppError("searchFiles", "api.post.search_files.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("searchFiles", "api.post.search_files.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
@@ -821,6 +821,6 @@ func searchFiles(c *Context, w http.ResponseWriter, r *http.Request, teamID stri
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if err := json.NewEncoder(w).Encode(results); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -84,7 +84,7 @@ func testDoUploadFileRequest(t testing.TB, c *model.Client4, url string, blob []
var res model.FileUploadResponse
if jsonErr := json.NewDecoder(resp.Body).Decode(&res); jsonErr != nil {
return nil, nil, model.NewAppError("doUploadFile", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
return nil, nil, model.NewAppError("doUploadFile", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
}
return &res, model.BuildResponse(resp), nil
}

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

@@ -78,7 +78,7 @@ func (api *API) graphQL(c *Context, w http.ResponseWriter, r *http.Request) {
defer func() {
if response != nil {
if err := json.NewEncoder(w).Encode(response); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
}()

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

@@ -44,7 +44,7 @@ func (c *graphQLClient) login(loginId string, password string) (*model.User, *mo
var user model.User
if jsonErr := json.NewDecoder(r.Body).Decode(&user); jsonErr != nil {
return nil, nil, model.NewAppError("login", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
return nil, nil, model.NewAppError("login", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
}
return &user, model.BuildResponse(r), nil
}

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

@@ -132,7 +132,7 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
var group *model.GroupWithUserIds
if jsonErr := json.NewDecoder(r.Body).Decode(&group); jsonErr != nil {
c.SetInvalidParam("group")
c.SetInvalidParamWithErr("group", jsonErr)
return
}
@@ -215,7 +215,7 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
var groupPatch model.GroupPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&groupPatch); jsonErr != nil {
c.SetInvalidParam("group")
c.SetInvalidParamWithErr("group", jsonErr)
return
}
@@ -1030,7 +1030,7 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
var newMembers *model.GroupModifyMembers
if jsonErr := json.NewDecoder(r.Body).Decode(&newMembers); jsonErr != nil {
c.SetInvalidParam("addGroupMembers")
c.SetInvalidParamWithErr("addGroupMembers", jsonErr)
return
}
@@ -1083,7 +1083,7 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
var deleteBody *model.GroupModifyMembers
if jsonErr := json.NewDecoder(r.Body).Decode(&deleteBody); jsonErr != nil {
c.SetInvalidParam("deleteGroupMembers")
c.SetInvalidParamWithErr("deleteGroupMembers", jsonErr)
return
}

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

@@ -8,6 +8,7 @@ import (
"net/http"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
func (api *API) InitAction() {
@@ -24,7 +25,10 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
}
var actionRequest model.DoPostActionRequest
json.NewDecoder(r.Body).Decode(&actionRequest)
err := json.NewDecoder(r.Body).Decode(&actionRequest)
if err != nil {
c.Logger.Warn("Error decoding the action request", mlog.Err(err))
}
var cookie *model.PostActionCookie
if actionRequest.Cookie != "" {
@@ -68,7 +72,7 @@ func openDialog(c *Context, w http.ResponseWriter, r *http.Request) {
var dialog model.OpenDialogRequest
err := json.NewDecoder(r.Body).Decode(&dialog)
if err != nil {
c.SetInvalidParam("dialog")
c.SetInvalidParamWithErr("dialog", err)
return
}
@@ -90,7 +94,7 @@ func submitDialog(c *Context, w http.ResponseWriter, r *http.Request) {
jsonErr := json.NewDecoder(r.Body).Decode(&submit)
if jsonErr != nil {
c.SetInvalidParam("dialog")
c.SetInvalidParamWithErr("dialog", jsonErr)
return
}

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

@@ -47,7 +47,7 @@ func getJob(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(job); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -106,7 +106,7 @@ func downloadJob(c *Context, w http.ResponseWriter, r *http.Request) {
func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
var job model.Job
if jsonErr := json.NewDecoder(r.Body).Decode(&job); jsonErr != nil {
c.SetInvalidParam("job")
c.SetInvalidParamWithErr("job", jsonErr)
return
}
@@ -137,7 +137,7 @@ func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rjob); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -10,6 +10,7 @@ import (
"github.com/mattermost/mattermost-server/v6/audit"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
type mixedUnlinkedGroup struct {
@@ -51,7 +52,10 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
IncludeRemovedMembers bool `json:"include_removed_members"`
}
var opts LdapSyncOptions
json.NewDecoder(r.Body).Decode(&opts)
err := json.NewDecoder(r.Body).Decode(&opts)
if err != nil {
c.Logger.Warn("Error decoding LDAP sync options", mlog.Err(err))
}
auditRec := c.MakeAuditRecord("syncLdap", audit.Fail)
defer c.LogAuditRec(auditRec)

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

@@ -136,7 +136,7 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(license); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -73,7 +73,7 @@ func localAddLicense(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(license); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -27,7 +27,7 @@ func (api *API) InitOAuth() {
func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
var oauthApp model.OAuthApp
if jsonErr := json.NewDecoder(r.Body).Decode(&oauthApp); jsonErr != nil {
c.SetInvalidParam("oauth_app")
c.SetInvalidParamWithErr("oauth_app", jsonErr)
return
}
@@ -60,7 +60,7 @@ func createOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rapp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -82,7 +82,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
var oauthApp model.OAuthApp
if jsonErr := json.NewDecoder(r.Body).Decode(&oauthApp); jsonErr != nil {
c.SetInvalidParam("oauth_app")
c.SetInvalidParamWithErr("oauth_app", jsonErr)
return
}
auditRec.AddEventParameter("oauth_app", oauthApp)
@@ -121,7 +121,7 @@ func updateOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(updatedOAuthApp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -178,7 +178,7 @@ func getOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(oauthApp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -196,7 +196,7 @@ func getOAuthAppInfo(c *Context, w http.ResponseWriter, r *http.Request) {
oauthApp.Sanitize()
if err := json.NewEncoder(w).Encode(oauthApp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -280,7 +280,7 @@ func regenerateOAuthAppSecret(c *Context, w http.ResponseWriter, r *http.Request
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(oauthApp); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -167,7 +167,7 @@ func installMarketplacePlugin(c *Context, w http.ResponseWriter, r *http.Request
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(manifest); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -189,7 +189,7 @@ func getPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(response); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -211,7 +211,7 @@ func getPluginStatuses(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(response); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -402,7 +402,7 @@ func installPlugin(c *Context, w http.ResponseWriter, plugin io.ReadSeeker, forc
}
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(manifest); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -462,6 +462,6 @@ func getFirstAdminVisitMarketplaceStatus(c *Context, w http.ResponseWriter, r *h
auditRec.Success()
if err := json.NewEncoder(w).Encode(firstAdminVisitMarketplaceObj); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -43,7 +43,7 @@ func (api *API) InitPost() {
func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
var post model.Post
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
c.SetInvalidParam("post")
c.SetInvalidParamWithErr("post", jsonErr)
return
}
@@ -106,14 +106,19 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
// Note that rp has already had PreparePostForClient called on it by App.CreatePost
if err := rp.EncodeJSON(w); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) {
ephRequest := model.PostEphemeral{}
json.NewDecoder(r.Body).Decode(&ephRequest)
jsonErr := json.NewDecoder(r.Body).Decode(&ephRequest)
if jsonErr != nil {
c.SetInvalidParamWithErr("body", jsonErr)
return
}
if ephRequest.UserID == "" {
c.SetInvalidParam("user_id")
return
@@ -476,7 +481,7 @@ func getPostsByIds(c *Context, w http.ResponseWriter, r *http.Request) {
w.Header().Set(model.HeaderFirstInaccessiblePostTime, strconv.FormatInt(firstInaccessiblePostTime, 10))
if err := json.NewEncoder(w).Encode(posts); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -525,6 +530,35 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
rPost, err := c.App.GetSinglePost(c.Params.PostId, false)
if err != nil {
c.Err = err
return
}
hasPermission := false
becauseCompliance := false
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), rPost.ChannelId, model.PermissionReadChannel) {
hasPermission = true
} else if channel, cErr := c.App.GetChannel(c.AppContext, rPost.ChannelId); cErr == nil {
if channel.Type == model.ChannelTypeOpen &&
c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), channel.TeamId, model.PermissionReadPublicChannel) {
hasPermission = true
if *c.App.Config().MessageExportSettings.EnableExport {
hasPermission = false
becauseCompliance = true
}
}
}
if !hasPermission {
if becauseCompliance {
c.Err = model.NewAppError("getPostThread", "api.post.compliance_enabled.join_channel_to_view_post", nil, "", http.StatusForbidden)
} else {
c.SetPermissionError(model.PermissionReadChannel)
}
return
}
// For now, by default we return all items unless it's set to maintain
// backwards compatibility with mobile. But when the next ESR passes, we need to
// change this to web.PerPageDefault.
@@ -627,7 +661,7 @@ func searchPostsInAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
func searchPosts(c *Context, w http.ResponseWriter, r *http.Request, teamId string) {
var params model.SearchParameter
if jsonErr := json.NewDecoder(r.Body).Decode(&params); jsonErr != nil {
c.Err = model.NewAppError("searchPosts", "api.post.search_posts.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("searchPosts", "api.post.search_posts.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
@@ -710,7 +744,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
var post model.Post
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
c.SetInvalidParam("post")
c.SetInvalidParamWithErr("post", jsonErr)
return
}
@@ -771,7 +805,7 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
var post model.PostPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
c.SetInvalidParam("post")
c.SetInvalidParamWithErr("post", jsonErr)
return
}
@@ -840,7 +874,7 @@ func setPostUnread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := json.NewEncoder(w).Encode(state); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -861,7 +895,7 @@ func setPostReminder(c *Context, w http.ResponseWriter, r *http.Request) {
var reminder model.PostReminder
if jsonErr := json.NewDecoder(r.Body).Decode(&reminder); jsonErr != nil {
c.SetInvalidParam("target_time")
c.SetInvalidParamWithErr("target_time", jsonErr)
return
}

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

@@ -25,6 +25,7 @@ import (
"github.com/mattermost/mattermost-server/v6/app"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v6/utils"
"github.com/mattermost/mattermost-server/v6/utils/testutils"
@@ -306,7 +307,10 @@ func testCreatePostWithOutgoingHook(
if requestContentType == "application/json" {
decoder := json.NewDecoder(r.Body)
o := &model.OutgoingWebhookPayload{}
decoder.Decode(&o)
err := decoder.Decode(&o)
if err != nil {
th.TestLogger.Warn("Error decoding body", mlog.Err(err))
}
if !reflect.DeepEqual(expectedPayload, o) {
t.Logf("JSON payload is %+v, should be %+v", o, expectedPayload)
@@ -448,7 +452,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 +465,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 +502,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 +518,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()
@@ -924,7 +928,7 @@ func TestPatchPost(t *testing.T) {
t.Run("invalid requests", func(t *testing.T) {
r, err := client.DoAPIPut("/posts/"+post.Id+"/patch", "garbage")
require.EqualError(t, err, ": Invalid or missing post in request body., ")
require.EqualError(t, err, ": Invalid or missing post in request body.")
require.Equal(t, http.StatusBadRequest, r.StatusCode, "wrong status code")
patch := &model.PostPatch{}
@@ -2191,10 +2195,26 @@ func TestGetPostThread(t *testing.T) {
client.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser.Id)
// Channel is public, should be able to read post
messageExportEnabled := *th.App.Config().MessageExportSettings.EnableExport
// Channel is public, and compliance export is OFF, should be able to read post
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.MessageExportSettings.EnableExport = false
})
_, _, err = client.GetPostThread(th.BasicPost.Id, "", false)
require.NoError(t, err)
// channel is public, and compliance export is ON, should NOT be able to read post
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.MessageExportSettings.EnableExport = true
})
_, resp, err = client.GetPostThread(th.BasicPost.Id, "", false)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.MessageExportSettings.EnableExport = messageExportEnabled
})
privatePost := th.CreatePostWithClient(client, th.BasicPrivateChannel)
_, _, err = client.GetPostThread(privatePost.Id, "", false)

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

@@ -38,7 +38,7 @@ func getPreferences(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(preferences); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -60,7 +60,7 @@ func getPreferencesByCategory(c *Context, w http.ResponseWriter, r *http.Request
}
if err := json.NewEncoder(w).Encode(preferences); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -82,7 +82,7 @@ func getPreferenceByCategoryAndName(c *Context, w http.ResponseWriter, r *http.R
}
if err := json.NewEncoder(w).Encode(preferences); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -102,7 +102,7 @@ func updatePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
var preferences model.Preferences
if jsonErr := json.NewDecoder(r.Body).Decode(&preferences); jsonErr != nil {
c.SetInvalidParam("preferences")
c.SetInvalidParamWithErr("preferences", jsonErr)
return
}
@@ -150,7 +150,7 @@ func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) {
var preferences model.Preferences
if jsonErr := json.NewDecoder(r.Body).Decode(&preferences); jsonErr != nil {
c.SetInvalidParam("preferences")
c.SetInvalidParamWithErr("preferences", jsonErr)
return
}

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

@@ -21,7 +21,7 @@ func (api *API) InitReaction() {
func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
var reaction model.Reaction
if jsonErr := json.NewDecoder(r.Body).Decode(&reaction); jsonErr != nil {
c.SetInvalidParam("reaction")
c.SetInvalidParamWithErr("reaction", jsonErr)
return
}
@@ -47,7 +47,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(re); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -32,7 +32,7 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
var frame model.RemoteClusterFrame
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
c.Err = model.NewAppError("remoteClusterPing", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("remoteClusterPing", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
@@ -78,7 +78,7 @@ func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Reque
var frame model.RemoteClusterFrame
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
@@ -124,7 +124,7 @@ func remoteClusterConfirmInvite(c *Context, w http.ResponseWriter, r *http.Reque
var frame model.RemoteClusterFrame
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
c.Err = model.NewAppError("remoteClusterConfirmInvite", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("remoteClusterConfirmInvite", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
@@ -216,7 +216,7 @@ func uploadRemoteData(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(info); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -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
}

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

@@ -71,7 +71,7 @@ func getGraphQLTeams(c *web.Context, teamIDs []string) ([]*model.Team, error) {
}
}
if !c.App.SessionHasPermissionToTeams(c.AppContext, *c.AppContext.Session(), teamsToCheck, model.PermissionViewMembers) {
if !c.App.SessionHasPermissionToTeams(c.AppContext, *c.AppContext.Session(), teamsToCheck, model.PermissionViewTeam) {
c.SetPermissionError(model.PermissionViewTeam)
return nil, c.Err
}

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

@@ -289,3 +289,123 @@ func TestGraphQLTeamMembers(t *testing.T) {
assert.Len(t, q.TeamMembers, 1)
})
}
func TestGraphQLTeamMembersAsGuest(t *testing.T) {
os.Setenv("MM_FEATUREFLAGS_GRAPHQL", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_GRAPHQL")
th := Setup(t)
id := model.NewId()
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: th.GenerateTestEmail(),
Type: model.TeamOpen,
AllowOpenInvite: true,
}
var err error
team, _, err = th.Client.CreateTeam(team)
require.NoError(t, err)
th.BasicTeam = team
th.BasicChannel = th.CreatePublicChannel()
th.LinkUserToTeam(th.BasicUser, th.BasicTeam)
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicChannel, false)
th.LoginBasic()
defer th.TearDown()
require.Nil(t, th.App.DemoteUserToGuest(th.Context, th.BasicUser))
var q struct {
TeamMembers []struct {
User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
NickName string `json:"nickname"`
} `json:"user"`
Team struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
Name string `json:"name"`
CreateAt float64 `json:"createAt"`
DeleteAt float64 `json:"deleteAt"`
SchemeId *string `json:"schemeId"`
PolicyId *string `json:"policyId"`
CloudLimitsArchived bool `json:"cloudLimitsArchived"`
} `json:"team"`
Roles []struct {
ID string `json:"id"`
Name string `json:"Name"`
Permissions []string `json:"permissions"`
SchemeManaged bool `json:"schemeManaged"`
BuiltIn bool `json:"builtIn"`
} `json:"roles"`
DeleteAt float64 `json:"deleteAt"`
SchemeGuest bool `json:"schemeGuest"`
SchemeUser bool `json:"schemeUser"`
SchemeAdmin bool `json:"schemeAdmin"`
} `json:"teamMembers"`
}
t.Run("User", func(t *testing.T) {
input := graphQLInput{
OperationName: "teamMembers",
Query: `
query teamMembers($userId: String = "", $teamId: String = "") {
teamMembers(userId: $userId, teamId: $teamId) {
team {
id
displayName
}
user {
id
username
email
firstName
lastName
}
roles {
id
name
}
schemeGuest
schemeUser
schemeAdmin
}
}
`,
Variables: map[string]any{
"userId": "me",
},
}
resp, err := th.MakeGraphQLRequest(&input)
require.NoError(t, err)
require.Len(t, resp.Errors, 0)
require.NoError(t, json.Unmarshal(resp.Data, &q))
assert.Len(t, q.TeamMembers, 1)
tm := q.TeamMembers[0]
assert.Equal(t, th.BasicTeam.Id, tm.Team.ID)
assert.Equal(t, th.BasicTeam.DisplayName, tm.Team.DisplayName)
assert.Equal(t, th.BasicUser.Id, tm.User.ID)
assert.Equal(t, th.BasicUser.Username, tm.User.Username)
assert.Equal(t, th.BasicUser.Email, tm.User.Email)
assert.Equal(t, th.BasicUser.FirstName, tm.User.FirstName)
assert.Equal(t, th.BasicUser.LastName, tm.User.LastName)
require.Len(t, tm.Roles, 1)
assert.NotEmpty(t, tm.Roles[0].ID)
assert.Equal(t, "team_guest", tm.Roles[0].Name)
assert.True(t, tm.SchemeGuest)
assert.False(t, tm.SchemeUser)
assert.False(t, tm.SchemeAdmin)
})
}

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

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

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

@@ -60,7 +60,7 @@ func getRole(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(role); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -77,7 +77,7 @@ func getRoleByName(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(role); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -117,7 +117,7 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
var patch model.RolePatch
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
c.SetInvalidParam("role")
c.SetInvalidParamWithErr("role", jsonErr)
return
}
@@ -214,6 +214,6 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
if err := json.NewEncoder(w).Encode(role); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -232,7 +232,7 @@ func getSamlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request
status := c.App.GetSamlCertificateStatus()
if err := json.NewEncoder(w).Encode(status); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -256,7 +256,7 @@ func getSamlMetadataFromIdp(c *Context, w http.ResponseWriter, r *http.Request)
}
if err := json.NewEncoder(w).Encode(metadata); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -273,7 +273,7 @@ func resetAuthDataToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
var params *ResetAuthDataParams
jsonErr := json.NewDecoder(r.Body).Decode(&params)
if jsonErr != nil {
c.Err = model.NewAppError("resetAuthDataToEmail", "model.utils.decode_json.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("resetAuthDataToEmail", "model.utils.decode_json.app_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
numAffected, appErr := c.App.ResetSamlAuthDataToEmail(params.IncludeDeleted, params.DryRun, params.SpecifiedUserIDs)
@@ -281,6 +281,14 @@ func resetAuthDataToEmail(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = appErr
return
}
b, _ := json.Marshal(map[string]any{"num_affected": numAffected})
w.Write(b)
n := struct {
NumAffected int `json:"num_affected"`
}{
NumAffected: numAffected,
}
if err := json.NewEncoder(w).Encode(n); err != nil {
c.Logger.Warn("Error writing response", mlog.Err(err))
}
}

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

@@ -25,7 +25,7 @@ func (api *API) InitScheme() {
func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
var scheme model.Scheme
if jsonErr := json.NewDecoder(r.Body).Decode(&scheme); jsonErr != nil {
c.SetInvalidParam("scheme")
c.SetInvalidParamWithErr("scheme", jsonErr)
return
}
@@ -55,7 +55,7 @@ func createScheme(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(returnedScheme); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -77,7 +77,7 @@ func getScheme(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(scheme); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -172,7 +172,7 @@ func getChannelsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(channels); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -184,7 +184,7 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
var patch model.SchemePatch
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
c.SetInvalidParam("scheme")
c.SetInvalidParamWithErr("scheme", jsonErr)
return
}
@@ -223,7 +223,7 @@ func patchScheme(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
if err := json.NewEncoder(w).Encode(scheme); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

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

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

@@ -44,7 +44,7 @@ func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(statusMap[0]); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -86,7 +86,7 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
var status model.Status
if jsonErr := json.NewDecoder(r.Body).Decode(&status); jsonErr != nil {
c.SetInvalidParam("status")
c.SetInvalidParamWithErr("status", jsonErr)
return
}
@@ -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 {
@@ -137,7 +137,7 @@ func updateUserCustomStatus(c *Context, w http.ResponseWriter, r *http.Request)
var customStatus model.CustomStatus
jsonErr := json.NewDecoder(r.Body).Decode(&customStatus)
if jsonErr != nil || (customStatus.Emoji == "" && customStatus.Text == "") || !customStatus.AreDurationAndExpirationTimeValid() {
c.SetInvalidParam("custom_status")
c.SetInvalidParamWithErr("custom_status", jsonErr)
return
}
@@ -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
}
@@ -193,7 +193,7 @@ func removeUserRecentCustomStatus(c *Context, w http.ResponseWriter, r *http.Req
var recentCustomStatus model.CustomStatus
if jsonErr := json.NewDecoder(r.Body).Decode(&recentCustomStatus); jsonErr != nil {
c.SetInvalidParam("recent_custom_status")
c.SetInvalidParamWithErr("recent_custom_status", jsonErr)
return
}

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

@@ -271,7 +271,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.AddEventParameter("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))
}
}
@@ -410,7 +410,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(rows); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -543,9 +543,9 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
c.Err = model.NewAppError("pushNotificationAck",
"api.push_notifications_ack.message.parse.app_error",
nil,
jsonErr.Error(),
"",
http.StatusBadRequest,
)
).Wrap(jsonErr)
return
}
@@ -586,7 +586,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err2 := json.NewEncoder(w).Encode(msg); err2 != nil {
mlog.Warn("Error while writing response", mlog.Err(err2))
c.Logger.Warn("Error while writing response", mlog.Err(err2))
}
}
@@ -814,7 +814,7 @@ func sendWarnMetricAckEmail(c *Context, w http.ResponseWriter, r *http.Request)
var ack model.SendWarnMetricAck
if jsonErr := json.NewDecoder(r.Body).Decode(&ack); jsonErr != nil {
c.SetInvalidParam("ack")
c.SetInvalidParamWithErr("ack", jsonErr)
return
}
@@ -916,7 +916,7 @@ func getOnboarding(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(firstAdminCompleteSetupObj); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -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()

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

@@ -80,7 +80,7 @@ func (api *API) InitTeam() {
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var team model.Team
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
c.SetInvalidParam("team")
c.SetInvalidParamWithErr("team", jsonErr)
return
}
team.Email = strings.ToLower(team.Email)
@@ -131,7 +131,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rteam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -154,7 +154,7 @@ func getTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.App.SanitizeTeam(*c.AppContext.Session(), team)
if err := json.NewEncoder(w).Encode(team); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -177,7 +177,7 @@ func getTeamByName(c *Context, w http.ResponseWriter, r *http.Request) {
c.App.SanitizeTeam(*c.AppContext.Session(), team)
if err := json.NewEncoder(w).Encode(team); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -189,7 +189,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var team model.Team
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
c.SetInvalidParam("team")
c.SetInvalidParamWithErr("team", jsonErr)
return
}
@@ -222,7 +222,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.App.SanitizeTeam(*c.AppContext.Session(), updatedTeam)
if err := json.NewEncoder(w).Encode(updatedTeam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -234,7 +234,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var team model.TeamPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
c.SetInvalidParam("team")
c.SetInvalidParamWithErr("team", jsonErr)
return
}
@@ -266,7 +266,7 @@ func patchTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
if err := json.NewEncoder(w).Encode(patchedTeam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -325,7 +325,7 @@ func restoreTeam(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(team); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -380,7 +380,7 @@ func updateTeamPrivacy(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
if err := json.NewEncoder(w).Encode(team); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -413,7 +413,7 @@ func regenerateTeamInviteId(c *Context, w http.ResponseWriter, r *http.Request)
c.LogAudit("")
if err := json.NewEncoder(w).Encode(patchedTeam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -559,7 +559,7 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(team); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -687,7 +687,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
var member model.TeamMember
if jsonErr := json.NewDecoder(r.Body).Decode(&member); jsonErr != nil {
c.Err = model.NewAppError("addTeamMember", "api.team.add_team_member.invalid_body.app_error", nil, "Error in model.TeamMemberFromJSON()", http.StatusBadRequest)
c.Err = model.NewAppError("addTeamMember", "api.team.add_team_member.invalid_body.app_error", nil, "Error in model.TeamMemberFromJSON()", http.StatusBadRequest).Wrap(jsonErr)
return
}
if member.TeamId != c.Params.TeamId {
@@ -763,7 +763,7 @@ func addTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(tm); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -803,7 +803,7 @@ func addUserToTeamFromInvite(c *Context, w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(member); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -818,7 +818,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
var members []*model.TeamMember
if jsonErr := json.NewDecoder(r.Body).Decode(&members); jsonErr != nil {
c.SetInvalidParam("members")
c.SetInvalidParamWithErr("members", jsonErr)
return
}
@@ -991,7 +991,7 @@ func getTeamUnread(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(unreadTeam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -1019,7 +1019,7 @@ func getTeamStats(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))
}
}
@@ -1067,7 +1067,7 @@ func updateTeamMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.Requ
var schemeRoles model.SchemeRoles
if jsonErr := json.NewDecoder(r.Body).Decode(&schemeRoles); jsonErr != nil {
c.SetInvalidParam("scheme_roles")
c.SetInvalidParamWithErr("scheme_roles", jsonErr)
return
}
@@ -1155,7 +1155,7 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
var props model.TeamSearch
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
c.SetInvalidParam("team_search")
c.SetInvalidParamWithErr("team_search", jsonErr)
return
}
// Only system managers may use the ExcludePolicyConstrained field
@@ -1476,7 +1476,7 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
var guestsInvite model.GuestsInvite
if jsonErr := json.NewDecoder(r.Body).Decode(&guestsInvite); jsonErr != nil {
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
return
}
auditRec.AddEventParameter("guests_invite", guestsInvite)
@@ -1695,7 +1695,7 @@ func updateTeamScheme(c *Context, w http.ResponseWriter, r *http.Request) {
var p model.SchemeIDPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&p); jsonErr != nil {
c.SetInvalidParam("scheme_id")
c.SetInvalidParamWithErr("scheme_id", jsonErr)
return
}

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

@@ -244,7 +244,7 @@ func normalizeDomains(domains string) []string {
func localCreateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
var team model.Team
if jsonErr := json.NewDecoder(r.Body).Decode(&team); jsonErr != nil {
c.SetInvalidParam("team")
c.SetInvalidParamWithErr("team", jsonErr)
return
}
@@ -268,6 +268,6 @@ func localCreateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rteam); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -26,7 +26,7 @@ func getLatestTermsOfService(c *Context, w http.ResponseWriter, r *http.Request)
}
if err := json.NewEncoder(w).Encode(termsOfService); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -67,11 +67,11 @@ func createTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(termsOfService); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
} else {
if err := json.NewEncoder(w).Encode(oldTermsOfService); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
auditRec.Success()

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

@@ -31,7 +31,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
var us model.UploadSession
if jsonErr := json.NewDecoder(r.Body).Decode(&us); jsonErr != nil {
c.SetInvalidParam("upload")
c.SetInvalidParamWithErr("upload", jsonErr)
return
}
@@ -74,7 +74,7 @@ func createUpload(c *Context, w http.ResponseWriter, r *http.Request) {
auditRec.Success()
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rus); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -96,7 +96,7 @@ func getUpload(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(us); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -152,7 +152,7 @@ func uploadData(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := json.NewEncoder(w).Encode(info); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -108,7 +108,7 @@ func (api *API) InitUser() {
func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
var user model.User
if jsonErr := json.NewDecoder(r.Body).Decode(&user); jsonErr != nil {
c.SetInvalidParam("user")
c.SetInvalidParamWithErr("user", jsonErr)
return
}
@@ -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))
}
}
@@ -970,7 +970,7 @@ func getKnownUsers(c *Context, w http.ResponseWriter, r *http.Request) {
func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
var props model.UserSearch
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
c.SetInvalidParam("")
c.SetInvalidParamWithErr("props", jsonErr)
return
}
@@ -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))
}
}
@@ -1168,7 +1168,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
var user model.User
if jsonErr := json.NewDecoder(r.Body).Decode(&user); jsonErr != nil {
c.SetInvalidParam("user")
c.SetInvalidParamWithErr("user", jsonErr)
return
}
@@ -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))
}
}
@@ -1250,7 +1250,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
var patch model.UserPatch
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
c.SetInvalidParam("user")
c.SetInvalidParamWithErr("user", jsonErr)
return
}
@@ -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
@@ -1515,7 +1515,7 @@ func updateUserAuth(c *Context, w http.ResponseWriter, r *http.Request) {
var userAuth model.UserAuth
if jsonErr := json.NewDecoder(r.Body).Decode(&userAuth); jsonErr != nil {
c.SetInvalidParam("user")
c.SetInvalidParamWithErr("user", jsonErr)
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
}
@@ -2235,7 +2235,7 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
var switchRequest model.SwitchRequest
if jsonErr := json.NewDecoder(r.Body).Decode(&switchRequest); jsonErr != nil {
c.SetInvalidParam("switch_request")
c.SetInvalidParamWithErr("switch_request", jsonErr)
return
}
@@ -2297,7 +2297,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
var accessToken model.UserAccessToken
if jsonErr := json.NewDecoder(r.Body).Decode(&accessToken); jsonErr != nil {
c.SetInvalidParam("user_access_token")
c.SetInvalidParamWithErr("user_access_token", jsonErr)
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))
}
}
@@ -2344,7 +2344,7 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
var props model.UserAccessTokenSearch
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
c.SetInvalidParam("user_access_token_search")
c.SetInvalidParamWithErr("user_access_token_search", jsonErr)
return
}
@@ -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))
}
}
@@ -2728,7 +2728,7 @@ func publishUserTyping(c *Context, w http.ResponseWriter, r *http.Request) {
var typingRequest model.TypingRequest
if jsonErr := json.NewDecoder(r.Body).Decode(&typingRequest); jsonErr != nil {
c.SetInvalidParam("typing_request")
c.SetInvalidParamWithErr("typing_request", jsonErr)
return
}
@@ -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))
}
}

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

@@ -225,7 +225,7 @@ func localGetUser(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))
}
}
@@ -308,7 +308,7 @@ func localGetUserByUsername(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))
}
}
@@ -339,7 +339,7 @@ func localGetUserByEmail(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))
}
}

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

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

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

@@ -30,7 +30,7 @@ func (api *API) InitWebhook() {
func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook model.IncomingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
c.SetInvalidParam("incoming_webhook")
c.SetInvalidParamWithErr("incoming_webhook", jsonErr)
return
}
@@ -86,7 +86,7 @@ func createIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(incomingHook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -98,7 +98,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var updatedHook model.IncomingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&updatedHook); jsonErr != nil {
c.SetInvalidParam("incoming_webhook")
c.SetInvalidParamWithErr("incoming_webhook", jsonErr)
return
}
@@ -173,7 +173,7 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(incomingHook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -273,7 +273,7 @@ func getIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(hook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -342,7 +342,7 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var updatedHook model.OutgoingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&updatedHook); jsonErr != nil {
c.SetInvalidParam("outgoing_webhook")
c.SetInvalidParamWithErr("outgoing_webhook", jsonErr)
return
}
@@ -395,14 +395,14 @@ func updateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(rhook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook model.OutgoingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
c.SetInvalidParam("outgoing_webhook")
c.SetInvalidParamWithErr("outgoing_webhook", jsonErr)
return
}
@@ -446,7 +446,7 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rhook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -545,7 +545,7 @@ func getOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(hook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
@@ -592,7 +592,7 @@ func regenOutgoingHookToken(c *Context, w http.ResponseWriter, r *http.Request)
c.LogAudit("success")
if err := json.NewEncoder(w).Encode(rhook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}

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

@@ -29,7 +29,7 @@ func (api *API) InitWebhookLocal() {
func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook model.IncomingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
c.SetInvalidParam("incoming_webhook")
c.SetInvalidParamWithErr("incoming_webhook", jsonErr)
return
}
@@ -68,14 +68,14 @@ func localCreateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(incomingHook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}
func localCreateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
var hook model.OutgoingWebhook
if jsonErr := json.NewDecoder(r.Body).Decode(&hook); jsonErr != nil {
c.SetInvalidParam("outgoing_webhook")
c.SetInvalidParamWithErr("outgoing_webhook", jsonErr)
return
}
@@ -109,6 +109,6 @@ func localCreateOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(rhook); err != nil {
mlog.Warn("Error while writing response", mlog.Err(err))
c.Logger.Warn("Error while writing response", mlog.Err(err))
}
}