diff options
author | George Goldberg <george@gberg.me> | 2017-05-11 00:16:45 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-05-10 19:16:45 -0400 |
commit | 6026ed9d537cc2f41a263694a06b56cd645081b7 (patch) | |
tree | dab17c0f1f108b94801bf2d3f26fc63f28705ef5 /app | |
parent | 2b7e71e47a0679396e64993b49c6d7c3d4321030 (diff) | |
download | chat-6026ed9d537cc2f41a263694a06b56cd645081b7.tar.gz chat-6026ed9d537cc2f41a263694a06b56cd645081b7.tar.bz2 chat-6026ed9d537cc2f41a263694a06b56cd645081b7.zip |
PLT-6523: Don't crash when replying to a post whose poster has left the channel. (#6388)
Diffstat (limited to 'app')
-rw-r--r-- | app/notification.go | 2 | ||||
-rw-r--r-- | app/post_test.go | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/app/notification.go b/app/notification.go index c48465003..0f59fae21 100644 --- a/app/notification.go +++ b/app/notification.go @@ -83,7 +83,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe for _, threadPost := range list.Posts { profile := profileMap[threadPost.UserId] - if profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0]) { + if profile != nil && (profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0])) { mentionedUserIds[threadPost.UserId] = true } } diff --git a/app/post_test.go b/app/post_test.go new file mode 100644 index 000000000..9bc5ee742 --- /dev/null +++ b/app/post_test.go @@ -0,0 +1,44 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "testing" + + "github.com/mattermost/platform/model" + "fmt" +) + +func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) { + // This test ensures that when replying to a root post made by a user who has since left the channel, the reply + // post completes successfully. This is a regression test for PLT-6523. + th := Setup().InitBasic() + + channel := th.BasicChannel + userInChannel := th.BasicUser2 + userNotInChannel := th.BasicUser + rootPost := th.BasicPost + + if _, err := AddUserToChannel(userInChannel, channel); err != nil { + t.Fatal(err) + } + + if err := RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil { + t.Fatal(err) + } + + replyPost := model.Post{ + Message: "asd", + ChannelId: channel.Id, + RootId: rootPost.Id, + ParentId: rootPost.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: userInChannel.Id, + CreateAt: 0, + } + + if _, err := CreatePostAsUser(&replyPost); err != nil { + t.Fatal(err) + } +} |