2017-04-13 07:04:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class SuspensionsController < BaseController
|
|
|
|
before_action :set_account
|
|
|
|
|
2018-08-22 05:53:41 -04:00
|
|
|
def new
|
|
|
|
@suspension = Form::AdminSuspensionConfirmation.new(report_id: params[:report_id])
|
|
|
|
end
|
|
|
|
|
2017-04-13 07:04:23 -04:00
|
|
|
def create
|
2017-11-11 14:23:33 -05:00
|
|
|
authorize @account, :suspend?
|
2018-08-22 05:53:41 -04:00
|
|
|
|
|
|
|
@suspension = Form::AdminSuspensionConfirmation.new(suspension_params)
|
|
|
|
|
|
|
|
if suspension_params[:acct] == @account.acct
|
|
|
|
resolve_report! if suspension_params[:report_id]
|
|
|
|
perform_suspend!
|
|
|
|
mark_reports_resolved!
|
|
|
|
redirect_to admin_accounts_path
|
|
|
|
else
|
|
|
|
flash.now[:alert] = I18n.t('admin.suspensions.bad_acct_msg')
|
|
|
|
render :new
|
|
|
|
end
|
2017-04-13 07:04:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2017-11-11 14:23:33 -05:00
|
|
|
authorize @account, :unsuspend?
|
2017-11-07 13:06:44 -05:00
|
|
|
@account.unsuspend!
|
2017-11-23 20:05:53 -05:00
|
|
|
log_action :unsuspend, @account
|
2017-04-13 07:04:23 -04:00
|
|
|
redirect_to admin_accounts_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_account
|
|
|
|
@account = Account.find(params[:account_id])
|
|
|
|
end
|
2018-08-22 05:53:41 -04:00
|
|
|
|
|
|
|
def suspension_params
|
|
|
|
params.require(:form_admin_suspension_confirmation).permit(:acct, :report_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_report!
|
|
|
|
report = Report.find(suspension_params[:report_id])
|
|
|
|
report.resolve!(current_account)
|
|
|
|
log_action :resolve, report
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform_suspend!
|
|
|
|
@account.suspend!
|
|
|
|
Admin::SuspensionWorker.perform_async(@account.id)
|
|
|
|
log_action :suspend, @account
|
|
|
|
end
|
|
|
|
|
|
|
|
def mark_reports_resolved!
|
|
|
|
Report.where(target_account: @account).unresolved.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
|
|
|
|
end
|
2017-04-13 07:04:23 -04:00
|
|
|
end
|
|
|
|
end
|