[MM-58745] export/import: enable exporting and importing bots canonically (#28214)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3049191e2f
Коммит
f41d2d7774
@@ -153,6 +153,13 @@ func (a *App) BulkExport(ctx request.CTX, writer io.Writer, outPath string, job
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.Logger().Info("Bulk export: exporting bots")
|
||||
botPPs, err := a.exportAllBots(ctx, job, writer, opts.IncludeProfilePictures)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
profilePictures = append(profilePictures, botPPs...)
|
||||
|
||||
ctx.Logger().Info("Bulk export: exporting posts")
|
||||
attachments, err := a.exportAllPosts(ctx, job, writer, opts.IncludeAttachments, opts.IncludeArchivedChannels)
|
||||
if err != nil {
|
||||
@@ -455,6 +462,11 @@ func (a *App) exportAllUsers(ctx request.CTX, job *model.Job, writer io.Writer,
|
||||
for _, user := range users {
|
||||
afterId = user.Id
|
||||
|
||||
// Skip bots as they are exported separately.
|
||||
if user.IsBot {
|
||||
continue
|
||||
}
|
||||
|
||||
// Gathering here the exportable preferences to pass them on to ImportLineFromUser
|
||||
exportedPrefs := make(map[string]*string)
|
||||
allPrefs, err := a.GetPreferencesForUser(ctx, user.Id)
|
||||
@@ -531,6 +543,64 @@ func (a *App) exportAllUsers(ctx request.CTX, job *model.Job, writer io.Writer,
|
||||
return profilePictures, nil
|
||||
}
|
||||
|
||||
func (a *App) exportAllBots(ctx request.CTX, job *model.Job, writer io.Writer, includeProfilePictures bool) ([]string, *model.AppError) {
|
||||
afterId := ""
|
||||
cnt := 0
|
||||
profilePictures := []string{}
|
||||
|
||||
const pageSize = 1000
|
||||
|
||||
for {
|
||||
bots, err := a.Srv().Store().Bot().GetAllAfter(pageSize, afterId)
|
||||
if err != nil {
|
||||
return profilePictures, model.NewAppError("exportAllBots", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
cnt += len(bots)
|
||||
updateJobProgress(ctx.Logger(), a.Srv().Store(), job, "bots_exported", cnt)
|
||||
|
||||
for _, bot := range bots {
|
||||
afterId = bot.UserId
|
||||
|
||||
var ownerUsername string
|
||||
owner, err := a.Srv().Store().User().Get(ctx.Context(), bot.OwnerId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if errors.As(err, &nfErr) {
|
||||
ownerUsername = bot.OwnerId
|
||||
} else {
|
||||
return profilePictures, model.NewAppError("exportAllBots", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
} else {
|
||||
ownerUsername = owner.Username
|
||||
}
|
||||
|
||||
botLine := ImportLineFromBot(bot, ownerUsername)
|
||||
|
||||
if includeProfilePictures {
|
||||
pp, err := a.GetProfileImagePath(model.UserFromBot(bot))
|
||||
if err != nil {
|
||||
return profilePictures, err
|
||||
}
|
||||
if pp != "" {
|
||||
botLine.Bot.ProfileImage = &pp
|
||||
profilePictures = append(profilePictures, pp)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.exportWriteLine(writer, botLine); err != nil {
|
||||
return profilePictures, err
|
||||
}
|
||||
}
|
||||
|
||||
if len(bots) < pageSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return profilePictures, nil
|
||||
}
|
||||
|
||||
func (a *App) buildUserTeamAndChannelMemberships(c request.CTX, userID string, includeArchivedChannels bool) (*[]imports.UserTeamImportData, *model.AppError) {
|
||||
var memberships []imports.UserTeamImportData
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user