[MM-54132] Use annotated logger for log messages from jobs (#24275)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fcfcbd9909
Коммит
30b12f199b
@@ -333,7 +333,7 @@ type AppIface interface {
|
||||
// SyncLdap starts an LDAP sync job.
|
||||
// If includeRemovedMembers is true, then members who left or were removed from a team/channel will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
SyncLdap(includeRemovedMembers bool)
|
||||
SyncLdap(c *request.Context, includeRemovedMembers bool)
|
||||
// SyncPlugins synchronizes the plugins installed locally
|
||||
// with the plugin bundles available in the file store.
|
||||
SyncPlugins() *model.AppError
|
||||
@@ -444,7 +444,7 @@ type AppIface interface {
|
||||
BulkImport(c *request.Context, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int) (*model.AppError, int)
|
||||
BulkImportWithPath(c *request.Context, jsonlReader io.Reader, attachmentsReader *zip.Reader, dryRun bool, workers int, importPath string) (*model.AppError, int)
|
||||
CanNotifyAdmin(trial bool) bool
|
||||
CancelJob(jobId string) *model.AppError
|
||||
CancelJob(c *request.Context, jobId string) *model.AppError
|
||||
ChannelMembersToRemove(teamID *string) ([]*model.ChannelMember, *model.AppError)
|
||||
Channels() *Channels
|
||||
CheckCanInviteToSharedChannel(channelId string) error
|
||||
@@ -487,7 +487,7 @@ type AppIface interface {
|
||||
CreateGroupChannel(c request.CTX, userIDs []string, creatorId string) (*model.Channel, *model.AppError)
|
||||
CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Group, *model.AppError)
|
||||
CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError)
|
||||
CreateJob(job *model.Job) (*model.Job, *model.AppError)
|
||||
CreateJob(c *request.Context, job *model.Job) (*model.Job, *model.AppError)
|
||||
CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
CreateOAuthStateToken(extra string) (*model.Token, *model.AppError)
|
||||
CreateOAuthUser(c *request.Context, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
@@ -581,7 +581,7 @@ type AppIface interface {
|
||||
GenerateMfaSecret(userID string) (*model.MfaSecret, *model.AppError)
|
||||
GeneratePresignURLForExport(name string) (*model.PresignURLResponse, *model.AppError)
|
||||
GeneratePublicLink(siteURL string, info *model.FileInfo) string
|
||||
GenerateSupportPacket() []model.FileData
|
||||
GenerateSupportPacket(c *request.Context) []model.FileData
|
||||
GetAcknowledgementsForPost(postID string) ([]*model.PostAcknowledgement, *model.AppError)
|
||||
GetAcknowledgementsForPostList(postList *model.PostList) (map[string][]*model.PostAcknowledgement, *model.AppError)
|
||||
GetActivePluginManifests() ([]*model.Manifest, *model.AppError)
|
||||
@@ -678,13 +678,11 @@ type AppIface interface {
|
||||
GetIncomingWebhooksForTeamPageByUser(teamID string, userID string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetIncomingWebhooksPageByUser(userID string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError)
|
||||
GetJob(id string) (*model.Job, *model.AppError)
|
||||
GetJobs(offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypes(jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypesPage(jobType []string, page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetJob(c *request.Context, id string) (*model.Job, *model.AppError)
|
||||
GetJobsByType(c *request.Context, jobType string, offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypePage(c *request.Context, jobType string, page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypes(c *request.Context, jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError)
|
||||
GetJobsByTypesPage(c *request.Context, jobType []string, page int, perPage int) ([]*model.Job, *model.AppError)
|
||||
GetLatestTermsOfService() (*model.TermsOfService, *model.AppError)
|
||||
GetLatestVersion(latestVersionUrl string) (*model.GithubReleaseInfo, *model.AppError)
|
||||
GetLogs(c request.CTX, page, perPage int) ([]string, *model.AppError)
|
||||
@@ -877,8 +875,8 @@ type AppIface interface {
|
||||
ImageProxyRemover() (f func(string) string)
|
||||
ImportPermissions(jsonl io.Reader) error
|
||||
InitPlugins(c *request.Context, pluginDir, webappPluginDir string)
|
||||
InvalidateAllEmailInvites() *model.AppError
|
||||
InvalidateAllResendInviteEmailJobs() *model.AppError
|
||||
InvalidateAllEmailInvites(c *request.Context) *model.AppError
|
||||
InvalidateAllResendInviteEmailJobs(c *request.Context) *model.AppError
|
||||
InvalidateCacheForUser(userID string)
|
||||
InvalidatePasswordRecoveryTokensForUser(userID string) *model.AppError
|
||||
InviteGuestsToChannels(teamID string, guestsInvite *model.GuestsInvite, senderId string) *model.AppError
|
||||
|
||||
@@ -287,8 +287,7 @@ func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T)
|
||||
}
|
||||
|
||||
func TestProcessAttachments(t *testing.T) {
|
||||
logger, _ := mlog.NewLogger()
|
||||
c := request.EmptyContext(logger)
|
||||
c := request.EmptyContext(mlog.CreateConsoleTestLogger(t))
|
||||
|
||||
genAttachments := func() *[]imports.AttachmentImportData {
|
||||
return &[]imports.AttachmentImportData{
|
||||
|
||||
@@ -8,11 +8,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
func (a *App) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
job, err := a.Srv().Store().Job().Get(id)
|
||||
func (a *App) GetJob(c *request.Context, id string) (*model.Job, *model.AppError) {
|
||||
job, err := a.Srv().Store().Job().Get(c, id)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -26,25 +27,12 @@ func (a *App) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func (a *App) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return a.GetJobs(page*perPage, perPage)
|
||||
func (a *App) GetJobsByTypePage(c *request.Context, jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return a.GetJobsByType(c, jobType, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
jobs, err := a.Srv().Store().Job().GetAllPage(offset, limit)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetJobs", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (a *App) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return a.GetJobsByType(jobType, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
jobs, err := a.Srv().Store().Job().GetAllByTypePage(jobType, offset, limit)
|
||||
func (a *App) GetJobsByType(c *request.Context, jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
jobs, err := a.Srv().Store().Job().GetAllByTypePage(c, jobType, offset, limit)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -52,24 +40,24 @@ func (a *App) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (a *App) GetJobsByTypesPage(jobType []string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return a.GetJobsByTypes(jobType, page*perPage, perPage)
|
||||
func (a *App) GetJobsByTypesPage(c *request.Context, jobType []string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
return a.GetJobsByTypes(c, jobType, page*perPage, perPage)
|
||||
}
|
||||
|
||||
func (a *App) GetJobsByTypes(jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
jobs, err := a.Srv().Store().Job().GetAllByTypesPage(jobTypes, offset, limit)
|
||||
func (a *App) GetJobsByTypes(c *request.Context, jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
jobs, err := a.Srv().Store().Job().GetAllByTypesPage(c, jobTypes, offset, limit)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetJobsByType", "app.job.get_all.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (a *App) CreateJob(job *model.Job) (*model.Job, *model.AppError) {
|
||||
return a.Srv().Jobs.CreateJob(job.Type, job.Data)
|
||||
func (a *App) CreateJob(c *request.Context, job *model.Job) (*model.Job, *model.AppError) {
|
||||
return a.Srv().Jobs.CreateJob(c, job.Type, job.Data)
|
||||
}
|
||||
|
||||
func (a *App) CancelJob(jobId string) *model.AppError {
|
||||
return a.Srv().Jobs.RequestCancellation(jobId)
|
||||
func (a *App) CancelJob(c *request.Context, jobId string) *model.AppError {
|
||||
return a.Srv().Jobs.RequestCancellation(c, jobId)
|
||||
}
|
||||
|
||||
func (a *App) SessionHasPermissionToCreateJob(session model.Session, job *model.Job) (bool, *model.Permission) {
|
||||
|
||||
@@ -11,23 +11,27 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
)
|
||||
|
||||
func TestGetJob(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
status := &model.Job{
|
||||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
status.InitLogger(th.TestLogger)
|
||||
|
||||
_, err := th.App.Srv().Store().Job().Save(status)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer th.App.Srv().Store().Job().Delete(status.Id)
|
||||
|
||||
received, appErr := th.App.GetJob(status.Id)
|
||||
received, appErr := th.App.GetJob(ctx, status.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, status, received, "incorrect job status received")
|
||||
}
|
||||
@@ -216,6 +220,7 @@ func TestSessionHasPermissionToReadJob(t *testing.T) {
|
||||
func TestGetJobByType(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
@@ -238,18 +243,20 @@ func TestGetJobByType(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
status.InitLogger(th.TestLogger)
|
||||
|
||||
_, err := th.App.Srv().Store().Job().Save(status)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
received, err := th.App.GetJobsByType(jobType, 0, 2)
|
||||
received, err := th.App.GetJobsByType(ctx, jobType, 0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of statuses")
|
||||
require.Equal(t, statuses[2], received[0], "should've received newest job first")
|
||||
require.Equal(t, statuses[0], received[1], "should've received second newest job second")
|
||||
|
||||
received, err = th.App.GetJobsByType(jobType, 2, 2)
|
||||
received, err = th.App.GetJobsByType(ctx, jobType, 2, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of statuses")
|
||||
require.Equal(t, statuses[1], received[0], "should've received oldest job last")
|
||||
@@ -258,6 +265,7 @@ func TestGetJobByType(t *testing.T) {
|
||||
func TestGetJobsByTypes(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
jobType := model.NewId()
|
||||
jobType1 := model.NewId()
|
||||
@@ -282,25 +290,27 @@ func TestGetJobsByTypes(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
status.InitLogger(th.TestLogger)
|
||||
|
||||
_, err := th.App.Srv().Store().Job().Save(status)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
jobTypes := []string{jobType, jobType1, jobType2}
|
||||
received, err := th.App.GetJobsByTypes(jobTypes, 0, 2)
|
||||
received, err := th.App.GetJobsByTypes(ctx, jobTypes, 0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[2], received[0], "should've received newest job first")
|
||||
require.Equal(t, statuses[0], received[1], "should've received second newest job second")
|
||||
|
||||
received, err = th.App.GetJobsByTypes(jobTypes, 2, 2)
|
||||
received, err = th.App.GetJobsByTypes(ctx, jobTypes, 2, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[1], received[0], "should've received oldest job last")
|
||||
|
||||
jobTypes = []string{jobType1, jobType2}
|
||||
received, err = th.App.GetJobsByTypes(jobTypes, 0, 3)
|
||||
received, err = th.App.GetJobsByTypes(ctx, jobTypes, 0, 3)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[2], received[0], "received wrong job type")
|
||||
|
||||
@@ -11,12 +11,13 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
// SyncLdap starts an LDAP sync job.
|
||||
// If includeRemovedMembers is true, then members who left or were removed from a team/channel will
|
||||
// be re-added; otherwise, they will not be re-added.
|
||||
func (a *App) SyncLdap(includeRemovedMembers bool) {
|
||||
func (a *App) SyncLdap(c *request.Context, includeRemovedMembers bool) {
|
||||
a.Srv().Go(func() {
|
||||
|
||||
if license := a.Srv().License(); license != nil && *license.Features.LDAP {
|
||||
@@ -30,7 +31,7 @@ func (a *App) SyncLdap(includeRemovedMembers bool) {
|
||||
mlog.Error("Not executing ldap sync because ldap is not available")
|
||||
return
|
||||
}
|
||||
ldapI.StartSynchronizeJob(false, includeRemovedMembers)
|
||||
ldapI.StartSynchronizeJob(c, false, includeRemovedMembers)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
const EmojisPermissionsMigrationKey = "EmojisPermissionsMigrationComplete"
|
||||
@@ -554,7 +555,7 @@ func (s *Server) doPostPriorityConfigDefaultTrueMigration() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) doElasticsearchFixChannelIndex() {
|
||||
func (s *Server) doElasticsearchFixChannelIndex(c *request.Context) {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if _, err := s.Store().System().GetByName(model.MigrationKeyElasticsearchFixChannelIndex); err == nil {
|
||||
return
|
||||
@@ -566,13 +567,13 @@ func (s *Server) doElasticsearchFixChannelIndex() {
|
||||
return
|
||||
}
|
||||
|
||||
if _, appErr := s.Jobs.CreateJob(model.JobTypeElasticsearchFixChannelIndex, nil); appErr != nil {
|
||||
if _, appErr := s.Jobs.CreateJob(c, model.JobTypeElasticsearchFixChannelIndex, nil); appErr != nil {
|
||||
mlog.Fatal("failed to start job for fixing Elasticsearch channels index", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) doCloudS3PathMigrations() {
|
||||
func (s *Server) doCloudS3PathMigrations(c *request.Context) {
|
||||
// This migration is only applicable for cloud environments
|
||||
if os.Getenv("MM_CLOUD_FILESTORE_BIFROST") == "" {
|
||||
return
|
||||
@@ -585,7 +586,7 @@ func (s *Server) doCloudS3PathMigrations() {
|
||||
|
||||
// If there is a job already pending, no need to schedule again.
|
||||
// This is possible if the pod was rolled over.
|
||||
jobs, err := s.Store().Job().GetAllByTypeAndStatus(model.JobTypeS3PathMigration, model.JobStatusPending)
|
||||
jobs, err := s.Store().Job().GetAllByTypeAndStatus(c, model.JobTypeS3PathMigration, model.JobStatusPending)
|
||||
if err != nil {
|
||||
mlog.Fatal("failed to get jobs by type and status", mlog.Err(err))
|
||||
return
|
||||
@@ -594,7 +595,7 @@ func (s *Server) doCloudS3PathMigrations() {
|
||||
return
|
||||
}
|
||||
|
||||
if _, appErr := s.Jobs.CreateJobOnce(model.JobTypeS3PathMigration, nil); appErr != nil {
|
||||
if _, appErr := s.Jobs.CreateJobOnce(c, model.JobTypeS3PathMigration, nil); appErr != nil {
|
||||
mlog.Fatal("failed to start job for migrating s3 file paths", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
@@ -606,6 +607,8 @@ func (a *App) DoAppMigrations() {
|
||||
}
|
||||
|
||||
func (s *Server) doAppMigrations() {
|
||||
c := request.EmptyContext(s.Log())
|
||||
|
||||
s.doAdvancedPermissionsMigration()
|
||||
s.doEmojisPermissionsMigration()
|
||||
s.doGuestRolesCreationMigration()
|
||||
@@ -622,6 +625,6 @@ func (s *Server) doAppMigrations() {
|
||||
s.doFirstAdminSetupCompleteMigration()
|
||||
s.doRemainingSchemaMigrations()
|
||||
s.doPostPriorityConfigDefaultTrueMigration()
|
||||
s.doElasticsearchFixChannelIndex()
|
||||
s.doCloudS3PathMigrations()
|
||||
s.doElasticsearchFixChannelIndex(c)
|
||||
s.doCloudS3PathMigrations(c)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -22,10 +21,10 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("no error sending non trial upgrade post when no notifications are available", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
err := th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
@@ -33,10 +32,10 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("no error sending trial upgrade post when no notifications are available", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
err := th.App.SendNotifyAdminPosts(ctx, "", "", true)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
@@ -44,6 +43,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("successfully send upgrade notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -62,7 +62,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -98,6 +97,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("successfully send trial upgrade notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -110,7 +110,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -146,6 +145,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("successfully send install plugin notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// some notifications
|
||||
_, appErr := th.App.SaveAdminNotifyData(&model.NotifyAdminData{
|
||||
@@ -156,7 +156,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -191,6 +190,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("persist notify admin data after sending the install plugin notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// some notifications
|
||||
_, appErr := th.App.SaveAdminNotifyData(&model.NotifyAdminData{
|
||||
@@ -201,7 +201,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -261,6 +260,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("error when trying to send upgrade post before end of cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -272,7 +272,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -293,6 +292,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("can send upgrade post at the end of cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -307,7 +307,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -329,6 +328,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("can filter notifications when plan changes within cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -349,7 +349,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", model.LicenseShortSkuProfessional, false) // try and send notification but workspace currentSKU has since changed to cloud-professional
|
||||
require.Nil(t, appErr)
|
||||
|
||||
@@ -385,13 +384,13 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("correctly send upgrade and install plugin post with the correct user request", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
os.Setenv("MM_NOTIFY_ADMIN_COOL_OFF_DAYS", "0")
|
||||
defer os.Unsetenv("MM_NOTIFY_ADMIN_COOL_OFF_DAYS")
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
|
||||
// some notifications
|
||||
_, appErr := th.App.SaveAdminNotifyData(&model.NotifyAdminData{
|
||||
UserId: th.BasicUser.Id,
|
||||
|
||||
@@ -1075,7 +1075,7 @@ func (a *OpenTracingAppLayer) CanNotifyAdmin(trial bool) bool {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CancelJob(jobId string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) CancelJob(c *request.Context, jobId string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CancelJob")
|
||||
|
||||
@@ -1087,7 +1087,7 @@ func (a *OpenTracingAppLayer) CancelJob(jobId string) *model.AppError {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.CancelJob(jobId)
|
||||
resultVar0 := a.app.CancelJob(c, jobId)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -2175,7 +2175,7 @@ func (a *OpenTracingAppLayer) CreateIncomingWebhookForChannel(creatorId string,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CreateJob(job *model.Job) (*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CreateJob(c *request.Context, job *model.Job) (*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CreateJob")
|
||||
|
||||
@@ -2187,7 +2187,7 @@ func (a *OpenTracingAppLayer) CreateJob(job *model.Job) (*model.Job, *model.AppE
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.CreateJob(job)
|
||||
resultVar0, resultVar1 := a.app.CreateJob(c, job)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -4623,7 +4623,7 @@ func (a *OpenTracingAppLayer) GeneratePublicLink(siteURL string, info *model.Fil
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GenerateSupportPacket() []model.FileData {
|
||||
func (a *OpenTracingAppLayer) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GenerateSupportPacket")
|
||||
|
||||
@@ -4635,7 +4635,7 @@ func (a *OpenTracingAppLayer) GenerateSupportPacket() []model.FileData {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.GenerateSupportPacket()
|
||||
resultVar0 := a.app.GenerateSupportPacket(c)
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
@@ -6991,7 +6991,7 @@ func (a *OpenTracingAppLayer) GetIncomingWebhooksPageByUser(userID string, page
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetJob(c *request.Context, id string) (*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJob")
|
||||
|
||||
@@ -7003,7 +7003,7 @@ func (a *OpenTracingAppLayer) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJob(id)
|
||||
resultVar0, resultVar1 := a.app.GetJob(c, id)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7013,29 +7013,7 @@ func (a *OpenTracingAppLayer) GetJob(id string) (*model.Job, *model.AppError) {
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobs(offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobs")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobs(offset, limit)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobsByType(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetJobsByType(c *request.Context, jobType string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobsByType")
|
||||
|
||||
@@ -7047,7 +7025,7 @@ func (a *OpenTracingAppLayer) GetJobsByType(jobType string, offset int, limit in
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobsByType(jobType, offset, limit)
|
||||
resultVar0, resultVar1 := a.app.GetJobsByType(c, jobType, offset, limit)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7057,7 +7035,7 @@ func (a *OpenTracingAppLayer) GetJobsByType(jobType string, offset int, limit in
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypePage(jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypePage(c *request.Context, jobType string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobsByTypePage")
|
||||
|
||||
@@ -7069,7 +7047,7 @@ func (a *OpenTracingAppLayer) GetJobsByTypePage(jobType string, page int, perPag
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypePage(jobType, page, perPage)
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypePage(c, jobType, page, perPage)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7079,7 +7057,7 @@ func (a *OpenTracingAppLayer) GetJobsByTypePage(jobType string, page int, perPag
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypes(jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypes(c *request.Context, jobTypes []string, offset int, limit int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobsByTypes")
|
||||
|
||||
@@ -7091,7 +7069,7 @@ func (a *OpenTracingAppLayer) GetJobsByTypes(jobTypes []string, offset int, limi
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypes(jobTypes, offset, limit)
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypes(c, jobTypes, offset, limit)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7101,7 +7079,7 @@ func (a *OpenTracingAppLayer) GetJobsByTypes(jobTypes []string, offset int, limi
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypesPage(jobType []string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetJobsByTypesPage(c *request.Context, jobType []string, page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobsByTypesPage")
|
||||
|
||||
@@ -7113,29 +7091,7 @@ func (a *OpenTracingAppLayer) GetJobsByTypesPage(jobType []string, page int, per
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypesPage(jobType, page, perPage)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetJobsPage(page int, perPage int) ([]*model.Job, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetJobsPage")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetJobsPage(page, perPage)
|
||||
resultVar0, resultVar1 := a.app.GetJobsByTypesPage(c, jobType, page, perPage)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -11708,7 +11664,7 @@ func (a *OpenTracingAppLayer) InstallPlugin(pluginFile io.ReadSeeker, replace bo
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) InvalidateAllEmailInvites() *model.AppError {
|
||||
func (a *OpenTracingAppLayer) InvalidateAllEmailInvites(c *request.Context) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.InvalidateAllEmailInvites")
|
||||
|
||||
@@ -11720,7 +11676,7 @@ func (a *OpenTracingAppLayer) InvalidateAllEmailInvites() *model.AppError {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.InvalidateAllEmailInvites()
|
||||
resultVar0 := a.app.InvalidateAllEmailInvites(c)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -11730,7 +11686,7 @@ func (a *OpenTracingAppLayer) InvalidateAllEmailInvites() *model.AppError {
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) InvalidateAllResendInviteEmailJobs() *model.AppError {
|
||||
func (a *OpenTracingAppLayer) InvalidateAllResendInviteEmailJobs(c *request.Context) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.InvalidateAllResendInviteEmailJobs")
|
||||
|
||||
@@ -11742,7 +11698,7 @@ func (a *OpenTracingAppLayer) InvalidateAllResendInviteEmailJobs() *model.AppErr
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.InvalidateAllResendInviteEmailJobs()
|
||||
resultVar0 := a.app.InvalidateAllResendInviteEmailJobs(c)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -16736,7 +16692,7 @@ func (a *OpenTracingAppLayer) SwitchOAuthToEmail(email string, password string,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SyncLdap(includeRemovedMembers bool) {
|
||||
func (a *OpenTracingAppLayer) SyncLdap(c *request.Context, includeRemovedMembers bool) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SyncLdap")
|
||||
|
||||
@@ -16748,7 +16704,7 @@ func (a *OpenTracingAppLayer) SyncLdap(includeRemovedMembers bool) {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
a.app.SyncLdap(includeRemovedMembers)
|
||||
a.app.SyncLdap(c, includeRemovedMembers)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SyncPlugins() *model.AppError {
|
||||
|
||||
@@ -5,7 +5,6 @@ package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -944,10 +943,9 @@ func TestErrorString(t *testing.T) {
|
||||
func TestHookContext(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// We don't actually have a session, we are faking it so just set something arbitrarily
|
||||
ctx := request.NewContext(context.Background(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.NewId(), model.Session{}, nil)
|
||||
ctx.SetLogger(th.TestLogger)
|
||||
ctx.Session().Id = model.NewId()
|
||||
|
||||
var mockAPI plugintest.API
|
||||
|
||||
@@ -1487,7 +1487,7 @@ func (ch *Channels) ClientConfigHash() string {
|
||||
}
|
||||
|
||||
func (s *Server) initJobs() {
|
||||
s.Jobs = jobs.NewJobServer(s.platform, s.Store(), s.GetMetrics())
|
||||
s.Jobs = jobs.NewJobServer(s.platform, s.Store(), s.GetMetrics(), s.Log())
|
||||
|
||||
if jobsDataRetentionJobInterface != nil {
|
||||
builder := jobsDataRetentionJobInterface(s)
|
||||
|
||||
@@ -15,10 +15,11 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
)
|
||||
|
||||
func (a *App) GenerateSupportPacket() []model.FileData {
|
||||
func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
// If any errors we come across within this function, we will log it in a warning.txt file so that we know why certain files did not get produced if any
|
||||
var warnings []string
|
||||
|
||||
@@ -26,7 +27,7 @@ func (a *App) GenerateSupportPacket() []model.FileData {
|
||||
fileDatas := []model.FileData{}
|
||||
|
||||
// A array of the functions that we can iterate through since they all have the same return value
|
||||
functions := map[string]func() (*model.FileData, error){
|
||||
functions := map[string]func(c *request.Context) (*model.FileData, error){
|
||||
"support package": a.generateSupportPacketYaml,
|
||||
"plugins": a.createPluginsFile,
|
||||
"config": a.createSanitizedConfigFile,
|
||||
@@ -35,7 +36,7 @@ func (a *App) GenerateSupportPacket() []model.FileData {
|
||||
}
|
||||
|
||||
for name, fn := range functions {
|
||||
fileData, err := fn()
|
||||
fileData, err := fn(c)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to generate file for support package", mlog.Err(err), mlog.String("file", name))
|
||||
warnings = append(warnings, err.Error())
|
||||
@@ -56,7 +57,7 @@ func (a *App) GenerateSupportPacket() []model.FileData {
|
||||
return fileDatas
|
||||
}
|
||||
|
||||
func (a *App) generateSupportPacketYaml() (*model.FileData, error) {
|
||||
func (a *App) generateSupportPacketYaml(c *request.Context) (*model.FileData, error) {
|
||||
var rErr error
|
||||
|
||||
/* DB */
|
||||
@@ -112,31 +113,31 @@ func (a *App) generateSupportPacketYaml() (*model.FileData, error) {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting user count"))
|
||||
}
|
||||
|
||||
dataRetentionJobs, err := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeDataRetention, 0, 2)
|
||||
dataRetentionJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeDataRetention, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting data retention jobs"))
|
||||
}
|
||||
messageExportJobs, err := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeMessageExport, 0, 2)
|
||||
messageExportJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeMessageExport, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting message export jobs"))
|
||||
}
|
||||
elasticPostIndexingJobs, err := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeElasticsearchPostIndexing, 0, 2)
|
||||
elasticPostIndexingJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeElasticsearchPostIndexing, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post indexing jobs"))
|
||||
}
|
||||
elasticPostAggregationJobs, _ := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeElasticsearchPostAggregation, 0, 2)
|
||||
elasticPostAggregationJobs, _ := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeElasticsearchPostAggregation, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post aggregation jobs"))
|
||||
}
|
||||
blevePostIndexingJobs, _ := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeBlevePostIndexing, 0, 2)
|
||||
blevePostIndexingJobs, _ := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeBlevePostIndexing, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting bleve post indexing jobs"))
|
||||
}
|
||||
ldapSyncJobs, err := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeLdapSync, 0, 2)
|
||||
ldapSyncJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeLdapSync, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting LDAP sync jobs"))
|
||||
}
|
||||
migrationJobs, err := a.Srv().Store().Job().GetAllByTypePage(model.JobTypeMigrations, 0, 2)
|
||||
migrationJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeMigrations, 0, 2)
|
||||
if err != nil {
|
||||
rErr = multierror.Append(errors.Wrap(err, "error while getting migration jobs"))
|
||||
}
|
||||
@@ -219,7 +220,8 @@ func (a *App) generateSupportPacketYaml() (*model.FileData, error) {
|
||||
return fileData, rErr
|
||||
}
|
||||
|
||||
func (a *App) createPluginsFile() (*model.FileData, error) {
|
||||
func (a *App) createPluginsFile(_ *request.Context) (*model.FileData, error) {
|
||||
|
||||
// Getting the plugins installed on the server, prettify it, and then add them to the file data array
|
||||
pluginsResponse, appErr := a.GetPlugins()
|
||||
if appErr != nil {
|
||||
@@ -239,7 +241,7 @@ func (a *App) createPluginsFile() (*model.FileData, error) {
|
||||
|
||||
}
|
||||
|
||||
func (a *App) getNotificationsLog() (*model.FileData, error) {
|
||||
func (a *App) getNotificationsLog(_ *request.Context) (*model.FileData, error) {
|
||||
if !*a.Config().NotificationLogSettings.EnableFile {
|
||||
return nil, errors.New("Unable to retrieve notifications.log because LogSettings: EnableFile is set to false")
|
||||
}
|
||||
@@ -257,7 +259,7 @@ func (a *App) getNotificationsLog() (*model.FileData, error) {
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) getMattermostLog() (*model.FileData, error) {
|
||||
func (a *App) getMattermostLog(_ *request.Context) (*model.FileData, error) {
|
||||
if !*a.Config().LogSettings.EnableFile {
|
||||
return nil, errors.New("Unable to retrieve mattermost.log because LogSettings: EnableFile is set to false")
|
||||
}
|
||||
@@ -275,7 +277,7 @@ func (a *App) getMattermostLog() (*model.FileData, error) {
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) createSanitizedConfigFile() (*model.FileData, error) {
|
||||
func (a *App) createSanitizedConfigFile(_ *request.Context) (*model.FileData, error) {
|
||||
// Getting sanitized config, prettifying it, and then adding it to our file data array
|
||||
sanitizedConfigPrettyJSON, err := json.MarshalIndent(a.GetSanitizedConfig(), "", " ")
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
fmocks "github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks"
|
||||
)
|
||||
@@ -20,9 +21,10 @@ import (
|
||||
func TestCreatePluginsFile(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Happy path where we have a plugins file with no err
|
||||
fileData, err := th.App.createPluginsFile()
|
||||
fileData, err := th.App.createPluginsFile(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "plugins.json", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -34,7 +36,7 @@ func TestCreatePluginsFile(t *testing.T) {
|
||||
})
|
||||
|
||||
// Plugins off in settings so no fileData and we get a warning instead
|
||||
fileData, err = th.App.createPluginsFile()
|
||||
fileData, err = th.App.createPluginsFile(ctx)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed to get plugin list for support package")
|
||||
}
|
||||
@@ -42,6 +44,7 @@ func TestCreatePluginsFile(t *testing.T) {
|
||||
func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
licenseUsers := 100
|
||||
license := model.NewTestLicense()
|
||||
@@ -51,7 +54,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
t.Run("Happy path", func(t *testing.T) {
|
||||
// Happy path where we have a support packet yaml file without any warnings
|
||||
|
||||
fileData, err := th.App.generateSupportPacketYaml()
|
||||
fileData, err := th.App.generateSupportPacketYaml(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "support_packet.yaml", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -72,7 +75,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
fb.On("DriverName").Return("mock")
|
||||
fb.On("TestConnection").Return(errors.New("all broken"))
|
||||
|
||||
fileData, err := th.App.generateSupportPacketYaml()
|
||||
fileData, err := th.App.generateSupportPacketYaml(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "support_packet.yaml", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -89,6 +92,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
func TestGenerateSupportPacket(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
d1 := []byte("hello\ngo\n")
|
||||
err := os.WriteFile("mattermost.log", d1, 0777)
|
||||
@@ -96,7 +100,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
err = os.WriteFile("notifications.log", d1, 0777)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileDatas := th.App.GenerateSupportPacket()
|
||||
fileDatas := th.App.GenerateSupportPacket(ctx)
|
||||
var rFileNames []string
|
||||
testFiles := []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "mattermost.log", "notifications.log"}
|
||||
for _, fileData := range fileDatas {
|
||||
@@ -112,7 +116,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
err = os.Remove("mattermost.log")
|
||||
require.NoError(t, err)
|
||||
fileDatas = th.App.GenerateSupportPacket()
|
||||
fileDatas = th.App.GenerateSupportPacket(ctx)
|
||||
testFiles = []string{"support_packet.yaml", "plugins.json", "sanitized_config.json", "warning.txt"}
|
||||
rFileNames = nil
|
||||
for _, fileData := range fileDatas {
|
||||
@@ -127,13 +131,14 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
func TestGetNotificationsLog(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Disable notifications file to get an error
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.NotificationLogSettings.EnableFile = false
|
||||
})
|
||||
|
||||
fileData, err := th.App.getNotificationsLog()
|
||||
fileData, err := th.App.getNotificationsLog(ctx)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "Unable to retrieve notifications.log because LogSettings: EnableFile is set to false")
|
||||
|
||||
@@ -145,7 +150,7 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
// If any previous notifications.log file, lets delete it
|
||||
os.Remove("notifications.log")
|
||||
|
||||
fileData, err = th.App.getNotificationsLog()
|
||||
fileData, err = th.App.getNotificationsLog(ctx)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed read notifcation log file at path")
|
||||
|
||||
@@ -155,7 +160,7 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
defer os.Remove("notifications.log")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileData, err = th.App.getNotificationsLog()
|
||||
fileData, err = th.App.getNotificationsLog(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "notifications.log", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -165,13 +170,14 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
func TestGetMattermostLog(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// disable mattermost log file setting in config so we should get an warning
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LogSettings.EnableFile = false
|
||||
})
|
||||
|
||||
fileData, err := th.App.getMattermostLog()
|
||||
fileData, err := th.App.getMattermostLog(ctx)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "Unable to retrieve mattermost.log because LogSettings: EnableFile is set to false")
|
||||
|
||||
@@ -183,7 +189,7 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
// If any previous mattermost.log file, lets delete it
|
||||
os.Remove("mattermost.log")
|
||||
|
||||
fileData, err = th.App.getMattermostLog()
|
||||
fileData, err = th.App.getMattermostLog(ctx)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed read mattermost log file at path mattermost.log")
|
||||
|
||||
@@ -193,7 +199,7 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
defer os.Remove("mattermost.log")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileData, err = th.App.getMattermostLog()
|
||||
fileData, err = th.App.getMattermostLog(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "mattermost.log", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -203,9 +209,10 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
func TestCreateSanitizedConfigFile(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Happy path where we have a sanitized config file with no err
|
||||
fileData, err := th.App.createSanitizedConfigFile()
|
||||
fileData, err := th.App.createSanitizedConfigFile(ctx)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "sanitized_config.json", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
|
||||
@@ -2057,21 +2057,21 @@ func (a *App) RemoveTeamIcon(teamID string) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) InvalidateAllEmailInvites() *model.AppError {
|
||||
func (a *App) InvalidateAllEmailInvites(c *request.Context) *model.AppError {
|
||||
if err := a.Srv().Store().Token().RemoveAllTokensByType(TokenTypeTeamInvitation); err != nil {
|
||||
return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
if err := a.Srv().Store().Token().RemoveAllTokensByType(TokenTypeGuestInvitation); err != nil {
|
||||
return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
if err := a.InvalidateAllResendInviteEmailJobs(); err != nil {
|
||||
if err := a.InvalidateAllResendInviteEmailJobs(c); err != nil {
|
||||
return model.NewAppError("InvalidateAllEmailInvites", "api.team.invalidate_all_email_invites.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) InvalidateAllResendInviteEmailJobs() *model.AppError {
|
||||
jobs, appErr := a.Srv().Jobs.GetJobsByTypeAndStatus(model.JobTypeResendInvitationEmail, model.JobStatusPending)
|
||||
func (a *App) InvalidateAllResendInviteEmailJobs(c *request.Context) *model.AppError {
|
||||
jobs, appErr := a.Srv().Jobs.GetJobsByTypeAndStatus(c, model.JobTypeResendInvitationEmail, model.JobStatusPending)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/email"
|
||||
emailmocks "github.com/mattermost/mattermost/server/v8/channels/app/email/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/teams"
|
||||
@@ -1357,18 +1358,19 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
func TestInvalidateAllResendInviteEmailJobs(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
job, err := th.App.Srv().Jobs.CreateJob(model.JobTypeResendInvitationEmail, map[string]string{})
|
||||
job, err := th.App.Srv().Jobs.CreateJob(ctx, model.JobTypeResendInvitationEmail, map[string]string{})
|
||||
require.Nil(t, err)
|
||||
|
||||
sysVar := &model.System{Name: job.Id, Value: "0"}
|
||||
e := th.App.Srv().Store().System().SaveOrUpdate(sysVar)
|
||||
require.NoError(t, e)
|
||||
|
||||
appErr := th.App.InvalidateAllResendInviteEmailJobs()
|
||||
appErr := th.App.InvalidateAllResendInviteEmailJobs(ctx)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
j, e := th.App.Srv().Store().Job().Get(job.Id)
|
||||
j, e := th.App.Srv().Store().Job().Get(ctx, job.Id)
|
||||
require.NoError(t, e)
|
||||
require.Equal(t, j.Status, model.JobStatusCanceled)
|
||||
|
||||
@@ -1380,6 +1382,7 @@ func TestInvalidateAllResendInviteEmailJobs(t *testing.T) {
|
||||
func TestInvalidateAllEmailInvites(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
t1 := model.Token{
|
||||
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
@@ -1408,7 +1411,7 @@ func TestInvalidateAllEmailInvites(t *testing.T) {
|
||||
err = th.App.Srv().Store().Token().Save(&t3)
|
||||
require.NoError(t, err)
|
||||
|
||||
appErr := th.App.InvalidateAllEmailInvites()
|
||||
appErr := th.App.InvalidateAllEmailInvites(ctx)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(t1.Token)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
@@ -80,7 +81,7 @@ func setupTestHelper(s store.Store, includeCacheLayer bool, tb testing.TB) *Test
|
||||
},
|
||||
wh: &mockWebHub{},
|
||||
},
|
||||
Context: request.EmptyContext(nil),
|
||||
Context: request.EmptyContext(mlog.CreateConsoleTestLogger(tb)),
|
||||
configStore: configStore,
|
||||
dbStore: s,
|
||||
LogBuffer: buffer,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
@@ -78,7 +79,7 @@ func setupTestHelper(s store.Store, includeCacheLayer bool, tb testing.TB) *Test
|
||||
oAuthStore: s.OAuth(),
|
||||
config: configStore.Get,
|
||||
},
|
||||
Context: request.EmptyContext(nil),
|
||||
Context: request.EmptyContext(mlog.CreateConsoleTestLogger(tb)),
|
||||
configStore: configStore,
|
||||
dbStore: s,
|
||||
LogBuffer: buffer,
|
||||
|
||||
Ссылка в новой задаче
Block a user