[MM-38705] Move import validators into own package (#20914)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a5ea445bf9
Коммит
aef5165cdc
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/imports"
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
@@ -23,7 +24,7 @@ import (
|
||||
|
||||
// We use this map to identify the exportable preferences.
|
||||
// Here we link the preference category and name, to the name of the relevant field in the import struct.
|
||||
var exportablePreferences = map[ComparablePreference]string{{
|
||||
var exportablePreferences = map[imports.ComparablePreference]string{{
|
||||
Category: model.PreferenceCategoryTheme,
|
||||
Name: "",
|
||||
}: "Theme", {
|
||||
@@ -141,7 +142,7 @@ func (a *App) BulkExport(ctx request.CTX, writer io.Writer, outPath string, opts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) exportWriteLine(w io.Writer, line *LineImportData) *model.AppError {
|
||||
func (a *App) exportWriteLine(w io.Writer, line *imports.LineImportData) *model.AppError {
|
||||
b, err := json.Marshal(line)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkExport", "app.export.export_write_line.json_marshall.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
@@ -156,7 +157,7 @@ func (a *App) exportWriteLine(w io.Writer, line *LineImportData) *model.AppError
|
||||
|
||||
func (a *App) exportVersion(writer io.Writer) *model.AppError {
|
||||
version := 1
|
||||
versionLine := &LineImportData{
|
||||
versionLine := &imports.LineImportData{
|
||||
Type: "version",
|
||||
Version: &version,
|
||||
}
|
||||
@@ -271,7 +272,7 @@ func (a *App) exportAllUsers(writer io.Writer) *model.AppError {
|
||||
pref.Value = ""
|
||||
}
|
||||
}
|
||||
id, ok := exportablePreferences[ComparablePreference{
|
||||
id, ok := exportablePreferences[imports.ComparablePreference{
|
||||
Category: pref.Category,
|
||||
Name: pref.Name,
|
||||
}]
|
||||
@@ -306,8 +307,8 @@ func (a *App) exportAllUsers(writer io.Writer) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]UserTeamImportData, *model.AppError) {
|
||||
var memberships []UserTeamImportData
|
||||
func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]imports.UserTeamImportData, *model.AppError) {
|
||||
var memberships []imports.UserTeamImportData
|
||||
|
||||
members, err := a.Srv().Store.Team().GetTeamMembersForExport(userID)
|
||||
|
||||
@@ -343,8 +344,8 @@ func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]UserTeamImpo
|
||||
return &memberships, nil
|
||||
}
|
||||
|
||||
func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]UserChannelImportData, *model.AppError) {
|
||||
var memberships []UserChannelImportData
|
||||
func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]imports.UserChannelImportData, *model.AppError) {
|
||||
var memberships []imports.UserChannelImportData
|
||||
|
||||
members, nErr := a.Srv().Store.Channel().GetChannelMembersForExport(userID, teamID)
|
||||
if nErr != nil {
|
||||
@@ -363,7 +364,7 @@ func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]User
|
||||
return &memberships, nil
|
||||
}
|
||||
|
||||
func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *UserNotifyPropsImportData {
|
||||
func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *imports.UserNotifyPropsImportData {
|
||||
|
||||
getProp := func(key string) *string {
|
||||
if v, ok := notifyProps[key]; ok {
|
||||
@@ -372,7 +373,7 @@ func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *UserNotifyProps
|
||||
return nil
|
||||
}
|
||||
|
||||
return &UserNotifyPropsImportData{
|
||||
return &imports.UserNotifyPropsImportData{
|
||||
Desktop: getProp(model.DesktopNotifyProp),
|
||||
DesktopSound: getProp(model.DesktopSoundNotifyProp),
|
||||
Email: getProp(model.EmailNotifyProp),
|
||||
@@ -384,8 +385,8 @@ func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *UserNotifyProps
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]AttachmentImportData, *model.AppError) {
|
||||
var attachments []AttachmentImportData
|
||||
func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]imports.AttachmentImportData, *model.AppError) {
|
||||
var attachments []imports.AttachmentImportData
|
||||
afterId := strings.Repeat("0", 26)
|
||||
|
||||
for {
|
||||
@@ -418,7 +419,7 @@ func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments
|
||||
}
|
||||
|
||||
postLine.Post.Replies = &replies
|
||||
postLine.Post.Reactions = &[]ReactionImportData{}
|
||||
postLine.Post.Reactions = &[]imports.ReactionImportData{}
|
||||
if post.HasReactions {
|
||||
postLine.Post.Reactions, err = a.BuildPostReactions(ctx, post.Id)
|
||||
if err != nil {
|
||||
@@ -445,9 +446,9 @@ func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) buildPostReplies(ctx request.CTX, postID string, withAttachments bool) ([]ReplyImportData, []AttachmentImportData, *model.AppError) {
|
||||
var replies []ReplyImportData
|
||||
var attachments []AttachmentImportData
|
||||
func (a *App) buildPostReplies(ctx request.CTX, postID string, withAttachments bool) ([]imports.ReplyImportData, []imports.AttachmentImportData, *model.AppError) {
|
||||
var replies []imports.ReplyImportData
|
||||
var attachments []imports.AttachmentImportData
|
||||
|
||||
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postID)
|
||||
if nErr != nil {
|
||||
@@ -481,7 +482,7 @@ func (a *App) buildPostReplies(ctx request.CTX, postID string, withAttachments b
|
||||
}
|
||||
|
||||
func (a *App) BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImportData, *model.AppError) {
|
||||
var reactionsOfPost []ReactionImportData
|
||||
var reactionsOfPost []imports.ReactionImportData
|
||||
|
||||
reactions, nErr := a.Srv().Store.Reaction().GetForPost(postID, true)
|
||||
if nErr != nil {
|
||||
@@ -505,15 +506,15 @@ func (a *App) BuildPostReactions(ctx request.CTX, postID string) (*[]ReactionImp
|
||||
|
||||
}
|
||||
|
||||
func (a *App) buildPostAttachments(postID string) ([]AttachmentImportData, *model.AppError) {
|
||||
func (a *App) buildPostAttachments(postID string) ([]imports.AttachmentImportData, *model.AppError) {
|
||||
infos, nErr := a.Srv().Store.FileInfo().GetForPost(postID, false, false, false)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
attachments := make([]AttachmentImportData, 0, len(infos))
|
||||
attachments := make([]imports.AttachmentImportData, 0, len(infos))
|
||||
for _, info := range infos {
|
||||
attachments = append(attachments, AttachmentImportData{Path: &info.Path})
|
||||
attachments = append(attachments, imports.AttachmentImportData{Path: &info.Path})
|
||||
}
|
||||
|
||||
return attachments, nil
|
||||
@@ -635,8 +636,8 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]AttachmentImportData, *model.AppError) {
|
||||
var attachments []AttachmentImportData
|
||||
func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]imports.AttachmentImportData, *model.AppError) {
|
||||
var attachments []imports.AttachmentImportData
|
||||
afterId := strings.Repeat("0", 26)
|
||||
for {
|
||||
posts, err := a.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, afterId)
|
||||
@@ -657,7 +658,7 @@ func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttach
|
||||
}
|
||||
|
||||
// Handle attachments.
|
||||
var postAttachments []AttachmentImportData
|
||||
var postAttachments []imports.AttachmentImportData
|
||||
var err *model.AppError
|
||||
if len(post.FileIds) > 0 {
|
||||
postAttachments, err = a.buildPostAttachments(post.Id)
|
||||
|
||||
Ссылка в новой задаче
Block a user