Change actions in reports to require only one click (#17487)

This commit is contained in:
Eugen Rochko 2022-02-11 21:51:57 +01:00 committed by GitHub
parent a27729ee48
commit d0fcf07436
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 154 additions and 36 deletions

View file

@ -0,0 +1,50 @@
# frozen_string_literal: true
class Admin::Reports::ActionsController < Admin::BaseController
before_action :set_report
def create
authorize @report, :show?
case action_from_button
when 'delete'
status_batch_action = Admin::StatusBatchAction.new(
type: action_from_button,
status_ids: @report.status_ids,
current_account: current_account,
report_id: @report.id,
send_email_notification: !@report.spam?
)
status_batch_action.save!
when 'silence', 'suspend'
account_action = Admin::AccountAction.new(
type: action_from_button,
report_id: @report.id,
target_account: @report.target_account,
current_account: current_account,
send_email_notification: !@report.spam?
)
account_action.save!
end
redirect_to admin_reports_path
end
private
def set_report
@report = Report.find(params[:report_id])
end
def action_from_button
if params[:delete]
'delete'
elsif params[:silence]
'silence'
elsif params[:suspend]
'suspend'
end
end
end

View file

@ -1394,8 +1394,9 @@ a.sparkline {
} }
&__button { &__button {
box-sizing: border-box;
flex: 0 0 auto; flex: 0 0 auto;
width: 100px; width: 200px;
padding: 15px; padding: 15px;
padding-right: 0; padding-right: 0;
@ -1411,4 +1412,38 @@ a.sparkline {
color: $dark-text-color; color: $dark-text-color;
} }
} }
@media screen and (max-width: 800px) {
border: 0;
&__item {
flex-direction: column;
border: 0;
&__button {
width: 100%;
padding: 15px 0;
}
&__description {
padding: 0;
padding-bottom: 15px;
}
}
}
}
.section-skip-link {
float: right;
a {
color: $ui-highlight-color;
text-decoration: none;
&:hover,
&:focus,
&:active {
text-decoration: underline;
}
}
} }

View file

@ -8,6 +8,12 @@ class Admin::StatusBatchAction
attr_accessor :current_account, :type, attr_accessor :current_account, :type,
:status_ids, :report_id :status_ids, :report_id
attr_reader :send_email_notification
def send_email_notification=(value)
@send_email_notification = ActiveModel::Type::Boolean.new.cast(value)
end
def save! def save!
process_action! process_action!
end end
@ -55,7 +61,7 @@ class Admin::StatusBatchAction
statuses.each { |status| Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true) } unless target_account.local? statuses.each { |status| Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true) } unless target_account.local?
end end
UserMailer.warning(target_account.user, @warning).deliver_later! if target_account.local? UserMailer.warning(target_account.user, @warning).deliver_later! if warnable?
RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] } RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
end end
@ -82,6 +88,10 @@ class Admin::StatusBatchAction
!report.nil? !report.nil?
end end
def warnable?
send_email_notification && target_account.local?
end
def target_account def target_account
@target_account ||= statuses.first.account @target_account ||= statuses.first.account
end end

View file

@ -0,0 +1,27 @@
= form_tag admin_report_actions_path(@report), method: :post do
.report-actions
.report-actions__item
.report-actions__item__button
= link_to t('admin.reports.mark_as_resolved'), resolve_admin_report_path(@report), method: :post, class: 'button'
.report-actions__item__description
= t('admin.reports.actions.resolve_description_html')
.report-actions__item
.report-actions__item__button
= button_tag t('admin.reports.delete_and_resolve'), name: :delete, class: 'button button--destructive'
.report-actions__item__description
= t('admin.reports.actions.delete_description_html')
.report-actions__item
.report-actions__item__button
= button_tag t('admin.accounts.silence'), name: :silence, class: 'button button--destructive'
.report-actions__item__description
= t('admin.reports.actions.silence_description_html')
.report-actions__item
.report-actions__item__button
= button_tag t('admin.accounts.suspend'), name: :suspend, class: 'button button--destructive'
.report-actions__item__description
= t('admin.reports.actions.suspend_description_html')
.report-actions__item
.report-actions__item__button
= link_to t('admin.accounts.custom'), new_admin_account_action_path(@report.target_account_id, report_id: @report.id), class: 'button'
.report-actions__item__description
= t('admin.reports.actions.other_description_html')

