mirror of
https://github.com/discourse/discourse.git
synced 2025-02-24 06:27:24 +08:00
SECURITY: Unread post notifications should respect whispers
This commit is contained in:
parent
7f24b601c8
commit
c72f0160de
@ -51,7 +51,8 @@ class PostAlerter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unread_posts(user, topic)
|
def unread_posts(user, topic)
|
||||||
Post.where('post_number > COALESCE((
|
Post.secured(Guardian.new(user))
|
||||||
|
.where('post_number > COALESCE((
|
||||||
SELECT last_read_post_number FROM topic_users tu
|
SELECT last_read_post_number FROM topic_users tu
|
||||||
WHERE tu.user_id = ? AND tu.topic_id = ? ),0)',
|
WHERE tu.user_id = ? AND tu.topic_id = ? ),0)',
|
||||||
user.id, topic.id)
|
user.id, topic.id)
|
||||||
|
@ -9,6 +9,20 @@ describe PostAlerter do
|
|||||||
PostAlerter.post_created(post)
|
PostAlerter.post_created(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "unread" do
|
||||||
|
it "does not return whispers as unread posts" do
|
||||||
|
op = Fabricate(:post)
|
||||||
|
whisper = Fabricate(:post, raw: 'this is a whisper post',
|
||||||
|
user: Fabricate(:admin),
|
||||||
|
topic: op.topic,
|
||||||
|
reply_to_post_number: op.post_number,
|
||||||
|
post_type: Post.types[:whisper])
|
||||||
|
|
||||||
|
|
||||||
|
expect(PostAlerter.new.first_unread_post(op.user, op.topic)).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'likes' do
|
context 'likes' do
|
||||||
it 'does not double notify users on likes' do
|
it 'does not double notify users on likes' do
|
||||||
ActiveRecord::Base.observers.enable :all
|
ActiveRecord::Base.observers.enable :all
|
||||||
|
Loading…
x
Reference in New Issue
Block a user