FIX: Respect muted tags for mailing list mode

If a user has a tag muted, don't send them emails about that tag.
We've done this forever for categories so it makes sense to do it
for tags too.
This commit is contained in:
Robin Ward 2020-02-19 15:14:42 -05:00
parent 223edd1286
commit 345764565f
2 changed files with 19 additions and 1 deletions

View File

@ -53,6 +53,14 @@ module Jobs
WHERE cu.category_id = ? AND cu.user_id = users.id AND cu.notification_level = ?
)', post.topic.category_id, CategoryUser.notification_levels[:muted])
if SiteSetting.tagging_enabled?
users = users.where('NOT EXISTS (
SELECT 1
FROM tag_users tu
WHERE tu.tag_id in (:tag_ids) AND tu.user_id = users.id AND tu.notification_level = :muted
)', tag_ids: post.topic.tag_ids, muted: TagUser.notification_levels[:muted])
end
if SiteSetting.must_approve_users
users = users.where(approved: true)
end

View File

@ -7,9 +7,14 @@ describe Jobs::NotifyMailingListSubscribers do
fab!(:mailing_list_user) { Fabricate(:user) }
before { mailing_list_user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 1) }
before do
SiteSetting.tagging_enabled = true
end
fab!(:tag) { Fabricate(:tag) }
fab!(:topic) { Fabricate(:topic, tags: [tag]) }
fab!(:user) { Fabricate(:user) }
fab!(:post) { Fabricate(:post, user: user) }
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
shared_examples "no emails" do
it "doesn't send any emails" do
@ -127,6 +132,11 @@ describe Jobs::NotifyMailingListSubscribers do
include_examples "no emails"
end
context "from a muted tag" do
before { TagUser.create(user: mailing_list_user, tag: tag, notification_level: TagUser.notification_levels[:muted]) }
include_examples "no emails"
end
context "max emails per day was reached" do
before { SiteSetting.max_emails_per_day_per_user = 2 }