Skip to content

Commit

Permalink
port tootsuite#11639 to monsterfork: Add option to include reported s…
Browse files Browse the repository at this point in the history
…tatuses in warning e-mail
  • Loading branch information
Gargron authored and multiple creatures committed Feb 27, 2020
1 parent 3681f7d commit 1213311
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/account_actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AccountActionsController < BaseController
before_action :set_account

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
end

Expand All @@ -30,7 +30,7 @@ def set_account
end

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
7 changes: 7 additions & 0 deletions app/javascript/styles/mailer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ h5 {
.status {
padding-bottom: 32px;

&--highlighted {
border: 1px solid lighten($ui-base-color, 8%);
border-radius: 4px;
padding-bottom: 16px;
margin-bottom: 16px;
}

.status-header {
td {
font-size: 14px;
Expand Down
3 changes: 2 additions & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ def backup_ready(user, backup)
end
end

def warning(user, warning)
def warning(user, warning, status_ids = nil)
@resource = user
@warning = warning
@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
mail to: @resource.email,
Expand Down
25 changes: 17 additions & 8 deletions app/models/admin/account_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,27 @@ class Admin::AccountAction
:type,
:text,
:report_id,
:warning_preset_id,
:send_email_notification
:warning_preset_id

attr_reader :warning
attr_reader :warning, :send_email_notification, :include_statuses

def send_email_notification=(value)
@send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
end

def include_statuses=(value)
@include_statuses = ActiveModel::Type::Boolean.new.cast(value)
end

def save!
ApplicationRecord.transaction do
process_action!
process_warning!
end

queue_email!
process_email!
process_reports!
process_queue!
end

def report
Expand Down Expand Up @@ -135,7 +143,6 @@ def handle_suspend!
authorize(target_account, :suspend?)
log_action(:suspend, target_account)
target_account.suspend!
queue_suspension_worker!
end

def handle_mark_unknown!
Expand All @@ -158,10 +165,12 @@ def queue_suspension_worker!
Admin::SuspensionWorker.perform_async(target_account.id)
end

def queue_email!
return unless warnable?
def process_queue!
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

def warnable?
Expand Down
4 changes: 4 additions & 0 deletions app/views/admin/account_actions/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
.fields-group
= 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/

- unless @warning_presets.empty?
Expand Down
8 changes: 7 additions & 1 deletion app/views/notification_mailer/_status.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- i ||= 0
- highlighted ||= false

%table.email-table{ cellspacing: 0, cellpadding: 0, dir: 'ltr' }
%tbody
Expand All @@ -14,7 +15,7 @@
%table.column{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
%td.column-cell.padded.status
%td.column-cell.padded.status{ class: highlighted ? 'status--highlighted' : '' }
%table.status-header{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
Expand All @@ -32,5 +33,10 @@
%div{ dir: rtl_status?(status) ? 'rtl' : 'ltr' }
= 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
= link_to l(status.created_at), web_url("statuses/#{status.id}")
27 changes: 26 additions & 1 deletion app/views/user_mailer/warning.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
- unless @warning.text.blank?
= 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 }
%tbody
%tr
Expand All @@ -50,7 +58,7 @@
%table.content-section{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
%td.content-cell
%td.content-cell{ class: @statuses.empty? ? '' : 'content-start' }
%table.column{ cellspacing: 0, cellpadding: 0 }
%tbody
%tr
Expand All @@ -61,3 +69,20 @@
%td.button-primary
= link_to about_more_url do
%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
13 changes: 13 additions & 0 deletions app/views/user_mailer/warning.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@
<% end %>
<%= @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 %>
6 changes: 4 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,11 @@ en:
disable: While your account is frozen, your account data remains intact, but you cannot perform any actions until it is unlocked.
force_sensitive: Your account's media has been forced to sensitive visibility until this limit is removed by a moderator.
force_unlisted: Your account's roars have been forced to unlisted visibility until this limit is removed by a moderator.
silence: While your account is limited, only monsters who are already following you will see your roars on this server, and you may be excluded from various public listings. However, others may still manually join your pack.
suspend: Your account has been suspended. All of your roars and your uploaded media files have been irreversibly removed from this server, and servers where you had packmates.
silence: While your account is limited, only those 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 join your pack.
suspend: Your account has been suspended, and all of your content has 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
statuses: 'Specifically, for:'
subject:
disable: "%{acct}, you account has been frozen."
none: "%{acct}, you've been given a moderation warning."
Expand Down
6 changes: 6 additions & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en:
admin_account_action:
send_email_notification: The creature will receive an explanation of what happened with their account
text_html: Optional. You can use roar syntax. You can <a href="%{path}">add warning presets</a> to save time
include_statuses: The creature will see which roars have caused the moderation action or warning
type_html: Choose what to do with <strong>%{acct}</strong>
warning_preset_id: Optional. You can still add custom text to end of the preset
defaults:
Expand Down Expand Up @@ -75,7 +76,12 @@ en:
account_warning_preset:
text: Preset text
admin_account_action:
<<<<<<< HEAD
send_email_notification: Notify the creature per e-mail
=======
include_statuses: Include reported toots in the e-mail
send_email_notification: Notify the user per e-mail
>>>>>>> 73ca0bb92... Add option to include reported statuses in warning e-mail (#11639)
text: Custom warning
type: Action
types:
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def backup_ready

# Preview this email at http://localhost:3000/rails/mailers/user_mailer/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
4 changes: 2 additions & 2 deletions spec/models/admin/account_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
end.to change { Admin::ActionLog.count }.by 1
end

it 'calls queue_email!' do
expect(account_action).to receive(:queue_email!)
it 'calls process_email!' do
expect(account_action).to receive(:process_email!)
subject
end

Expand Down

0 comments on commit 1213311

Please sign in to comment.