[MM-54132] Use annotated logger for log messages from jobs (#24275)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fcfcbd9909
Коммит
30b12f199b
@@ -31,7 +31,7 @@ func getJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
job, err := c.App.GetJob(c.Params.JobId)
|
||||
job, err := c.App.GetJob(c.AppContext, c.Params.JobId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -67,7 +67,7 @@ func downloadJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
job, err := c.App.GetJob(c.Params.JobId)
|
||||
job, err := c.App.GetJob(c.AppContext, c.Params.JobId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -126,7 +126,7 @@ func createJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rjob, err := c.App.CreateJob(&job)
|
||||
rjob, err := c.App.CreateJob(c.AppContext, &job)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -163,7 +163,7 @@ func getJobs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, appErr := c.App.GetJobsByTypesPage(validJobTypes, c.Params.Page, c.Params.PerPage)
|
||||
jobs, appErr := c.App.GetJobsByTypesPage(c.AppContext, validJobTypes, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
@@ -193,7 +193,7 @@ func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, appErr := c.App.GetJobsByTypePage(c.Params.JobType, c.Params.Page, c.Params.PerPage)
|
||||
jobs, appErr := c.App.GetJobsByTypePage(c.AppContext, c.Params.JobType, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
@@ -218,7 +218,7 @@ func cancelJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
audit.AddEventParameter(auditRec, "job_id", c.Params.JobId)
|
||||
|
||||
job, err := c.App.GetJob(c.Params.JobId)
|
||||
job, err := c.App.GetJob(c.AppContext, c.Params.JobId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -239,7 +239,7 @@ func cancelJob(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.CancelJob(c.Params.JobId); err != nil {
|
||||
if err := c.App.CancelJob(c.AppContext, c.Params.JobId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SyncLdap(opts.IncludeRemovedMembers)
|
||||
c.App.SyncLdap(c.AppContext, opts.IncludeRemovedMembers)
|
||||
|
||||
auditRec.Success()
|
||||
ReturnStatusOK(w)
|
||||
|
||||
@@ -145,13 +145,14 @@ func TestSyncLdap(t *testing.T) {
|
||||
ldapMock := &mocks.LdapInterface{}
|
||||
mockCall := ldapMock.On(
|
||||
"StartSynchronizeJob",
|
||||
mock.AnythingOfType("*request.Context"),
|
||||
mock.AnythingOfType("bool"),
|
||||
mock.AnythingOfType("bool"),
|
||||
).Return(nil, nil)
|
||||
ready := make(chan bool)
|
||||
includeRemovedMembers := false
|
||||
mockCall.RunFn = func(args mock.Arguments) {
|
||||
includeRemovedMembers = args[1].(bool)
|
||||
includeRemovedMembers = args[2].(bool)
|
||||
ready <- true
|
||||
}
|
||||
th.App.Channels().Ldap = ldapMock
|
||||
|
||||
@@ -98,7 +98,7 @@ func generateSupportPacket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
fileDatas := c.App.GenerateSupportPacket()
|
||||
fileDatas := c.App.GenerateSupportPacket(c.AppContext)
|
||||
|
||||
// Constructing the ZIP file name as per spec (mattermost_support_packet_YYYY-MM-DD-HH-MM.zip)
|
||||
now := time.Now()
|
||||
|
||||
@@ -1432,7 +1432,7 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// we then manually schedule the job to send another invite after 48 hours
|
||||
_, appErr = c.App.Srv().Jobs.CreateJob(model.JobTypeResendInvitationEmail, jobData)
|
||||
_, appErr = c.App.Srv().Jobs.CreateJob(c.AppContext, model.JobTypeResendInvitationEmail, jobData)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeam", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
|
||||
return
|
||||
@@ -1592,7 +1592,7 @@ func invalidateAllEmailInvites(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
auditRec := c.MakeAuditRecord("invalidateAllEmailInvites", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
if err := c.App.InvalidateAllEmailInvites(); err != nil {
|
||||
if err := c.App.InvalidateAllEmailInvites(c.AppContext); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3196,15 +3196,14 @@ func TestValidateUserPermissionsOnChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// define user session and context
|
||||
context := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
t.Run("User WITH permissions on private channel CAN invite members to it", func(t *testing.T) {
|
||||
channelIds := []string{th.BasicChannel.Id, th.BasicPrivateChannel.Id}
|
||||
|
||||
require.Len(t, channelIds, 2)
|
||||
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(context, th.BasicUser.Id, channelIds)
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(ctx, th.BasicUser.Id, channelIds)
|
||||
|
||||
// basicUser has permission onBasicChannel and BasicPrivateChannel so he can invite to both channels
|
||||
require.Len(t, channelIds, 2)
|
||||
@@ -3216,7 +3215,7 @@ func TestValidateUserPermissionsOnChannels(t *testing.T) {
|
||||
|
||||
require.Len(t, channelIds, 2)
|
||||
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(context, th.BasicUser.Id, channelIds)
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(ctx, th.BasicUser.Id, channelIds)
|
||||
|
||||
// basicUser DOES NOT have permission on BasicPrivateChannel2 so he can only invite to BasicChannel
|
||||
require.Len(t, channelIds, 1)
|
||||
|
||||
@@ -3072,7 +3072,7 @@ func migrateAuthToLDAP(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if migrate := c.App.AccountMigration(); migrate != nil {
|
||||
if err := migrate.MigrateToLdap(from, matchField, force, false); err != nil {
|
||||
if err := migrate.MigrateToLdap(c.AppContext, from, matchField, force, false); err != nil {
|
||||
c.Err = model.NewAppError("api.migrateAuthToLdap", "api.migrate_to_saml.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user