Enforce channel display name limits on slash command (#7309)
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
ce77d836fc
Коммит
82a8bd99cc
@@ -53,6 +53,10 @@ func (me *RenameProvider) DoCommand(args *model.CommandArgs, message string) *mo
|
||||
|
||||
if len(message) == 0 {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.message.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else if len(message) > model.CHANNEL_NAME_UI_MAX_LENGTH {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.too_long.app_error", map[string]interface{}{"Length": len(message)}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
} else if len(message) < model.CHANNEL_NAME_MIN_LENGTH {
|
||||
return &model.CommandResponse{Text: args.T("api.command_channel_rename.too_short.app_error", map[string]interface{}{"Length": len(message)}), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
patch := &model.ChannelPatch{
|
||||
|
||||
31
app/command_channel_rename_test.go
Обычный файл
31
app/command_channel_rename_test.go
Обычный файл
@@ -0,0 +1,31 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRenameProviderDoCommand(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
rp := RenameProvider{}
|
||||
args := &model.CommandArgs{
|
||||
T: func(s string, args ...interface{}) string { return s },
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Session: model.Session{UserId: th.BasicUser.Id, TeamMembers: []*model.TeamMember{&model.TeamMember{TeamId: th.BasicTeam.Id, Roles: model.ROLE_TEAM_USER.Id}}},
|
||||
}
|
||||
|
||||
// Blank text is a success
|
||||
for msg, expected := range map[string]string{
|
||||
"": "api.command_channel_rename.message.app_error",
|
||||
"o": "api.command_channel_rename.too_short.app_error",
|
||||
"joram": "",
|
||||
"1234567890123456789012": "",
|
||||
"12345678901234567890123": "api.command_channel_rename.too_long.app_error",
|
||||
} {
|
||||
actual := rp.DoCommand(args, msg).Text
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
}
|
||||
@@ -583,6 +583,14 @@
|
||||
"id": "api.command_channel_rename.message.app_error",
|
||||
"translation": "A message must be provided with the /rename command."
|
||||
},
|
||||
{
|
||||
"id": "api.command_channel_rename.too_long.app_error",
|
||||
"translation": "Channel name must be {{.Length}} or fewer characters"
|
||||
},
|
||||
{
|
||||
"id": "api.command_channel_rename.too_short.app_error",
|
||||
"translation": "Channel name must be {{.Length}} or more characters"
|
||||
},
|
||||
{
|
||||
"id": "api.command_channel_rename.name",
|
||||
"translation": "rename"
|
||||
|
||||
@@ -24,6 +24,7 @@ const (
|
||||
CHANNEL_DISPLAY_NAME_MAX_RUNES = 64
|
||||
CHANNEL_NAME_MIN_LENGTH = 2
|
||||
CHANNEL_NAME_MAX_LENGTH = 64
|
||||
CHANNEL_NAME_UI_MAX_LENGTH = 22
|
||||
CHANNEL_HEADER_MAX_RUNES = 1024
|
||||
CHANNEL_PURPOSE_MAX_RUNES = 250
|
||||
CHANNEL_CACHE_SIZE = 25000
|
||||
|
||||
Ссылка в новой задаче
Block a user