Improves notify props validation (#24031)

* Adds the channel member notify props max runes restriction

* Fix translations
Этот коммит содержится в:
Miguel de la Cruz
2023-07-18 17:25:11 +02:00
коммит произвёл GitHub
родитель 3c31629813
Коммит 4803889158
7 изменённых файлов: 97 добавлений и 16 удалений

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

@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
sq "github.com/mattermost/squirrel"
"github.com/pkg/errors"
@@ -1916,10 +1917,15 @@ func (s SqlChannelStore) UpdateMemberNotifyProps(channelID, userID string, props
}
defer finalizeTransactionX(tx, &err)
jsonNotifyProps := model.MapToJSON(props)
if utf8.RuneCountInString(jsonNotifyProps) > model.ChannelMemberNotifyPropsMaxRunes {
return nil, store.NewErrInvalidInput("ChannelMember", "NotifyProps", props)
}
if s.DriverName() == model.DatabaseDriverPostgres {
sql, args, err2 := s.getQueryBuilder().
Update("channelmembers").
Set("notifyprops", sq.Expr("notifyprops || ?::jsonb", model.MapToJSON(props))).
Set("notifyprops", sq.Expr("notifyprops || ?::jsonb", jsonNotifyProps)).
Where(sq.Eq{
"userid": userID,
"channelid": channelID,