[MM-51517] Sentry crash fix (#22985)
* add cloud limit check * add test * add warning for the inaccessible root-post --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -1901,6 +1901,12 @@ func isCommentMention(user *model.User, post *model.Post, otherPosts map[string]
|
|||||||
return mentioned
|
return mentioned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := otherPosts[post.RootId]; !ok {
|
||||||
|
mlog.Warn("Can't determine the comment mentions as the rootPost is past the cloud plan's limit", mlog.String("rootPostID", post.RootId), mlog.String("commentID", post.Id))
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Whether or not the user was mentioned because they started the thread
|
// Whether or not the user was mentioned because they started the thread
|
||||||
mentioned := otherPosts[post.RootId].UserId == user.Id
|
mentioned := otherPosts[post.RootId].UserId == user.Id
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -2068,6 +2069,66 @@ func TestCountMentionsFromPost(t *testing.T) {
|
|||||||
assert.Equal(t, 1, count)
|
assert.Equal(t, 1, count)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should not include comments made before the given post when rootPost is inaccessible", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||||
|
|
||||||
|
user1 := th.BasicUser
|
||||||
|
user2 := th.BasicUser2
|
||||||
|
|
||||||
|
channel := th.CreateChannel(th.Context, th.BasicTeam)
|
||||||
|
th.AddUserToChannel(user2, channel)
|
||||||
|
|
||||||
|
user2.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||||
|
|
||||||
|
post1, err := th.App.CreatePost(th.Context, &model.Post{
|
||||||
|
UserId: user1.Id,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: "test1",
|
||||||
|
}, channel, false, true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||||
|
UserId: user2.Id,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
RootId: post1.Id,
|
||||||
|
Message: "test2",
|
||||||
|
}, channel, false, true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
time.Sleep(time.Millisecond * 2)
|
||||||
|
|
||||||
|
post3, err := th.App.CreatePost(th.Context, &model.Post{
|
||||||
|
UserId: user1.Id,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: "test3",
|
||||||
|
}, channel, false, true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
_, err = th.App.CreatePost(th.Context, &model.Post{
|
||||||
|
UserId: user1.Id,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
RootId: post1.Id,
|
||||||
|
Message: "test4",
|
||||||
|
}, channel, false, true)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
// Make posts created before post3 inaccessible
|
||||||
|
e := th.App.Srv().Store().System().SaveOrUpdate(&model.System{
|
||||||
|
Name: model.SystemLastAccessiblePostTime,
|
||||||
|
Value: strconv.FormatInt(post3.CreateAt, 10),
|
||||||
|
})
|
||||||
|
require.NoError(t, e)
|
||||||
|
|
||||||
|
// post4 should mention the user, but since post2 is inaccessible due to the cloud plan's limit,
|
||||||
|
// post4 does not notify the user.
|
||||||
|
|
||||||
|
count, _, _, err := th.App.countMentionsFromPost(th.Context, user2, post3)
|
||||||
|
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Zero(t, count)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("should count mentions from the user's webhook posts", func(t *testing.T) {
|
t.Run("should count mentions from the user's webhook posts", func(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user