-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
admin_mailer.rb
144 lines (133 loc) · 4.73 KB
/
admin_mailer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# frozen_string_literal: true
class AdminMailer < ActionMailer::Base
helper :application
include ApplicationHelper
default from: "notifications@#{ActionMailer::Base.default_url_options[:host]}"
def notify_node_moderators(node)
subject = '[New Public Lab poster needs moderation] ' + node.title
@node = node
@user = node.author
@footer = feature('email-footer')
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')
end
if node.status == 4 # only if it remains unmoderated
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
end
def notify_comment_moderators(comment)
subject = '[New Public Lab poster needs moderation]'
@comment = comment
@user = comment.author
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
if comment.status == 4 # only if it remains unmoderated
mail(
to: "comment-moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
end
def notify_author_of_approval(node, moderator)
subject = '[Public Lab] Your post was approved!'
@author = node.author
@moderator = moderator
@node = node
@footer = feature('email-footer')
mail(to: @author.email, subject: subject)
end
def notify_author_of_comment_approval(comment, moderator)
subject = '[Public Lab] Your comment was approved!'
@author_mail = comment.author.email
@moderator = moderator
@comment = comment
@footer = feature('email-footer')
mail(to: @author_mail, subject: subject)
end
# Will this further bait spammers? If we don't,
# will non-spammers whose posts were moderated get confused?
# Should: show explanation/appeal process to authors who visit again
# Should: prompt moderators to reach out if it's not spam, but a guidelines
# violation
# def notify_author_of_spam(node)
# end
def notify_moderators_of_comment_spam(comment, moderator)
subject = '[New Public Lab comment needs moderation]'
@author = comment.author
@moderator = moderator
@comment = comment
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
mail(
to: "comment-moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
def notify_moderators_of_approval(node, moderator)
subject = '[New Public Lab poster needs moderation] ' + node.title
@author = node.author
@moderator = moderator
@node = node
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
def notify_moderators_of_comment_approval(comment, moderator)
subject = '[New Public Lab commenter needs moderation]'
@author = comment.author
@moderator = moderator
@comment = comment
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
mail(
to: "comment-moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
def notify_moderators_of_spam(node, moderator)
subject = '[New Public Lab poster needs moderation] ' + node.title
@author = node.author
@moderator = moderator
@node = node
@footer = feature('email-footer')
moderators = User.where(role: %w(moderator admin)).collect(&:email)
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
)
end
def send_digest_spam(nodes, frequency_digest)
if frequency_digest == User::Frequency::DAILY
@subject = 'Your daily digest for moderation'
elsif frequency_digest == User::Frequency::WEEKLY
@subject = 'Your weekly digest for moderation'
end
all_moderators = User.where(role: %w(moderator admin))
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')
end
end
@nodes = nodes
mail(
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators.collect(&:email),
subject: @subject
)
end
end