1
0
Fork 0
forked from fedi/mastodon

Add option to include reported statuses in warning e-mail (#11639)

This commit is contained in:
Eugen Rochko 2019-08-23 22:37:23 +02:00 committed by GitHub
parent 37f612074e
commit 73ca0bb925
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 85 additions and 14 deletions

View file

@ -5,7 +5,7 @@ module Admin
before_action :set_account before_action :set_account
def new def new
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true) @account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true)
@warning_presets = AccountWarningPreset.all @warning_presets = AccountWarningPreset.all
end end
@ -30,7 +30,7 @@ module Admin
end end
def resource_params def resource_params
params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification) params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification, :include_statuses)
end end
end end
end end

View file

@ -457,6 +457,13 @@ h5 {
.status { .status {
padding-bottom: 32px; padding-bottom: 32px;
&--highlighted {
border: 1px solid lighten($ui-base-color, 8%);
border-radius: 4px;
padding-bottom: 16px;
margin-bottom: 16px;
}
.status-header { .status-header {
td { td {
font-size: 14px; font-size: 14px;

View file

@ -5,6 +5,7 @@ class UserMailer < Devise::Mailer
helper :application helper :application
helper :instance helper :instance
helper :statuses
add_template_helper RoutingHelper add_template_helper RoutingHelper
@ -79,10 +80,11 @@ class UserMailer < Devise::Mailer
end end
end end
def warning(user, warning) def warning(user, warning, status_ids = nil)
@resource = user @resource = user
@warning = warning @warning = warning
@instance = Rails.configuration.x.local_domain @instance = Rails.configuration.x.local_domain
@statuses = Status.where(id: status_ids).includes(:account) if status_ids.is_a?(Array)
I18n.with_locale(@resource.locale || I18n.default_locale) do I18n.with_locale(@resource.locale || I18n.default_locale) do
mail to: @resource.email, mail to: @resource.email,

View file

@ -19,20 +19,25 @@ class Admin::AccountAction
:report_id, :report_id,
:warning_preset_id :warning_preset_id
attr_reader :warning, :send_email_notification attr_reader :warning, :send_email_notification, :include_statuses
def send_email_notification=(value) def send_email_notification=(value)
@send_email_notification = ActiveModel::Type::Boolean.new.cast(value) @send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
end end
def include_statuses=(value)
@include_statuses = ActiveModel::Type::Boolean.new.cast(value)
end
def save! def save!
ApplicationRecord.transaction do ApplicationRecord.transaction do
process_action! process_action!
process_warning! process_warning!
end end
queue_email! process_email!
process_reports! process_reports!
process_queue!
end end
def report def report
@ -110,7 +115,6 @@ class Admin::AccountAction
authorize(target_account, :suspend?) authorize(target_account, :suspend?)
log_action(:suspend, target_account) log_action(:suspend, target_account)
target_account.suspend! target_account.suspend!
queue_suspension_worker!
end end
def text_for_warning def text_for_warning
@ -121,16 +125,22 @@ class Admin::AccountAction
Admin::SuspensionWorker.perform_async(target_account.id) Admin::SuspensionWorker.perform_async(target_account.id)
end end
def queue_email! def process_queue!
return unless warnable? queue_suspension_worker! if type == 'suspend'
end
UserMailer.warning(target_account.user, warning).deliver_later! def process_email!
UserMailer.warning(target_account.user, warning, status_ids).deliver_now! if warnable?
end end
def warnable? def warnable?
send_email_notification && target_account.local? send_email_notification && target_account.local?
end end
def status_ids
@report.status_ids if @report && include_statuses
end
def warning_preset def warning_preset
@warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present? @warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present?
end end

View file

@ -13,6 +13,10 @@
.fields-group .fields-group
= f.input :send_email_notification, as: :boolean, wrapper: :with_label = f.input :send_email_notification, as: :boolean, wrapper: :with_label
- if params[:report_id].present?
.fields-group
= f.input :include_statuses, as: :boolean, wrapper: :with_label
%hr.spacer/ %hr.spacer/
- unless @warning_presets.empty? - unless @warning_presets.empty?

View file

@ -1,4 +1,5 @@
- i ||= 0 - i ||= 0
- highlighted ||= false
%table.email-table{ cellspacing: 0, cellpadding: 0, dir: 'ltr' } %table.email-table{ cellspacing: 0, cellpadding: 0, dir: 'ltr' }
%tbody %tbody
@ -14,7 +15,7 @@
%table.column{ cellspacing: 0, cellpadding: 0 } %table.column{ cellspacing: 0, cellpadding: 0 }
%tbody %tbody
%tr %tr
%td.column-cell.padded.status %td.column-cell.padded.status{ class: highlighted ? 'status--highlighted' : '' }
%table.status-header{ cellspacing: 0, cellpadding: 0 } %table.status-header{ cellspacing: 0, cellpadding: 0 }
%tbody %tbody
%tr %tr
@ -32,5 +33,10 @@
%div{ dir: rtl_status?(status) ? 'rtl' : 'ltr' } %div{ dir: rtl_status?(status) ? 'rtl' : 'ltr' }
= Formatter.instance.format(status) = Formatter.instance.format(status)
- if status.media_attachments.size > 0
%p
- status.media_attachments.each do |a|
= link_to medium_url(a), medium_url(a)
%p.status-footer %p.status-footer
= link_to l(status.created_at), web_url("statuses/#{status.id}") = link_to l(status.created_at), web_url("statuses/#{status.id}")

View file

@ -42,6 +42,14 @@
- unless @warning.text.blank? - unless @warning.text.blank?
= Formatter.instance.linkify(@warning.text) = Formatter.instance.linkify(@warning.text)
- unless @statuses.empty?
%p
%strong= t('user_mailer.warning.statuses')
- unless @statuses.empty?
- @statuses.each_with_index do |status, i|
= render 'notification_mailer/status', status: status, i: i + 1, highlighted: true
%table.email-table{ cellspacing: 0, cellpadding: 0 } %table.email-table{ cellspacing: 0, cellpadding: 0 }
%tbody %tbody
%tr %tr
@ -50,7 +58,7 @@
%table.content-section{ cellspacing: 0, cellpadding: 0 } %table.content-section{ cellspacing: 0, cellpadding: 0 }
%tbody %tbody
%tr %tr
%td.content-cell %td.content-cell{ class: @statuses.empty? ? '' : 'content-start' }
%table.column{ cellspacing: 0, cellpadding: 0 } %table.column{ cellspacing: 0, cellpadding: 0 }
%tbody %tbody
%tr %tr
@ -61,3 +69,20 @@
%td.button-primary %td.button-primary
= link_to about_more_url do = link_to about_more_url do
%span= t 'user_mailer.warning.review_server_policies' %span= t 'user_mailer.warning.review_server_policies'
%table.email-table{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
%td.email-body
.email-container
%table.content-section{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
%td.content-cell
.email-row
.col-6
%table.column{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
%td.column-cell.text-center
%p= t 'user_mailer.warning.get_in_touch', instance: @instance

View file

@ -7,3 +7,16 @@
<% end %> <% end %>
<%= @warning.text %> <%= @warning.text %>
<% unless @statuses.empty? %>
<%= t('user_mailer.warning.statuses') %>
<% @statuses.each do |status| %>
<%= render 'notification_mailer/status', status: status %>
---
<% end %>
<% else %>
---
<% end %>
<%= t 'user_mailer.warning.get_in_touch', instance: @instance %>

View file

@ -1115,7 +1115,9 @@ en:
disable: While your account is frozen, your account data remains intact, but you cannot perform any actions until it is unlocked. disable: While your account is frozen, your account data remains intact, but you cannot perform any actions until it is unlocked.
silence: While your account is limited, only people who are already following you will see your toots on this server, and you may be excluded from various public listings. However, others may still manually follow you. silence: While your account is limited, only people who are already following you will see your toots on this server, and you may be excluded from various public listings. However, others may still manually follow you.
suspend: Your account has been suspended, and all of your toots and your uploaded media files have been irreversibly removed from this server, and servers where you had followers. suspend: Your account has been suspended, and all of your toots and your uploaded media files have been irreversibly removed from this server, and servers where you had followers.
get_in_touch: You can reply to this e-mail to get in touch with the staff of %{instance}.
review_server_policies: Review server policies review_server_policies: Review server policies
statuses: 'Specifically, for:'
subject: subject:
disable: Your account %{acct} has been frozen disable: Your account %{acct} has been frozen
none: Warning for %{acct} none: Warning for %{acct}

View file

@ -5,6 +5,7 @@ en:
account_warning_preset: account_warning_preset:
text: You can use toot syntax, such as URLs, hashtags and mentions text: You can use toot syntax, such as URLs, hashtags and mentions
admin_account_action: admin_account_action:
include_statuses: The user will see which toots have caused the moderation action or warning
send_email_notification: The user will receive an explanation of what happened with their account send_email_notification: The user will receive an explanation of what happened with their account
text_html: Optional. You can use toot syntax. You can <a href="%{path}">add warning presets</a> to save time text_html: Optional. You can use toot syntax. You can <a href="%{path}">add warning presets</a> to save time
type_html: Choose what to do with <strong>%{acct}</strong> type_html: Choose what to do with <strong>%{acct}</strong>
@ -60,6 +61,7 @@ en:
account_warning_preset: account_warning_preset:
text: Preset text text: Preset text
admin_account_action: admin_account_action:
include_statuses: Include reported toots in the e-mail
send_email_notification: Notify the user per e-mail send_email_notification: Notify the user per e-mail
text: Custom warning text: Custom warning
type: Action type: Action

View file

@ -42,6 +42,6 @@ class UserMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/warning # Preview this email at http://localhost:3000/rails/mailers/user_mailer/warning
def warning def warning
UserMailer.warning(User.first, AccountWarning.new(text: '', action: :silence)) UserMailer.warning(User.first, AccountWarning.new(text: '', action: :silence), [Status.first.id])
end end
end end

View file

@ -58,8 +58,8 @@ RSpec.describe Admin::AccountAction, type: :model do
end.to change { Admin::ActionLog.count }.by 1 end.to change { Admin::ActionLog.count }.by 1
end end
it 'calls queue_email!' do it 'calls process_email!' do
expect(account_action).to receive(:queue_email!) expect(account_action).to receive(:process_email!)
subject subject
end end