A platform for community discussion. Free, open, simple.
FIX: Exclude shared drafts from digests
Robin Ward6da7a97eee30
diff --git a/app/models/topic.rb b/app/models/topic.rbindex eb156e6528f..89338482154 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -509,14 +509,17 @@ class Topic < ActiveRecord::Basetopics = 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 tagsdiff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rbindex b438e095e49..c229f89f702 100644--- a/spec/mailers/user_notifications_spec.rb+++ b/spec/mailers/user_notifications_spec.rb@@ -174,6 +174,23 @@ describe UserNotifications doexpect(html).to_not include post.rawend+ 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" dot = 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)