Skip to content

Commit 132ddf2

Browse files
Gargronhiyuki2578
authored andcommitted
Add option to include reported statuses in warning e-mail (mastodon#11639)
1 parent 91df32d commit 132ddf2

12 files changed

Lines changed: 85 additions & 14 deletions

File tree

app/controllers/admin/account_actions_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class AccountActionsController < BaseController
55
before_action :set_account
66

77
def new
8-
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true)
8+
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true)
99
@warning_presets = AccountWarningPreset.all
1010
end
1111

@@ -30,7 +30,7 @@ def set_account
3030
end
3131

3232
def resource_params
33-
params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification)
33+
params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification, :include_statuses)
3434
end
3535
end
3636
end

app/javascript/styles/mailer.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ h5 {
457457
.status {
458458
padding-bottom: 32px;
459459

460+
&--highlighted {
461+
border: 1px solid lighten($ui-base-color, 8%);
462+
border-radius: 4px;
463+
padding-bottom: 16px;
464+
margin-bottom: 16px;
465+
}
466+
460467
.status-header {
461468
td {
462469
font-size: 14px;

app/mailers/user_mailer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class UserMailer < Devise::Mailer
55

66
helper :application
77
helper :instance
8+
helper :statuses
89

910
add_template_helper RoutingHelper
1011

@@ -79,10 +80,11 @@ def backup_ready(user, backup)
7980
end
8081
end
8182

82-
def warning(user, warning)
83+
def warning(user, warning, status_ids = nil)
8384
@resource = user
8485
@warning = warning
8586
@instance = Rails.configuration.x.local_domain
87+
@statuses = Status.where(id: status_ids).includes(:account) if status_ids.is_a?(Array)
8688

8789
I18n.with_locale(@resource.locale || I18n.default_locale) do
8890
mail to: @resource.email,

app/models/admin/account_action.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@ class Admin::AccountAction
1919
:report_id,
2020
:warning_preset_id
2121

22-
attr_reader :warning, :send_email_notification
22+
attr_reader :warning, :send_email_notification, :include_statuses
2323

2424
def send_email_notification=(value)
2525
@send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
2626
end
2727

28+
def include_statuses=(value)
29+
@include_statuses = ActiveModel::Type::Boolean.new.cast(value)
30+
end
31+
2832
def save!
2933
ApplicationRecord.transaction do
3034
process_action!
3135
process_warning!
3236
end
3337

34-
queue_email!
38+
process_email!
3539
process_reports!
40+
process_queue!
3641
end
3742

3843
def report
@@ -110,7 +115,6 @@ def handle_suspend!
110115
authorize(target_account, :suspend?)
111116
log_action(:suspend, target_account)
112117
target_account.suspend!
113-
queue_suspension_worker!
114118
end
115119

116120
def text_for_warning
@@ -121,16 +125,22 @@ def queue_suspension_worker!
121125
Admin::SuspensionWorker.perform_async(target_account.id)
122126
end
123127

124-
def queue_email!
125-
return unless warnable?
128+
def process_queue!
129+
queue_suspension_worker! if type == 'suspend'
130+
end
126131

127-
UserMailer.warning(target_account.user, warning).deliver_later!
132+
def process_email!
133+
UserMailer.warning(target_account.user, warning, status_ids).deliver_now! if warnable?
128134
end
129135

130136
def warnable?
131137
send_email_notification && target_account.local?
132138
end
133139

140+
def status_ids
141+
@report.status_ids if @report && include_statuses
142+
end
143+
134144
def warning_preset
135145
@warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present?
136146
end

app/views/admin/account_actions/new.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
.fields-group
1414
= f.input :send_email_notification, as: :boolean, wrapper: :with_label
1515

16+
- if params[:report_id].present?
17+
.fields-group
18+
= f.input :include_statuses, as: :boolean, wrapper: :with_label
19+
1620
%hr.spacer/
1721

1822
- unless @warning_presets.empty?

app/views/notification_mailer/_status.html.haml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- i ||= 0
2+
- highlighted ||= false
23

34
%table.email-table{ cellspacing: 0, cellpadding: 0, dir: 'ltr' }
45
%tbody
@@ -14,7 +15,7 @@
1415
%table.column{ cellspacing: 0, cellpadding: 0 }
1516
%tbody
1617
%tr
17-
%td.column-cell.padded.status
18+
%td.column-cell.padded.status{ class: highlighted ? 'status--highlighted' : '' }
1819
%table.status-header{ cellspacing: 0, cellpadding: 0 }
1920
%tbody
2021
%tr
@@ -32,5 +33,10 @@
3233
%div{ dir: rtl_status?(status) ? 'rtl' : 'ltr' }
3334
= Formatter.instance.format(status, nyaize: status.account.cat)
3435

36+
- if status.media_attachments.size > 0
37+
%p
38+
- status.media_attachments.each do |a|
39+
= link_to medium_url(a), medium_url(a)
40+
3541
%p.status-footer
3642
= link_to l(status.created_at), web_url("statuses/#{status.id}")

app/views/user_mailer/warning.html.haml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
- unless @warning.text.blank?
4343
= Formatter.instance.linkify(@warning.text)
4444

45+
- unless @statuses.empty?
46+
%p
47+
%strong= t('user_mailer.warning.statuses')
48+
49+
- unless @statuses.empty?
50+
- @statuses.each_with_index do |status, i|
51+
= render 'notification_mailer/status', status: status, i: i + 1, highlighted: true
52+
4553
%table.email-table{ cellspacing: 0, cellpadding: 0 }
4654
%tbody
4755
%tr
@@ -50,7 +58,7 @@
5058
%table.content-section{ cellspacing: 0, cellpadding: 0 }
5159
%tbody
5260
%tr
53-
%td.content-cell
61+
%td.content-cell{ class: @statuses.empty? ? '' : 'content-start' }
5462
%table.column{ cellspacing: 0, cellpadding: 0 }
5563
%tbody
5664
%tr
@@ -61,3 +69,20 @@
6169
%td.button-primary
6270
= link_to about_more_url do
6371
%span= t 'user_mailer.warning.review_server_policies'
72+
73+
%table.email-table{ cellspacing: 0, cellpadding: 0 }
74+
%tbody
75+
%tr
76+
%td.email-body
77+
.email-container
78+
%table.content-section{ cellspacing: 0, cellpadding: 0 }
79+
%tbody
80+
%tr
81+
%td.content-cell
82+
.email-row
83+
.col-6
84+
%table.column{ cellspacing: 0, cellpadding: 0 }
85+
%tbody
86+
%tr
87+
%td.column-cell.text-center
88+
%p= t 'user_mailer.warning.get_in_touch', instance: @instance

app/views/user_mailer/warning.text.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@
77

88
<% end %>
99
<%= @warning.text %>
10+
<% unless @statuses.empty? %>
11+
<%= t('user_mailer.warning.statuses') %>
12+
13+
<% @statuses.each do |status| %>
14+
15+
<%= render 'notification_mailer/status', status: status %>
16+
---
17+
<% end %>
18+
<% else %>
19+
---
20+
<% end %>
21+
22+
<%= t 'user_mailer.warning.get_in_touch', instance: @instance %>

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,9 @@ en:
11181118
disable: While your account is frozen, your account data remains intact, but you cannot perform any actions until it is unlocked.
11191119
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.
11201120
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.
1121+
get_in_touch: You can reply to this e-mail to get in touch with the staff of %{instance}.
11211122
review_server_policies: Review server policies
1123+
statuses: 'Specifically, for:'
11221124
subject:
11231125
disable: Your account %{acct} has been frozen
11241126
none: Warning for %{acct}

config/locales/simple_form.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ en:
55
account_warning_preset:
66
text: You can use toot syntax, such as URLs, hashtags and mentions
77
admin_account_action:
8+
include_statuses: The user will see which toots have caused the moderation action or warning
89
send_email_notification: The user will receive an explanation of what happened with their account
910
text_html: Optional. You can use toot syntax. You can <a href="%{path}">add warning presets</a> to save time
1011
type_html: Choose what to do with <strong>%{acct}</strong>
@@ -61,6 +62,7 @@ en:
6162
account_warning_preset:
6263
text: Preset text
6364
admin_account_action:
65+
include_statuses: Include reported toots in the e-mail
6466
send_email_notification: Notify the user per e-mail
6567
text: Custom warning
6668
type: Action

0 commit comments

Comments
 (0)