Skip to content

Commit 96eae2a

Browse files
committed
Add emails and tests
1 parent 2f5def2 commit 96eae2a

8 files changed

Lines changed: 109 additions & 1 deletion

File tree

app/mailers/complaints_mailer.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class ComplaintsMailer < ApplicationMailer
2+
helper :complaints
3+
4+
def new_complaint
5+
@complaint = params[:complaint]
6+
mail(from: "#{SiteSetting['NoReplySenderName']} <#{SiteSetting['NoReplySenderEmail']}>",
7+
subject: 'Your report has been received',
8+
to: @complaint.email)
9+
end
10+
11+
def complaint_reviewed
12+
@complaint = params[:complaint]
13+
mail(from: "#{SiteSetting['NoReplySenderName']} <#{SiteSetting['NoReplySenderEmail']}>",
14+
subject: 'Your report has been reviewed',
15+
to: @complaint.email)
16+
end
17+
end

app/models/complaint.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Complaint < ApplicationRecord
55

66
after_create :generate_access_token
77
after_create :assign_status
8+
after_create :send_receipt_email
9+
after_update :send_reviewed_email
810

911
validates :email, presence: -> { !user.present? }
1012
validates :report_type, presence: true
@@ -24,7 +26,6 @@ def update_status(new_status, attribute_to = nil)
2426
attribution = attribute_to.nil? ? 'automatically' : "by #{attribute_to}"
2527
comments.create(content: "Status updated to #{new_status} at #{dt.iso8601} #{attribution}.", internal: true,
2628
user_id: -1)
27-
# TODO: send email
2829
end
2930

3031
##
@@ -49,4 +50,14 @@ def generate_access_token
4950
def assign_status
5051
update_status 'new'
5152
end
53+
54+
def send_receipt_email
55+
ComplaintsMailer.with(complaint: self).new_complaint.deliver_later
56+
end
57+
58+
def send_reviewed_email
59+
if status == 'reviewed' && !outcome.nil? && user_wants_updates?
60+
ComplaintsMailer.with(complaint: self).complaint_reviewed.deliver_later
61+
end
62+
end
5263
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h1 class="has-font-size-heading">Your report has been reviewed</h1>
2+
<p>
3+
Thank you for your <%= report_type(@complaint.report_type)['name'].downcase %> of
4+
<%= @complaint.created_at.strftime '%d %B %Y' %>. We can confirm that we have now reviewed your report.
5+
</p>
6+
7+
<p>
8+
The outcome of your report is: <strong><%= outcome(@complaint.outcome)['name'] %></strong>. This means
9+
<%= outcome(@complaint.outcome)['user_facing'] %>
10+
</p>
11+
12+
<p>
13+
For the full details and the response from the member of staff who reviewed your report, please
14+
<%= link_to 'view your report here', complaint_url(@complaint.access_token) %>.
15+
</p>
16+
17+
<p>Thank you again for taking the time to report this to us and helping to keep our corner of the Internet safe.</p>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<h1 class="has-font-size-heading">Your report has been received</h1>
2+
<p>
3+
This email is to confirm that we have received your <%= report_type(@complaint.report_type)['name'].downcase %>.
4+
</p>
5+
<p>
6+
We want to reassure you that we take all content reports seriously. A member of staff will be assigned to review your
7+
report and will take any appropriate action.
8+
</p>
9+
10+
<% if @complaint.user_wants_updates? %>
11+
<p>
12+
You will receive a further email when your report has been reviewed and responded to.
13+
</p>
14+
<% else %>
15+
<p>
16+
You have requested that we <em>not</em> contact you further about this report, so this is the only email you will
17+
receive in relation to your report.
18+
</p>
19+
<% end %>
20+
21+
<p>
22+
If you would like to view the progress of your report, you can
23+
<%= link_to 'view it here', complaint_url(@complaint.access_token) %>.
24+
</p>
25+
26+
<p>Thank you for taking the time to report this to us.</p>

config/config/safety_center.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ outcomes:
2929
upheld:
3030
name: Upheld
3131
description: The report is upheld; the reporter's classification of the content is correct.
32+
user_facing: our community team agreed with your report and how you classified this content, and have taken
33+
appropriate action.
3234
actionable:
3335
name: Actionable
3436
description: The content is actionable but the reported classification is not correct.
37+
user_facing: our community team agreed that the content you reported was actionable and have taken appropriate
38+
action, but have changed your classification of the content for reporting purposes.
3539
disputed:
3640
name: Disputed
3741
description: The reporter's classification is disputed; the content does not appear to be actionable.
42+
user_facing: our community team have reviewed your report and have decided that the content you reported is not
43+
actionable. This does not mean that the content cannot be removed by community moderators for breaking
44+
community-specific rules, just that it does not breach our Content Policy.
3845

3946
report_types:
4047
illegal:

test/fixtures/complaints.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ reviewed:
4040
user_wants_updates: true
4141
email: test1@example.com
4242
status: reviewed
43+
outcome: disputed
4344
access_token: a84acee3-117a-4719-a5d5-72ad720bbfd7
4445
status_updated_at: <%= 1.day.ago %>
4546

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'test_helper'
2+
3+
class ComplaintsMailerTest < ActionMailer::TestCase
4+
test 'new_complaint' do
5+
email = ComplaintsMailer.with(complaint: complaints(:anonymous)).new_complaint
6+
assert_emails 1 do
7+
email.deliver_later
8+
end
9+
assert_operator email.from[0].length, :>, 3, 'Sender appears to be empty or default value'
10+
end
11+
12+
test 'complaint_reviewed' do
13+
email = ComplaintsMailer.with(complaint: complaints(:reviewed)).complaint_reviewed
14+
assert_emails 1 do
15+
email.deliver_later
16+
end
17+
assert_operator email.from[0].length, :>, 3, 'Sender appears to be empty or default value'
18+
end
19+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Preview all emails at http://localhost:3000/rails/mailers/complaints_mailer
2+
class ComplaintsMailerPreview < ActionMailer::Preview
3+
def new_complaint
4+
ComplaintsMailer.with(complaint: Complaint.first).new_complaint
5+
end
6+
7+
def complaint_reviewed
8+
ComplaintsMailer.with(complaint: Complaint.where(status: 'reviewed').first).complaint_reviewed
9+
end
10+
end

0 commit comments

Comments
 (0)