2024-02-26 15:27:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Actualiza la relación entre un sitio y una instancia
|
|
|
|
class InstanceModerationsController < ApplicationController
|
2024-02-26 20:37:34 +00:00
|
|
|
before_action :authorize_policy, except: %i[action_on_several]
|
2024-02-28 19:32:03 +00:00
|
|
|
around_action :redirect_to_moderation_queue!
|
2024-02-26 15:27:56 +00:00
|
|
|
|
|
|
|
def pause
|
2024-02-28 19:32:03 +00:00
|
|
|
instance_moderation.pause! if instance_moderation.may_pause?
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def allow
|
2024-02-28 19:32:03 +00:00
|
|
|
instance_moderation.allow! if instance_moderation.may_allow?
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def block
|
2024-02-28 19:32:03 +00:00
|
|
|
instance_moderation.block! if instance_moderation.may_block?
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
|
2024-02-26 20:37:34 +00:00
|
|
|
def action_on_several
|
|
|
|
instance_moderations = site.instance_moderations.where(id: params[:instance_moderation])
|
|
|
|
|
|
|
|
authorize instance_moderations
|
|
|
|
|
|
|
|
action = params[:instance_moderation_action].to_sym
|
|
|
|
method = :"#{action}!"
|
2024-03-01 19:12:34 +00:00
|
|
|
may = :"may_#{action}?"
|
|
|
|
events = instance_moderation.aasm.events.map(&:name)
|
|
|
|
|
|
|
|
return unless events.include? action
|
2024-02-26 20:37:34 +00:00
|
|
|
|
|
|
|
InstanceModeration.transaction do
|
|
|
|
instance_moderations.find_each do |instance_moderation|
|
2024-03-01 19:12:34 +00:00
|
|
|
instance_moderation.public_send(method) if instance_moderation.public_send(may)
|
2024-02-26 20:37:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-26 15:27:56 +00:00
|
|
|
private
|
|
|
|
|
2024-02-28 19:32:03 +00:00
|
|
|
def redirect_to_moderation_queue!(&action)
|
|
|
|
redirect_back fallback_location: site_moderation_queue_path, state: session[:moderation_queue_filtered_by_state]
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
2024-02-26 15:27:56 +00:00
|
|
|
# @return [InstanceModeration]
|
|
|
|
def instance_moderation
|
|
|
|
@instance_moderation ||= site.instance_moderations.find(params[:instance_moderation_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_policy
|
|
|
|
authorize instance_moderation
|
|
|
|
end
|
|
|
|
end
|