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.

76 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. account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
  12. @statuses.merge!(Status.where(id: account_media_status_ids))
  13. end
  14. @statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
  15. @form = Form::StatusBatch.new
  16. end
  17. def show
  18. authorize :status, :index?
  19. @statuses = @account.statuses.where(id: params[:id])
  20. authorize @statuses.first, :show?
  21. @form = Form::StatusBatch.new
  22. end
  23. def create
  24. authorize :status, :update?
  25. @form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account, action: action_from_button))
  26. flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
  27. redirect_to admin_account_statuses_path(@account.id, current_params)
  28. rescue ActionController::ParameterMissing
  29. flash[:alert] = I18n.t('admin.statuses.no_status_selected')
  30. redirect_to admin_account_statuses_path(@account.id, current_params)
  31. end
  32. private
  33. def form_status_batch_params
  34. params.require(:form_status_batch).permit(:action, status_ids: [])
  35. end
  36. def set_account
  37. @account = Account.find(params[:account_id])
  38. end
  39. def current_params
  40. page = (params[:page] || 1).to_i
  41. {
  42. media: params[:media],
  43. page: page > 1 && page,
  44. }.select { |_, value| value.present? }
  45. end
  46. def action_from_button
  47. if params[:nsfw_on]
  48. 'nsfw_on'
  49. elsif params[:nsfw_off]
  50. 'nsfw_off'
  51. elsif params[:delete]
  52. 'delete'
  53. end
  54. end
  55. end
  56. end