[MM-58745] export/import: enable exporting and importing bots canonically (#28214)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3049191e2f
Коммит
f41d2d7774
@@ -83,6 +83,7 @@ const (
|
||||
LineTypeTeam = "team"
|
||||
LineTypeChannel = "channel"
|
||||
LineTypeUser = "user"
|
||||
LineTypeBot = "bot"
|
||||
LineTypePost = "post"
|
||||
LineTypeDirectChannel = "direct_channel"
|
||||
LineTypeDirectPost = "direct_post"
|
||||
@@ -410,6 +411,8 @@ func (v *Validator) validateLine(info ImportFileInfo, line imports.LineImportDat
|
||||
err = v.validateChannel(info, line)
|
||||
case LineTypeUser:
|
||||
err = v.validateUser(info, line)
|
||||
case LineTypeBot:
|
||||
err = v.validateBot(info, line)
|
||||
case LineTypePost:
|
||||
err = v.validatePost(info, line)
|
||||
case LineTypeDirectChannel:
|
||||
@@ -725,6 +728,36 @@ func (v *Validator) validateUser(info ImportFileInfo, line imports.LineImportDat
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Validator) validateBot(info ImportFileInfo, line imports.LineImportData) (err error) {
|
||||
ivErr := validateNotNil(info, "bot", line.Bot, func(data imports.BotImportData) *ImportValidationError {
|
||||
appErr := imports.ValidateBotImportData(&data)
|
||||
if appErr != nil {
|
||||
return &ImportValidationError{
|
||||
ImportFileInfo: info,
|
||||
FieldName: "bot",
|
||||
Err: appErr,
|
||||
}
|
||||
}
|
||||
|
||||
if data.Username != nil {
|
||||
// e-mails are for bots are converted to the the username@localhost format
|
||||
// see model.BotFromUser
|
||||
botMail := model.NormalizeEmail(fmt.Sprintf("%s@localhost", *data.Username))
|
||||
if ive := v.checkDuplicateUser(info, *data.Username, botMail); ive != nil {
|
||||
return ive
|
||||
}
|
||||
v.users[*data.Username] = info
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if ivErr != nil {
|
||||
return v.onError(ivErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Validator) validatePost(info ImportFileInfo, line imports.LineImportData) (err error) {
|
||||
ivErr := validateNotNil(info, "post", line.Post, func(data imports.PostImportData) *ImportValidationError {
|
||||
appErr := imports.ValidatePostImportData(&data, v.maxPostSize)
|
||||
|
||||
@@ -215,7 +215,9 @@ func createUser(idx int, teamMemberships int, channelMemberships int, teamsAndCh
|
||||
}
|
||||
|
||||
user := imports.UserImportData{
|
||||
ProfileImage: profileImage,
|
||||
Avatar: imports.Avatar{
|
||||
ProfileImage: profileImage,
|
||||
},
|
||||
Username: &username,
|
||||
Email: &email,
|
||||
Password: &password,
|
||||
|
||||
Ссылка в новой задаче
Block a user