GH-27059: Rewrite error messages about msg length (#29252)

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Pavel Mokeev
2024-12-10 16:32:13 +03:00
коммит произвёл GitHub
родитель f1d5884532
Коммит 8b86e1276e
4 изменённых файлов: 13 добавлений и 6 удалений

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

@@ -9277,8 +9277,8 @@
"translation": "Invalid file ids."
},
{
"id": "model.draft.is_valid.msg.app_error",
"translation": "Invalid message."
"id": "model.draft.is_valid.message_length.app_error",
"translation": "Draft Message property is longer than the maximum permitted length."
},
{
"id": "model.draft.is_valid.priority.app_error",
@@ -9729,8 +9729,8 @@
"translation": "Invalid Id."
},
{
"id": "model.post.is_valid.msg.app_error",
"translation": "Invalid message."
"id": "model.post.is_valid.message_length.app_error",
"translation": "Post Message property is longer than the maximum permitted length."
},
{
"id": "model.post.is_valid.original_id.app_error",

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

@@ -28,7 +28,8 @@ type Draft struct {
func (o *Draft) IsValid(maxDraftSize int) *AppError {
if utf8.RuneCountInString(o.Message) > maxDraftSize {
return NewAppError("Drafts.IsValid", "model.draft.is_valid.msg.app_error", nil, "channelid="+o.ChannelId, http.StatusBadRequest)
return NewAppError("Drafts.IsValid", "model.draft.is_valid.message_length.app_error",
map[string]any{"Length": utf8.RuneCountInString(o.Message), "MaxLength": maxDraftSize}, "channelid="+o.ChannelId, http.StatusBadRequest)
}
return o.BaseIsValid()

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

@@ -437,7 +437,8 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
}
if utf8.RuneCountInString(o.Message) > maxPostSize {
return NewAppError("Post.IsValid", "model.post.is_valid.msg.app_error", nil, "id="+o.Id, http.StatusBadRequest)
return NewAppError("Post.IsValid", "model.post.is_valid.message_length.app_error",
map[string]any{"Length": utf8.RuneCountInString(o.Message), "MaxLength": maxPostSize}, "id="+o.Id, http.StatusBadRequest)
}
if utf8.RuneCountInString(o.Hashtags) > PostHashtagsMaxRunes {

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

@@ -59,6 +59,11 @@ func TestPostIsValid(t *testing.T) {
appErr = o.IsValid(maxPostSize)
require.NotNil(t, appErr)
// In case message property length is too long.
o.Message = strings.Repeat("0", maxPostSize+1)
appErr = o.IsValid(maxPostSize)
require.NotNil(t, appErr)
o.Message = strings.Repeat("0", maxPostSize)
appErr = o.IsValid(maxPostSize)
require.Nil(t, appErr)