[MM-62427] Add message attachments validation (#30180)
* Add message attachments validation * Add props validation * Validate slack attachment fields * Update tests and library usage * Improve interactive dialog error for length checks * Allow predefined colors for slack attachments * Fix TestPostAction * Use const for data source * Add tests * Cleanup unused props * Add happy path tests * lint fixes * Add validation for PostActionOptions
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5609489e86
Коммит
9b5d8d52bf
@@ -147,7 +147,7 @@ func newSqlPostStore(sqlStore *SqlStore, metrics einterfaces.MetricsInterface) s
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, error) {
|
||||
func (s *SqlPostStore) SaveMultiple(rctx request.CTX, posts []*model.Post) ([]*model.Post, int, error) {
|
||||
channelNewPosts := make(map[string]int)
|
||||
channelNewRootPosts := make(map[string]int)
|
||||
maxDateNewPosts := make(map[string]int64)
|
||||
@@ -160,9 +160,11 @@ func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, er
|
||||
}
|
||||
post.PreSave()
|
||||
maxPostSize := s.GetMaxPostSize()
|
||||
|
||||
if err := post.IsValid(maxPostSize); err != nil {
|
||||
return nil, idx, err
|
||||
}
|
||||
post.ValidateProps(rctx.Logger())
|
||||
|
||||
if currentChannelCount, ok := channelNewPosts[post.ChannelId]; !ok {
|
||||
if post.IsJoinLeaveMessage() {
|
||||
@@ -293,7 +295,7 @@ func (s *SqlPostStore) SaveMultiple(posts []*model.Post) ([]*model.Post, int, er
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Save(rctx request.CTX, post *model.Post) (*model.Post, error) {
|
||||
posts, _, err := s.SaveMultiple([]*model.Post{post})
|
||||
posts, _, err := s.SaveMultiple(rctx, []*model.Post{post})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -356,6 +358,7 @@ func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *mo
|
||||
if err := newPost.IsValid(maxPostSize); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newPost.ValidateProps(rctx.Logger())
|
||||
|
||||
if _, err := s.GetMaster().NamedExec(`UPDATE Posts
|
||||
SET CreateAt=:CreateAt,
|
||||
@@ -409,14 +412,16 @@ func (s *SqlPostStore) Update(rctx request.CTX, newPost *model.Post, oldPost *mo
|
||||
return newPost, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) OverwriteMultiple(posts []*model.Post) (_ []*model.Post, _ int, err error) {
|
||||
func (s *SqlPostStore) OverwriteMultiple(rctx request.CTX, posts []*model.Post) (_ []*model.Post, _ int, err error) {
|
||||
updateAt := model.GetMillis()
|
||||
maxPostSize := s.GetMaxPostSize()
|
||||
for idx, post := range posts {
|
||||
post.UpdateAt = updateAt
|
||||
|
||||
if appErr := post.IsValid(maxPostSize); appErr != nil {
|
||||
return nil, idx, appErr
|
||||
}
|
||||
post.ValidateProps(rctx.Logger())
|
||||
}
|
||||
|
||||
tx, err := s.GetMaster().Beginx()
|
||||
@@ -464,7 +469,7 @@ func (s *SqlPostStore) OverwriteMultiple(posts []*model.Post) (_ []*model.Post,
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) Overwrite(rctx request.CTX, post *model.Post) (*model.Post, error) {
|
||||
posts, _, err := s.OverwriteMultiple([]*model.Post{post})
|
||||
posts, _, err := s.OverwriteMultiple(rctx, []*model.Post{post})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user