statuses_controller.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # frozen_string_literal: true
  2. class Admin::Trends::StatusesController < Admin::BaseController
  3. def index
  4. authorize :status, :review?
  5. @statuses = filtered_statuses.page(params[:page])
  6. @form = Trends::StatusBatch.new
  7. end
  8. def batch
  9. authorize :status, :review?
  10. @form = Trends::StatusBatch.new(trends_status_batch_params.merge(current_account: current_account, action: action_from_button))
  11. @form.save
  12. rescue ActionController::ParameterMissing
  13. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  14. ensure
  15. redirect_to admin_trends_statuses_path(filter_params)
  16. end
  17. private
  18. def filtered_statuses
  19. Trends::StatusFilter.new(filter_params.with_defaults(trending: 'all')).results.includes(:account, :media_attachments, :active_mentions)
  20. end
  21. def filter_params
  22. params.slice(:page, *Trends::StatusFilter::KEYS).permit(:page, *Trends::StatusFilter::KEYS)
  23. end
  24. def trends_status_batch_params
  25. params.require(:trends_status_batch).permit(:action, status_ids: [])
  26. end
  27. def action_from_button
  28. if params[:approve]
  29. 'approve'
  30. elsif params[:approve_accounts]
  31. 'approve_accounts'
  32. elsif params[:reject]
  33. 'reject'
  34. elsif params[:reject_accounts]
  35. 'reject_accounts'
  36. end
  37. end
  38. end