# frozen_string_literal: true # Gestiona la cola de moderación de actores class ActorModerationsController < ApplicationController include ModerationConcern ActorModeration.events.each do |actor_event| define_method(actor_event) do authorize actor_moderation # Crea una RemoteFlag si se envían los parámetros adecuados actor_moderation.update(actor_moderation_params(actor_moderation)) if actor_event == :report actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?") redirect_to_moderation_queue! end end # Ver el perfil remoto def show @remote_profile = actor_moderation.actor.content 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}!" may = :"may_#{action}?" redirect_to_moderation_queue! return unless ActorModeration.events.include? action ActorModeration.transaction do actor_moderations.find_each do |actor_moderation| next unless actor_moderation.public_send(may) actor_moderation.update(actor_moderation_params(actor_moderation)) if action == :report actor_moderation.public_send(method) end end end private def actor_moderation @actor_moderation ||= site.actor_moderations.find(params[:actor_moderation_id] || params[:id]) end # @return [String] def panel_actor_mention @panel_actor_mention ||= ENV.fetch('PANEL_ACTOR_MENTION', '@sutty@sutty.nl') end # @return [Hash] def actor_moderation_params(actor_moderation) { remote_flag_attributes: { id: actor_moderation.remote_flag_id, message: '' } }.tap do |p| p[:remote_flag_attributes][:site_id] = actor_moderation.site_id p[:remote_flag_attributes][:actor_id] = actor_moderation.actor_id I18n.available_locales.each do |locale| p[:remote_flag_attributes][:message].tap do |m| m += I18n.t(locale) m += ': ' m += I18n.t('actor_moderations.report_message', locale: locale, panel_actor_mention: panel_actor_mention) m += '\n\n' end end end end end