[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
@@ -106,7 +106,7 @@ func TestDMWithAttachments(t *testing.T) {
|
||||
ChannelId: dmChannelID,
|
||||
Type: model.PostTypeSlackAttachment,
|
||||
Props: model.StringInterface{
|
||||
"attachments": attachments,
|
||||
model.PostPropsAttachments: attachments,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ func (f *Flow) handle(
|
||||
}
|
||||
|
||||
func (f *Flow) processButtonPostActions(post *model.Post) {
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
attachments, ok := post.GetProp(model.PostPropsAttachments).([]*model.SlackAttachment)
|
||||
if !ok || len(attachments) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func (s Step) render(f *Flow, done bool, selectedButton int) (*model.Post, bool,
|
||||
|
||||
buttons := processButtons(s.buttons, f.state.AppState)
|
||||
|
||||
attachments, ok := post.GetProp("attachments").([]*model.SlackAttachment)
|
||||
attachments, ok := post.GetProp(model.PostPropsAttachments).([]*model.SlackAttachment)
|
||||
if !ok || len(attachments) != 1 {
|
||||
return nil, false, errors.New("expected 1 slack attachment")
|
||||
}
|
||||
@@ -224,6 +224,7 @@ func processDialog(in *model.Dialog, state State) model.Dialog {
|
||||
|
||||
func renderButton(b Button, stepName Name, i int, state State) *model.PostAction {
|
||||
return &model.PostAction{
|
||||
Type: model.PostActionTypeButton,
|
||||
Name: formatState(b.Name, state),
|
||||
Disabled: b.Disabled,
|
||||
Style: string(b.Color),
|
||||
|
||||
@@ -75,6 +75,7 @@ func (s *boolSetting) GetSlackAttachments(userID, settingHandler string, disable
|
||||
currentValueMessage = fmt.Sprintf("Current value: %s", currentTextValue)
|
||||
|
||||
actionTrue := model.PostAction{
|
||||
Type: model.PostActionTypeButton,
|
||||
Name: "Yes",
|
||||
Integration: &model.PostActionIntegration{
|
||||
URL: settingHandler,
|
||||
@@ -86,6 +87,7 @@ func (s *boolSetting) GetSlackAttachments(userID, settingHandler string, disable
|
||||
}
|
||||
|
||||
actionFalse := model.PostAction{
|
||||
Type: model.PostActionTypeButton,
|
||||
Name: "No",
|
||||
Integration: &model.PostActionIntegration{
|
||||
URL: settingHandler,
|
||||
|
||||
@@ -62,6 +62,7 @@ func (s *optionSetting) GetSlackAttachments(userID, settingHandler string, disab
|
||||
currentValueMessage = fmt.Sprintf("Current value: %s", currentTextValue)
|
||||
|
||||
actionOptions := model.PostAction{
|
||||
Type: model.PostActionTypeSelect,
|
||||
Name: "Select an option:",
|
||||
Integration: &model.PostActionIntegration{
|
||||
URL: settingHandler + "?" + s.id + "=true",
|
||||
@@ -69,7 +70,6 @@ func (s *optionSetting) GetSlackAttachments(userID, settingHandler string, disab
|
||||
ContextIDKey: s.id,
|
||||
},
|
||||
},
|
||||
Type: "select",
|
||||
Options: stringsToOptions(s.options),
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user