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.

75 lines
1.9 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class StatusesController < BaseController
  4. helper_method :current_params
  5. before_action :set_account
  6. PER_PAGE = 20
  7. def index
  8. authorize :status, :index?
  9. @statuses = @account.statuses.where(visibility: [:public, :unlisted])
  10. if params[:media]
  11. @statuses.merge!(Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id)).reorder('statuses.id desc')
  12. end
  13. @statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
  14. @form = Form::StatusBatch.new
  15. end
  16. def show
  17. authorize :status, :index?
  18. @statuses = @account.statuses.where(id: params[:id])
  19. authorize @statuses.first, :show?
  20. @form = Form::StatusBatch.new
  21. end
  22. def create
  23. authorize :status, :update?
  24. @form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account, action: action_from_button))
  25. flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
  26. redirect_to admin_account_statuses_path(@account.id, current_params)
  27. rescue ActionController::ParameterMissing
  28. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  29. redirect_to admin_account_statuses_path(@account.id, current_params)
  30. end
  31. private
  32. def form_status_batch_params
  33. params.require(:form_status_batch).permit(:action, status_ids: [])
  34. end
  35. def set_account
  36. @account = Account.find(params[:account_id])
  37. end
  38. def current_params
  39. page = (params[:page] || 1).to_i
  40. {
  41. media: params[:media],
  42. page: page > 1 && page,
  43. }.select { |_, value| value.present? }
  44. end
  45. def action_from_button
  46. if params[:nsfw_on]
  47. 'nsfw_on'
  48. elsif params[:nsfw_off]
  49. 'nsfw_off'
  50. elsif params[:delete]
  51. 'delete'
  52. end
  53. end
  54. end
  55. end