PLT-7818 Updates to post type (#7579)
* Updates to post type * Update tests
Этот коммит содержится в:
коммит произвёл
Chris
родитель
0da0cf1a21
Коммит
9adaf53e11
@@ -41,6 +41,11 @@ func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model
|
||||
post.Message = parseSlackLinksToMarkdown(response.Text)
|
||||
post.CreateAt = model.GetMillis()
|
||||
|
||||
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
|
||||
err := model.NewAppError("CreateCommandPost", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response.Attachments != nil {
|
||||
parseSlackAttachment(post, response.Attachments)
|
||||
}
|
||||
|
||||
@@ -45,3 +45,23 @@ func TestMoveCommand(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId)
|
||||
}
|
||||
|
||||
func TestCreateCommandPost(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
post := &model.Post{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
Type: model.POST_SYSTEM_GENERIC,
|
||||
}
|
||||
|
||||
resp := &model.CommandResponse{
|
||||
Text: "some message",
|
||||
}
|
||||
|
||||
_, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp)
|
||||
if err == nil && err.Id != "api.context.invalid_param.app_error" {
|
||||
t.Fatal("should have failed - bad post type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ func (a *App) CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError)
|
||||
channel = result.Data.(*model.Channel)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
|
||||
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if channel.DeleteAt != 0 {
|
||||
err := model.NewAppError("createPost", "api.post.create_post.can_not_post_to_deleted.error", nil, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
|
||||
@@ -131,6 +131,11 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
post := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType}
|
||||
post.AddProp("from_webhook", "true")
|
||||
|
||||
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
|
||||
err := model.NewAppError("CreateWebhookPost", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if metrics := a.Metrics; metrics != nil {
|
||||
metrics.IncrementWebhookPost()
|
||||
}
|
||||
|
||||
@@ -44,4 +44,9 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
t.Fatal(k)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", nil, model.POST_SYSTEM_GENERIC)
|
||||
if err == nil {
|
||||
t.Fatal("should have failed - bad post type")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user