[MM-16751] golint model (#17896)
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
953eebdef4
Коммит
97ccf0bdf6
@@ -143,16 +143,16 @@ func (si *SlackImporter) SlackImport(fileData multipart.File, fileSize int64, te
|
||||
return model.NewAppError("SlackImport", "api.slackimport.slack_import.open.app_error", map[string]interface{}{"Filename": file.Name}, err.Error(), http.StatusInternalServerError), log
|
||||
}
|
||||
if file.Name == "channels.json" {
|
||||
publicChannels, _ = slackParseChannels(reader, model.CHANNEL_OPEN)
|
||||
publicChannels, _ = slackParseChannels(reader, model.ChannelTypeOpen)
|
||||
channels = append(channels, publicChannels...)
|
||||
} else if file.Name == "dms.json" {
|
||||
directChannels, _ = slackParseChannels(reader, model.CHANNEL_DIRECT)
|
||||
directChannels, _ = slackParseChannels(reader, model.ChannelTypeDirect)
|
||||
channels = append(channels, directChannels...)
|
||||
} else if file.Name == "groups.json" {
|
||||
privateChannels, _ = slackParseChannels(reader, model.CHANNEL_PRIVATE)
|
||||
privateChannels, _ = slackParseChannels(reader, model.ChannelTypePrivate)
|
||||
channels = append(channels, privateChannels...)
|
||||
} else if file.Name == "mpims.json" {
|
||||
groupChannels, _ = slackParseChannels(reader, model.CHANNEL_GROUP)
|
||||
groupChannels, _ = slackParseChannels(reader, model.ChannelTypeGroup)
|
||||
channels = append(channels, groupChannels...)
|
||||
} else if file.Name == "users.json" {
|
||||
users, _ = slackParseUsers(reader)
|
||||
@@ -378,7 +378,7 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
|
||||
ChannelId: channel.Id,
|
||||
CreateAt: slackConvertTimeStamp(sPost.TimeStamp),
|
||||
Message: sPost.Text,
|
||||
Type: model.POST_SLACK_ATTACHMENT,
|
||||
Type: model.PostTypeSlackAttachment,
|
||||
}
|
||||
|
||||
postId := si.oldImportIncomingWebhookPost(post, props)
|
||||
@@ -398,9 +398,9 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
|
||||
|
||||
var postType string
|
||||
if sPost.SubType == "channel_join" {
|
||||
postType = model.POST_JOIN_CHANNEL
|
||||
postType = model.PostTypeJoinChannel
|
||||
} else {
|
||||
postType = model.POST_LEAVE_CHANNEL
|
||||
postType = model.PostTypeLeaveChannel
|
||||
}
|
||||
|
||||
newPost := model.Post{
|
||||
@@ -448,7 +448,7 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
|
||||
ChannelId: channel.Id,
|
||||
Message: sPost.Text,
|
||||
CreateAt: slackConvertTimeStamp(sPost.TimeStamp),
|
||||
Type: model.POST_HEADER_CHANGE,
|
||||
Type: model.PostTypeHeaderChange,
|
||||
}
|
||||
si.oldImportPost(&newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "channel_purpose":
|
||||
@@ -465,7 +465,7 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
|
||||
ChannelId: channel.Id,
|
||||
Message: sPost.Text,
|
||||
CreateAt: slackConvertTimeStamp(sPost.TimeStamp),
|
||||
Type: model.POST_PURPOSE_CHANGE,
|
||||
Type: model.PostTypePurposeChange,
|
||||
}
|
||||
si.oldImportPost(&newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "channel_name":
|
||||
@@ -482,7 +482,7 @@ func (si *SlackImporter) slackAddPosts(teamId string, channel *model.Channel, po
|
||||
ChannelId: channel.Id,
|
||||
Message: sPost.Text,
|
||||
CreateAt: slackConvertTimeStamp(sPost.TimeStamp),
|
||||
Type: model.POST_DISPLAYNAME_CHANGE,
|
||||
Type: model.PostTypeDisplaynameChange,
|
||||
}
|
||||
si.oldImportPost(&newPost)
|
||||
default:
|
||||
@@ -542,24 +542,24 @@ func (si *SlackImporter) addSlackUsersToChannel(members []string, users map[stri
|
||||
}
|
||||
|
||||
func slackSanitiseChannelProperties(channel model.Channel) model.Channel {
|
||||
if utf8.RuneCountInString(channel.DisplayName) > model.CHANNEL_DISPLAY_NAME_MAX_RUNES {
|
||||
if utf8.RuneCountInString(channel.DisplayName) > model.ChannelDisplayNameMaxRunes {
|
||||
mlog.Warn("Slack Import: Channel display name exceeds the maximum length. It will be truncated when imported.", mlog.String("channel_display_name", channel.DisplayName))
|
||||
channel.DisplayName = truncateRunes(channel.DisplayName, model.CHANNEL_DISPLAY_NAME_MAX_RUNES)
|
||||
channel.DisplayName = truncateRunes(channel.DisplayName, model.ChannelDisplayNameMaxRunes)
|
||||
}
|
||||
|
||||
if len(channel.Name) > model.CHANNEL_NAME_MAX_LENGTH {
|
||||
if len(channel.Name) > model.ChannelNameMaxLength {
|
||||
mlog.Warn("Slack Import: Channel handle exceeds the maximum length. It will be truncated when imported.", mlog.String("channel_display_name", channel.DisplayName))
|
||||
channel.Name = channel.Name[0:model.CHANNEL_NAME_MAX_LENGTH]
|
||||
channel.Name = channel.Name[0:model.ChannelNameMaxLength]
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(channel.Purpose) > model.CHANNEL_PURPOSE_MAX_RUNES {
|
||||
if utf8.RuneCountInString(channel.Purpose) > model.ChannelPurposeMaxRunes {
|
||||
mlog.Warn("Slack Import: Channel purpose exceeds the maximum length. It will be truncated when imported.", mlog.String("channel_display_name", channel.DisplayName))
|
||||
channel.Purpose = truncateRunes(channel.Purpose, model.CHANNEL_PURPOSE_MAX_RUNES)
|
||||
channel.Purpose = truncateRunes(channel.Purpose, model.ChannelPurposeMaxRunes)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(channel.Header) > model.CHANNEL_HEADER_MAX_RUNES {
|
||||
if utf8.RuneCountInString(channel.Header) > model.ChannelHeaderMaxRunes {
|
||||
mlog.Warn("Slack Import: Channel header exceeds the maximum length. It will be truncated when imported.", mlog.String("channel_display_name", channel.DisplayName))
|
||||
channel.Header = truncateRunes(channel.Header, model.CHANNEL_HEADER_MAX_RUNES)
|
||||
channel.Header = truncateRunes(channel.Header, model.ChannelHeaderMaxRunes)
|
||||
}
|
||||
|
||||
return channel
|
||||
@@ -582,7 +582,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if newChannel.Type == model.ChannelTypeDirect {
|
||||
sChannel.Name = sChannel.Id
|
||||
}
|
||||
|
||||
@@ -610,7 +610,7 @@ func (si *SlackImporter) slackAddChannels(teamId string, slackchannels []slackCh
|
||||
}
|
||||
|
||||
// Members for direct and group channels are added during the creation of the channel in the oldImportChannel function
|
||||
if sChannel.Type == model.CHANNEL_OPEN || sChannel.Type == model.CHANNEL_PRIVATE {
|
||||
if sChannel.Type == model.ChannelTypeOpen || sChannel.Type == model.ChannelTypePrivate {
|
||||
si.addSlackUsersToChannel(sChannel.Members, users, mChannel, importerLog)
|
||||
}
|
||||
importerLog.WriteString(newChannel.DisplayName + "\r\n")
|
||||
@@ -683,7 +683,7 @@ func (si *SlackImporter) oldImportPost(post *model.Post) string {
|
||||
func (si *SlackImporter) oldImportUser(team *model.Team, user *model.User) *model.User {
|
||||
user.MakeNonNil()
|
||||
|
||||
user.Roles = model.SYSTEM_USER_ROLE_ID
|
||||
user.Roles = model.SystemUserRoleId
|
||||
|
||||
ruser, nErr := si.store.User().Save(user)
|
||||
if nErr != nil {
|
||||
@@ -704,7 +704,7 @@ func (si *SlackImporter) oldImportUser(team *model.Team, user *model.User) *mode
|
||||
|
||||
func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slackChannel, users map[string]*model.User) *model.Channel {
|
||||
switch {
|
||||
case channel.Type == model.CHANNEL_DIRECT:
|
||||
case channel.Type == model.ChannelTypeDirect:
|
||||
if len(sChannel.Members) < 2 {
|
||||
return nil
|
||||
}
|
||||
@@ -721,7 +721,7 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
|
||||
|
||||
return sc
|
||||
// check if direct channel has less than 8 members and if not import as private channel instead
|
||||
case channel.Type == model.CHANNEL_GROUP && len(sChannel.Members) < 8:
|
||||
case channel.Type == model.ChannelTypeGroup && len(sChannel.Members) < 8:
|
||||
members := make([]string, len(sChannel.Members))
|
||||
|
||||
for i := range sChannel.Members {
|
||||
@@ -743,8 +743,8 @@ func (si *SlackImporter) oldImportChannel(channel *model.Channel, sChannel slack
|
||||
}
|
||||
|
||||
return sc
|
||||
case channel.Type == model.CHANNEL_GROUP:
|
||||
channel.Type = model.CHANNEL_PRIVATE
|
||||
case channel.Type == model.ChannelTypeGroup:
|
||||
channel.Type = model.ChannelTypePrivate
|
||||
sc, err := si.actions.CreateChannel(channel, false)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -791,7 +791,7 @@ func (si *SlackImporter) oldImportIncomingWebhookPost(post *model.Post, props mo
|
||||
post.AddProp("from_webhook", "true")
|
||||
|
||||
if _, ok := props["override_username"]; !ok {
|
||||
post.AddProp("override_username", model.DEFAULT_WEBHOOK_USERNAME)
|
||||
post.AddProp("override_username", model.DefaultWebhookUsername)
|
||||
}
|
||||
|
||||
if len(props) > 0 {
|
||||
|
||||
@@ -329,7 +329,7 @@ func TestOldImportChannel(t *testing.T) {
|
||||
t.Run("No panic on direct channel", func(t *testing.T) {
|
||||
//ch := th.CreateDmChannel(u1)
|
||||
ch := &model.Channel{
|
||||
Type: model.CHANNEL_DIRECT,
|
||||
Type: model.ChannelTypeDirect,
|
||||
Name: "test-channel",
|
||||
}
|
||||
users := map[string]*model.User{
|
||||
@@ -349,7 +349,7 @@ func TestOldImportChannel(t *testing.T) {
|
||||
|
||||
t.Run("No panic on direct channel with 1 member", func(t *testing.T) {
|
||||
ch := &model.Channel{
|
||||
Type: model.CHANNEL_DIRECT,
|
||||
Type: model.ChannelTypeDirect,
|
||||
Name: "test-channel",
|
||||
}
|
||||
users := map[string]*model.User{
|
||||
@@ -369,7 +369,7 @@ func TestOldImportChannel(t *testing.T) {
|
||||
|
||||
t.Run("No panic on group channel", func(t *testing.T) {
|
||||
ch := &model.Channel{
|
||||
Type: model.CHANNEL_GROUP,
|
||||
Type: model.ChannelTypeGroup,
|
||||
Name: "test-channel",
|
||||
}
|
||||
users := map[string]*model.User{
|
||||
|
||||
Ссылка в новой задаче
Block a user