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-03-04 17:47:20 +00:00
|
|
|
include ModerationConcern
|
2024-02-26 15:27:56 +00:00
|
|
|
|
2024-03-04 17:47:20 +00:00
|
|
|
InstanceModeration.events.each do |event|
|
|
|
|
define_method(event) do
|
|
|
|
authorize instance_moderation
|
2024-02-26 15:27:56 +00:00
|
|
|
|
2024-03-04 17:47:20 +00:00
|
|
|
instance_moderation.public_send(:"#{event}!") if instance_moderation.public_send(:"may_#{event}?")
|
2024-02-26 15:27:56 +00:00
|
|
|
|
2024-03-12 16:57:31 +00:00
|
|
|
flash[:success] = I18n.t("instance_moderations.#{event}.success")
|
|
|
|
rescue Exception => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, params: params.permit!.to_h })
|
|
|
|
|
|
|
|
flash[:error] = I18n.t("instance_moderations.#{event}.error")
|
|
|
|
ensure
|
2024-03-04 17:47:20 +00:00
|
|
|
redirect_to_moderation_queue!
|
|
|
|
end
|
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
|
2024-03-12 16:57:31 +00:00
|
|
|
method = :"#{action}_all!"
|
2024-03-01 19:12:34 +00:00
|
|
|
|
2024-03-04 17:47:20 +00:00
|
|
|
redirect_to_moderation_queue!
|
|
|
|
|
|
|
|
return unless InstanceModeration.events.include? action
|
2024-02-26 20:37:34 +00:00
|
|
|
|
|
|
|
InstanceModeration.transaction do
|
2024-03-12 16:57:31 +00:00
|
|
|
message = instance_moderations.public_send(method) ? :success : :error
|
|
|
|
|
|
|
|
flash[:message] = I18n.t("instance_moderations.action_on_several.#{message}")
|
2024-02-26 20:37:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-26 15:27:56 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
# @return [InstanceModeration]
|
|
|
|
def instance_moderation
|
|
|
|
@instance_moderation ||= site.instance_moderations.find(params[:instance_moderation_id])
|
|
|
|
end
|
|
|
|
end
|