diff options
author | Hanzei <Hanzei@users.noreply.github.com> | 2018-09-19 14:39:37 +0200 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-09-19 08:39:36 -0400 |
commit | 1463df21a57290f8c74fe4ad58deffb111b9f79e (patch) | |
tree | 501598bb152ef80f6e70317781c1b29350dc4c70 | |
parent | 0204c45b7ac308d31c1d4249a2dc92fd44d76aec (diff) | |
download | chat-1463df21a57290f8c74fe4ad58deffb111b9f79e.tar.gz chat-1463df21a57290f8c74fe4ad58deffb111b9f79e.tar.bz2 chat-1463df21a57290f8c74fe4ad58deffb111b9f79e.zip |
Add ChannelId and TeamId to PostActionIntegrationRequest (#9384)
* Add ChannelId and TeamId to PostActionIntegrationRequest
* Add tests
-rw-r--r-- | app/post.go | 18 | ||||
-rw-r--r-- | app/post_test.go | 9 | ||||
-rw-r--r-- | model/post.go | 2 |
3 files changed, 21 insertions, 8 deletions
diff --git a/app/post.go b/app/post.go index a36e9709f..9914f6db0 100644 --- a/app/post.go +++ b/app/post.go @@ -840,16 +840,26 @@ func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) *mod post = result.Data.(*model.Post) } + cchan := a.Srv.Store.Channel().GetForPost(postId) + var channel *model.Channel + if result := <-cchan; result.Err != nil { + return result.Err + } else { + channel = result.Data.(*model.Channel) + } + action := post.GetAction(actionId) if action == nil || action.Integration == nil { return model.NewAppError("DoPostAction", "api.post.do_action.action_id.app_error", nil, fmt.Sprintf("action=%v", action), http.StatusNotFound) } request := &model.PostActionIntegrationRequest{ - UserId: userId, - PostId: postId, - Type: action.Type, - Context: action.Integration.Context, + UserId: userId, + ChannelId: post.ChannelId, + TeamId: channel.TeamId, + PostId: postId, + Type: action.Type, + Context: action.Integration.Context, } if action.Type == model.POST_ACTION_TYPE_SELECT { diff --git a/app/post_test.go b/app/post_test.go index ae13a7627..2dce8bab8 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -4,7 +4,6 @@ package app import ( - "encoding/json" "fmt" "net/http" "net/http/httptest" @@ -130,10 +129,12 @@ func TestPostAction(t *testing.T) { }) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - var request model.PostActionIntegrationRequest - err := json.NewDecoder(r.Body).Decode(&request) - assert.NoError(t, err) + request := model.PostActionIntegrationRequesteFromJson(r.Body) + assert.NotNil(t, request) + assert.Equal(t, request.UserId, th.BasicUser.Id) + assert.Equal(t, request.ChannelId, th.BasicChannel.Id) + assert.Equal(t, request.TeamId, th.BasicTeam.Id) if request.Type == model.POST_ACTION_TYPE_SELECT { assert.Equal(t, request.DataSource, "some_source") assert.Equal(t, request.Context["selected_option"], "selected") diff --git a/model/post.go b/model/post.go index 0df698279..1f89cb419 100644 --- a/model/post.go +++ b/model/post.go @@ -154,6 +154,8 @@ type PostActionIntegration struct { type PostActionIntegrationRequest struct { UserId string `json:"user_id"` + ChannelId string `json:"channel_id"` + TeamId string `json:"team_id"` PostId string `json:"post_id"` Type string `json:"type"` DataSource string `json:"data_source"` |