Change actions in reports to require only one click (#17487)
This commit is contained in:
		
							parent
							
								
									a27729ee48
								
							
						
					
					
						commit
						d0fcf07436
					
				
					 7 changed files with 154 additions and 36 deletions
				
			
		
							
								
								
									
										50
									
								
								app/controllers/admin/reports/actions_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								app/controllers/admin/reports/actions_controller.rb
									
									
									
									
									
										Normal 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 | ||||
|  | @ -1394,8 +1394,9 @@ a.sparkline { | |||
|     } | ||||
| 
 | ||||
|     &__button { | ||||
|       box-sizing: border-box; | ||||
|       flex: 0 0 auto; | ||||
|       width: 100px; | ||||
|       width: 200px; | ||||
|       padding: 15px; | ||||
|       padding-right: 0; | ||||
| 
 | ||||
|  | @ -1411,4 +1412,38 @@ a.sparkline { | |||
|       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; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -8,6 +8,12 @@ class Admin::StatusBatchAction | |||
|   attr_accessor :current_account, :type, | ||||
|                 :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! | ||||
|     process_action! | ||||
|   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? | ||||
|     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? }] } | ||||
|   end | ||||
| 
 | ||||
|  | @ -82,6 +88,10 @@ class Admin::StatusBatchAction | |||
|     !report.nil? | ||||
|   end | ||||
| 
 | ||||
|   def warnable? | ||||
|     send_email_notification && target_account.local? | ||||
|   end | ||||
| 
 | ||||
|   def target_account | ||||
|     @target_account ||= statuses.first.account | ||||
|   end | ||||
|  |  | |||
							
								
								
									
										27
									
								
								app/views/admin/reports/_actions.html.haml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								app/views/admin/reports/_actions.html.haml
									
									
									
									
									
										Normal 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') | ||||
|  | @ -124,6 +124,7 @@ | |||
| - if @report.comment.present? | ||||
|   %p= t('admin.reports.comment_description_html', name: content_tag(:strong, @report.account.username, class: 'username')) | ||||
| 
 | ||||
|   .report-notes | ||||
|     .report-notes__item | ||||
|       = image_tag @report.account.avatar.url, class: 'report-notes__item__avatar' | ||||
| 
 | ||||
|  | @ -141,7 +142,12 @@ | |||
| 
 | ||||
| %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 | ||||
|   = t 'admin.reports.statuses_description_html' | ||||
|  | @ -156,8 +162,6 @@ | |||
|       .batch-table__toolbar__actions | ||||
|         - 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('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 | ||||
|       - if @statuses.empty? | ||||
|         = nothing_here 'nothing-here--under-tabs' | ||||
|  | @ -167,24 +171,9 @@ | |||
| - if @report.unresolved? | ||||
|   %hr.spacer/ | ||||
| 
 | ||||
|   %p= t 'admin.reports.actions_description_html' | ||||
|   %p#actions= t 'admin.reports.actions_description_html' | ||||
| 
 | ||||
|   .report-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') | ||||
|   = render partial: 'admin/reports/actions' | ||||
| 
 | ||||
| - unless @action_logs.empty? | ||||
|   %hr.spacer/ | ||||
|  |  | |||
|  | @ -206,6 +206,7 @@ en: | |||
|       statuses: Posts | ||||
|       strikes: Previous strikes | ||||
|       subscribe: Subscribe | ||||
|       suspend: Suspend | ||||
|       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_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_taken_by: Action taken by | ||||
|       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. | ||||
|         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. | ||||
|         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 | ||||
|       are_you_sure: Are you sure? | ||||
|       assign_to_self: Assign to me | ||||
|  | @ -575,7 +578,7 @@ en: | |||
|         none: None | ||||
|       comment_description_html: 'To provide more information, %{name} wrote:' | ||||
|       created_at: Reported | ||||
|       delete_and_resolve: Delete and resolve | ||||
|       delete_and_resolve: Delete posts | ||||
|       forwarded: Forwarded | ||||
|       forwarded_to: Forwarded to %{domain} | ||||
|       mark_as_resolved: Mark as resolved | ||||
|  | @ -589,12 +592,14 @@ en: | |||
|         placeholder: Describe what actions have been taken, or any other related updates... | ||||
|         title: Notes | ||||
|       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 | ||||
|       report: 'Report #%{id}' | ||||
|       reported_account: Reported account | ||||
|       reported_by: Reported by | ||||
|       resolved: Resolved | ||||
|       resolved_msg: Report successfully resolved! | ||||
|       skip_to_actions: Skip to actions | ||||
|       status: Status | ||||
|       statuses: Reported content | ||||
|       statuses_description_html: Offending content will be cited in communication with the reported account | ||||
|  |  | |||
|  | @ -225,6 +225,8 @@ Rails.application.routes.draw do | |||
|     resources :rules | ||||
| 
 | ||||
|     resources :reports, only: [:index, :show] do | ||||
|       resources :actions, only: [:create], controller: 'reports/actions' | ||||
| 
 | ||||
|       member do | ||||
|         post :assign_to_self | ||||
|         post :unassign | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue