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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f1d5884532
Коммит
8b86e1276e
@@ -9277,8 +9277,8 @@
|
|||||||
"translation": "Invalid file ids."
|
"translation": "Invalid file ids."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.draft.is_valid.msg.app_error",
|
"id": "model.draft.is_valid.message_length.app_error",
|
||||||
"translation": "Invalid message."
|
"translation": "Draft Message property is longer than the maximum permitted length."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.draft.is_valid.priority.app_error",
|
"id": "model.draft.is_valid.priority.app_error",
|
||||||
@@ -9729,8 +9729,8 @@
|
|||||||
"translation": "Invalid Id."
|
"translation": "Invalid Id."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.post.is_valid.msg.app_error",
|
"id": "model.post.is_valid.message_length.app_error",
|
||||||
"translation": "Invalid message."
|
"translation": "Post Message property is longer than the maximum permitted length."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.post.is_valid.original_id.app_error",
|
"id": "model.post.is_valid.original_id.app_error",
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ type Draft struct {
|
|||||||
|
|
||||||
func (o *Draft) IsValid(maxDraftSize int) *AppError {
|
func (o *Draft) IsValid(maxDraftSize int) *AppError {
|
||||||
if utf8.RuneCountInString(o.Message) > maxDraftSize {
|
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()
|
return o.BaseIsValid()
|
||||||
|
|||||||
@@ -437,7 +437,8 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if utf8.RuneCountInString(o.Message) > maxPostSize {
|
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 {
|
if utf8.RuneCountInString(o.Hashtags) > PostHashtagsMaxRunes {
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ func TestPostIsValid(t *testing.T) {
|
|||||||
appErr = o.IsValid(maxPostSize)
|
appErr = o.IsValid(maxPostSize)
|
||||||
require.NotNil(t, appErr)
|
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)
|
o.Message = strings.Repeat("0", maxPostSize)
|
||||||
appErr = o.IsValid(maxPostSize)
|
appErr = o.IsValid(maxPostSize)
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user