Skip to content

Commit

Permalink
FEATURE: Digest suppression by tags (#23089)
Browse files Browse the repository at this point in the history
* FEATURE: Digest suppression by tags

* fixed stree issues

* fixed code so untagged topics are not suppressed when suppressing certain tags
  • Loading branch information
jdmartinez1062 committed Aug 18, 2023
1 parent 3d86fc1 commit 477a5dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/topic.rb
Expand Up @@ -585,6 +585,13 @@ def self.for_digest(user, since, opts = nil)
SiteSetting.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),
)
end
remove_category_ids << SiteSetting.shared_drafts_category if SiteSetting.shared_drafts_enabled?
if remove_category_ids.present?
remove_category_ids.uniq!
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Expand Up @@ -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')."
Expand Down
3 changes: 3 additions & 0 deletions config/site_settings.yml
Expand Up @@ -1156,6 +1156,9 @@ email:
digest_suppress_categories:
type: category_list
default: ""
digest_suppress_tags:
type: tag_list
default: ""
disable_digest_emails:
default: false
client: true
Expand Down
21 changes: 21 additions & 0 deletions spec/models/topic_spec.rb
Expand Up @@ -2363,6 +2363,27 @@ def set_state!(group, user, state)
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
end

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" do
new_user = Fabricate(:user, trust_level: 0)
Fabricate(:topic, user: new_user, created_at: 1.minute.ago)
Expand Down

0 comments on commit 477a5dd

Please sign in to comment.