FIX: Exclude shared drafts from digests

This commit is contained in:
Robin Ward 2020-08-04 13:35:48 -04:00
parent 1bef008a1e
commit 6da7a97eee
2 changed files with 26 additions and 6 deletions

View File

@ -509,14 +509,17 @@ class Topic < ActiveRecord::Base
topics = topics.where("topics.id NOT IN (?)", category_topic_ids)
end
# Remove muted categories
muted_category_ids = CategoryUser.where(user_id: user.id, notification_level: CategoryUser.notification_levels[:muted]).pluck(:category_id)
# Remove muted and shared draft categories
remove_category_ids = CategoryUser.where(user_id: user.id, notification_level: CategoryUser.notification_levels[:muted]).pluck(:category_id)
if SiteSetting.digest_suppress_categories.present?
muted_category_ids += SiteSetting.digest_suppress_categories.split("|").map(&:to_i)
muted_category_ids = muted_category_ids.uniq
remove_category_ids += SiteSetting.digest_suppress_categories.split("|").map(&:to_i)
end
if muted_category_ids.present?
topics = topics.where("topics.category_id NOT IN (?)", muted_category_ids)
if SiteSetting.shared_drafts_category.present?
remove_category_ids << SiteSetting.shared_drafts_enabled?
end
if remove_category_ids.present?
remove_category_ids.uniq!
topics = topics.where("topics.category_id NOT IN (?)", remove_category_ids)
end
# Remove muted tags

View File

@ -174,6 +174,23 @@ describe UserNotifications do
expect(html).to_not include post.raw
end
it "excludes shared drafts" do
cat = Fabricate(:category)
SiteSetting.shared_drafts_category = cat.id
topic = Fabricate(:topic, title: "This is a draft", category_id: cat.id, created_at: 1.hour.ago)
post = Fabricate(
:post,
topic: topic,
score: 100.0,
post_number: 2,
raw: "secret draft content",
created_at: 1.hour.ago
)
html = subject.html_part.body.to_s
expect(html).to_not include topic.title
expect(html).to_not include post.raw
end
it "excludes whispers and other post types that don't belong" do
t = Fabricate(:topic, user: Fabricate(:user), title: "Who likes the same stuff I like?", created_at: 1.hour.ago)
whisper = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "You like weird stuff", post_type: Post.types[:whisper], created_at: 1.hour.ago)