Skip to content

Commit c72f016

Browse files
committed
SECURITY: Unread post notifications should respect whispers
1 parent 7f24b60 commit c72f016

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/services/post_alerter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def after_save_post(post)
5151
end
5252

5353
def unread_posts(user, topic)
54-
Post.where('post_number > COALESCE((
54+
Post.secured(Guardian.new(user))
55+
.where('post_number > COALESCE((
5556
SELECT last_read_post_number FROM topic_users tu
5657
WHERE tu.user_id = ? AND tu.topic_id = ? ),0)',
5758
user.id, topic.id)

spec/services/post_alerter_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ def create_post_with_alerts(args={})
99
PostAlerter.post_created(post)
1010
end
1111

12+
context "unread" do
13+
it "does not return whispers as unread posts" do
14+
op = Fabricate(:post)
15+
whisper = Fabricate(:post, raw: 'this is a whisper post',
16+
user: Fabricate(:admin),
17+
topic: op.topic,
18+
reply_to_post_number: op.post_number,
19+
post_type: Post.types[:whisper])
20+
21+
22+
expect(PostAlerter.new.first_unread_post(op.user, op.topic)).to be_blank
23+
end
24+
end
25+
1226
context 'likes' do
1327
it 'does not double notify users on likes' do
1428
ActiveRecord::Base.observers.enable :all

0 commit comments

Comments
 (0)