PLT-7818 Updates to post type (#7579)
* Updates to post type * Update tests
Этот коммит содержится в:
коммит произвёл
Chris
родитель
0da0cf1a21
Коммит
9adaf53e11
@@ -61,6 +61,11 @@ func TestCreatePost(t *testing.T) {
|
|||||||
t.Fatal("Newly craeted post shouldn't have EditAt set")
|
t.Fatal("Newly craeted post shouldn't have EditAt set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = Client.CreatePost(&model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a", Type: model.POST_SYSTEM_GENERIC})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have failed - bad post type")
|
||||||
|
}
|
||||||
|
|
||||||
post2 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
|
post2 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
|
||||||
rpost2, err := Client.CreatePost(post2)
|
rpost2, err := Client.CreatePost(post2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -454,13 +459,12 @@ func TestUpdatePost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post3 := &model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE}
|
rpost3, err := th.App.CreatePost(&model.Post{ChannelId: channel1.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE, UserId: th.BasicUser.Id}, channel1, false)
|
||||||
rpost3, err := Client.CreatePost(post3)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
up3 := &model.Post{Id: rpost3.Data.(*model.Post).Id, ChannelId: channel1.Id, Message: "zz" + model.NewId() + " update post 3"}
|
up3 := &model.Post{Id: rpost3.Id, ChannelId: channel1.Id, Message: "zz" + model.NewId() + " update post 3"}
|
||||||
if _, err := Client.UpdatePost(up3); err == nil {
|
if _, err := Client.UpdatePost(up3); err == nil {
|
||||||
t.Fatal("shouldn't have been able to update system message")
|
t.Fatal("shouldn't have been able to update system message")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ func TestCreatePost(t *testing.T) {
|
|||||||
t.Fatal("create at should not match")
|
t.Fatal("create at should not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post.RootId = ""
|
||||||
|
post.ParentId = ""
|
||||||
|
post.Type = model.POST_SYSTEM_GENERIC
|
||||||
|
_, resp = Client.CreatePost(post)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
|
||||||
|
post.Type = ""
|
||||||
post.RootId = rpost2.Id
|
post.RootId = rpost2.Id
|
||||||
post.ParentId = rpost2.Id
|
post.ParentId = rpost2.Id
|
||||||
_, resp = Client.CreatePost(post)
|
_, resp = Client.CreatePost(post)
|
||||||
@@ -417,9 +424,10 @@ func TestUpdatePost(t *testing.T) {
|
|||||||
t.Fatal("failed to updates")
|
t.Fatal("failed to updates")
|
||||||
}
|
}
|
||||||
|
|
||||||
post2 := &model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE}
|
rpost2, err := th.App.CreatePost(&model.Post{ChannelId: channel.Id, Message: "zz" + model.NewId() + "a", Type: model.POST_JOIN_LEAVE, UserId: th.BasicUser.Id}, channel, false)
|
||||||
rpost2, resp := Client.CreatePost(post2)
|
if err != nil {
|
||||||
CheckNoError(t, resp)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
up2 := &model.Post{Id: rpost2.Id, ChannelId: channel.Id, Message: "zz" + model.NewId() + " update post 2"}
|
up2 := &model.Post{Id: rpost2.Id, ChannelId: channel.Id, Message: "zz" + model.NewId() + " update post 2"}
|
||||||
_, resp = Client.UpdatePost(rpost2.Id, up2)
|
_, resp = Client.UpdatePost(rpost2.Id, up2)
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model
|
|||||||
post.Message = parseSlackLinksToMarkdown(response.Text)
|
post.Message = parseSlackLinksToMarkdown(response.Text)
|
||||||
post.CreateAt = model.GetMillis()
|
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 {
|
if response.Attachments != nil {
|
||||||
parseSlackAttachment(post, response.Attachments)
|
parseSlackAttachment(post, response.Attachments)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,3 +45,23 @@ func TestMoveCommand(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.EqualValues(t, targetTeam.Id, retrievedCommand.TeamId)
|
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)
|
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 {
|
if channel.DeleteAt != 0 {
|
||||||
err := model.NewAppError("createPost", "api.post.create_post.can_not_post_to_deleted.error", nil, "", http.StatusBadRequest)
|
err := model.NewAppError("createPost", "api.post.create_post.can_not_post_to_deleted.error", nil, "", http.StatusBadRequest)
|
||||||
return nil, err
|
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 := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType}
|
||||||
post.AddProp("from_webhook", "true")
|
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 {
|
if metrics := a.Metrics; metrics != nil {
|
||||||
metrics.IncrementWebhookPost()
|
metrics.IncrementWebhookPost()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,9 @@ func TestCreateWebhookPost(t *testing.T) {
|
|||||||
t.Fatal(k)
|
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