[MM-38705] Move import validators into own package (#20914)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a5ea445bf9
Коммит
aef5165cdc
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"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/app/request"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
@@ -23,7 +24,7 @@ import (
|
|||||||
|
|
||||||
// We use this map to identify the exportable preferences.
|
// 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.
|
// 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,
|
Category: model.PreferenceCategoryTheme,
|
||||||
Name: "",
|
Name: "",
|
||||||
}: "Theme", {
|
}: "Theme", {
|
||||||
@@ -141,7 +142,7 @@ func (a *App) BulkExport(ctx request.CTX, writer io.Writer, outPath string, opts
|
|||||||
return nil
|
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)
|
b, err := json.Marshal(line)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("BulkExport", "app.export.export_write_line.json_marshall.error", nil, "", http.StatusBadRequest).Wrap(err)
|
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 {
|
func (a *App) exportVersion(writer io.Writer) *model.AppError {
|
||||||
version := 1
|
version := 1
|
||||||
versionLine := &LineImportData{
|
versionLine := &imports.LineImportData{
|
||||||
Type: "version",
|
Type: "version",
|
||||||
Version: &version,
|
Version: &version,
|
||||||
}
|
}
|
||||||
@@ -271,7 +272,7 @@ func (a *App) exportAllUsers(writer io.Writer) *model.AppError {
|
|||||||
pref.Value = ""
|
pref.Value = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id, ok := exportablePreferences[ComparablePreference{
|
id, ok := exportablePreferences[imports.ComparablePreference{
|
||||||
Category: pref.Category,
|
Category: pref.Category,
|
||||||
Name: pref.Name,
|
Name: pref.Name,
|
||||||
}]
|
}]
|
||||||
@@ -306,8 +307,8 @@ func (a *App) exportAllUsers(writer io.Writer) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]UserTeamImportData, *model.AppError) {
|
func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]imports.UserTeamImportData, *model.AppError) {
|
||||||
var memberships []UserTeamImportData
|
var memberships []imports.UserTeamImportData
|
||||||
|
|
||||||
members, err := a.Srv().Store.Team().GetTeamMembersForExport(userID)
|
members, err := a.Srv().Store.Team().GetTeamMembersForExport(userID)
|
||||||
|
|
||||||
@@ -343,8 +344,8 @@ func (a *App) buildUserTeamAndChannelMemberships(userID string) (*[]UserTeamImpo
|
|||||||
return &memberships, nil
|
return &memberships, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]UserChannelImportData, *model.AppError) {
|
func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]imports.UserChannelImportData, *model.AppError) {
|
||||||
var memberships []UserChannelImportData
|
var memberships []imports.UserChannelImportData
|
||||||
|
|
||||||
members, nErr := a.Srv().Store.Channel().GetChannelMembersForExport(userID, teamID)
|
members, nErr := a.Srv().Store.Channel().GetChannelMembersForExport(userID, teamID)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
@@ -363,7 +364,7 @@ func (a *App) buildUserChannelMemberships(userID string, teamID string) (*[]User
|
|||||||
return &memberships, nil
|
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 {
|
getProp := func(key string) *string {
|
||||||
if v, ok := notifyProps[key]; ok {
|
if v, ok := notifyProps[key]; ok {
|
||||||
@@ -372,7 +373,7 @@ func (a *App) buildUserNotifyProps(notifyProps model.StringMap) *UserNotifyProps
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &UserNotifyPropsImportData{
|
return &imports.UserNotifyPropsImportData{
|
||||||
Desktop: getProp(model.DesktopNotifyProp),
|
Desktop: getProp(model.DesktopNotifyProp),
|
||||||
DesktopSound: getProp(model.DesktopSoundNotifyProp),
|
DesktopSound: getProp(model.DesktopSoundNotifyProp),
|
||||||
Email: getProp(model.EmailNotifyProp),
|
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) {
|
func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]imports.AttachmentImportData, *model.AppError) {
|
||||||
var attachments []AttachmentImportData
|
var attachments []imports.AttachmentImportData
|
||||||
afterId := strings.Repeat("0", 26)
|
afterId := strings.Repeat("0", 26)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -418,7 +419,7 @@ func (a *App) exportAllPosts(ctx request.CTX, writer io.Writer, withAttachments
|
|||||||
}
|
}
|
||||||
|
|
||||||
postLine.Post.Replies = &replies
|
postLine.Post.Replies = &replies
|
||||||
postLine.Post.Reactions = &[]ReactionImportData{}
|
postLine.Post.Reactions = &[]imports.ReactionImportData{}
|
||||||
if post.HasReactions {
|
if post.HasReactions {
|
||||||
postLine.Post.Reactions, err = a.BuildPostReactions(ctx, post.Id)
|
postLine.Post.Reactions, err = a.BuildPostReactions(ctx, post.Id)
|
||||||
if err != nil {
|
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) {
|
func (a *App) buildPostReplies(ctx request.CTX, postID string, withAttachments bool) ([]imports.ReplyImportData, []imports.AttachmentImportData, *model.AppError) {
|
||||||
var replies []ReplyImportData
|
var replies []imports.ReplyImportData
|
||||||
var attachments []AttachmentImportData
|
var attachments []imports.AttachmentImportData
|
||||||
|
|
||||||
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postID)
|
replyPosts, nErr := a.Srv().Store.Post().GetRepliesForExport(postID)
|
||||||
if nErr != nil {
|
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) {
|
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)
|
reactions, nErr := a.Srv().Store.Reaction().GetForPost(postID, true)
|
||||||
if nErr != nil {
|
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)
|
infos, nErr := a.Srv().Store.FileInfo().GetForPost(postID, false, false, false)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
return nil, model.NewAppError("buildPostAttachments", "app.file_info.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
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 {
|
for _, info := range infos {
|
||||||
attachments = append(attachments, AttachmentImportData{Path: &info.Path})
|
attachments = append(attachments, imports.AttachmentImportData{Path: &info.Path})
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachments, nil
|
return attachments, nil
|
||||||
@@ -635,8 +636,8 @@ func (a *App) exportAllDirectChannels(writer io.Writer) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]AttachmentImportData, *model.AppError) {
|
func (a *App) exportAllDirectPosts(ctx request.CTX, writer io.Writer, withAttachments bool) ([]imports.AttachmentImportData, *model.AppError) {
|
||||||
var attachments []AttachmentImportData
|
var attachments []imports.AttachmentImportData
|
||||||
afterId := strings.Repeat("0", 26)
|
afterId := strings.Repeat("0", 26)
|
||||||
for {
|
for {
|
||||||
posts, err := a.Srv().Store.Post().GetDirectPostParentsForExportAfter(1000, afterId)
|
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.
|
// Handle attachments.
|
||||||
var postAttachments []AttachmentImportData
|
var postAttachments []imports.AttachmentImportData
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if len(post.FileIds) > 0 {
|
if len(post.FileIds) > 0 {
|
||||||
postAttachments, err = a.buildPostAttachments(post.Id)
|
postAttachments, err = a.buildPostAttachments(post.Id)
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ package app
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app/imports"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ImportLineFromTeam(team *model.TeamForExport) *LineImportData {
|
func ImportLineFromTeam(team *model.TeamForExport) *imports.LineImportData {
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "team",
|
Type: "team",
|
||||||
Team: &TeamImportData{
|
Team: &imports.TeamImportData{
|
||||||
Name: &team.Name,
|
Name: &team.Name,
|
||||||
DisplayName: &team.DisplayName,
|
DisplayName: &team.DisplayName,
|
||||||
Type: &team.Type,
|
Type: &team.Type,
|
||||||
@@ -23,10 +24,10 @@ func ImportLineFromTeam(team *model.TeamForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineFromChannel(channel *model.ChannelForExport) *LineImportData {
|
func ImportLineFromChannel(channel *model.ChannelForExport) *imports.LineImportData {
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "channel",
|
Type: "channel",
|
||||||
Channel: &ChannelImportData{
|
Channel: &imports.ChannelImportData{
|
||||||
Team: &channel.TeamName,
|
Team: &channel.TeamName,
|
||||||
Name: &channel.Name,
|
Name: &channel.Name,
|
||||||
DisplayName: &channel.DisplayName,
|
DisplayName: &channel.DisplayName,
|
||||||
@@ -38,30 +39,30 @@ func ImportLineFromChannel(channel *model.ChannelForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineFromDirectChannel(channel *model.DirectChannelForExport) *LineImportData {
|
func ImportLineFromDirectChannel(channel *model.DirectChannelForExport) *imports.LineImportData {
|
||||||
channelMembers := *channel.Members
|
channelMembers := *channel.Members
|
||||||
if len(channelMembers) == 1 {
|
if len(channelMembers) == 1 {
|
||||||
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
||||||
}
|
}
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "direct_channel",
|
Type: "direct_channel",
|
||||||
DirectChannel: &DirectChannelImportData{
|
DirectChannel: &imports.DirectChannelImportData{
|
||||||
Header: &channel.Header,
|
Header: &channel.Header,
|
||||||
Members: &channelMembers,
|
Members: &channelMembers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineFromUser(user *model.User, exportedPrefs map[string]*string) *LineImportData {
|
func ImportLineFromUser(user *model.User, exportedPrefs map[string]*string) *imports.LineImportData {
|
||||||
// Bulk Importer doesn't accept "empty string" for AuthService.
|
// Bulk Importer doesn't accept "empty string" for AuthService.
|
||||||
var authService *string
|
var authService *string
|
||||||
if user.AuthService != "" {
|
if user.AuthService != "" {
|
||||||
authService = &user.AuthService
|
authService = &user.AuthService
|
||||||
}
|
}
|
||||||
|
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "user",
|
Type: "user",
|
||||||
User: &UserImportData{
|
User: &imports.UserImportData{
|
||||||
Username: &user.Username,
|
Username: &user.Username,
|
||||||
Email: &user.Email,
|
Email: &user.Email,
|
||||||
AuthService: authService,
|
AuthService: authService,
|
||||||
@@ -88,7 +89,7 @@ func ImportLineFromUser(user *model.User, exportedPrefs map[string]*string) *Lin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportUserTeamDataFromTeamMember(member *model.TeamMemberForExport) *UserTeamImportData {
|
func ImportUserTeamDataFromTeamMember(member *model.TeamMemberForExport) *imports.UserTeamImportData {
|
||||||
rolesList := strings.Fields(member.Roles)
|
rolesList := strings.Fields(member.Roles)
|
||||||
if member.SchemeAdmin {
|
if member.SchemeAdmin {
|
||||||
rolesList = append(rolesList, model.TeamAdminRoleId)
|
rolesList = append(rolesList, model.TeamAdminRoleId)
|
||||||
@@ -100,13 +101,13 @@ func ImportUserTeamDataFromTeamMember(member *model.TeamMemberForExport) *UserTe
|
|||||||
rolesList = append(rolesList, model.TeamGuestRoleId)
|
rolesList = append(rolesList, model.TeamGuestRoleId)
|
||||||
}
|
}
|
||||||
roles := strings.Join(rolesList, " ")
|
roles := strings.Join(rolesList, " ")
|
||||||
return &UserTeamImportData{
|
return &imports.UserTeamImportData{
|
||||||
Name: &member.TeamName,
|
Name: &member.TeamName,
|
||||||
Roles: &roles,
|
Roles: &roles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelMemberForExport, preferences *model.Preferences) *UserChannelImportData {
|
func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelMemberForExport, preferences *model.Preferences) *imports.UserChannelImportData {
|
||||||
rolesList := strings.Fields(member.Roles)
|
rolesList := strings.Fields(member.Roles)
|
||||||
if member.SchemeAdmin {
|
if member.SchemeAdmin {
|
||||||
rolesList = append(rolesList, model.ChannelAdminRoleId)
|
rolesList = append(rolesList, model.ChannelAdminRoleId)
|
||||||
@@ -118,7 +119,7 @@ func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelM
|
|||||||
rolesList = append(rolesList, model.ChannelGuestRoleId)
|
rolesList = append(rolesList, model.ChannelGuestRoleId)
|
||||||
}
|
}
|
||||||
props := member.NotifyProps
|
props := member.NotifyProps
|
||||||
notifyProps := UserChannelNotifyPropsImportData{}
|
notifyProps := imports.UserChannelNotifyPropsImportData{}
|
||||||
|
|
||||||
desktop, exist := props[model.DesktopNotifyProp]
|
desktop, exist := props[model.DesktopNotifyProp]
|
||||||
if exist {
|
if exist {
|
||||||
@@ -141,7 +142,7 @@ func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelM
|
|||||||
}
|
}
|
||||||
|
|
||||||
roles := strings.Join(rolesList, " ")
|
roles := strings.Join(rolesList, " ")
|
||||||
return &UserChannelImportData{
|
return &imports.UserChannelImportData{
|
||||||
Name: &member.ChannelName,
|
Name: &member.ChannelName,
|
||||||
Roles: &roles,
|
Roles: &roles,
|
||||||
NotifyProps: ¬ifyProps,
|
NotifyProps: ¬ifyProps,
|
||||||
@@ -149,10 +150,10 @@ func ImportUserChannelDataFromChannelMemberAndPreferences(member *model.ChannelM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineForPost(post *model.PostForExport) *LineImportData {
|
func ImportLineForPost(post *model.PostForExport) *imports.LineImportData {
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "post",
|
Type: "post",
|
||||||
Post: &PostImportData{
|
Post: &imports.PostImportData{
|
||||||
Team: &post.TeamName,
|
Team: &post.TeamName,
|
||||||
Channel: &post.ChannelName,
|
Channel: &post.ChannelName,
|
||||||
User: &post.Username,
|
User: &post.Username,
|
||||||
@@ -165,14 +166,14 @@ func ImportLineForPost(post *model.PostForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineForDirectPost(post *model.DirectPostForExport) *LineImportData {
|
func ImportLineForDirectPost(post *model.DirectPostForExport) *imports.LineImportData {
|
||||||
channelMembers := *post.ChannelMembers
|
channelMembers := *post.ChannelMembers
|
||||||
if len(channelMembers) == 1 {
|
if len(channelMembers) == 1 {
|
||||||
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
channelMembers = []string{channelMembers[0], channelMembers[0]}
|
||||||
}
|
}
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "direct_post",
|
Type: "direct_post",
|
||||||
DirectPost: &DirectPostImportData{
|
DirectPost: &imports.DirectPostImportData{
|
||||||
ChannelMembers: &channelMembers,
|
ChannelMembers: &channelMembers,
|
||||||
User: &post.User,
|
User: &post.User,
|
||||||
Type: &post.Type,
|
Type: &post.Type,
|
||||||
@@ -184,8 +185,8 @@ func ImportLineForDirectPost(post *model.DirectPostForExport) *LineImportData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportReplyFromPost(post *model.ReplyForExport) *ReplyImportData {
|
func ImportReplyFromPost(post *model.ReplyForExport) *imports.ReplyImportData {
|
||||||
return &ReplyImportData{
|
return &imports.ReplyImportData{
|
||||||
User: &post.Username,
|
User: &post.Username,
|
||||||
Type: &post.Type,
|
Type: &post.Type,
|
||||||
Message: &post.Message,
|
Message: &post.Message,
|
||||||
@@ -194,18 +195,18 @@ func ImportReplyFromPost(post *model.ReplyForExport) *ReplyImportData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportReactionFromPost(user *model.User, reaction *model.Reaction) *ReactionImportData {
|
func ImportReactionFromPost(user *model.User, reaction *model.Reaction) *imports.ReactionImportData {
|
||||||
return &ReactionImportData{
|
return &imports.ReactionImportData{
|
||||||
User: &user.Username,
|
User: &user.Username,
|
||||||
EmojiName: &reaction.EmojiName,
|
EmojiName: &reaction.EmojiName,
|
||||||
CreateAt: &reaction.CreateAt,
|
CreateAt: &reaction.CreateAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ImportLineFromEmoji(emoji *model.Emoji, filePath string) *LineImportData {
|
func ImportLineFromEmoji(emoji *model.Emoji, filePath string) *imports.LineImportData {
|
||||||
return &LineImportData{
|
return &imports.LineImportData{
|
||||||
Type: "emoji",
|
Type: "emoji",
|
||||||
Emoji: &EmojiImportData{
|
Emoji: &imports.EmojiImportData{
|
||||||
Name: &emoji.Name,
|
Name: &emoji.Name,
|
||||||
Image: &filePath,
|
Image: &filePath,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,17 +15,20 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app/imports"
|
||||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ReactionImportData = imports.ReactionImportData // part of the app interface
|
||||||
|
|
||||||
const (
|
const (
|
||||||
importMultiplePostsThreshold = 1000
|
importMultiplePostsThreshold = 1000
|
||||||
maxScanTokenSize = 16 * 1024 * 1024 // Need to set a higher limit than default because some customers cross the limit. See MM-22314
|
maxScanTokenSize = 16 * 1024 * 1024 // Need to set a higher limit than default because some customers cross the limit. See MM-22314
|
||||||
)
|
)
|
||||||
|
|
||||||
func stopOnError(c request.CTX, err LineImportWorkerError) bool {
|
func stopOnError(c request.CTX, err imports.LineImportWorkerError) bool {
|
||||||
switch err.Error.Id {
|
switch err.Error.Id {
|
||||||
case "api.file.upload_file.large_image.app_error":
|
case "api.file.upload_file.large_image.app_error":
|
||||||
c.Logger().Warn("Large image import error", mlog.Err(err.Error))
|
c.Logger().Warn("Large image import error", mlog.Err(err.Error))
|
||||||
@@ -38,7 +41,7 @@ func stopOnError(c request.CTX, err LineImportWorkerError) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processAttachmentPaths(files *[]AttachmentImportData, basePath string, filesMap map[string]*zip.File) error {
|
func processAttachmentPaths(files *[]imports.AttachmentImportData, basePath string, filesMap map[string]*zip.File) error {
|
||||||
if files == nil {
|
if files == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -58,11 +61,11 @@ func processAttachmentPaths(files *[]AttachmentImportData, basePath string, file
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processAttachments(line *LineImportData, basePath string, filesMap map[string]*zip.File) error {
|
func processAttachments(line *imports.LineImportData, basePath string, filesMap map[string]*zip.File) error {
|
||||||
var ok bool
|
var ok bool
|
||||||
switch line.Type {
|
switch line.Type {
|
||||||
case "post", "direct_post":
|
case "post", "direct_post":
|
||||||
var replies []ReplyImportData
|
var replies []imports.ReplyImportData
|
||||||
if line.Type == "direct_post" {
|
if line.Type == "direct_post" {
|
||||||
if err := processAttachmentPaths(line.DirectPost.Attachments, basePath, filesMap); err != nil {
|
if err := processAttachmentPaths(line.DirectPost.Attachments, basePath, filesMap); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -108,48 +111,48 @@ func processAttachments(line *LineImportData, basePath string, filesMap map[stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) bulkImportWorker(c request.CTX, dryRun bool, wg *sync.WaitGroup, lines <-chan LineImportWorkerData, errors chan<- LineImportWorkerError) {
|
func (a *App) bulkImportWorker(c request.CTX, dryRun bool, wg *sync.WaitGroup, lines <-chan imports.LineImportWorkerData, errors chan<- imports.LineImportWorkerError) {
|
||||||
postLines := []LineImportWorkerData{}
|
postLines := []imports.LineImportWorkerData{}
|
||||||
directPostLines := []LineImportWorkerData{}
|
directPostLines := []imports.LineImportWorkerData{}
|
||||||
for line := range lines {
|
for line := range lines {
|
||||||
switch {
|
switch {
|
||||||
case line.LineImportData.Type == "post":
|
case line.LineImportData.Type == "post":
|
||||||
postLines = append(postLines, line)
|
postLines = append(postLines, line)
|
||||||
if line.Post == nil {
|
if line.Post == nil {
|
||||||
errors <- LineImportWorkerError{model.NewAppError("BulkImport", "app.import.import_line.null_post.error", nil, "", http.StatusBadRequest), line.LineNumber}
|
errors <- imports.LineImportWorkerError{Error: model.NewAppError("BulkImport", "app.import.import_line.null_post.error", nil, "", http.StatusBadRequest), LineNumber: line.LineNumber}
|
||||||
}
|
}
|
||||||
if len(postLines) >= importMultiplePostsThreshold {
|
if len(postLines) >= importMultiplePostsThreshold {
|
||||||
if errLine, err := a.importMultiplePostLines(c, postLines, dryRun); err != nil {
|
if errLine, err := a.importMultiplePostLines(c, postLines, dryRun); err != nil {
|
||||||
errors <- LineImportWorkerError{err, errLine}
|
errors <- imports.LineImportWorkerError{Error: err, LineNumber: errLine}
|
||||||
}
|
}
|
||||||
postLines = []LineImportWorkerData{}
|
postLines = []imports.LineImportWorkerData{}
|
||||||
}
|
}
|
||||||
case line.LineImportData.Type == "direct_post":
|
case line.LineImportData.Type == "direct_post":
|
||||||
directPostLines = append(directPostLines, line)
|
directPostLines = append(directPostLines, line)
|
||||||
if line.DirectPost == nil {
|
if line.DirectPost == nil {
|
||||||
errors <- LineImportWorkerError{model.NewAppError("BulkImport", "app.import.import_line.null_direct_post.error", nil, "", http.StatusBadRequest), line.LineNumber}
|
errors <- imports.LineImportWorkerError{Error: model.NewAppError("BulkImport", "app.import.import_line.null_direct_post.error", nil, "", http.StatusBadRequest), LineNumber: line.LineNumber}
|
||||||
}
|
}
|
||||||
if len(directPostLines) >= importMultiplePostsThreshold {
|
if len(directPostLines) >= importMultiplePostsThreshold {
|
||||||
if errLine, err := a.importMultipleDirectPostLines(c, directPostLines, dryRun); err != nil {
|
if errLine, err := a.importMultipleDirectPostLines(c, directPostLines, dryRun); err != nil {
|
||||||
errors <- LineImportWorkerError{err, errLine}
|
errors <- imports.LineImportWorkerError{Error: err, LineNumber: errLine}
|
||||||
}
|
}
|
||||||
directPostLines = []LineImportWorkerData{}
|
directPostLines = []imports.LineImportWorkerData{}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if err := a.importLine(c, line.LineImportData, dryRun); err != nil {
|
if err := a.importLine(c, line.LineImportData, dryRun); err != nil {
|
||||||
errors <- LineImportWorkerError{err, line.LineNumber}
|
errors <- imports.LineImportWorkerError{Error: err, LineNumber: line.LineNumber}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(postLines) > 0 {
|
if len(postLines) > 0 {
|
||||||
if errLine, err := a.importMultiplePostLines(c, postLines, dryRun); err != nil {
|
if errLine, err := a.importMultiplePostLines(c, postLines, dryRun); err != nil {
|
||||||
errors <- LineImportWorkerError{err, errLine}
|
errors <- imports.LineImportWorkerError{Error: err, LineNumber: errLine}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(directPostLines) > 0 {
|
if len(directPostLines) > 0 {
|
||||||
if errLine, err := a.importMultipleDirectPostLines(c, directPostLines, dryRun); err != nil {
|
if errLine, err := a.importMultipleDirectPostLines(c, directPostLines, dryRun); err != nil {
|
||||||
errors <- LineImportWorkerError{err, errLine}
|
errors <- imports.LineImportWorkerError{Error: err, LineNumber: errLine}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
@@ -177,9 +180,9 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
|||||||
a.Srv().Store.LockToMaster()
|
a.Srv().Store.LockToMaster()
|
||||||
defer a.Srv().Store.UnlockFromMaster()
|
defer a.Srv().Store.UnlockFromMaster()
|
||||||
|
|
||||||
errorsChan := make(chan LineImportWorkerError, (2*workers)+1) // size chosen to ensure it never gets filled up completely.
|
errorsChan := make(chan imports.LineImportWorkerError, (2*workers)+1) // size chosen to ensure it never gets filled up completely.
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var linesChan chan LineImportWorkerData
|
var linesChan chan imports.LineImportWorkerData
|
||||||
lastLineType := ""
|
lastLineType := ""
|
||||||
|
|
||||||
var attachedFiles map[string]*zip.File
|
var attachedFiles map[string]*zip.File
|
||||||
@@ -194,7 +197,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
|||||||
decoder := json.NewDecoder(bytes.NewReader(scanner.Bytes()))
|
decoder := json.NewDecoder(bytes.NewReader(scanner.Bytes()))
|
||||||
lineNumber++
|
lineNumber++
|
||||||
|
|
||||||
var line LineImportData
|
var line imports.LineImportData
|
||||||
if err := decoder.Decode(&line); err != nil {
|
if err := decoder.Decode(&line); err != nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, "", http.StatusBadRequest).Wrap(err), lineNumber
|
return model.NewAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, "", http.StatusBadRequest).Wrap(err), lineNumber
|
||||||
}
|
}
|
||||||
@@ -234,7 +237,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
|||||||
|
|
||||||
// Set up the workers and channel for this type.
|
// Set up the workers and channel for this type.
|
||||||
lastLineType = line.Type
|
lastLineType = line.Type
|
||||||
linesChan = make(chan LineImportWorkerData, workers)
|
linesChan = make(chan imports.LineImportWorkerData, workers)
|
||||||
for i := 0; i < workers; i++ {
|
for i := 0; i < workers; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go a.bulkImportWorker(c, dryRun, &wg, linesChan, errorsChan)
|
go a.bulkImportWorker(c, dryRun, &wg, linesChan, errorsChan)
|
||||||
@@ -242,7 +245,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case linesChan <- LineImportWorkerData{line, lineNumber}:
|
case linesChan <- imports.LineImportWorkerData{LineImportData: line, LineNumber: lineNumber}:
|
||||||
case err := <-errorsChan:
|
case err := <-errorsChan:
|
||||||
if stopOnError(c, err) {
|
if stopOnError(c, err) {
|
||||||
close(linesChan)
|
close(linesChan)
|
||||||
@@ -273,7 +276,7 @@ func (a *App) bulkImport(c request.CTX, jsonlReader io.Reader, attachmentsReader
|
|||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func processImportDataFileVersionLine(line LineImportData) (int, *model.AppError) {
|
func processImportDataFileVersionLine(line imports.LineImportData) (int, *model.AppError) {
|
||||||
if line.Type != "version" || line.Version == nil {
|
if line.Type != "version" || line.Version == nil {
|
||||||
return -1, model.NewAppError("BulkImport", "app.import.process_import_data_file_version_line.invalid_version.error", nil, "", http.StatusBadRequest)
|
return -1, model.NewAppError("BulkImport", "app.import.process_import_data_file_version_line.invalid_version.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -281,7 +284,7 @@ func processImportDataFileVersionLine(line LineImportData) (int, *model.AppError
|
|||||||
return *line.Version, nil
|
return *line.Version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importLine(c request.CTX, line LineImportData, dryRun bool) *model.AppError {
|
func (a *App) importLine(c request.CTX, line imports.LineImportData, dryRun bool) *model.AppError {
|
||||||
switch {
|
switch {
|
||||||
case line.Type == "scheme":
|
case line.Type == "scheme":
|
||||||
if line.Scheme == nil {
|
if line.Scheme == nil {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app/imports"
|
||||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||||
"github.com/mattermost/mattermost-server/v6/app/teams"
|
"github.com/mattermost/mattermost-server/v6/app/teams"
|
||||||
"github.com/mattermost/mattermost-server/v6/app/users"
|
"github.com/mattermost/mattermost-server/v6/app/users"
|
||||||
@@ -30,8 +31,8 @@ import (
|
|||||||
// still enforced.
|
// still enforced.
|
||||||
//
|
//
|
||||||
|
|
||||||
func (a *App) importScheme(data *SchemeImportData, dryRun bool) *model.AppError {
|
func (a *App) importScheme(data *imports.SchemeImportData, dryRun bool) *model.AppError {
|
||||||
if err := validateSchemeImportData(data); err != nil {
|
if err := imports.ValidateSchemeImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +78,7 @@ func (a *App) importScheme(data *SchemeImportData, dryRun bool) *model.AppError
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultTeamGuestRole == nil {
|
if data.DefaultTeamGuestRole == nil {
|
||||||
data.DefaultTeamGuestRole = &RoleImportData{
|
data.DefaultTeamGuestRole = &imports.RoleImportData{
|
||||||
DisplayName: model.NewString("Team Guest Role for Scheme"),
|
DisplayName: model.NewString("Team Guest Role for Scheme"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,7 @@ func (a *App) importScheme(data *SchemeImportData, dryRun bool) *model.AppError
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultChannelGuestRole == nil {
|
if data.DefaultChannelGuestRole == nil {
|
||||||
data.DefaultChannelGuestRole = &RoleImportData{
|
data.DefaultChannelGuestRole = &imports.RoleImportData{
|
||||||
DisplayName: model.NewString("Channel Guest Role for Scheme"),
|
DisplayName: model.NewString("Channel Guest Role for Scheme"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,9 +113,9 @@ func (a *App) importScheme(data *SchemeImportData, dryRun bool) *model.AppError
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *model.AppError {
|
func (a *App) importRole(data *imports.RoleImportData, dryRun bool, isSchemeRole bool) *model.AppError {
|
||||||
if !isSchemeRole {
|
if !isSchemeRole {
|
||||||
if err := validateRoleImportData(data); err != nil {
|
if err := imports.ValidateRoleImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,8 +159,8 @@ func (a *App) importRole(data *RoleImportData, dryRun bool, isSchemeRole bool) *
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importTeam(c request.CTX, data *TeamImportData, dryRun bool) *model.AppError {
|
func (a *App) importTeam(c request.CTX, data *imports.TeamImportData, dryRun bool) *model.AppError {
|
||||||
if err := validateTeamImportData(data); err != nil {
|
if err := imports.ValidateTeamImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,8 +227,8 @@ func (a *App) importTeam(c request.CTX, data *TeamImportData, dryRun bool) *mode
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importChannel(c request.CTX, data *ChannelImportData, dryRun bool) *model.AppError {
|
func (a *App) importChannel(c request.CTX, data *imports.ChannelImportData, dryRun bool) *model.AppError {
|
||||||
if err := validateChannelImportData(data); err != nil {
|
if err := imports.ValidateChannelImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,8 +292,8 @@ func (a *App) importChannel(c request.CTX, data *ChannelImportData, dryRun bool)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *model.AppError {
|
func (a *App) importUser(c request.CTX, data *imports.UserImportData, dryRun bool) *model.AppError {
|
||||||
if err := validateUserImportData(data); err != nil {
|
if err := imports.ValidateUserImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +731,7 @@ func (a *App) importUser(c request.CTX, data *UserImportData, dryRun bool) *mode
|
|||||||
return a.importUserTeams(c, savedUser, data.Teams)
|
return a.importUserTeams(c, savedUser, data.Teams)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamImportData) *model.AppError {
|
func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]imports.UserTeamImportData) *model.AppError {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -745,7 +746,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI
|
|||||||
}
|
}
|
||||||
|
|
||||||
teamThemePreferencesByID := map[string]model.Preferences{}
|
teamThemePreferencesByID := map[string]model.Preferences{}
|
||||||
channels := map[string][]UserChannelImportData{}
|
channels := map[string][]imports.UserChannelImportData{}
|
||||||
teamsByID := map[string]*model.Team{}
|
teamsByID := map[string]*model.Team{}
|
||||||
teamMemberByTeamID := map[string]*model.TeamMember{}
|
teamMemberByTeamID := map[string]*model.TeamMember{}
|
||||||
newTeamMembers := []*model.TeamMember{}
|
newTeamMembers := []*model.TeamMember{}
|
||||||
@@ -820,7 +821,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI
|
|||||||
channels[team.Id] = append(channels[team.Id], *tdata.Channels...)
|
channels[team.Id] = append(channels[team.Id], *tdata.Channels...)
|
||||||
}
|
}
|
||||||
if !user.IsGuest() {
|
if !user.IsGuest() {
|
||||||
channels[team.Id] = append(channels[team.Id], UserChannelImportData{Name: model.NewString(model.DefaultChannelName)})
|
channels[team.Id] = append(channels[team.Id], imports.UserChannelImportData{Name: model.NewString(model.DefaultChannelName)})
|
||||||
}
|
}
|
||||||
|
|
||||||
teamsByID[team.Id] = team
|
teamsByID[team.Id] = team
|
||||||
@@ -890,7 +891,7 @@ func (a *App) importUserTeams(c request.CTX, user *model.User, data *[]UserTeamI
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Team, data *[]UserChannelImportData) *model.AppError {
|
func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Team, data *[]imports.UserChannelImportData) *model.AppError {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1060,8 +1061,8 @@ func (a *App) importUserChannels(c request.CTX, user *model.User, team *model.Te
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.AppError {
|
func (a *App) importReaction(data *imports.ReactionImportData, post *model.Post) *model.AppError {
|
||||||
if err := validateReactionImportData(data, post.CreateAt); err != nil {
|
if err := imports.ValidateReactionImportData(data, post.CreateAt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1090,12 +1091,12 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importReplies(c request.CTX, data []ReplyImportData, post *model.Post, teamID string) *model.AppError {
|
func (a *App) importReplies(c request.CTX, data []imports.ReplyImportData, post *model.Post, teamID string) *model.AppError {
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
usernames := []string{}
|
usernames := []string{}
|
||||||
for _, replyData := range data {
|
for _, replyData := range data {
|
||||||
replyData := replyData
|
replyData := replyData
|
||||||
if err = validateReplyImportData(&replyData, post.CreateAt, a.MaxPostSize()); err != nil {
|
if err = imports.ValidateReplyImportData(&replyData, post.CreateAt, a.MaxPostSize()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
usernames = append(usernames, *replyData.User)
|
usernames = append(usernames, *replyData.User)
|
||||||
@@ -1192,7 +1193,7 @@ func (a *App) importReplies(c request.CTX, data []ReplyImportData, post *model.P
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importAttachment(c request.CTX, data *AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
|
func (a *App) importAttachment(c request.CTX, data *imports.AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
|
||||||
var (
|
var (
|
||||||
name string
|
name string
|
||||||
file io.Reader
|
file io.Reader
|
||||||
@@ -1264,9 +1265,9 @@ func (a *App) importAttachment(c request.CTX, data *AttachmentImportData, post *
|
|||||||
|
|
||||||
type postAndData struct {
|
type postAndData struct {
|
||||||
post *model.Post
|
post *model.Post
|
||||||
postData *PostImportData
|
postData *imports.PostImportData
|
||||||
directPostData *DirectPostImportData
|
directPostData *imports.DirectPostImportData
|
||||||
replyData *ReplyImportData
|
replyData *imports.ReplyImportData
|
||||||
team *model.Team
|
team *model.Team
|
||||||
lineNumber int
|
lineNumber int
|
||||||
}
|
}
|
||||||
@@ -1316,7 +1317,7 @@ func (a *App) getChannelsByNames(names []string, teamID string) (map[string]*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getChannelsForPosts returns map[teamName]map[channelName]*model.Channel
|
// getChannelsForPosts returns map[teamName]map[channelName]*model.Channel
|
||||||
func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*PostImportData) (map[string]map[string]*model.Channel, *model.AppError) {
|
func (a *App) getChannelsForPosts(teams map[string]*model.Team, data []*imports.PostImportData) (map[string]map[string]*model.Channel, *model.AppError) {
|
||||||
teamChannels := make(map[string]map[string]*model.Channel)
|
teamChannels := make(map[string]map[string]*model.Channel)
|
||||||
for _, postData := range data {
|
for _, postData := range data {
|
||||||
teamName := *postData.Team
|
teamName := *postData.Team
|
||||||
@@ -1343,13 +1344,13 @@ func getPostStrID(post *model.Post) string {
|
|||||||
|
|
||||||
// importMultiplePostLines will return an error and the line that
|
// importMultiplePostLines will return an error and the line that
|
||||||
// caused it whenever possible
|
// caused it whenever possible
|
||||||
func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
func (a *App) importMultiplePostLines(c request.CTX, lines []imports.LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if err := validatePostImportData(line.Post, a.MaxPostSize()); err != nil {
|
if err := imports.ValidatePostImportData(line.Post, a.MaxPostSize()); err != nil {
|
||||||
return line.LineNumber, err
|
return line.LineNumber, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1361,7 +1362,7 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat
|
|||||||
|
|
||||||
usernames := []string{}
|
usernames := []string{}
|
||||||
teamNames := make([]string, len(lines))
|
teamNames := make([]string, len(lines))
|
||||||
postsData := make([]*PostImportData, len(lines))
|
postsData := make([]*imports.PostImportData, len(lines))
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
usernames = append(usernames, *line.Post.User)
|
usernames = append(usernames, *line.Post.User)
|
||||||
if line.Post.FlaggedBy != nil {
|
if line.Post.FlaggedBy != nil {
|
||||||
@@ -1532,7 +1533,7 @@ func (a *App) importMultiplePostLines(c request.CTX, lines []LineImportWorkerDat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// uploadAttachments imports new attachments and returns current attachments of the post as a map
|
// uploadAttachments imports new attachments and returns current attachments of the post as a map
|
||||||
func (a *App) uploadAttachments(c request.CTX, attachments *[]AttachmentImportData, post *model.Post, teamID string) map[string]bool {
|
func (a *App) uploadAttachments(c request.CTX, attachments *[]imports.AttachmentImportData, post *model.Post, teamID string) map[string]bool {
|
||||||
if attachments == nil {
|
if attachments == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1564,9 +1565,9 @@ func (a *App) updateFileInfoWithPostId(post *model.Post) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData, dryRun bool) *model.AppError {
|
func (a *App) importDirectChannel(c request.CTX, data *imports.DirectChannelImportData, dryRun bool) *model.AppError {
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if err = validateDirectChannelImportData(data); err != nil {
|
if err = imports.ValidateDirectChannelImportData(data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1645,13 +1646,13 @@ func (a *App) importDirectChannel(c request.CTX, data *DirectChannelImportData,
|
|||||||
|
|
||||||
// importMultipleDirectPostLines will return an error and the line
|
// importMultipleDirectPostLines will return an error and the line
|
||||||
// that caused it whenever possible
|
// that caused it whenever possible
|
||||||
func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
func (a *App) importMultipleDirectPostLines(c request.CTX, lines []imports.LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if err := validateDirectPostImportData(line.DirectPost, a.MaxPostSize()); err != nil {
|
if err := imports.ValidateDirectPostImportData(line.DirectPost, a.MaxPostSize()); err != nil {
|
||||||
return line.LineNumber, err
|
return line.LineNumber, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1840,8 +1841,8 @@ func (a *App) importMultipleDirectPostLines(c request.CTX, lines []LineImportWor
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) importEmoji(data *EmojiImportData, dryRun bool) *model.AppError {
|
func (a *App) importEmoji(data *imports.EmojiImportData, dryRun bool) *model.AppError {
|
||||||
aerr := validateEmojiImportData(data)
|
aerr := imports.ValidateEmojiImportData(data)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
if aerr.Id == "model.emoji.system_emoji_name.app_error" {
|
if aerr.Id == "model.emoji.system_emoji_name.app_error" {
|
||||||
mlog.Warn("Skipping emoji import due to name conflict with system emoji", mlog.String("emoji_name", *data.Name))
|
mlog.Warn("Skipping emoji import due to name conflict with system emoji", mlog.String("emoji_name", *data.Name))
|
||||||
|
|||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app/imports"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils"
|
"github.com/mattermost/mattermost-server/v6/utils"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils/fileutils"
|
"github.com/mattermost/mattermost-server/v6/utils/fileutils"
|
||||||
@@ -83,7 +84,7 @@ func TestImportImportLine(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
// Try import line with an invalid type.
|
// Try import line with an invalid type.
|
||||||
line := LineImportData{
|
line := imports.LineImportData{
|
||||||
Type: "gibberish",
|
Type: "gibberish",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,29 +131,29 @@ func TestStopOnError(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
assert.True(t, stopOnError(th.Context, LineImportWorkerError{
|
assert.True(t, stopOnError(th.Context, imports.LineImportWorkerError{
|
||||||
model.NewAppError("test", "app.import.attachment.bad_file.error", nil, "", http.StatusBadRequest),
|
Error: model.NewAppError("test", "app.import.attachment.bad_file.error", nil, "", http.StatusBadRequest),
|
||||||
1,
|
LineNumber: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
assert.True(t, stopOnError(th.Context, LineImportWorkerError{
|
assert.True(t, stopOnError(th.Context, imports.LineImportWorkerError{
|
||||||
model.NewAppError("test", "app.import.attachment.file_upload.error", nil, "", http.StatusBadRequest),
|
Error: model.NewAppError("test", "app.import.attachment.file_upload.error", nil, "", http.StatusBadRequest),
|
||||||
1,
|
LineNumber: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
assert.False(t, stopOnError(th.Context, LineImportWorkerError{
|
assert.False(t, stopOnError(th.Context, imports.LineImportWorkerError{
|
||||||
model.NewAppError("test", "api.file.upload_file.large_image.app_error", nil, "", http.StatusBadRequest),
|
Error: model.NewAppError("test", "api.file.upload_file.large_image.app_error", nil, "", http.StatusBadRequest),
|
||||||
1,
|
LineNumber: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
assert.False(t, stopOnError(th.Context, LineImportWorkerError{
|
assert.False(t, stopOnError(th.Context, imports.LineImportWorkerError{
|
||||||
model.NewAppError("test", "app.import.validate_direct_channel_import_data.members_too_few.error", nil, "", http.StatusBadRequest),
|
Error: model.NewAppError("test", "app.import.validate_direct_channel_import_data.members_too_few.error", nil, "", http.StatusBadRequest),
|
||||||
1,
|
LineNumber: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
assert.False(t, stopOnError(th.Context, LineImportWorkerError{
|
assert.False(t, stopOnError(th.Context, imports.LineImportWorkerError{
|
||||||
model.NewAppError("test", "app.import.validate_direct_channel_import_data.members_too_many.error", nil, "", http.StatusBadRequest),
|
Error: model.NewAppError("test", "app.import.validate_direct_channel_import_data.members_too_many.error", nil, "", http.StatusBadRequest),
|
||||||
1,
|
LineNumber: 1,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +247,7 @@ func TestImportBulkImport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
||||||
data := LineImportData{
|
data := imports.LineImportData{
|
||||||
Type: "version",
|
Type: "version",
|
||||||
Version: ptrInt(1),
|
Version: ptrInt(1),
|
||||||
}
|
}
|
||||||
@@ -284,8 +285,8 @@ func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessAttachments(t *testing.T) {
|
func TestProcessAttachments(t *testing.T) {
|
||||||
genAttachments := func() *[]AttachmentImportData {
|
genAttachments := func() *[]imports.AttachmentImportData {
|
||||||
return &[]AttachmentImportData{
|
return &[]imports.AttachmentImportData{
|
||||||
{
|
{
|
||||||
Path: model.NewString("file.jpg"),
|
Path: model.NewString("file.jpg"),
|
||||||
},
|
},
|
||||||
@@ -295,36 +296,36 @@ func TestProcessAttachments(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
line := LineImportData{
|
line := imports.LineImportData{
|
||||||
Type: "post",
|
Type: "post",
|
||||||
Post: &PostImportData{
|
Post: &imports.PostImportData{
|
||||||
Attachments: genAttachments(),
|
Attachments: genAttachments(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
line2 := LineImportData{
|
line2 := imports.LineImportData{
|
||||||
Type: "direct_post",
|
Type: "direct_post",
|
||||||
DirectPost: &DirectPostImportData{
|
DirectPost: &imports.DirectPostImportData{
|
||||||
Attachments: genAttachments(),
|
Attachments: genAttachments(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
userLine := LineImportData{
|
userLine := imports.LineImportData{
|
||||||
Type: "user",
|
Type: "user",
|
||||||
User: &UserImportData{
|
User: &imports.UserImportData{
|
||||||
ProfileImage: model.NewString("profile.jpg"),
|
ProfileImage: model.NewString("profile.jpg"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
emojiLine := LineImportData{
|
emojiLine := imports.LineImportData{
|
||||||
Type: "emoji",
|
Type: "emoji",
|
||||||
Emoji: &EmojiImportData{
|
Emoji: &imports.EmojiImportData{
|
||||||
Image: model.NewString("emoji.png"),
|
Image: model.NewString("emoji.png"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("empty path", func(t *testing.T) {
|
t.Run("empty path", func(t *testing.T) {
|
||||||
expected := &[]AttachmentImportData{
|
expected := &[]imports.AttachmentImportData{
|
||||||
{
|
{
|
||||||
Path: model.NewString("file.jpg"),
|
Path: model.NewString("file.jpg"),
|
||||||
},
|
},
|
||||||
@@ -341,7 +342,7 @@ func TestProcessAttachments(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("valid path", func(t *testing.T) {
|
t.Run("valid path", func(t *testing.T) {
|
||||||
expected := &[]AttachmentImportData{
|
expected := &[]imports.AttachmentImportData{
|
||||||
{
|
{
|
||||||
Path: model.NewString("/tmp/file.jpg"),
|
Path: model.NewString("/tmp/file.jpg"),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
package app
|
package imports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
package app
|
package imports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func validateSchemeImportData(data *SchemeImportData) *model.AppError {
|
func ValidateSchemeImportData(data *SchemeImportData) *model.AppError {
|
||||||
|
|
||||||
if data.Scope == nil {
|
if data.Scope == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_scheme_import_data.null_scope.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_scheme_import_data.null_scope.error", nil, "", http.StatusBadRequest)
|
||||||
@@ -46,37 +46,37 @@ func validateSchemeImportData(data *SchemeImportData) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultTeamAdminRole != nil {
|
if data.DefaultTeamAdminRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultTeamAdminRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultTeamAdminRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultTeamUserRole != nil {
|
if data.DefaultTeamUserRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultTeamUserRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultTeamUserRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultTeamGuestRole != nil {
|
if data.DefaultTeamGuestRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultTeamGuestRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultTeamGuestRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultChannelAdminRole != nil {
|
if data.DefaultChannelAdminRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultChannelAdminRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultChannelAdminRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultChannelUserRole != nil {
|
if data.DefaultChannelUserRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultChannelUserRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultChannelUserRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.DefaultChannelGuestRole != nil {
|
if data.DefaultChannelGuestRole != nil {
|
||||||
if err := validateRoleImportData(data.DefaultChannelGuestRole); err != nil {
|
if err := ValidateRoleImportData(data.DefaultChannelGuestRole); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ func validateSchemeImportData(data *SchemeImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateRoleImportData(data *RoleImportData) *model.AppError {
|
func ValidateRoleImportData(data *RoleImportData) *model.AppError {
|
||||||
|
|
||||||
if data.Name == nil || !model.IsValidRoleName(*data.Name) {
|
if data.Name == nil || !model.IsValidRoleName(*data.Name) {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_role_import_data.name_invalid.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_role_import_data.name_invalid.error", nil, "", http.StatusBadRequest)
|
||||||
@@ -117,7 +117,7 @@ func validateRoleImportData(data *RoleImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateTeamImportData(data *TeamImportData) *model.AppError {
|
func ValidateTeamImportData(data *TeamImportData) *model.AppError {
|
||||||
|
|
||||||
if data.Name == nil {
|
if data.Name == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_team_import_data.name_missing.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_team_import_data.name_missing.error", nil, "", http.StatusBadRequest)
|
||||||
@@ -152,7 +152,7 @@ func validateTeamImportData(data *TeamImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateChannelImportData(data *ChannelImportData) *model.AppError {
|
func ValidateChannelImportData(data *ChannelImportData) *model.AppError {
|
||||||
|
|
||||||
if data.Team == nil {
|
if data.Team == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_channel_import_data.team_missing.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_channel_import_data.team_missing.error", nil, "", http.StatusBadRequest)
|
||||||
@@ -193,7 +193,7 @@ func validateChannelImportData(data *ChannelImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateUserImportData(data *UserImportData) *model.AppError {
|
func ValidateUserImportData(data *UserImportData) *model.AppError {
|
||||||
if data.ProfileImage != nil {
|
if data.ProfileImage != nil {
|
||||||
if _, err := os.Stat(*data.ProfileImage); os.IsNotExist(err) {
|
if _, err := os.Stat(*data.ProfileImage); os.IsNotExist(err) {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.profile_image.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_user_import_data.profile_image.error", nil, "", http.StatusBadRequest)
|
||||||
@@ -306,13 +306,13 @@ func validateUserImportData(data *UserImportData) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.Teams != nil {
|
if data.Teams != nil {
|
||||||
return validateUserTeamsImportData(data.Teams)
|
return ValidateUserTeamsImportData(data.Teams)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
func ValidateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ func validateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tdata.Channels != nil {
|
if tdata.Channels != nil {
|
||||||
if err := validateUserChannelsImportData(tdata.Channels); err != nil {
|
if err := ValidateUserChannelsImportData(tdata.Channels); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ func validateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateUserChannelsImportData(data *[]UserChannelImportData) *model.AppError {
|
func ValidateUserChannelsImportData(data *[]UserChannelImportData) *model.AppError {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -375,7 +375,7 @@ func validateUserChannelsImportData(data *[]UserChannelImportData) *model.AppErr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateReactionImportData(data *ReactionImportData, parentCreateAt int64) *model.AppError {
|
func ValidateReactionImportData(data *ReactionImportData, parentCreateAt int64) *model.AppError {
|
||||||
if data.User == nil {
|
if data.User == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_reaction_import_data.user_missing.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_reaction_import_data.user_missing.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -397,7 +397,7 @@ func validateReactionImportData(data *ReactionImportData, parentCreateAt int64)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPostSize int) *model.AppError {
|
func ValidateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPostSize int) *model.AppError {
|
||||||
if data.User == nil {
|
if data.User == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.user_missing.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_reply_import_data.user_missing.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ func validateReplyImportData(data *ReplyImportData, parentCreateAt int64, maxPos
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppError {
|
func ValidatePostImportData(data *PostImportData, maxPostSize int) *model.AppError {
|
||||||
if data.Team == nil {
|
if data.Team == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.team_missing.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_post_import_data.team_missing.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -447,14 +447,14 @@ func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppErr
|
|||||||
if data.Reactions != nil {
|
if data.Reactions != nil {
|
||||||
for _, reaction := range *data.Reactions {
|
for _, reaction := range *data.Reactions {
|
||||||
reaction := reaction
|
reaction := reaction
|
||||||
validateReactionImportData(&reaction, *data.CreateAt)
|
ValidateReactionImportData(&reaction, *data.CreateAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Replies != nil {
|
if data.Replies != nil {
|
||||||
for _, reply := range *data.Replies {
|
for _, reply := range *data.Replies {
|
||||||
reply := reply
|
reply := reply
|
||||||
validateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
ValidateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +465,7 @@ func validatePostImportData(data *PostImportData, maxPostSize int) *model.AppErr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDirectChannelImportData(data *DirectChannelImportData) *model.AppError {
|
func ValidateDirectChannelImportData(data *DirectChannelImportData) *model.AppError {
|
||||||
if data.Members == nil {
|
if data.Members == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_direct_channel_import_data.members_required.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_direct_channel_import_data.members_required.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -500,7 +500,7 @@ func validateDirectChannelImportData(data *DirectChannelImportData) *model.AppEr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *model.AppError {
|
func ValidateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *model.AppError {
|
||||||
if data.ChannelMembers == nil {
|
if data.ChannelMembers == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.channel_members_required.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_direct_post_import_data.channel_members_required.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
@@ -547,23 +547,23 @@ func validateDirectPostImportData(data *DirectPostImportData, maxPostSize int) *
|
|||||||
if data.Reactions != nil {
|
if data.Reactions != nil {
|
||||||
for _, reaction := range *data.Reactions {
|
for _, reaction := range *data.Reactions {
|
||||||
reaction := reaction
|
reaction := reaction
|
||||||
validateReactionImportData(&reaction, *data.CreateAt)
|
ValidateReactionImportData(&reaction, *data.CreateAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.Replies != nil {
|
if data.Replies != nil {
|
||||||
for _, reply := range *data.Replies {
|
for _, reply := range *data.Replies {
|
||||||
reply := reply
|
reply := reply
|
||||||
validateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
ValidateReplyImportData(&reply, *data.CreateAt, maxPostSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateEmojiImportData validates emoji data and returns if the import name
|
// ValidateEmojiImportData validates emoji data and returns if the import name
|
||||||
// conflicts with a system emoji.
|
// conflicts with a system emoji.
|
||||||
func validateEmojiImportData(data *EmojiImportData) *model.AppError {
|
func ValidateEmojiImportData(data *EmojiImportData) *model.AppError {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.validate_emoji_import_data.empty.error", nil, "", http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.validate_emoji_import_data.empty.error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Ссылка в новой задаче
Block a user