1
0

statuses_controller.rb 1.3 KB

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