Revert " PLT-7 adding loc for db calls"
Этот коммит содержится в:
@@ -7,14 +7,12 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
)
|
||||
|
||||
type SlackChannel struct {
|
||||
@@ -91,7 +89,7 @@ func SlackParsePosts(data io.Reader) []SlackPost {
|
||||
return posts
|
||||
}
|
||||
|
||||
func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User {
|
||||
func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User {
|
||||
// Log header
|
||||
log.WriteString("\r\n Users Created\r\n")
|
||||
log.WriteString("===============\r\n\r\n")
|
||||
@@ -118,7 +116,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
|
||||
Password: password,
|
||||
}
|
||||
|
||||
if mUser := ImportUser(T, &newUser); mUser != nil {
|
||||
if mUser := ImportUser(&newUser); mUser != nil {
|
||||
addedUsers[sUser.Id] = mUser
|
||||
log.WriteString("Email, Password: " + newUser.Email + ", " + password + "\r\n")
|
||||
} else {
|
||||
@@ -129,7 +127,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
|
||||
return addedUsers
|
||||
}
|
||||
|
||||
func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
|
||||
func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
|
||||
for _, sPost := range posts {
|
||||
switch {
|
||||
case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"):
|
||||
@@ -146,7 +144,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
|
||||
Message: sPost.Text,
|
||||
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
|
||||
}
|
||||
ImportPost(T, &newPost)
|
||||
ImportPost(&newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "file_comment":
|
||||
if sPost.Comment["user"] == "" {
|
||||
l4g.Debug("Message without user")
|
||||
@@ -161,7 +159,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
|
||||
Message: sPost.Comment["comment"],
|
||||
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
|
||||
}
|
||||
ImportPost(T, &newPost)
|
||||
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
|
||||
@@ -172,7 +170,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack
|
||||
}
|
||||
}
|
||||
|
||||
func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel {
|
||||
func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel {
|
||||
// Write Header
|
||||
log.WriteString("\r\n Channels Added \r\n")
|
||||
log.WriteString("=================\r\n\r\n")
|
||||
@@ -186,10 +184,10 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
|
||||
Name: SlackConvertChannelName(sChannel.Name),
|
||||
Purpose: sChannel.Topic["value"],
|
||||
}
|
||||
mChannel := ImportChannel(T, &newChannel)
|
||||
mChannel := ImportChannel(&newChannel)
|
||||
if mChannel == nil {
|
||||
// Maybe it already exists?
|
||||
if result := <-Srv.Store.Channel().GetByName(T, teamId, sChannel.Name); result.Err != nil {
|
||||
if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil {
|
||||
l4g.Debug("Failed to import: %s", newChannel.DisplayName)
|
||||
log.WriteString("Failed to import: " + newChannel.DisplayName + "\r\n")
|
||||
continue
|
||||
@@ -200,13 +198,13 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
|
||||
}
|
||||
log.WriteString(newChannel.DisplayName + "\r\n")
|
||||
addedChannels[sChannel.Id] = mChannel
|
||||
SlackAddPosts(T, mChannel, posts[sChannel.Name], users)
|
||||
SlackAddPosts(mChannel, posts[sChannel.Name], users)
|
||||
}
|
||||
|
||||
return addedChannels
|
||||
}
|
||||
|
||||
func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
|
||||
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.NewAppError("SlackImport", "Unable to open zip file", err.Error()), nil
|
||||
@@ -242,8 +240,8 @@ func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64
|
||||
}
|
||||
}
|
||||
|
||||
addedUsers := SlackAddUsers(T, teamID, users, log)
|
||||
SlackAddChannels(T, teamID, channels, posts, addedUsers, log)
|
||||
addedUsers := SlackAddUsers(teamID, users, log)
|
||||
SlackAddChannels(teamID, channels, posts, addedUsers, log)
|
||||
|
||||
log.WriteString("\r\n Notes \r\n")
|
||||
log.WriteString("=======\r\n\r\n")
|
||||
|
||||
Ссылка в новой задаче
Block a user