Skip to content

Commit

Permalink
Filter out moderators for moderator email notifications (#9269)
Browse files Browse the repository at this point in the history
* Filter out moderators for moderator email notifications

* Added notifications:noemail tag to filter moderator emails
  • Loading branch information
17sushmita authored Mar 16, 2021
1 parent 40cde18 commit c9349ca
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def notify_node_moderators(node)
all_moderators = User.where(role: %w(moderator admin))
moderators = []
all_moderators.each do |mod_user|
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails')
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
if node.status == 4 # only if it remains unmoderated
mail(
Expand Down Expand Up @@ -71,7 +71,11 @@ def notify_moderators_of_comment_spam(comment, moderator)
@moderator = moderator
@comment = comment
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
all_moderators = User.where(role: %w(moderator admin))
moderators = []
all_moderators.each do |mod_user|
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
mail(
to: "comment-moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
Expand All @@ -85,7 +89,11 @@ def notify_moderators_of_approval(node, moderator)
@moderator = moderator
@node = node
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
all_moderators = User.where(role: %w(moderator admin))
moderators = []
all_moderators.each do |mod_user|
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
Expand All @@ -99,7 +107,11 @@ def notify_moderators_of_comment_approval(comment, moderator)
@moderator = moderator
@comment = comment
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
all_moderators = User.where(role: %w(moderator admin))
moderators = []
all_moderators.each do |mod_user|
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
mail(
to: "comment-moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
Expand All @@ -113,7 +125,11 @@ def notify_moderators_of_spam(node, moderator)
@moderator = moderator
@node = node
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
all_moderators = User.where(role: %w(moderator admin))
moderators = []
all_moderators.each do |mod_user|
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
Expand All @@ -131,7 +147,7 @@ def send_digest_spam(nodes, frequency_digest)
moderators = []
all_moderators.each do |mod_user|
if (frequency_digest == User::Frequency::DAILY && mod_user.has_tag('digest:daily:spam')) || (frequency_digest == User::Frequency::WEEKLY && mod_user.has_tag('digest:weekly:spam'))
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails')
moderators << mod_user.email unless mod_user.has_tag('no-moderation-emails') || mod_user.has_tag('notifications:noemail')
end
end
@nodes = nodes
Expand Down

0 comments on commit c9349ca

Please sign in to comment.