Improves notify props validation (#24031)
* Adds the channel member notify props max runes restriction * Fix translations
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3c31629813
Коммит
4803889158
@@ -6,22 +6,24 @@ package model
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
ChannelNotifyDefault = "default"
|
||||
ChannelNotifyAll = "all"
|
||||
ChannelNotifyMention = "mention"
|
||||
ChannelNotifyNone = "none"
|
||||
ChannelMarkUnreadAll = "all"
|
||||
ChannelMarkUnreadMention = "mention"
|
||||
IgnoreChannelMentionsDefault = "default"
|
||||
IgnoreChannelMentionsOff = "off"
|
||||
IgnoreChannelMentionsOn = "on"
|
||||
IgnoreChannelMentionsNotifyProp = "ignore_channel_mentions"
|
||||
ChannelAutoFollowThreadsOff = "off"
|
||||
ChannelAutoFollowThreadsOn = "on"
|
||||
ChannelAutoFollowThreads = "channel_auto_follow_threads"
|
||||
ChannelNotifyDefault = "default"
|
||||
ChannelNotifyAll = "all"
|
||||
ChannelNotifyMention = "mention"
|
||||
ChannelNotifyNone = "none"
|
||||
ChannelMarkUnreadAll = "all"
|
||||
ChannelMarkUnreadMention = "mention"
|
||||
IgnoreChannelMentionsDefault = "default"
|
||||
IgnoreChannelMentionsOff = "off"
|
||||
IgnoreChannelMentionsOn = "on"
|
||||
IgnoreChannelMentionsNotifyProp = "ignore_channel_mentions"
|
||||
ChannelAutoFollowThreadsOff = "off"
|
||||
ChannelAutoFollowThreadsOn = "on"
|
||||
ChannelAutoFollowThreads = "channel_auto_follow_threads"
|
||||
ChannelMemberNotifyPropsMaxRunes = 800000
|
||||
)
|
||||
|
||||
type ChannelUnread struct {
|
||||
@@ -186,6 +188,11 @@ func (o *ChannelMember) IsValid() *AppError {
|
||||
map[string]any{"Limit": UserRolesMaxLength}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
jsonStringNotifyProps := string(ToJSON(o.NotifyProps))
|
||||
if utf8.RuneCountInString(jsonStringNotifyProps) > ChannelMemberNotifyPropsMaxRunes {
|
||||
return NewAppError("ChannelMember.IsValid", "model.channel_member.is_valid.notify_props.app_error", nil, "channel_id="+o.ChannelId+" user_id="+o.UserId, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -37,4 +38,7 @@ func TestChannelMemberIsValid(t *testing.T) {
|
||||
|
||||
o.Roles = ""
|
||||
require.Nil(t, o.IsValid(), "should be invalid")
|
||||
|
||||
o.NotifyProps["property"] = strings.Repeat("Z", ChannelMemberNotifyPropsMaxRunes)
|
||||
require.NotNil(t, o.IsValid(), "should be invalid")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user