about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-27 00:04:00 +0200
committerGitHub <noreply@github.com>2017-06-27 00:04:00 +0200
commit42b82206322c73c4a4d7ac29ca9a781ab11e7b1a (patch)
treed27e31942c373cf8c919b512b0d6e45c0809468f /app
parenta91d968cab5120ca389fcc7d6788cafca85e69e7 (diff)
Fix #1624 - Send e-mail notifications to admins about new reports (#3949)
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/reports_controller.rb3
-rw-r--r--app/mailers/admin_mailer.rb13
-rw-r--r--app/mailers/application_mailer.rb8
-rw-r--r--app/mailers/notification_mailer.rb8
-rw-r--r--app/views/admin_mailer/new_report.text.erb5
5 files changed, 29 insertions, 8 deletions
diff --git a/app/controllers/api/v1/reports_controller.rb b/app/controllers/api/v1/reports_controller.rb
index 71df76e92..8e7070d07 100644
--- a/app/controllers/api/v1/reports_controller.rb
+++ b/app/controllers/api/v1/reports_controller.rb
@@ -17,6 +17,9 @@ class Api::V1::ReportsController < Api::BaseController
       status_ids: reported_status_ids,
       comment: report_params[:comment]
     )
+
+    User.admins.includes(:account).each { |u| AdminMailer.new_report(u.account, @report).deliver_later }
+
     render :show
   end
 
diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb
new file mode 100644
index 000000000..fc19a6d40
--- /dev/null
+++ b/app/mailers/admin_mailer.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class AdminMailer < ApplicationMailer
+  def new_report(recipient, report)
+    @report   = report
+    @me       = recipient
+    @instance = Rails.configuration.x.local_domain
+
+    locale_for_account(@me) do
+      mail to: @me.user_email, subject: I18n.t('admin_mailer.new_report.subject', instance: @instance, id: @report.id)
+    end
+  end
+end
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index e5dbfeeda..2e730c19b 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -4,4 +4,12 @@ class ApplicationMailer < ActionMailer::Base
   default from: ENV.fetch('SMTP_FROM_ADDRESS') { 'notifications@localhost' }
   layout 'mailer'
   helper :instance
+
+  protected
+
+  def locale_for_account(account)
+    I18n.with_locale(account.user_locale || I18n.default_locale) do
+      yield
+    end
+  end
 end
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index a944db137..12b92bf45 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -67,12 +67,4 @@ class NotificationMailer < ApplicationMailer
            )
     end
   end
-
-  private
-
-  def locale_for_account(account)
-    I18n.with_locale(account.user_locale || I18n.default_locale) do
-      yield
-    end
-  end
 end
diff --git a/app/views/admin_mailer/new_report.text.erb b/app/views/admin_mailer/new_report.text.erb
new file mode 100644
index 000000000..6fa744bc3
--- /dev/null
+++ b/app/views/admin_mailer/new_report.text.erb
@@ -0,0 +1,5 @@
+<%= display_name(@me) %>,
+
+<%= raw t('admin_mailer.new_report.body', target: @report.target_account.acct, reporter: @report.account.acct) %>
+
+<%= raw t('application_mailer.view')%> <%= admin_report_url(@report) %>