From 64feffbb60a588b4cabcb27230b11e42a13ff30e Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sat, 26 Mar 2016 00:42:00 +0530 Subject: [PATCH] FEATURE: site setting for suppressing categories from digest email --- app/models/topic.rb | 4 ++++ config/locales/server.en.yml | 1 + config/site_settings.yml | 3 +++ spec/models/topic_spec.rb | 12 +++++++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index a38c2b2e4e7..7150e00ecbd 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -339,6 +339,10 @@ class Topic < ActiveRecord::Base # Remove muted categories muted_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 + end if muted_category_ids.present? topics = topics.where("topics.category_id NOT IN (?)", muted_category_ids) end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index daf57b981da..f4f603f8a70 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1195,6 +1195,7 @@ en: digest_topics: "The maximum number of topics to display in the email digest." digest_min_excerpt_length: "Minimum post excerpt in the email digest, in characters." delete_digest_email_after_days: "Suppress digest emails for users not seen on the site for more than (n) days." + digest_suppress_categories: "Suppress these categories from digest emails." disable_digest_emails: "Disable digest emails for all users." detect_custom_avatars: "Whether or not to check that users have uploaded custom profile pictures." diff --git a/config/site_settings.yml b/config/site_settings.yml index bb593681b84..3a4bc825fc2 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -512,6 +512,9 @@ email: digest_min_excerpt_length: 100 digest_topics: 20 delete_digest_email_after_days: 365 + digest_suppress_categories: + type: category_list + default: '' disable_digest_emails: default: false client: true diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index e2ae6c0549f..6c071fce293 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1296,6 +1296,16 @@ describe Topic do expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank end + it "doesn't return topics from suppressed categories" do + user = Fabricate(:user) + category = Fabricate(:category) + Fabricate(:topic, category: category) + + SiteSetting.digest_suppress_categories = "#{category.id}" + + expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank + end + it "doesn't return topics from TL0 users" do new_user = Fabricate(:user, trust_level: 0) Fabricate(:topic, user_id: new_user.id) @@ -1607,7 +1617,7 @@ describe Topic do topic.update_status('closed', true, user) topic.reload - + expect(@topic_status_event_triggered).to eq(true) end end