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.

74 lines
1.8 KiB

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