From 6c61aec60e177d522e0dacd7d50152c6ec72b5d0 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 29 Feb 2024 16:45:06 -0300 Subject: [PATCH] feat: al modificar un fediblock, cambiar el estado a todes les actores --- app/models/actor_moderation.rb | 12 ++++++++++++ app/models/fediblock_state.rb | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/models/actor_moderation.rb b/app/models/actor_moderation.rb index f186dd69..1d9bae5d 100644 --- a/app/models/actor_moderation.rb +++ b/app/models/actor_moderation.rb @@ -7,6 +7,18 @@ class ActorModeration < ApplicationRecord belongs_to :site belongs_to :actor, class_name: 'ActivityPub::Actor' + # Bloquea todes les Actores bloqueables + def self.block_all! + self.update_all(aasm_state: 'blocked', updated_at: Time.now) + end + + def self.pause_all! + self.update_all(aasm_state: 'paused', updated_at: Time.now) + end + + # Todos los eventos de la máquina de estados + # + # @return [Array] def self.events aasm.events.map(&:name) end diff --git a/app/models/fediblock_state.rb b/app/models/fediblock_state.rb index a160c43a..180a45b5 100644 --- a/app/models/fediblock_state.rb +++ b/app/models/fediblock_state.rb @@ -37,6 +37,11 @@ class FediblockState < ApplicationRecord # Luego esta tarea crea las que falten e ignora las que ya se # bloquearon. ActivityPub::InstanceModerationJob.perform_now(site: site, hostnames: fediblock.hostnames) + + # Bloquear a todes les Actores de las instancias bloqueadas para + # indicarle a le usuarie que les tiene que desbloquear + # manualmente. + ActorModeration.where(actor_id: actor_ids).paused.block_all! end end @@ -52,15 +57,27 @@ class FediblockState < ApplicationRecord disable_remotely! instance_moderations.pause_all! + + # Volver a pausar todes les actores de esta instancia que fueron + # bloqueades. + ActorModeration.where(actor_id: actor_ids).blocked.pause_all! end end end private + def actor_ids + ActivityPub::Actor.where(instance_id: instance_ids).pluck(:id) + end + + def instance_ids + fediblock.instances.pluck(:id) + end + # Todas las instancias de moderación de este sitio def instance_moderations - site.instance_moderations.where(instance_id: fediblock.instances.pluck(:id)) + site.instance_moderations.where(instance_id: instance_ids) end # @return [Array]