Commit a87f3139 authored by Dennis Schubert's avatar Dennis Schubert

Merge pull request #6679 from svbergerem/post-report-reason-in-mail

Add reason for post report to email sent to admins
parents 0c1483b1 482cbe7f
......@@ -114,6 +114,7 @@ Contributions are very welcome, the hard work is done!
* Add white color theme [#6631](https://github.com/diaspora/diaspora/pull/6631)
* Add answer counts to poll [#6641](https://github.com/diaspora/diaspora/pull/6641)
* Check for collapsible posts after images in posts have loaded [#6671](https://github.com/diaspora/diaspora/pull/6671)
* Add reason for post report to email sent to admins [#6679](https://github.com/diaspora/diaspora/pull/6679)
# 0.5.7.0
......
class ReportMailer < ActionMailer::Base
default from: AppConfig.mail.sender_address
def self.new_report(type, id)
Role.moderators.map {|role| super(type, id, role) }
def self.new_report(report_id)
report = Report.find_by_id(report_id)
Role.moderators.map {|role| super(report.item_type, report.item_id, report.text, role) }
end
def new_report(type, id, role)
def new_report(type, id, reason, role)
resource = {
url: report_index_url,
type: I18n.t("notifier.report_email.type.#{type.downcase}"),
id: id
url: report_index_url,
type: I18n.t("notifier.report_email.type.#{type.downcase}"),
id: id,
reason: reason
}
person = Person.find(role.person_id)
return unless person.local?
......
......@@ -56,6 +56,6 @@ class Report < ActiveRecord::Base
end
def send_report_notification
Workers::Mail::ReportWorker.perform_async(self.item_type, self.item_id)
Workers::Mail::ReportWorker.perform_async(id)
end
end
<%= t('notifier.report_email.body', url: resource[:url], type: resource[:type], id: resource[:id]) %>
<%= t("notifier.report_email.body",
url: resource[:url],
type: resource[:type],
id: resource[:id],
reason: resource[:reason]) %>
......@@ -3,8 +3,8 @@ module Workers
class ReportWorker < Base
sidekiq_options queue: :mail
def perform(type, id)
ReportMailer.new_report(type, id).each(&:deliver_now)
def perform(report_id)
ReportMailer.new_report(report_id).each(&:deliver_now)
end
end
end
......
......@@ -793,6 +793,8 @@ en:
the %{type} with ID %{id} was marked as offensive.
Reason: %{reason}
[%{url}][1]
Please review as soon as possible!
......
......@@ -7,6 +7,17 @@ require "spec_helper"
describe Report, type: :mailer do
describe "#make_notification" do
before do
@reported_user = bob
@post = @reported_user.post(:status_message, text: "hello", to: @reported_user.aspects.first.id)
@comment = @reported_user.comment!(@post, "welcome")
@post_report = @reported_user.reports.create(
item_id: @post.id, item_type: "Post",
text: "offensive content"
)
@comment_report = @reported_user.reports.create(
item_id: @comment.id, item_type: "Comment",
text: "offensive comment"
)
@remote = FactoryGirl.create(:person, diaspora_handle: "remote@remote.net")
@user = FactoryGirl.create(:user_with_aspect, username: "local", language: "de")
@user2 = FactoryGirl.create(:user_with_aspect, username: "locally")
......@@ -16,35 +27,35 @@ describe Report, type: :mailer do
it "should deliver successfully" do
expect {
ReportMailer.new_report("post", 666).each(&:deliver_now)
ReportMailer.new_report(@post_report.id).each(&:deliver_now)
}.to_not raise_error
end
it "should be added to the delivery queue" do
expect {
ReportMailer.new_report("post", 666).each(&:deliver_now)
ReportMailer.new_report(@post_report.id).each(&:deliver_now)
}.to change(ActionMailer::Base.deliveries, :size).by(2)
end
it "should include correct recipient" do
ReportMailer.new_report("post", 666).each(&:deliver_now)
ReportMailer.new_report(@post_report.id).each(&:deliver_now)
expect(ActionMailer::Base.deliveries[0].to[0]).to include(@user.email)
expect(ActionMailer::Base.deliveries[1].to[0]).to include(@user2.email)
end
it "should send mail in recipent's prefered language" do
ReportMailer.new_report("post", 666).each(&:deliver_now)
ReportMailer.new_report(@post_report.id).each(&:deliver_now)
expect(ActionMailer::Base.deliveries[0].subject).to match("Ein neuer post wurde als anstößig markiert")
expect(ActionMailer::Base.deliveries[1].subject).to match("A new post was marked as offensive")
end
it "should find correct post translation" do
ReportMailer.new_report("PosT", 666).each(&:deliver_now)
ReportMailer.new_report(@post_report.id).each(&:deliver_now)
expect(ActionMailer::Base.deliveries[0].subject).not_to match("translation missing")
end
it "should find correct comment translation" do
ReportMailer.new_report("CoMMenT", 666).each(&:deliver_now)
ReportMailer.new_report(@comment_report.id).each(&:deliver_now)
expect(ActionMailer::Base.deliveries[0].subject).not_to match("translation missing")
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment