statuses_controller.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. authorize :status, :index?
  13. @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))
  14. @status_batch_action.save!
  15. rescue ActionController::ParameterMissing
  16. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  17. ensure
  18. redirect_to after_create_redirect_path
  19. end
  20. private
  21. def admin_status_batch_action_params
  22. params.require(:admin_status_batch_action).permit(status_ids: [])
  23. end
  24. def after_create_redirect_path
  25. report_id = @status_batch_action&.report_id || params[:report_id]
  26. if report_id.present?
  27. admin_report_path(report_id)
  28. else
  29. admin_account_statuses_path(params[:account_id], current_params)
  30. end
  31. end
  32. def set_account
  33. @account = Account.find(params[:account_id])
  34. end
  35. def set_statuses
  36. @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)
  37. end
  38. def filter_params
  39. params.slice(*Admin::StatusFilter::KEYS).permit(*Admin::StatusFilter::KEYS)
  40. end
  41. def current_params
  42. params.slice(:media, :page).permit(:media, :page)
  43. end
  44. def action_from_button
  45. if params[:report]
  46. 'report'
  47. elsif params[:remove_from_report]
  48. 'remove_from_report'
  49. elsif params[:delete]
  50. 'delete'
  51. end
  52. end
  53. end
  54. end