Admin reports controller improvements (#1714)
* Simplify admin/reports controller filtering for index * Rename parameter to resolved * Fix issue where reports view could not access filter_link_to * Add coverage for admin/reports controller * DRY up resolution of related reports for target account * Clean up admin/reports routes * Add Report#statuses method * DRY up current account action taken params * Rubocop styles
This commit is contained in:
18
app/controllers/admin/reported_statuses_controller.rb
Normal file
18
app/controllers/admin/reported_statuses_controller.rb
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class ReportedStatusesController < BaseController
|
||||
def destroy
|
||||
status = Status.find params[:id]
|
||||
|
||||
RemovalWorker.perform_async(status.id)
|
||||
redirect_to admin_report_path(report)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def report
|
||||
Report.find(params[:report_id])
|
||||
end
|
||||
end
|
||||
end
|
@ -5,38 +5,60 @@ module Admin
|
||||
before_action :set_report, except: [:index]
|
||||
|
||||
def index
|
||||
@reports = Report.includes(:account, :target_account).order('id desc').page(params[:page])
|
||||
@reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved
|
||||
@reports = filtered_reports.page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@statuses = Status.where(id: @report.status_ids)
|
||||
end
|
||||
def show; end
|
||||
|
||||
def resolve
|
||||
@report.update(action_taken: true, action_taken_by_account_id: current_account.id)
|
||||
redirect_to admin_report_path(@report)
|
||||
end
|
||||
|
||||
def suspend
|
||||
Admin::SuspensionWorker.perform_async(@report.target_account.id)
|
||||
Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id)
|
||||
redirect_to admin_report_path(@report)
|
||||
end
|
||||
|
||||
def silence
|
||||
@report.target_account.update(silenced: true)
|
||||
Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id)
|
||||
redirect_to admin_report_path(@report)
|
||||
end
|
||||
|
||||
def remove
|
||||
RemovalWorker.perform_async(params[:status_id])
|
||||
def update
|
||||
process_report
|
||||
redirect_to admin_report_path(@report)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def process_report
|
||||
case params[:outcome].to_s
|
||||
when 'resolve'
|
||||
@report.update(action_taken_by_current_attributes)
|
||||
when 'suspend'
|
||||
Admin::SuspensionWorker.perform_async(@report.target_account.id)
|
||||
resolve_all_target_account_reports
|
||||
when 'silence'
|
||||
@report.target_account.update(silenced: true)
|
||||
resolve_all_target_account_reports
|
||||
else
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
def action_taken_by_current_attributes
|
||||
{ action_taken: true, action_taken_by_account_id: current_account.id }
|
||||
end
|
||||
|
||||
def resolve_all_target_account_reports
|
||||
unresolved_reports_for_target_account.update_all(
|
||||
action_taken_by_current_attributes
|
||||
)
|
||||
end
|
||||
|
||||
def unresolved_reports_for_target_account
|
||||
Report.where(
|
||||
target_account: @report.target_account
|
||||
).unresolved
|
||||
end
|
||||
|
||||
def filtered_reports
|
||||
filtering_scope.order('id desc').includes(
|
||||
:account,
|
||||
:target_account
|
||||
)
|
||||
end
|
||||
|
||||
def filtering_scope
|
||||
params[:resolved].present? ? Report.resolved : Report.unresolved
|
||||
end
|
||||
|
||||
def set_report
|
||||
@report = Report.find(params[:id])
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
module Admin::AccountsHelper
|
||||
def filter_params(more_params)
|
||||
params.permit(:local, :remote, :by_domain, :silenced, :suspended, :recent).merge(more_params)
|
||||
params.permit(:local, :remote, :by_domain, :silenced, :suspended, :recent, :resolved).merge(more_params)
|
||||
end
|
||||
|
||||
def filter_link_to(text, more_params)
|
||||
|
@ -7,4 +7,8 @@ class Report < ApplicationRecord
|
||||
|
||||
scope :unresolved, -> { where(action_taken: false) }
|
||||
scope :resolved, -> { where(action_taken: true) }
|
||||
|
||||
def statuses
|
||||
Status.where(id: status_ids)
|
||||
end
|
||||
end
|
||||
|
@ -5,8 +5,8 @@
|
||||
.filter-subset
|
||||
%strong= t('admin.reports.status')
|
||||
%ul
|
||||
%li= filter_link_to t('admin.reports.unresolved'), action_taken: nil
|
||||
%li= filter_link_to t('admin.reports.resolved'), action_taken: '1'
|
||||
%li= filter_link_to t('admin.reports.unresolved'), resolved: nil
|
||||
%li= filter_link_to t('admin.reports.resolved'), resolved: '1'
|
||||
|
||||
= form_tag do
|
||||
|
||||
|
@ -14,15 +14,15 @@
|
||||
\:
|
||||
= @report.comment.presence || t('reports.comment.none')
|
||||
|
||||
- unless @statuses.empty?
|
||||
- unless @report.statuses.empty?
|
||||
%hr/
|
||||
|
||||
- @statuses.each do |status|
|
||||
- @report.statuses.each do |status|
|
||||
.report-status
|
||||
.activity-stream.activity-stream-headless
|
||||
.entry= render partial: 'stream_entries/simple_status', locals: { status: status }
|
||||
.report-status__actions
|
||||
= link_to remove_admin_report_path(@report, status_id: status.id), method: :post, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: t('admin.reports.delete') do
|
||||
= link_to admin_report_reported_status_path(@report, status), method: :delete, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: t('admin.reports.delete') do
|
||||
= fa_icon 'trash'
|
||||
|
||||
- if !@report.action_taken?
|
||||
@ -30,10 +30,10 @@
|
||||
|
||||
%div{ style: 'overflow: hidden' }
|
||||
%div{ style: 'float: right' }
|
||||
= link_to t('admin.reports.silence_account'), silence_admin_report_path(@report), method: :post, class: 'button'
|
||||
= link_to t('admin.reports.suspend_account'), suspend_admin_report_path(@report), method: :post, class: 'button'
|
||||
= link_to t('admin.reports.silence_account'), admin_report_path(@report, outcome: 'silence'), method: :put, class: 'button'
|
||||
= link_to t('admin.reports.suspend_account'), admin_report_path(@report, outcome: 'suspend'), method: :put, class: 'button'
|
||||
%div{ style: 'float: left' }
|
||||
= link_to t('admin.reports.mark_as_resolved'), resolve_admin_report_path(@report), method: :post, class: 'button'
|
||||
= link_to t('admin.reports.mark_as_resolved'), admin_report_path(@report, outcome: 'resolve'), method: :put, class: 'button'
|
||||
- elsif !@report.action_taken_by_account.nil?
|
||||
%hr/
|
||||
|
||||
|
Reference in New Issue
Block a user