suspensions_controller.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. module Admin
  3. class SuspensionsController < BaseController
  4. before_action :set_account
  5. def new
  6. @suspension = Form::AdminSuspensionConfirmation.new(report_id: params[:report_id])
  7. end
  8. def create
  9. authorize @account, :suspend?
  10. @suspension = Form::AdminSuspensionConfirmation.new(suspension_params)
  11. if suspension_params[:acct] == @account.acct
  12. resolve_report! if suspension_params[:report_id]
  13. perform_suspend!
  14. mark_reports_resolved!
  15. redirect_to admin_accounts_path
  16. else
  17. flash.now[:alert] = I18n.t('admin.suspensions.bad_acct_msg')
  18. render :new
  19. end
  20. end
  21. def destroy
  22. authorize @account, :unsuspend?
  23. @account.unsuspend!
  24. log_action :unsuspend, @account
  25. redirect_to admin_accounts_path
  26. end
  27. private
  28. def set_account
  29. @account = Account.find(params[:account_id])
  30. end
  31. def suspension_params
  32. params.require(:form_admin_suspension_confirmation).permit(:acct, :report_id)
  33. end
  34. def resolve_report!
  35. report = Report.find(suspension_params[:report_id])
  36. report.resolve!(current_account)
  37. log_action :resolve, report
  38. end
  39. def perform_suspend!
  40. @account.suspend!
  41. Admin::SuspensionWorker.perform_async(@account.id)
  42. log_action :suspend, @account
  43. end
  44. def mark_reports_resolved!
  45. Report.where(target_account: @account).unresolved.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
  46. end
  47. end
  48. end