Email confirmation to abuse reports (#12557)

* Notify user that the feedback was received

* Feedback response templates

* Specs for user feedback notification
This commit is contained in:
Anna Buianova 2021-02-03 22:59:50 +03:00 committed by GitHub
parent d699abfcbe
commit d2d1529185
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 96 additions and 0 deletions

View file

@ -20,6 +20,13 @@ class FeedbackMessagesController < ApplicationController
)
rate_limiter.track_limit_by_action(:feedback_message_creation)
if user_signed_in?
Rails.cache.fetch("user-#{current_user.id}-feedback-response-sent-at", expires_in: 24.hours) do
NotifyMailer.with(email_to: current_user.email).feedback_response_email.deliver_later
Time.current
end
end
respond_to do |format|
format.html { redirect_to feedback_messages_path }
format.json { render json: { success: true, message: "Your report is submitted" } }

View file

@ -58,6 +58,10 @@ class NotifyMailer < ApplicationMailer
mail(to: @user.email, subject: "You just got a badge")
end
def feedback_response_email
mail(to: params[:email_to], subject: "Thanks for your report on #{SiteConfig.community_name}")
end
def feedback_message_resolution_email
@user = User.find_by(email: params[:email_to])
@email_body = params[:email_body]

View file

@ -0,0 +1,17 @@
<p>
Hi there,
</p>
<p>
Thank you for flagging content that may be in violation of the <%= community_name %> Code of Conduct and/or our Terms of Use. We are looking into your report and will reach out if we require additional information in order to take appropriate action.
</p>
<p>
We appreciate your help as we work to foster a positive and inclusive environment for all!
</p>
<p>
Thanks,
<br>
The <%= community_name %> Team
</p>

View file

@ -0,0 +1,6 @@
Hi there,
Thank you for flagging content that may be in violation of the <%= community_name %> Code of Conduct and/or our Terms of Use. We are looking into your report and will reach out if we require additional information in order to take appropriate action.
We appreciate your help as we work to foster a positive and inclusive environment for all!
Thanks,
The <%= community_name %> Team

View file

@ -311,6 +311,28 @@ RSpec.describe NotifyMailer, type: :mailer do
end
end
describe "#feedback_response_email" do
let(:email) { described_class.with(email_to: user.email).feedback_response_email }
it "renders proper subject" do
expect(email.subject).to eq("Thanks for your report on #{SiteConfig.community_name}")
end
it "renders proper sender" do
expect(email.from).to eq([SiteConfig.email_addresses[:default]])
expected_from = "#{SiteConfig.community_name} <#{SiteConfig.email_addresses[:default]}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper receiver" do
expect(email.to).to eq([user.email])
end
it "renders proper body" do
expect(email.html_part.body).to include("Thank you for flagging content")
end
end
describe "#user_contact_email" do
let(:email_params) do
{

View file

@ -49,6 +49,14 @@ RSpec.describe "feedback_messages", type: :request do
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
end
end
it "doesn't try to send an email" do
expect do
perform_enqueued_jobs do
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
end
end.not_to change { ActionMailer::Base.deliveries.count }
end
end
context "when feedback is created by chat" do
@ -135,6 +143,38 @@ RSpec.describe "feedback_messages", type: :request do
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
end
end
it "sends an email when no cache" do
expect do
perform_enqueued_jobs do
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
end
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end
it "queues a correct email when no cache" do
mailer_class = NotifyMailer
mailer = double
message_delivery = double
allow(mailer_class).to receive(:with).and_return(mailer)
allow(mailer).to receive(:feedback_response_email).and_return(message_delivery)
allow(message_delivery).to receive(:deliver_later)
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
expect(mailer_class).to have_received(:with).with(email_to: user.email)
expect(mailer).to have_received(:feedback_response_email)
expect(message_delivery).to have_received(:deliver_later)
end
it "doesn't queue an email when cache is set" do
allow(Rails.cache).to receive(:read).and_return(Time.current)
expect do
perform_enqueued_jobs do
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
end
end.not_to change { ActionMailer::Base.deliveries.count }
end
end
context "when a user doesn't qualify to bypass the recaptcha submits a report" do