2017-07-18 23:38:22 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class StatusesController < BaseController
|
|
|
|
helper_method :current_params
|
|
|
|
|
|
|
|
before_action :set_account
|
|
|
|
|
2017-08-24 11:03:52 +09:00
|
|
|
PER_PAGE = 20
|
2017-07-18 23:38:22 +09:00
|
|
|
|
|
|
|
def index
|
2017-11-12 04:23:33 +09:00
|
|
|
authorize :status, :index?
|
|
|
|
|
2018-04-08 04:33:01 +09:00
|
|
|
@statuses = @account.statuses.where(visibility: [:public, :unlisted])
|
2017-11-12 04:23:33 +09:00
|
|
|
|
2017-07-18 23:38:22 +09:00
|
|
|
if params[:media]
|
2021-11-04 23:49:35 +09:00
|
|
|
@statuses.merge!(Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id)).reorder('statuses.id desc')
|
2017-07-18 23:38:22 +09:00
|
|
|
end
|
|
|
|
|
2017-11-12 04:23:33 +09:00
|
|
|
@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
|
|
|
|
@form = Form::StatusBatch.new
|
2017-07-18 23:38:22 +09:00
|
|
|
end
|
|
|
|
|
2019-01-04 21:10:43 +09:00
|
|
|
def show
|
|
|
|
authorize :status, :index?
|
|
|
|
|
|
|
|
@statuses = @account.statuses.where(id: params[:id])
|
|
|
|
authorize @statuses.first, :show?
|
|
|
|
|
|
|
|
@form = Form::StatusBatch.new
|
|
|
|
end
|
|
|
|
|
2017-07-18 23:38:22 +09:00
|
|
|
def create
|
2017-11-12 04:23:33 +09:00
|
|
|
authorize :status, :update?
|
|
|
|
|
2018-05-06 06:06:29 +09:00
|
|
|
@form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account, action: action_from_button))
|
2017-11-12 04:23:33 +09:00
|
|
|
flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
|
2017-07-18 23:38:22 +09:00
|
|
|
|
2018-08-17 03:02:52 +09:00
|
|
|
redirect_to admin_account_statuses_path(@account.id, current_params)
|
|
|
|
rescue ActionController::ParameterMissing
|
|
|
|
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
|
|
|
|
|
2017-07-18 23:38:22 +09:00
|
|
|
redirect_to admin_account_statuses_path(@account.id, current_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def form_status_batch_params
|
|
|
|
params.require(:form_status_batch).permit(:action, status_ids: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_account
|
|
|
|
@account = Account.find(params[:account_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_params
|
|
|
|
page = (params[:page] || 1).to_i
|
2017-11-12 04:23:33 +09:00
|
|
|
|
2017-07-18 23:38:22 +09:00
|
|
|
{
|
|
|
|
media: params[:media],
|
|
|
|
page: page > 1 && page,
|
|
|
|
}.select { |_, value| value.present? }
|
|
|
|
end
|
2018-05-06 06:06:29 +09:00
|
|
|
|
|
|
|
def action_from_button
|
|
|
|
if params[:nsfw_on]
|
|
|
|
'nsfw_on'
|
|
|
|
elsif params[:nsfw_off]
|
|
|
|
'nsfw_off'
|
|
|
|
elsif params[:delete]
|
|
|
|
'delete'
|
|
|
|
end
|
|
|
|
end
|
2017-07-18 23:38:22 +09:00
|
|
|
end
|
|
|
|
end
|