statuses_controller.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # frozen_string_literal: true
  2. module Admin
  3. class StatusesController < BaseController
  4. before_action :set_account
  5. before_action :set_statuses, except: :show
  6. before_action :set_status, only: :show
  7. PER_PAGE = 20
  8. def index
  9. authorize [:admin, :status], :index?
  10. @status_batch_action = Admin::StatusBatchAction.new
  11. end
  12. def show
  13. authorize [:admin, @status], :show?
  14. end
  15. def batch
  16. authorize [:admin, :status], :index?
  17. @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))
  18. @status_batch_action.save!
  19. rescue ActionController::ParameterMissing
  20. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  21. ensure
  22. redirect_to after_create_redirect_path
  23. end
  24. private
  25. def batched_ordered_status_edits
  26. @status.edits.includes(:account, status: [:account]).find_each(order: :asc)
  27. end
  28. helper_method :batched_ordered_status_edits
  29. def admin_status_batch_action_params
  30. params.require(:admin_status_batch_action).permit(status_ids: [])
  31. end
  32. def after_create_redirect_path
  33. report_id = @status_batch_action&.report_id || params[:report_id]
  34. if report_id.present?
  35. admin_report_path(report_id)
  36. else
  37. admin_account_statuses_path(params[:account_id], current_params)
  38. end
  39. end
  40. def set_account
  41. @account = Account.find(params[:account_id])
  42. end
  43. def set_status
  44. @status = @account.statuses.find(params[:id])
  45. end
  46. def set_statuses
  47. @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)
  48. end
  49. def filter_params
  50. params.slice(*Admin::StatusFilter::KEYS).permit(*Admin::StatusFilter::KEYS)
  51. end
  52. def current_params
  53. params.slice(:media, :page).permit(:media, :page)
  54. end
  55. def action_from_button
  56. if params[:report]
  57. 'report'
  58. elsif params[:remove_from_report]
  59. 'remove_from_report'
  60. elsif params[:delete]
  61. 'delete'
  62. end
  63. end
  64. end
  65. end