[MM-38375] Fix processing bulk import with attachments (#18352)

* Fix improper attachments in replies

* Fix import data path

* Improve errors

* Fix importing attachments directly from zip file

* Add some test cases to cover error paths
Этот коммит содержится в:
Claudio Costa
2021-09-21 17:39:52 +02:00
коммит произвёл GitHub
родитель c4a25ff339
Коммит 0c84885132
10 изменённых файлов: 264 добавлений и 58 удалений

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

@@ -565,13 +565,22 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
}
if data.ProfileImage != nil {
file, err := os.Open(*data.ProfileImage)
var file io.ReadCloser
var err error
if data.ProfileImageData != nil {
file, err = data.ProfileImageData.Open()
} else {
file, err = os.Open(*data.ProfileImage)
}
if err != nil {
mlog.Warn("Unable to open the profile image.", mlog.Err(err))
}
defer file.Close()
if err == nil {
if err := a.SetProfileImageFromMultiPartFile(savedUser.Id, file); err != nil {
} else {
defer file.Close()
if limitErr := checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); limitErr != nil {
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.check_image_limits.app_error", nil, "", http.StatusBadRequest)
}
if err := a.SetProfileImageFromFile(savedUser.Id, file); err != nil {
mlog.Warn("Unable to set the profile image from a file.", mlog.Err(err))
}
}
@@ -1804,7 +1813,12 @@ func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
emoji.PreSave()
}
file, err := os.Open(*data.Image)
var file io.ReadCloser
if data.Data != nil {
file, err = data.Data.Open()
} else {
file, err = os.Open(*data.Image)
}
if err != nil {
return model.NewAppError("BulkImport", "app.import.emoji.bad_file.error", map[string]interface{}{"EmojiName": *data.Name}, "", http.StatusBadRequest)
}