View file

@ -124,24 +124,30 @@
- if @report.comment.present? - if @report.comment.present?
%p= t('admin.reports.comment_description_html', name: content_tag(:strong, @report.account.username, class: 'username')) %p= t('admin.reports.comment_description_html', name: content_tag(:strong, @report.account.username, class: 'username'))
.report-notes__item .report-notes
= image_tag @report.account.avatar.url, class: 'report-notes__item__avatar' .report-notes__item
= image_tag @report.account.avatar.url, class: 'report-notes__item__avatar'
.report-notes__item__header .report-notes__item__header
%span.username %span.username
= link_to display_name(@report.account), admin_account_path(@report.account_id) = link_to display_name(@report.account), admin_account_path(@report.account_id)
%time{ datetime: @report.created_at.iso8601, title: l(@report.created_at) } %time{ datetime: @report.created_at.iso8601, title: l(@report.created_at) }
- if @report.created_at.today? - if @report.created_at.today?
= t('admin.report_notes.today_at', time: l(@report.created_at, format: :time)) = t('admin.report_notes.today_at', time: l(@report.created_at, format: :time))
- else - else
= l @report.created_at.to_date = l @report.created_at.to_date
.report-notes__item__content .report-notes__item__content
= simple_format(h(@report.comment)) = simple_format(h(@report.comment))
%hr.spacer/ %hr.spacer/
%h3= t 'admin.reports.statuses' %h3
= t 'admin.reports.statuses'
%small.section-skip-link
= link_to '#actions' do
= fa_icon 'angle-double-down'
= t('admin.reports.skip_to_actions')
%p %p
= t 'admin.reports.statuses_description_html' = t 'admin.reports.statuses_description_html'
@ -156,8 +162,6 @@
.batch-table__toolbar__actions .batch-table__toolbar__actions
- if !@statuses.empty? && @report.unresolved? - if !@statuses.empty? && @report.unresolved?
= f.button safe_join([fa_icon('times'), t('admin.statuses.batch.remove_from_report')]), name: :remove_from_report, class: 'table-action-link', type: :submit = f.button safe_join([fa_icon('times'), t('admin.statuses.batch.remove_from_report')]), name: :remove_from_report, class: 'table-action-link', type: :submit
= f.button safe_join([fa_icon('trash'), t('admin.reports.delete_and_resolve')]), name: :delete, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
- else
.batch-table__body .batch-table__body
- if @statuses.empty? - if @statuses.empty?
= nothing_here 'nothing-here--under-tabs' = nothing_here 'nothing-here--under-tabs'
@ -167,24 +171,9 @@
- if @report.unresolved? - if @report.unresolved?
%hr.spacer/ %hr.spacer/
%p= t 'admin.reports.actions_description_html' %p#actions= t 'admin.reports.actions_description_html'
.report-actions = render partial: 'admin/reports/actions'
.report-actions__item
.report-actions__item__button
= link_to t('admin.accounts.silence'), new_admin_account_action_path(@report.target_account_id, type: 'silence', report_id: @report.id), class: 'button button--destructive'
.report-actions__item__description
= t('admin.reports.actions.silence_description_html')
.report-actions__item
.report-actions__item__button
= link_to t('admin.accounts.perform_full_suspension'), new_admin_account_action_path(@report.target_account_id, report_id: @report.id, type: 'suspend'), class: 'button button--destructive'
.report-actions__item__description
= t('admin.reports.actions.suspend_description_html')
.report-actions__item
.report-actions__item__button
= link_to t('admin.accounts.custom'), new_admin_account_action_path(@report.target_account_id, report_id: @report.id), class: 'button'
.report-actions__item__description
= t('admin.reports.actions.other_description_html')
- unless @action_logs.empty? - unless @action_logs.empty?
%hr.spacer/ %hr.spacer/

View file

