Add ChannelId and TeamId to PostActionIntegrationRequest (#9384)
* Add ChannelId and TeamId to PostActionIntegrationRequest * Add tests
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
0204c45b7a
Коммит
1463df21a5
18
app/post.go
18
app/post.go
@@ -840,16 +840,26 @@ func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) *mod
|
|||||||
post = result.Data.(*model.Post)
|
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)
|
action := post.GetAction(actionId)
|
||||||
if action == nil || action.Integration == nil {
|
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)
|
return model.NewAppError("DoPostAction", "api.post.do_action.action_id.app_error", nil, fmt.Sprintf("action=%v", action), http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
request := &model.PostActionIntegrationRequest{
|
request := &model.PostActionIntegrationRequest{
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
PostId: postId,
|
ChannelId: post.ChannelId,
|
||||||
Type: action.Type,
|
TeamId: channel.TeamId,
|
||||||
Context: action.Integration.Context,
|
PostId: postId,
|
||||||
|
Type: action.Type,
|
||||||
|
Context: action.Integration.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if action.Type == model.POST_ACTION_TYPE_SELECT {
|
if action.Type == model.POST_ACTION_TYPE_SELECT {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -130,10 +129,12 @@ func TestPostAction(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var request model.PostActionIntegrationRequest
|
request := model.PostActionIntegrationRequesteFromJson(r.Body)
|
||||||
err := json.NewDecoder(r.Body).Decode(&request)
|
assert.NotNil(t, request)
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, request.UserId, th.BasicUser.Id)
|
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 {
|
if request.Type == model.POST_ACTION_TYPE_SELECT {
|
||||||
assert.Equal(t, request.DataSource, "some_source")
|
assert.Equal(t, request.DataSource, "some_source")
|
||||||
assert.Equal(t, request.Context["selected_option"], "selected")
|
assert.Equal(t, request.Context["selected_option"], "selected")
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ type PostActionIntegration struct {
|
|||||||
|
|
||||||
type PostActionIntegrationRequest struct {
|
type PostActionIntegrationRequest struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
|
ChannelId string `json:"channel_id"`
|
||||||
|
TeamId string `json:"team_id"`
|
||||||
PostId string `json:"post_id"`
|
PostId string `json:"post_id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
DataSource string `json:"data_source"`
|
DataSource string `json:"data_source"`
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user