2017-02-16 02:28:10 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 21:27:03 +02:00
|
|
|
module Admin
|
|
|
|
class ReportsController < BaseController
|
|
|
|
before_action :set_report, except: [:index]
|
|
|
|
|
|
|
|
def index
|
2017-11-11 20:23:33 +01:00
|
|
|
authorize :report, :index?
|
2017-04-14 11:10:28 +02:00
|
|
|
@reports = filtered_reports.page(params[:page])
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
|
2017-07-18 16:38:22 +02:00
|
|
|
def show
|
2017-11-11 20:23:33 +01:00
|
|
|
authorize @report, :show?
|
2018-04-20 02:28:48 +02:00
|
|
|
|
|
|
|
@report_note = @report.notes.new
|
|
|
|
@report_notes = (@report.notes.latest + @report.history).sort_by(&:created_at)
|
|
|
|
@form = Form::StatusBatch.new
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
2017-04-10 21:27:03 +02:00
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
def update
|
2017-11-11 20:23:33 +01:00
|
|
|
authorize @report, :update?
|
2017-04-14 11:10:28 +02:00
|
|
|
process_report
|
2018-04-02 22:04:14 +02:00
|
|
|
|
|
|
|
if @report.action_taken?
|
|
|
|
redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
|
|
|
|
else
|
|
|
|
redirect_to admin_report_path(@report)
|
|
|
|
end
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def process_report
|
|
|
|
case params[:outcome].to_s
|
2018-04-02 22:04:14 +02:00
|
|
|
when 'assign_to_self'
|
|
|
|
@report.update!(assigned_account_id: current_account.id)
|
|
|
|
log_action :assigned_to_self, @report
|
|
|
|
when 'unassign'
|
|
|
|
@report.update!(assigned_account_id: nil)
|
|
|
|
log_action :unassigned, @report
|
|
|
|
when 'reopen'
|
2018-04-10 20:27:59 +02:00
|
|
|
@report.unresolve!
|
2018-04-02 22:04:14 +02:00
|
|
|
log_action :reopen, @report
|
2017-04-14 11:10:28 +02:00
|
|
|
when 'resolve'
|
2018-04-10 20:27:59 +02:00
|
|
|
@report.resolve!(current_account)
|
2017-11-24 02:05:53 +01:00
|
|
|
log_action :resolve, @report
|
2017-04-14 11:10:28 +02:00
|
|
|
when 'suspend'
|
|
|
|
Admin::SuspensionWorker.perform_async(@report.target_account.id)
|
2018-04-10 20:27:59 +02:00
|
|
|
|
2017-11-24 02:05:53 +01:00
|
|
|
log_action :resolve, @report
|
|
|
|
log_action :suspend, @report.target_account
|
2018-04-10 20:27:59 +02:00
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
resolve_all_target_account_reports
|
|
|
|
when 'silence'
|
2017-11-24 02:05:53 +01:00
|
|
|
@report.target_account.update!(silenced: true)
|
2018-04-10 20:27:59 +02:00
|
|
|
|
2017-11-24 02:05:53 +01:00
|
|
|
log_action :resolve, @report
|
|
|
|
log_action :silence, @report.target_account
|
2018-04-10 20:27:59 +02:00
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
resolve_all_target_account_reports
|
|
|
|
else
|
|
|
|
raise ActiveRecord::RecordNotFound
|
|
|
|
end
|
2018-04-10 20:27:59 +02:00
|
|
|
@report.reload
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
def resolve_all_target_account_reports
|
2018-04-10 20:27:59 +02:00
|
|
|
unresolved_reports_for_target_account.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
def unresolved_reports_for_target_account
|
|
|
|
Report.where(
|
|
|
|
target_account: @report.target_account
|
|
|
|
).unresolved
|
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_reports
|
2017-05-16 12:10:09 +02:00
|
|
|
ReportFilter.new(filter_params).results.order(id: :desc).includes(
|
2017-04-14 11:10:28 +02:00
|
|
|
:account,
|
|
|
|
:target_account
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-04-18 19:36:18 +02:00
|
|
|
def filter_params
|
|
|
|
params.permit(
|
|
|
|
:account_id,
|
|
|
|
:resolved,
|
|
|
|
:target_account_id
|
|
|
|
)
|
2017-04-14 11:10:28 +02:00
|
|
|
end
|
2017-04-10 21:27:03 +02:00
|
|
|
|
|
|
|
def set_report
|
|
|
|
@report = Report.find(params[:id])
|
|
|
|
end
|
2017-02-17 00:42:52 +01:00
|
|
|
end
|
2017-02-16 02:28:10 +01:00
|
|
|
end
|