Fixed MM-14627, was incorrectly removing props from updated post (#10545)
* Fixed MM-14627, was incorrectly removing props from updated post - Fixed the wrong initialization of `remove` - Consolidated the list of properties to retain in `model.PostActionRetainPropKeys` - Added a test * Not sure why this broke the test, reverted the change
Этот коммит содержится в:
@@ -36,7 +36,7 @@ func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) (str
|
|||||||
|
|
||||||
func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError) {
|
func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption string, cookie *model.PostActionCookie) (string, *model.AppError) {
|
||||||
// the prop values that we need to retain/clear in replacement message to match the original
|
// the prop values that we need to retain/clear in replacement message to match the original
|
||||||
remove := []string{"override_username", "override_icon_url"}
|
remove := []string{}
|
||||||
retain := map[string]interface{}{}
|
retain := map[string]interface{}{}
|
||||||
datasource := ""
|
datasource := ""
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ func (a *App) DoPostActionWithCookie(postId, actionId, userId, selectedOption st
|
|||||||
upstreamRequest.Context = action.Integration.Context
|
upstreamRequest.Context = action.Integration.Context
|
||||||
datasource = action.DataSource
|
datasource = action.DataSource
|
||||||
|
|
||||||
retainPropKeys := []string{"override_username", "override_icon_url"}
|
// Set override_username, override_icon_ur to what they were before.
|
||||||
for _, key := range retainPropKeys {
|
for _, key := range model.PostActionRetainPropKeys {
|
||||||
value, ok := post.Props[key]
|
value, ok := post.Props[key]
|
||||||
if ok {
|
if ok {
|
||||||
retain[key] = value
|
retain[key] = value
|
||||||
|
|||||||
@@ -310,6 +310,82 @@ func TestPostAction(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostActionProps(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
|
||||||
|
})
|
||||||
|
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
request := model.PostActionIntegrationRequestFromJson(r.Body)
|
||||||
|
assert.NotNil(t, request)
|
||||||
|
|
||||||
|
fmt.Fprintf(w, `{
|
||||||
|
"update": {
|
||||||
|
"message": "updated",
|
||||||
|
"props": {
|
||||||
|
"override_username":"new_override_user",
|
||||||
|
"override_icon_url":"new_override_icon",
|
||||||
|
"A":"AA"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ephemeral_text": "foo"
|
||||||
|
}`)
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
interactivePost := model.Post{
|
||||||
|
Message: "Interactive post",
|
||||||
|
ChannelId: th.BasicChannel.Id,
|
||||||
|
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"attachments": []*model.SlackAttachment{
|
||||||
|
{
|
||||||
|
Text: "hello",
|
||||||
|
Actions: []*model.PostAction{
|
||||||
|
{
|
||||||
|
Integration: &model.PostActionIntegration{
|
||||||
|
Context: model.StringInterface{
|
||||||
|
"s": "foo",
|
||||||
|
"n": 3,
|
||||||
|
},
|
||||||
|
URL: ts.URL,
|
||||||
|
},
|
||||||
|
Name: "action",
|
||||||
|
Type: "some_type",
|
||||||
|
DataSource: "some_source",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"override_icon_url": "old_override_icon",
|
||||||
|
"B": "BB",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
post, err := th.App.CreatePostAsUser(&interactivePost, "")
|
||||||
|
require.Nil(t, err)
|
||||||
|
attachments, ok := post.Props["attachments"].([]*model.SlackAttachment)
|
||||||
|
require.True(t, ok)
|
||||||
|
|
||||||
|
clientTriggerId, err := th.App.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id, "")
|
||||||
|
require.Nil(t, err)
|
||||||
|
assert.True(t, len(clientTriggerId) == 26)
|
||||||
|
|
||||||
|
pchan := th.App.Srv.Store.Post().GetSingle(post.Id)
|
||||||
|
result := <-pchan
|
||||||
|
require.Nil(t, result.Err)
|
||||||
|
newPost := result.Data.(*model.Post)
|
||||||
|
|
||||||
|
assert.Nil(t, newPost.Props["B"])
|
||||||
|
assert.Nil(t, newPost.Props["override_username"])
|
||||||
|
assert.Equal(t, "AA", newPost.Props["A"])
|
||||||
|
assert.Equal(t, "old_override_icon", newPost.Props["override_icon_url"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestSubmitInteractiveDialog(t *testing.T) {
|
func TestSubmitInteractiveDialog(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ const (
|
|||||||
INTERACTIVE_DIALOG_TRIGGER_TIMEOUT_MILLISECONDS = 3000
|
INTERACTIVE_DIALOG_TRIGGER_TIMEOUT_MILLISECONDS = 3000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var PostActionRetainPropKeys = []string{"override_username", "override_icon_url"}
|
||||||
|
|
||||||
type DoPostActionRequest struct {
|
type DoPostActionRequest struct {
|
||||||
SelectedOption string `json:"selected_option,omitempty"`
|
SelectedOption string `json:"selected_option,omitempty"`
|
||||||
Cookie string `json:"cookie,omitempty"`
|
Cookie string `json:"cookie,omitempty"`
|
||||||
@@ -327,10 +329,9 @@ func AddPostActionCookies(o *Post, secret []byte) *Post {
|
|||||||
p := o.Clone()
|
p := o.Clone()
|
||||||
|
|
||||||
// retainedProps carry over their value from the old post, including no value
|
// retainedProps carry over their value from the old post, including no value
|
||||||
retainPropKeys := []string{"override_username", "override_icon_url"}
|
|
||||||
retainProps := map[string]interface{}{}
|
retainProps := map[string]interface{}{}
|
||||||
removeProps := []string{}
|
removeProps := []string{}
|
||||||
for _, key := range retainPropKeys {
|
for _, key := range PostActionRetainPropKeys {
|
||||||
value, ok := p.Props[key]
|
value, ok := p.Props[key]
|
||||||
if ok {
|
if ok {
|
||||||
retainProps[key] = value
|
retainProps[key] = value
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user