BUGFIX: hidden posts not absent from context

This commit is contained in:
Sam 2014-01-31 16:37:40 +11:00
parent d83548964c
commit 51c06dea03
2 changed files with 37 additions and 10 deletions

View file

@ -107,6 +107,22 @@ class UserNotifications < ActionMailer::Base
include UserNotificationsHelper
end
def self.get_context_posts(post, topic_user)
context_posts = Post.where(topic_id: post.topic_id)
.where("post_number < ?", post.post_number)
.where(user_deleted: false)
.where(hidden: false)
.order('created_at desc')
.limit(SiteSetting.email_posts_context)
if topic_user && topic_user.last_emailed_post_number
context_posts = context_posts.where("post_number > ?", topic_user.last_emailed_post_number)
end
context_posts
end
def notification_email(user, opts)
return unless @notification = opts[:notification]
return unless @post = opts[:post]
@ -116,16 +132,7 @@ class UserNotifications < ActionMailer::Base
context = ""
tu = TopicUser.get(@post.topic_id, user)
context_posts = Post.where(topic_id: @post.topic_id)
.where("post_number < ?", @post.post_number)
.where(user_deleted: false)
.order('created_at desc')
.limit(SiteSetting.email_posts_context)
if tu && tu.last_emailed_post_number
context_posts = context_posts.where("post_number > ?", tu.last_emailed_post_number)
end
context_posts = self.class.get_context_posts(@post, tu)
# make .present? cheaper
context_posts = context_posts.to_a

View file

@ -4,6 +4,26 @@ describe UserNotifications do
let(:user) { Fabricate(:admin) }
describe "#get_context_posts" do
it "does not include hidden/deleted/user_deleted posts in context" do
post = create_post
reply1 = create_post(topic: post.topic)
reply2 = create_post(topic: post.topic)
reply3 = create_post(topic: post.topic)
reply4 = create_post(topic: post.topic)
reply1.trash!
reply2.user_deleted = true
reply2.save
reply3.hidden = true
reply3.save
UserNotifications.get_context_posts(reply4, nil).count.should == 1
end
end
describe ".signup" do
subject { UserNotifications.signup(user) }