mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
6f9a7bd02c
* Allow to show a specific status in the admin interface * Let the front-end know the current account is a moderator * Add admin links to status and account menus If the current logged-in user is an admin, add quick links to the admin interface in account and toot dropdown menu. Suggestion by @ashkitten * Use @statuses.first instead of @statuses[0]
77 lines
1.9 KiB
Ruby
77 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Admin
|
|
class StatusesController < BaseController
|
|
helper_method :current_params
|
|
|
|
before_action :set_account
|
|
|
|
PER_PAGE = 20
|
|
|
|
def index
|
|
authorize :status, :index?
|
|
|
|
@statuses = @account.statuses.where(visibility: [:public, :unlisted])
|
|
|
|
if params[:media]
|
|
account_media_status_ids = @account.media_attachments.attached.reorder(nil).select(:status_id).distinct
|
|
@statuses.merge!(Status.where(id: account_media_status_ids))
|
|
end
|
|
|
|
@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
|
|
@form = Form::StatusBatch.new
|
|
end
|
|
|
|
def show
|
|
authorize :status, :index?
|
|
|
|
@statuses = @account.statuses.where(id: params[:id])
|
|
authorize @statuses.first, :show?
|
|
|
|
@form = Form::StatusBatch.new
|
|
end
|
|
|
|
def create
|
|
authorize :status, :update?
|
|
|
|
@form = Form::StatusBatch.new(form_status_batch_params.merge(current_account: current_account, action: action_from_button))
|
|
flash[:alert] = I18n.t('admin.statuses.failed_to_execute') unless @form.save
|
|
|
|
redirect_to admin_account_statuses_path(@account.id, current_params)
|
|
rescue ActionController::ParameterMissing
|
|
flash[:alert] = I18n.t('admin.statuses.no_status_selected')
|
|
|
|
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
|
|
|
|
{
|
|
media: params[:media],
|
|
page: page > 1 && page,
|
|
}.select { |_, value| value.present? }
|
|
end
|
|
|
|
def action_from_button
|
|
if params[:nsfw_on]
|
|
'nsfw_on'
|
|
elsif params[:nsfw_off]
|
|
'nsfw_off'
|
|
elsif params[:delete]
|
|
'delete'
|
|
end
|
|
end
|
|
end
|
|
end
|