diff --git a/app/models/post.rb b/app/models/post.rb index 417788a3499..51ac4442118 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -69,10 +69,13 @@ class Post < ActiveRecord::Base scope :visible, -> { joins(:topic).where('topics.visible = true').where(hidden: false) } scope :secured, lambda { |guardian| where('posts.post_type in (?)', Topic.visible_post_types(guardian && guardian.user))} scope :for_mailing_list, ->(user, since) { - created_since(since) - .joins(:topic) - .where(topic: Topic.for_digest(user, 100.years.ago)) # we want all topics with new content, regardless when they were created - .order('posts.created_at ASC') + q = created_since(since) + .joins(:topic) + .where(topic: Topic.for_digest(user, 100.years.ago)) # we want all topics with new content, regardless when they were created + + q = q.where.not(post_type: Post.types[:whisper]) unless user.staff? + + q.order('posts.created_at ASC') } scope :mailing_list_new_topics, ->(user, since) { for_mailing_list(user, since).where('topics.created_at > ?', since) } scope :mailing_list_updates, ->(user, since) { for_mailing_list(user, since).where('topics.created_at <= ?', since) } diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index d6359818c98..d24d76588f0 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -137,6 +137,21 @@ describe UserNotifications do expect(subject.subject).to match(/Try Discourse/) expect(subject.subject).not_to match(/Discourse Meta/) end + + it "excludes whispers" do + new_post_in_old_topic + whisper = Fabricate(:post, topic: old_topic, created_at: 1.hour.ago, raw: "This is secret", post_type: Post.types[:whisper]) + expect(subject.html_part.body.to_s).to include old_topic.title + expect(subject.html_part.body.to_s).to_not include whisper.cooked + end + + it "includes whispers for staff" do + user.admin = true; user.save! + new_post_in_old_topic + whisper = Fabricate(:post, topic: old_topic, created_at: 1.hour.ago, raw: "This is secret", post_type: Post.types[:whisper]) + expect(subject.html_part.body.to_s).to include old_topic.title + expect(subject.html_part.body.to_s).to include whisper.cooked + end end end