A platform for community discussion. Free, open, simple.
FEATURE: Digest suppression by tags (#23089)
Juan David Martínez Cubillos477a5dd371e9
diff --git a/app/models/topic.rb b/app/models/topic.rbindex d8f458f9728..4995b995a21 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -585,6 +585,13 @@ class Topic < ActiveRecord::BaseSiteSetting.digest_suppress_categories.split("|").map(&:to_i),)end+ if SiteSetting.digest_suppress_tags.present?+ topics =+ topics.joins("LEFT JOIN topic_tags tg ON topics.id = tg.topic_id").where(+ "tg.tag_id NOT IN (?) OR tg.tag_id IS NULL",+ SiteSetting.digest_suppress_tags.split("|").map(&:to_i),+ )+ endremove_category_ids << SiteSetting.shared_drafts_category if SiteSetting.shared_drafts_enabled?if remove_category_ids.present?remove_category_ids.uniq!diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 88475c0c074..80ec2c06df8 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2149,6 +2149,7 @@ en:digest_min_excerpt_length: "Minimum post excerpt in the email summary, in characters."suppress_digest_email_after_days: "Suppress summary emails for users not seen on the site for more than (n) days."digest_suppress_categories: "Suppress these categories from summary emails."+ digest_suppress_tags: "Suppress these tags from summary emails."disable_digest_emails: "Disable summary emails for all users."apply_custom_styles_to_digest: "Custom email template and css are applied to summary emails."email_accent_bg_color: "The accent color to be used as the background of some elements in HTML emails. Enter a color name ('red') or hex value ('#FF0000')."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 8714f818a3e..d898374cffa 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1156,6 +1156,9 @@ email:digest_suppress_categories:type: category_listdefault: ""+ digest_suppress_tags:+ type: tag_list+ default: ""disable_digest_emails:default: falseclient: truediff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex c47624002eb..8d372a6bd48 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -2363,6 +2363,27 @@ RSpec.describe Topic doexpect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blankend+ it "doesn't return topics from suppressed tags" do+ category = Fabricate(:category_with_definition, created_at: 2.minutes.ago)+ topic = Fabricate(:topic, category: category, created_at: 1.minute.ago)+ topic2 = Fabricate(:topic, category: category, created_at: 1.minute.ago)+ tag = Fabricate(:tag)+ Fabricate(:topic_tag, topic: topic, tag: tag)++ SiteSetting.digest_suppress_tags = "#{tag.id}"+ topics = Topic.for_digest(user, 1.year.ago, top_order: true)+ expect(topics).to eq([topic2])++ Fabricate(+ :topic_user,+ user: user,+ topic: topic,+ notification_level: TopicUser.notification_levels[:regular],+ )++ expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic2])+ end+it "doesn't return topics from TL0 users" donew_user = Fabricate(:user, trust_level: 0)Fabricate(:topic, user: new_user, created_at: 1.minute.ago)