statuses_controller.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. module Admin
  3. class StatusesController < BaseController
  4. before_action :set_account
  5. before_action :set_statuses
  6. PER_PAGE = 20
  7. def index
  8. authorize :status, :index?
  9. @status_batch_action = Admin::StatusBatchAction.new
  10. end
  11. def batch
  12. @status_batch_action = Admin::StatusBatchAction.new(admin_status_batch_action_params.merge(current_account: current_account, report_id: params[:report_id], type: action_from_button))
  13. @status_batch_action.save!
  14. rescue ActionController::ParameterMissing
  15. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  16. ensure
  17. redirect_to after_create_redirect_path
  18. end
  19. private
  20. def admin_status_batch_action_params
  21. params.require(:admin_status_batch_action).permit(status_ids: [])
  22. end
  23. def after_create_redirect_path
  24. report_id = @status_batch_action&.report_id || params[:report_id]
  25. if report_id.present?
  26. admin_report_path(report_id)
  27. else
  28. admin_account_statuses_path(params[:account_id], current_params)
  29. end
  30. end
  31. def set_account
  32. @account = Account.find(params[:account_id])
  33. end
  34. def set_statuses
  35. @statuses = Admin::StatusFilter.new(@account, filter_params).results.preload(:application, :preloadable_poll, :media_attachments, active_mentions: :account, reblog: [:account, :application, :preloadable_poll, :media_attachments, active_mentions: :account]).page(params[:page]).per(PER_PAGE)
  36. end
  37. def filter_params
  38. params.slice(*Admin::StatusFilter::KEYS).permit(*Admin::StatusFilter::KEYS)
  39. end
  40. def current_params
  41. params.slice(:media, :page).permit(:media, :page)
  42. end
  43. def action_from_button
  44. if params[:report]
  45. 'report'
  46. elsif params[:remove_from_report]
  47. 'remove_from_report'
  48. elsif params[:delete]
  49. 'delete'
  50. end
  51. end
  52. end
  53. end