闭社主体 forked from https://github.com/tootsuite/mastodon
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.

63 lines
1.6 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 create
  18. authorize :status, :update?
  19. @form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account, action: action_from_button))
  20. flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
  21. redirect_to admin_account_statuses_path(@account.id, current_params)
  22. end
  23. private
  24. def form_status_batch_params
  25. params.require(:form_status_batch).permit(:action, status_ids: [])
  26. end
  27. def set_account
  28. @account = Account.find(params[:account_id])
  29. end
  30. def current_params
  31. page = (params[:page] || 1).to_i
  32. {
  33. media: params[:media],
  34. page: page > 1 && page,
  35. }.select { |_, value| value.present? }
  36. end
  37. def action_from_button
  38. if params[:nsfw_on]
  39. 'nsfw_on'
  40. elsif params[:nsfw_off]
  41. 'nsfw_off'
  42. elsif params[:delete]
  43. 'delete'
  44. end
  45. end
  46. end
  47. end