2024-03-04 16:49:07 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Gestiona acciones de moderación
|
|
|
|
class ActivityPubsController < ApplicationController
|
2024-03-04 17:47:20 +00:00
|
|
|
include ModerationConcern
|
|
|
|
|
2024-03-04 16:49:07 +00:00
|
|
|
ActivityPub.events.each do |event|
|
|
|
|
define_method(event) do
|
2024-03-04 17:47:20 +00:00
|
|
|
authorize activity_pub
|
|
|
|
|
2024-03-05 17:18:06 +00:00
|
|
|
activity_pub.update(remote_flag_params(activity_pub)) if event == :report
|
2024-03-04 16:49:07 +00:00
|
|
|
activity_pub.public_send(:"#{event}!") if activity_pub.public_send(:"may_#{event}?")
|
|
|
|
|
2024-03-08 18:18:19 +00:00
|
|
|
flash[:success] = I18n.t("activity_pubs.#{event}.success")
|
|
|
|
rescue Exception => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, params: params.permit!.to_h })
|
|
|
|
|
|
|
|
flash[:error] = I18n.t("activity_pubs.#{event}.error")
|
|
|
|
ensure
|
2024-03-04 17:47:20 +00:00
|
|
|
redirect_to_moderation_queue!
|
2024-03-04 16:49:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_on_several
|
2024-03-04 18:13:01 +00:00
|
|
|
activity_pubs = site.activity_pubs.where(id: params[:activity_pub])
|
|
|
|
|
|
|
|
authorize activity_pubs
|
|
|
|
|
|
|
|
action = params[:activity_pub_action].to_sym
|
2024-03-12 16:57:31 +00:00
|
|
|
method = :"#{action}_all!"
|
2024-03-04 18:13:01 +00:00
|
|
|
may = :"may_#{action}?"
|
|
|
|
|
2024-03-04 17:47:20 +00:00
|
|
|
redirect_to_moderation_queue!
|
2024-03-04 18:13:01 +00:00
|
|
|
|
|
|
|
return unless ActivityPub.events.include? action
|
|
|
|
|
2024-03-05 18:46:33 +00:00
|
|
|
# Crear una sola remote flag por autore
|
2024-03-04 18:13:01 +00:00
|
|
|
ActivityPub.transaction do
|
2024-03-12 16:57:31 +00:00
|
|
|
if action == :report
|
|
|
|
message = remote_flag_params(activity_pubs.first).dig(:remote_flag_attributes, :message)
|
|
|
|
|
|
|
|
activity_pubs.distinct.pluck(:actor_id).each do |actor_id|
|
|
|
|
remote_flag = ActivityPub::RemoteFlag.find_or_initialize_by(actor_id: actor_id, site_id: site.id)
|
|
|
|
remote_flag.message = message
|
|
|
|
# Lo estamos actualizando, con lo que lo vamos a volver a enviar
|
|
|
|
remote_flag.requeue if remote_flag.persisted?
|
|
|
|
remote_flag.save
|
|
|
|
# XXX: Idealmente todas las ActivityPub que enviamos pueden
|
|
|
|
# cambiar de estado, pero chequeamos de todas formas.
|
|
|
|
remote_flag.activity_pubs << (activity_pubs.where(actor_id: actor_id).to_a.select { |a| a.public_send(may) })
|
|
|
|
end
|
|
|
|
end
|
2024-03-08 18:18:19 +00:00
|
|
|
|
2024-03-12 16:57:31 +00:00
|
|
|
message = activity_pubs.public_send(method) ? :success : :error
|
2024-03-08 18:18:19 +00:00
|
|
|
|
2024-03-12 16:57:31 +00:00
|
|
|
flash[message] = I18n.t("activity_pubs.action_on_several.#{message}")
|
2024-03-04 18:13:01 +00:00
|
|
|
end
|
2024-03-04 16:49:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def activity_pub
|
|
|
|
@activity_pub ||= site.activity_pubs.find(params[:activity_pub_id])
|
|
|
|
end
|
|
|
|
end
|