2017-07-18 16:38:22 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class StatusesController < BaseController
|
|
|
|
before_action :set_account
|
2022-10-26 13:42:29 +02:00
|
|
|
before_action :set_statuses, except: :show
|
|
|
|
before_action :set_status, only: :show
|
2017-07-18 16:38:22 +02:00
|
|
|
|
2017-08-24 04:03:52 +02:00
|
|
|
PER_PAGE = 20
|
2017-07-18 16:38:22 +02:00
|
|
|
|
|
|
|
def index
|
2022-10-26 13:42:29 +02:00
|
|
|
authorize [:admin, :status], :index?
|
2017-11-11 20:23:33 +01:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
@status_batch_action = Admin::StatusBatchAction.new
|
2019-01-04 13:10:43 +01:00
|
|
|
end
|
|
|
|
|
2022-10-26 13:42:29 +02:00
|
|
|
def show
|
|
|
|
authorize [:admin, @status], :show?
|
2024-11-15 10:38:01 +01:00
|
|
|
|
|
|
|
@status_batch_action = Admin::StatusBatchAction.new
|
2022-10-26 13:42:29 +02:00
|
|
|
end
|
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
def batch
|
2022-10-26 13:42:29 +02:00
|
|
|
authorize [:admin, :status], :index?
|
2022-07-05 02:41:40 +02:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
@status_batch_action = Admin::StatusBatchAction.new(admin_status_batch_action_params.merge(current_account: current_account, report_id: params[:report_id], type: action_from_button))
|
|
|
|
@status_batch_action.save!
|
2018-08-16 20:02:52 +02:00
|
|
|
rescue ActionController::ParameterMissing
|
|
|
|
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
|
2022-01-17 09:41:33 +01:00
|
|
|
ensure
|
|
|
|
redirect_to after_create_redirect_path
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-11-08 14:04:52 +01:00
|
|
|
def batched_ordered_status_edits
|
2023-11-23 10:26:11 +01:00
|
|
|
@status.edits.includes(:account, status: [:account]).find_each(order: :asc)
|
2023-11-08 14:04:52 +01:00
|
|
|
end
|
|
|
|
helper_method :batched_ordered_status_edits
|
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
def admin_status_batch_action_params
|
|
|
|
params.require(:admin_status_batch_action).permit(status_ids: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_create_redirect_path
|
2022-02-12 19:52:17 +01:00
|
|
|
report_id = @status_batch_action&.report_id || params[:report_id]
|
2022-10-26 13:42:29 +02:00
|
|
|
|
2022-02-12 19:52:17 +01:00
|
|
|
if report_id.present?
|
|
|
|
admin_report_path(report_id)
|
2022-01-17 09:41:33 +01:00
|
|
|
else
|
|
|
|
admin_account_statuses_path(params[:account_id], current_params)
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_account
|
|
|
|
@account = Account.find(params[:account_id])
|
|
|
|
end
|
|
|
|
|
2022-10-26 13:42:29 +02:00
|
|
|
def set_status
|
|
|
|
@status = @account.statuses.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
def set_statuses
|
|
|
|
@statuses = Admin::StatusFilter.new(@account, filter_params).results.preload(:application, :preloadable_poll, :media_attachments, active_mentions: :account, reblog: [:account, :application, :preloadable_poll, :media_attachments, active_mentions: :account]).page(params[:page]).per(PER_PAGE)
|
|
|
|
end
|
2017-11-11 20:23:33 +01:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
def filter_params
|
|
|
|
params.slice(*Admin::StatusFilter::KEYS).permit(*Admin::StatusFilter::KEYS)
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
2018-05-05 23:06:29 +02:00
|
|
|
|
2022-02-12 19:52:17 +01:00
|
|
|
def current_params
|
|
|
|
params.slice(:media, :page).permit(:media, :page)
|
|
|
|
end
|
|
|
|
|
2018-05-05 23:06:29 +02:00
|
|
|
def action_from_button
|
2022-01-17 09:41:33 +01:00
|
|
|
if params[:report]
|
|
|
|
'report'
|
|
|
|
elsif params[:remove_from_report]
|
|
|
|
'remove_from_report'
|
2018-05-05 23:06:29 +02:00
|
|
|
elsif params[:delete]
|
|
|
|
'delete'
|
|
|
|
end
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
end
|