mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Some improvments to slack import (#4010)
This commit is contained in:
committed by
Joram Wilander
parent
6d21dab421
commit
adfcda4802
@@ -66,7 +66,8 @@ func SlackParseChannels(data io.Reader) []SlackChannel {
|
||||
|
||||
var channels []SlackChannel
|
||||
if err := decoder.Decode(&channels); err != nil {
|
||||
return make([]SlackChannel, 0)
|
||||
l4g.Warn(utils.T("api.slackimport.slack_parse_channels.error"))
|
||||
return channels
|
||||
}
|
||||
return channels
|
||||
}
|
||||
@@ -89,7 +90,8 @@ func SlackParsePosts(data io.Reader) []SlackPost {
|
||||
|
||||
var posts []SlackPost
|
||||
if err := decoder.Decode(&posts); err != nil {
|
||||
return make([]SlackPost, 0)
|
||||
l4g.Warn(utils.T("api.slackimport.slack_parse_posts.error"))
|
||||
return posts
|
||||
}
|
||||
return posts
|
||||
}
|
||||
@@ -120,13 +122,23 @@ func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map
|
||||
lastName = name
|
||||
}
|
||||
|
||||
email := sUser.Profile["email"]
|
||||
|
||||
password := model.NewId()
|
||||
|
||||
// Check for email conflict and use existing user if found
|
||||
if result := <-Srv.Store.User().GetByEmail(email); result.Err == nil {
|
||||
existingUser := result.Data.(*model.User)
|
||||
addedUsers[sUser.Id] = existingUser
|
||||
log.WriteString(utils.T("api.slackimport.slack_add_users.merge_existing", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
|
||||
continue
|
||||
}
|
||||
|
||||
newUser := model.User{
|
||||
Username: sUser.Username,
|
||||
FirstName: firstName,
|
||||
LastName: lastName,
|
||||
Email: sUser.Profile["email"],
|
||||
Email: email,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
@@ -175,9 +187,23 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
|
||||
}
|
||||
ImportPost(&newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "bot_message":
|
||||
// In the future this will use the "Action Post" spec to post
|
||||
// a message without using a username. For now we just warn that we don't handle this case
|
||||
l4g.Warn(utils.T("api.slackimport.slack_add_posts.bot.warn"))
|
||||
continue
|
||||
case sPost.Type == "message" && (sPost.SubType == "channel_join" || sPost.SubType == "channel_leave"):
|
||||
if sPost.User == "" {
|
||||
l4g.Debug(utils.T("api.slackimport.slack_add_posts.msg_no_usr.debug"))
|
||||
continue
|
||||
} else if users[sPost.User] == nil {
|
||||
l4g.Debug(utils.T("api.slackimport.slack_add_posts.user_no_exists.debug"), sPost.User)
|
||||
continue
|
||||
}
|
||||
newPost := model.Post{
|
||||
UserId: users[sPost.User].Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: sPost.Text,
|
||||
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
|
||||
Type: model.POST_JOIN_LEAVE,
|
||||
}
|
||||
ImportPost(&newPost)
|
||||
default:
|
||||
l4g.Warn(utils.T("api.slackimport.slack_add_posts.unsupported.warn"), sPost.Type, sPost.SubType)
|
||||
}
|
||||
@@ -260,20 +286,22 @@ func SlackConvertUserMentions(users []SlackUser, posts map[string][]SlackPost) m
|
||||
}
|
||||
|
||||
func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
|
||||
zipreader, err := zip.NewReader(fileData, fileSize)
|
||||
if err != nil || zipreader.File == nil {
|
||||
return model.NewLocAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, err.Error()), nil
|
||||
}
|
||||
|
||||
// Create log file
|
||||
log := bytes.NewBufferString(utils.T("api.slackimport.slack_import.log"))
|
||||
|
||||
zipreader, err := zip.NewReader(fileData, fileSize)
|
||||
if err != nil || zipreader.File == nil {
|
||||
log.WriteString(utils.T("api.slackimport.slack_import.zip.app_error"))
|
||||
return model.NewLocAppError("SlackImport", "api.slackimport.slack_import.zip.app_error", nil, err.Error()), log
|
||||
}
|
||||
|
||||
var channels []SlackChannel
|
||||
var users []SlackUser
|
||||
posts := make(map[string][]SlackPost)
|
||||
for _, file := range zipreader.File {
|
||||
reader, err := file.Open()
|
||||
if err != nil {
|
||||
log.WriteString(utils.T("api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}))
|
||||
return model.NewLocAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}, err.Error()), log
|
||||
}
|
||||
if file.Name == "channels.json" {
|
||||
@@ -305,6 +333,7 @@ func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model
|
||||
|
||||
log.WriteString(utils.T("api.slackimport.slack_import.note1"))
|
||||
log.WriteString(utils.T("api.slackimport.slack_import.note2"))
|
||||
log.WriteString(utils.T("api.slackimport.slack_import.note3"))
|
||||
|
||||
return nil, log
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
@@ -896,7 +896,11 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=MattermostImportLog.txt")
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
http.ServeContent(w, r, "MattermostImportLog.txt", time.Now(), bytes.NewReader(log.Bytes()))
|
||||
if c.Err != nil {
|
||||
w.WriteHeader(c.Err.StatusCode)
|
||||
}
|
||||
io.Copy(w, bytes.NewReader(log.Bytes()))
|
||||
//http.ServeContent(w, r, "MattermostImportLog.txt", time.Now(), bytes.NewReader(log.Bytes()))
|
||||
}
|
||||
|
||||
func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
16
i18n/en.json
16
i18n/en.json
@@ -1423,6 +1423,14 @@
|
||||
"id": "api.slackimport.slack_add_channels.added",
|
||||
"translation": "\r\n Channels Added \r\n"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_parse_channels.error",
|
||||
"translation": "Error parsing slack channels. Import may work anyway."
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_parse_posts.error",
|
||||
"translation": "Error parsing some slack posts. Import may work anyway."
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_add_channels.failed_to_add_user",
|
||||
"translation": "Failed to add user to channel: {{.Username}}\r\n"
|
||||
@@ -1467,6 +1475,10 @@
|
||||
"id": "api.slackimport.slack_add_users.email_pwd",
|
||||
"translation": "Email, Password: {{.Email}}, {{.Password}}\r\n"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_add_users.merge_existing",
|
||||
"translation": "Merged user with existing account: {{.Email}}, {{.Username}}\r\n"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_add_users.unable_import",
|
||||
"translation": "Unable to import user: {{.Username}}\r\n"
|
||||
@@ -1491,6 +1503,10 @@
|
||||
"id": "api.slackimport.slack_import.note2",
|
||||
"translation": "- Slack bot posts are currently not supported.\r\n"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_import.note3",
|
||||
"translation": "- Additional errors may be found in the server logs.\r\n"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_import.notes",
|
||||
"translation": "\r\n Notes \r\n"
|
||||
|
||||
@@ -29,8 +29,8 @@ class TeamImportTab extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
onImportFailure() {
|
||||
this.setState({status: 'fail', link: ''});
|
||||
onImportFailure(e, err, res) {
|
||||
this.setState({status: 'fail', link: 'data:application/octet-stream;charset=utf-8,' + encodeURIComponent(res.text)});
|
||||
}
|
||||
|
||||
onImportSuccess(data, res) {
|
||||
|
||||
Reference in New Issue
Block a user