5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 19:36:21 +00:00
panel/app/controllers/actor_moderations_controller.rb

68 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Gestiona la cola de moderación de actores
class ActorModerationsController < ApplicationController
2024-03-04 17:47:20 +00:00
include ModerationConcern
2024-03-05 19:24:16 +00:00
include ModerationFiltersConcern
2024-03-04 17:47:20 +00:00
2024-03-01 18:51:54 +00:00
ActorModeration.events.each do |actor_event|
define_method(actor_event) do
authorize actor_moderation
2024-03-01 18:51:54 +00:00
# Crea una RemoteFlag si se envían los parámetros adecuados
2024-03-05 17:18:06 +00:00
actor_moderation.update(remote_flag_params(actor_moderation)) if actor_event == :report
2024-03-01 18:51:54 +00:00
actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?")
2024-03-08 18:07:32 +00:00
flash[:success] = I18n.t("actor_moderations.#{actor_event}.success")
rescue Exception => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, params: params.permit!.to_h })
flash[:error] = I18n.t("actor_moderations.#{actor_event}.error")
ensure
2024-03-04 17:47:20 +00:00
redirect_to_moderation_queue!
end
end
# Ver el perfil remoto
def show
@remote_profile = actor_moderation.actor.content
2024-03-08 18:07:32 +00:00
@moderation_queue = rubanok_process(site.activity_pubs.where(actor_id: actor_moderation.actor_id),
with: ActivityPubProcessor)
end
def action_on_several
actor_moderations = site.actor_moderations.where(id: params[:actor_moderation])
authorize actor_moderations
action = params[:actor_moderation_action].to_sym
method = :"#{action}_all!"
may = :"may_#{action}?"
2024-03-04 17:47:20 +00:00
redirect_to_moderation_queue!
return unless ActorModeration.events.include? action
ActorModeration.transaction do
if action == :report
actor_moderations.find_each do |actor_moderation|
next unless actor_moderation.public_send(may)
2024-03-04 20:14:46 +00:00
actor_moderation.update(actor_moderation_params(actor_moderation))
end
end
2024-03-08 18:07:32 +00:00
message = actor_moderation.public_send(method) ? :success : :error
2024-03-08 18:07:32 +00:00
flash[message] = I18n.t("actor_moderations.action_on_several.#{message}")
end
end
private
def actor_moderation
@actor_moderation ||= site.actor_moderations.find(params[:actor_moderation_id] || params[:id])
end
end