* add request context

* move initialialization to server

* use app interface instead of global app functions

* remove app context from webconn

* cleanup

* remove duplicated services

* move context to separate package

* remove finalize init method and move content to NewServer function

* restart workers and schedulers after adding license for tests

* reflect review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-05-11 13:00:44 +03:00
коммит произвёл GitHub
родитель c09369f14a
Коммит 5ea06e51d0
235 изменённых файлов: 4048 добавлений и 3819 удалений

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

@@ -15,6 +15,7 @@ import (
"path"
"strings"
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/shared/mlog"
"github.com/mattermost/mattermost-server/v5/store"
@@ -155,7 +156,7 @@ func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *
return err
}
func (a *App) importTeam(data *TeamImportData, dryRun bool) *model.AppError {
func (a *App) importTeam(c *request.Context, data *TeamImportData, dryRun bool) *model.AppError {
if err := validateTeamImportData(data); err != nil {
return err
}
@@ -202,7 +203,7 @@ func (a *App) importTeam(data *TeamImportData, dryRun bool) *model.AppError {
}
if team.Id == "" {
if _, err := a.CreateTeam(team); err != nil {
if _, err := a.CreateTeam(c, team); err != nil {
return err
}
} else {
@@ -214,7 +215,7 @@ func (a *App) importTeam(data *TeamImportData, dryRun bool) *model.AppError {
return nil
}
func (a *App) importChannel(data *ChannelImportData, dryRun bool) *model.AppError {
func (a *App) importChannel(c *request.Context, data *ChannelImportData, dryRun bool) *model.AppError {
if err := validateChannelImportData(data); err != nil {
return err
}
@@ -267,7 +268,7 @@ func (a *App) importChannel(data *ChannelImportData, dryRun bool) *model.AppErro
}
if channel.Id == "" {
if _, err := a.CreateChannel(channel, false); err != nil {
if _, err := a.CreateChannel(c, channel, false); err != nil {
return err
}
} else {
@@ -1020,7 +1021,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.
return nil
}
func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamID string) *model.AppError {
func (a *App) importReplies(c *request.Context, data []ReplyImportData, post *model.Post, teamID string) *model.AppError {
var err *model.AppError
usernames := []string{}
for _, replyData := range data {
@@ -1068,7 +1069,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamID str
reply.Message = *replyData.Message
reply.CreateAt = *replyData.CreateAt
fileIDs, err := a.uploadAttachments(replyData.Attachments, reply, teamID)
fileIDs, err := a.uploadAttachments(c, replyData.Attachments, reply, teamID)
if err != nil {
return err
}
@@ -1116,7 +1117,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamID str
return nil
}
func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
func (a *App) importAttachment(c *request.Context, data *AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
file, err := os.Open(*data.Path)
if file == nil || err != nil {
return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]interface{}{"FilePath": *data.Path}, "", http.StatusBadRequest)
@@ -1157,7 +1158,7 @@ func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, tea
mlog.Info("Uploading file with name", mlog.String("file_name", file.Name()))
fileInfo, appErr := a.DoUploadFile(timestamp, teamID, post.ChannelId, post.UserId, file.Name(), fileData)
fileInfo, appErr := a.DoUploadFile(c, timestamp, teamID, post.ChannelId, post.UserId, file.Name(), fileData)
if appErr != nil {
mlog.Error("Failed to upload file:", mlog.Err(appErr))
return nil, appErr
@@ -1251,7 +1252,7 @@ func getPostStrID(post *model.Post) string {
// importMultiplePostLines will return an error and the line that
// caused it whenever possible
func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
func (a *App) importMultiplePostLines(c *request.Context, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
if len(lines) == 0 {
return 0, nil
}
@@ -1332,7 +1333,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
post.Props = *line.Post.Props
}
fileIDs, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id)
fileIDs, appErr := a.uploadAttachments(c, line.Post.Attachments, post, team.Id)
if appErr != nil {
return line.LineNumber, appErr
}
@@ -1423,7 +1424,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
}
if postWithData.postData.Replies != nil && len(*postWithData.postData.Replies) > 0 {
err := a.importReplies(*postWithData.postData.Replies, postWithData.post, postWithData.team.Id)
err := a.importReplies(c, *postWithData.postData.Replies, postWithData.post, postWithData.team.Id)
if err != nil {
return postWithData.lineNumber, err
}
@@ -1434,14 +1435,14 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
}
// uploadAttachments imports new attachments and returns current attachments of the post as a map
func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model.Post, teamID string) (map[string]bool, *model.AppError) {
func (a *App) uploadAttachments(c *request.Context, attachments *[]AttachmentImportData, post *model.Post, teamID string) (map[string]bool, *model.AppError) {
if attachments == nil {
return nil, nil
}
fileIDs := make(map[string]bool)
for _, attachment := range *attachments {
attachment := attachment
fileInfo, err := a.importAttachment(&attachment, post, teamID)
fileInfo, err := a.importAttachment(c, &attachment, post, teamID)
if err != nil {
return nil, err
}
@@ -1538,7 +1539,7 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
// importMultipleDirectPostLines will return an error and the line
// that caused it whenever possible
func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
func (a *App) importMultipleDirectPostLines(c *request.Context, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
if len(lines) == 0 {
return 0, nil
}
@@ -1585,7 +1586,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
var channel *model.Channel
var ch *model.Channel
if len(userIDs) == 2 {
ch, err = a.GetOrCreateDirectChannel(userIDs[0], userIDs[1])
ch, err = a.GetOrCreateDirectChannel(c, userIDs[0], userIDs[1])
if err != nil && err.Id != store.ChannelExistsError {
return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_direct_channel.error", nil, err.Error(), http.StatusBadRequest)
}
@@ -1628,7 +1629,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
post.Props = *line.DirectPost.Props
}
fileIDs, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam")
fileIDs, err := a.uploadAttachments(c, line.DirectPost.Attachments, post, "noteam")
if err != nil {
return line.LineNumber, err
}
@@ -1717,7 +1718,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
}
if postWithData.directPostData.Replies != nil {
if err := a.importReplies(*postWithData.directPostData.Replies, postWithData.post, "noteam"); err != nil {
if err := a.importReplies(c, *postWithData.directPostData.Replies, postWithData.post, "noteam"); err != nil {
return postWithData.lineNumber, err
}
}