@ -206,6 +206,7 @@ en:
statuses: Posts statuses: Posts
strikes: Previous strikes strikes: Previous strikes
subscribe: Subscribe subscribe: Subscribe
suspend: Suspend
suspended: Suspended suspended: Suspended
suspension_irreversible: The data of this account has been irreversibly deleted. You can unsuspend the account to make it usable but it will not recover any data it previously had. suspension_irreversible: The data of this account has been irreversibly deleted. You can unsuspend the account to make it usable but it will not recover any data it previously had.
suspension_reversible_hint_html: The account has been suspended, and the data will be fully removed on %{date}. Until then, the account can be restored without any ill effects. If you wish to remove all of the account's data immediately, you can do so below. suspension_reversible_hint_html: The account has been suspended, and the data will be fully removed on %{date}. Until then, the account can be restored without any ill effects. If you wish to remove all of the account's data immediately, you can do so below.
@ -560,10 +561,12 @@ en:
action_log: Audit log action_log: Audit log
action_taken_by: Action taken by action_taken_by: Action taken by
actions: actions:
delete_description_html: The reported posts will be deleted and a strike will be recorded to help you escalate on future infractions by the same account.
other_description_html: See more options for controlling the account's behaviour and customize communication to the reported account. other_description_html: See more options for controlling the account's behaviour and customize communication to the reported account.
resolve_description_html: No action will be taken against the reported account, no strike recorded, and the report will be closed.
silence_description_html: The profile will be visible only to those who already follow it or manually look it up, severely limiting its reach. Can always be reverted. silence_description_html: The profile will be visible only to those who already follow it or manually look it up, severely limiting its reach. Can always be reverted.
suspend_description_html: The profile and all its contents will become inaccessible until it is eventually deleted. Interacting with the account will be impossible. Reversible within 30 days. suspend_description_html: The profile and all its contents will become inaccessible until it is eventually deleted. Interacting with the account will be impossible. Reversible within 30 days.
actions_description_html: 'If removing the offending content above is insufficient:' actions_description_html: Decide which action to take to resolve this report. If you take a punitive action against the reported account, an e-mail notification will be sent to them, except when the <strong>Spam</strong> category is selected.
add_to_report: Add more to report add_to_report: Add more to report
are_you_sure: Are you sure? are_you_sure: Are you sure?
assign_to_self: Assign to me assign_to_self: Assign to me
@ -575,7 +578,7 @@ en:
none: None none: None
comment_description_html: 'To provide more information, %{name} wrote:' comment_description_html: 'To provide more information, %{name} wrote:'
created_at: Reported created_at: Reported
delete_and_resolve: Delete and resolve delete_and_resolve: Delete posts
forwarded: Forwarded forwarded: Forwarded
forwarded_to: Forwarded to %{domain} forwarded_to: Forwarded to %{domain}
mark_as_resolved: Mark as resolved mark_as_resolved: Mark as resolved
@ -589,12 +592,14 @@ en:
placeholder: Describe what actions have been taken, or any other related updates... placeholder: Describe what actions have been taken, or any other related updates...
title: Notes title: Notes
notes_description_html: View and leave notes to other moderators and your future self notes_description_html: View and leave notes to other moderators and your future self
quick_actions_description_html: 'Take a quick action or scroll down to see reported content:'
reopen: Reopen report reopen: Reopen report
report: 'Report #%{id}' report: 'Report #%{id}'
reported_account: Reported account reported_account: Reported account
reported_by: Reported by reported_by: Reported by
resolved: Resolved resolved: Resolved
resolved_msg: Report successfully resolved! resolved_msg: Report successfully resolved!
skip_to_actions: Skip to actions
status: Status status: Status
statuses: Reported content statuses: Reported content
statuses_description_html: Offending content will be cited in communication with the reported account statuses_description_html: Offending content will be cited in communication with the reported account

View file

@ -225,6 +225,8 @@ Rails.application.routes.draw do
resources :rules resources :rules
resources :reports, only: [:index, :show] do resources :reports, only: [:index, :show] do
resources :actions, only: [:create], controller: 'reports/actions'
member do member do
post :assign_to_self post :assign_to_self
post :unassign post :unassign