You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

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