Revert "Fix initialism errors (PR-3) (#17062)" (#17202)

This reverts commit ea61458f16. This was causing panic in the plugins because the client and the plugin API changed with this PR
Этот коммит содержится в:
Mario de Frutos Dieguez
2021-03-23 10:32:54 +01:00
коммит произвёл GitHub
родитель 26b86cb3ef
Коммит c0971970e9
26 изменённых файлов: 1146 добавлений и 1146 удалений

Просмотреть файл

@@ -22,7 +22,7 @@ func slackConvertTimeStamp(ts string) int64 {
return timeStamp * 1000 // Convert to milliseconds
}
func slackConvertChannelName(channelName string, channelID string) string {
func slackConvertChannelName(channelName string, channelId string) string {
newName := strings.Trim(channelName, "_-")
if len(newName) == 1 {
return "slack-channel-" + newName
@@ -31,15 +31,15 @@ func slackConvertChannelName(channelName string, channelID string) string {
if isValidChannelNameCharacters(newName) {
return newName
}
return strings.ToLower(channelID)
return strings.ToLower(channelId)
}
func slackConvertUserMentions(users []slackUser, posts map[string][]slackPost) map[string][]slackPost {
var regexes = make(map[string]*regexp.Regexp, len(users))
for _, user := range users {
r, err := regexp.Compile("<@" + user.ID + `(\|` + user.Username + ")?>")
r, err := regexp.Compile("<@" + user.Id + `(\|` + user.Username + ")?>")
if err != nil {
mlog.Warn("Slack Import: Unable to compile the @mention, matching regular expression for the Slack user.", mlog.String("user_name", user.Username), mlog.String("user_id", user.ID))
mlog.Warn("Slack Import: Unable to compile the @mention, matching regular expression for the Slack user.", mlog.String("user_name", user.Username), mlog.String("user_id", user.Id))
continue
}
regexes["@"+user.Username] = r
@@ -65,9 +65,9 @@ func slackConvertUserMentions(users []slackUser, posts map[string][]slackPost) m
func slackConvertChannelMentions(channels []slackChannel, posts map[string][]slackPost) map[string][]slackPost {
var regexes = make(map[string]*regexp.Regexp, len(channels))
for _, channel := range channels {
r, err := regexp.Compile("<#" + channel.ID + `(\|` + channel.Name + ")?>")
r, err := regexp.Compile("<#" + channel.Id + `(\|` + channel.Name + ")?>")
if err != nil {
mlog.Warn("Slack Import: Unable to compile the !channel, matching regular expression for the Slack channel.", mlog.String("channel_id", channel.ID), mlog.String("channel_name", channel.Name))
mlog.Warn("Slack Import: Unable to compile the !channel, matching regular expression for the Slack channel.", mlog.String("channel_id", channel.Id), mlog.String("channel_name", channel.Name))
continue
}
regexes["~"+channel.Name] = r

Просмотреть файл

@@ -25,7 +25,7 @@ import (
)
type slackChannel struct {
ID string `json:"id"`
Id string `json:"id"`
Name string `json:"name"`
Creator string `json:"creator"`
Members []string `json:"members"`
@@ -45,19 +45,19 @@ type slackProfile struct {
}
type slackUser struct {
ID string `json:"id"`
Id string `json:"id"`
Username string `json:"name"`
Profile slackProfile `json:"profile"`
}
type slackFile struct {
ID string `json:"id"`
Id string `json:"id"`
Title string `json:"title"`
}
type slackPost struct {
User string `json:"user"`
BotID string `json:"bot_id"`
BotId string `json:"bot_id"`
BotUsername string `json:"username"`
Text string `json:"text"`
TimeStamp string `json:"ts"`
@@ -205,7 +205,7 @@ func truncateRunes(s string, i int) string {
return s
}
func (si *SlackImporter) slackAddUsers(teamID string, slackusers []slackUser, importerLog *bytes.Buffer) map[string]*model.User {
func (si *SlackImporter) slackAddUsers(teamId string, slackusers []slackUser, importerLog *bytes.Buffer) map[string]*model.User {
// Log header
importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.created"))
importerLog.WriteString("===============\r\n\r\n")
@@ -213,7 +213,7 @@ func (si *SlackImporter) slackAddUsers(teamID string, slackusers []slackUser, im
addedUsers := make(map[string]*model.User)
// Need the team
team, err := si.store.Team().Get(teamID)
team, err := si.store.Team().Get(teamId)
if err != nil {
importerLog.WriteString(i18n.T("api.slackimport.slack_import.team_fail"))
return addedUsers
@@ -233,8 +233,8 @@ func (si *SlackImporter) slackAddUsers(teamID string, slackusers []slackUser, im
// Check for email conflict and use existing user if found
if existingUser, err := si.store.User().GetByEmail(email); err == nil {
addedUsers[sUser.ID] = existingUser
if err := si.actions.JoinUserToTeam(team, addedUsers[sUser.ID], ""); err != nil {
addedUsers[sUser.Id] = existingUser
if err := si.actions.JoinUserToTeam(team, addedUsers[sUser.Id], ""); err != nil {
importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.merge_existing_failed", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
} else {
importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.merge_existing", map[string]interface{}{"Email": existingUser.Email, "Username": existingUser.Username}))
@@ -256,15 +256,15 @@ func (si *SlackImporter) slackAddUsers(teamID string, slackusers []slackUser, im
importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.unable_import", map[string]interface{}{"Username": sUser.Username}))
continue
}
addedUsers[sUser.ID] = mUser
addedUsers[sUser.Id] = mUser
importerLog.WriteString(i18n.T("api.slackimport.slack_add_users.email_pwd", map[string]interface{}{"Email": newUser.Email, "Password": password}))
}
return addedUsers
}
func (si *SlackImporter) slackAddBotUser(teamID string, log *bytes.Buffer) *model.User {
team, err := si.store.Team().Get(teamID)
func (si *SlackImporter) slackAddBotUser(teamId string, log *bytes.Buffer) *model.User {
team, err := si.store.Team().Get(teamId)
if err != nil {
log.WriteString(i18n.T("api.slackimport.slack_import.team_fail"))
return nil
@@ -292,7 +292,7 @@ func (si *SlackImporter) slackAddBotUser(teamID string, log *bytes.Buffer) *mode
return mUser
}
func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, posts []slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User) {
func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, posts []slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User) {
sort.Slice(posts, func(i, j int) bool {
return slackConvertTimeStamp(posts[i].TimeStamp) < slackConvertTimeStamp(posts[j].TimeStamp)
})
@@ -316,12 +316,12 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
}
if sPost.Upload {
if sPost.File != nil {
if fileInfo, ok := si.slackUploadFile(sPost.File, uploads, teamID, newPost.ChannelId, newPost.UserId, sPost.TimeStamp); ok {
if fileInfo, ok := si.slackUploadFile(sPost.File, uploads, teamId, newPost.ChannelId, newPost.UserId, sPost.TimeStamp); ok {
newPost.FileIds = append(newPost.FileIds, fileInfo.Id)
}
} else if sPost.Files != nil {
for _, file := range sPost.Files {
if fileInfo, ok := si.slackUploadFile(file, uploads, teamID, newPost.ChannelId, newPost.UserId, sPost.TimeStamp); ok {
if fileInfo, ok := si.slackUploadFile(file, uploads, teamId, newPost.ChannelId, newPost.UserId, sPost.TimeStamp); ok {
newPost.FileIds = append(newPost.FileIds, fileInfo.Id)
}
}
@@ -332,10 +332,10 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
newPost.RootId = threads[sPost.ThreadTS]
newPost.ParentId = threads[sPost.ThreadTS]
}
postID := si.oldImportPost(&newPost)
postId := si.oldImportPost(&newPost)
// If post is thread starter
if sPost.ThreadTS == sPost.TimeStamp {
threads[sPost.ThreadTS] = postID
threads[sPost.ThreadTS] = postId
}
case sPost.Type == "message" && sPost.SubType == "file_comment":
if sPost.Comment == nil {
@@ -362,7 +362,7 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
mlog.Warn("Slack Import: Unable to import the bot message as the bot user does not exist.")
continue
}
if sPost.BotID == "" {
if sPost.BotId == "" {
mlog.Warn("Slack Import: Unable to import bot message as the BotId field is missing.")
continue
}
@@ -381,10 +381,10 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
Type: model.POST_SLACK_ATTACHMENT,
}
postID := si.oldImportIncomingWebhookPost(post, props)
postId := si.oldImportIncomingWebhookPost(post, props)
// If post is thread starter
if sPost.ThreadTS == sPost.TimeStamp {
threads[sPost.ThreadTS] = postID
threads[sPost.ThreadTS] = postId
}
case sPost.Type == "message" && (sPost.SubType == "channel_join" || sPost.SubType == "channel_leave"):
if sPost.User == "" {
@@ -429,10 +429,10 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
Message: "*" + sPost.Text + "*",
CreateAt: slackConvertTimeStamp(sPost.TimeStamp),
}
postID := si.oldImportPost(&newPost)
postId := si.oldImportPost(&newPost)
// If post is thread starter
if sPost.ThreadTS == sPost.TimeStamp {
threads[sPost.ThreadTS] = postID
threads[sPost.ThreadTS] = postId
}
case sPost.Type == "message" && sPost.SubType == "channel_topic":
if sPost.User == "" {
@@ -495,27 +495,27 @@ func (si *SlackImporter) slackAddPosts(teamID string, channel *model.Channel, po
}
}
func (si *SlackImporter) slackUploadFile(slackPostFile *slackFile, uploads map[string]*zip.File, teamID string, channelID string, userID string, slackTimestamp string) (*model.FileInfo, bool) {
func (si *SlackImporter) slackUploadFile(slackPostFile *slackFile, uploads map[string]*zip.File, teamId string, channelId string, userId string, slackTimestamp string) (*model.FileInfo, bool) {
if slackPostFile == nil {
mlog.Warn("Slack Import: Unable to attach the file to the post as the latter has no file section present in Slack export.")
return nil, false
}
file, ok := uploads[slackPostFile.ID]
file, ok := uploads[slackPostFile.Id]
if !ok {
mlog.Warn("Slack Import: Unable to import file as the file is missing from the Slack export zip file.", mlog.String("file_id", slackPostFile.ID))
mlog.Warn("Slack Import: Unable to import file as the file is missing from the Slack export zip file.", mlog.String("file_id", slackPostFile.Id))
return nil, false
}
openFile, err := file.Open()
if err != nil {
mlog.Warn("Slack Import: Unable to open the file from the Slack export.", mlog.String("file_id", slackPostFile.ID), mlog.Err(err))
mlog.Warn("Slack Import: Unable to open the file from the Slack export.", mlog.String("file_id", slackPostFile.Id), mlog.Err(err))
return nil, false
}
defer openFile.Close()
timestamp := utils.TimeFromMillis(slackConvertTimeStamp(slackTimestamp))
uploadedFile, err := si.oldImportFile(timestamp, openFile, teamID, channelID, userID, filepath.Base(file.Name))
uploadedFile, err := si.oldImportFile(timestamp, openFile, teamId, channelId, userId, filepath.Base(file.Name))
if err != nil {
mlog.Warn("Slack Import: An error occurred when uploading file.", mlog.String("file_id", slackPostFile.ID), mlog.Err(err))
mlog.Warn("Slack Import: An error occurred when uploading file.", mlog.String("file_id", slackPostFile.Id), mlog.Err(err))
return nil, false
}
@@ -565,7 +565,7 @@ func slackSanitiseChannelProperties(channel model.Channel) model.Channel {
return channel
}
func (si *SlackImporter) slackAddChannels(teamID string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackChannel, posts map[string][]slackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
// Write Header
importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.added"))
importerLog.WriteString("=================\r\n\r\n")
@@ -573,27 +573,27 @@ func (si *SlackImporter) slackAddChannels(teamID string, slackchannels []slackCh
addedChannels := make(map[string]*model.Channel)
for _, sChannel := range slackchannels {
newChannel := model.Channel{
TeamId: teamID,
TeamId: teamId,
Type: sChannel.Type,
DisplayName: sChannel.Name,
Name: slackConvertChannelName(sChannel.Name, sChannel.ID),
Name: slackConvertChannelName(sChannel.Name, sChannel.Id),
Purpose: sChannel.Purpose.Value,
Header: sChannel.Topic.Value,
}
// Direct message channels in Slack don't have a name so we set the id as name or else the messages won't get imported.
if newChannel.Type == model.CHANNEL_DIRECT {
sChannel.Name = sChannel.ID
sChannel.Name = sChannel.Id
}
newChannel = slackSanitiseChannelProperties(newChannel)
var mChannel *model.Channel
var err error
if mChannel, err = si.store.Channel().GetByName(teamID, sChannel.Name, true); err == nil {
if mChannel, err = si.store.Channel().GetByName(teamId, sChannel.Name, true); err == nil {
// The channel already exists as an active channel. Merge with the existing one.
importerLog.WriteString(i18n.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
} else if _, nErr := si.store.Channel().GetDeletedByName(teamID, sChannel.Name); nErr == nil {
} else if _, nErr := si.store.Channel().GetDeletedByName(teamId, sChannel.Name); nErr == nil {
// The channel already exists but has been deleted. Generate a random string for the handle instead.
newChannel.Name = model.NewId()
newChannel = slackSanitiseChannelProperties(newChannel)
@@ -614,8 +614,8 @@ func (si *SlackImporter) slackAddChannels(teamID string, slackchannels []slackCh
si.addSlackUsersToChannel(sChannel.Members, users, mChannel, importerLog)
}
importerLog.WriteString(newChannel.DisplayName + "\r\n")
addedChannels[sChannel.ID] = mChannel
si.slackAddPosts(teamID, mChannel, posts[sChannel.Name], users, uploads, botUser)
addedChannels[sChannel.Id] = mChannel
si.slackAddPosts(teamId, mChannel, posts[sChannel.Name], users, uploads, botUser)
}
return addedChannels
@@ -630,9 +630,9 @@ func (si *SlackImporter) slackAddChannels(teamID string, slackchannels []slackCh
func (si *SlackImporter) oldImportPost(post *model.Post) string {
// Workaround for empty messages, which may be the case if they are webhook posts.
firstIteration := true
firstpostID := ""
firstPostId := ""
if post.ParentId != "" {
firstpostID = post.ParentId
firstPostId = post.ParentId
}
maxPostSize := si.actions.MaxPostSize()
for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0 || firstIteration; messageRuneCount = utf8.RuneCountInString(post.Message) {
@@ -646,8 +646,8 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
post.Hashtags, _ = model.ParseHashtags(post.Message)
post.RootId = firstpostID
post.ParentId = firstpostID
post.RootId = firstPostId
post.ParentId = firstPostId
_, err := si.store.Post().Save(post)
if err != nil {
@@ -655,11 +655,11 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
}
if firstIteration {
if firstpostID == "" {
firstpostID = post.Id
if firstPostId == "" {
firstPostId = post.Id
}
for _, fileID := range post.FileIds {
if err := si.store.FileInfo().AttachToPost(fileID, post.Id, post.UserId); err != nil {
for _, fileId := range post.FileIds {
if err := si.store.FileInfo().AttachToPost(fileId, post.Id, post.UserId); err != nil {
mlog.Error(
"Error attaching files to post.",
mlog.String("post_id", post.Id),
@@ -677,7 +677,7 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
post.Message = remainder
firstIteration = false
}
return firstpostID
return firstPostId
}
func (si *SlackImporter) oldImportUser(team *model.Team, user *model.User) *model.User {
@@ -761,12 +761,12 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
return sc
}
func (si *SlackImporter) oldImportFile(timestamp time.Time, file io.Reader, teamID string, channelID string, userID string, fileName string) (*model.FileInfo, error) {
func (si *SlackImporter) oldImportFile(timestamp time.Time, file io.Reader, teamId string, channelId string, userId string, fileName string) (*model.FileInfo, error) {
buf := bytes.NewBuffer(nil)
io.Copy(buf, file)
data := buf.Bytes()
fileInfo, err := si.actions.DoUploadFile(timestamp, teamID, channelID, userID, fileName, data)
fileInfo, err := si.actions.DoUploadFile(timestamp, teamId, channelId, userId, fileName, data)
if err != nil {
return nil, err
}

Просмотреть файл

@@ -38,8 +38,8 @@ func TestSlackConvertChannelName(t *testing.T) {
func TestSlackConvertUserMentions(t *testing.T) {
users := []slackUser{
{ID: "U00000A0A", Username: "firstuser"},
{ID: "U00000B1B", Username: "seconduser"},
{Id: "U00000A0A", Username: "firstuser"},
{Id: "U00000B1B", Username: "seconduser"},
}
posts := map[string][]slackPost{
@@ -81,8 +81,8 @@ func TestSlackConvertUserMentions(t *testing.T) {
func TestSlackConvertChannelMentions(t *testing.T) {
channels := []slackChannel{
{ID: "C000AA00A", Name: "one"},
{ID: "C000BB11B", Name: "two"},
{Id: "C000AA00A", Name: "one"},
{Id: "C000BB11B", Name: "two"},
}
posts := map[string][]slackPost{
@@ -336,7 +336,7 @@ func TestOldImportChannel(t *testing.T) {
u2.Id: u2,
}
sCh := slackChannel{
ID: "someid",
Id: "someid",
Members: []string{u1.Id, "randomID"},
Creator: "randomID2",
}
@@ -356,7 +356,7 @@ func TestOldImportChannel(t *testing.T) {
u1.Id: u1,
}
sCh := slackChannel{
ID: "someid",
Id: "someid",
Members: []string{u1.Id},
Creator: "randomID2",
}
@@ -376,7 +376,7 @@ func TestOldImportChannel(t *testing.T) {
u1.Id: u1,
}
sCh := slackChannel{
ID: "someid",
Id: "someid",
Members: []string{u1.Id},
Creator: "randomID2",
}