2024-02-26 15:27:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Mantiene el registro de relaciones entre sitios e instancias
|
|
|
|
class InstanceModeration < ApplicationRecord
|
2024-03-16 18:12:55 +00:00
|
|
|
IGNORED_EVENTS = [].freeze
|
|
|
|
IGNORED_STATES = [].freeze
|
2024-02-26 15:27:56 +00:00
|
|
|
|
2024-03-12 17:24:38 +00:00
|
|
|
include AASM
|
|
|
|
|
2024-02-26 15:27:56 +00:00
|
|
|
belongs_to :site
|
|
|
|
belongs_to :instance, class_name: 'ActivityPub::Instance'
|
|
|
|
|
|
|
|
aasm do
|
2024-03-16 18:12:55 +00:00
|
|
|
state :paused, initial: true, before_enter: :pause_remotely!
|
|
|
|
state :allowed, before_enter: :allow_remotely!
|
|
|
|
state :blocked, before_enter: :block_remotely!
|
|
|
|
|
|
|
|
error_on_all_events do |e|
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, instance: instance.hostname, instance_moderation: id })
|
|
|
|
end
|
2024-02-26 15:27:56 +00:00
|
|
|
|
2024-03-12 16:57:31 +00:00
|
|
|
# Al volver la instancia a pausa no cambiamos el estado de
|
|
|
|
# moderación de actores pre-existente.
|
2024-02-26 15:27:56 +00:00
|
|
|
event :pause do
|
2024-02-26 19:50:03 +00:00
|
|
|
transitions from: %i[allowed blocked], to: :paused
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
|
2024-03-13 18:29:34 +00:00
|
|
|
# Al permitir, solo bloqueamos la instancia, sin modificar el estado
|
|
|
|
# de les actores y comentarios retroactivamente.
|
2024-02-26 15:27:56 +00:00
|
|
|
event :allow do
|
2024-02-26 19:50:03 +00:00
|
|
|
transitions from: %i[paused blocked], to: :allowed
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
|
2024-03-13 18:29:34 +00:00
|
|
|
# Al bloquear, solo bloqueamos la instancia, sin modificar el estado
|
|
|
|
# de les actores y comentarios retroactivamente.
|
2024-02-26 15:27:56 +00:00
|
|
|
event :block do
|
2024-02-26 19:50:03 +00:00
|
|
|
transitions from: %i[paused allowed], to: :blocked
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|
|
|
|
end
|
2024-02-26 19:12:56 +00:00
|
|
|
|
2024-03-13 14:15:31 +00:00
|
|
|
# Definir eventos en masa
|
|
|
|
include AasmEventsConcern
|
|
|
|
|
2024-03-12 16:57:31 +00:00
|
|
|
# @return [Array<String>]
|
|
|
|
def actor_ids
|
2024-03-16 18:12:55 +00:00
|
|
|
ActivityPub::Actor.where(instance_id: instance_id).ids
|
2024-03-12 16:57:31 +00:00
|
|
|
end
|
|
|
|
|
2024-02-26 19:12:56 +00:00
|
|
|
# Elimina la instancia de todas las listas
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def pause_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-26 19:50:03 +00:00
|
|
|
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
|
2024-02-26 19:12:56 +00:00
|
|
|
site.social_inbox.allowlist.delete(list: [instance.list_name]).ok?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Deja de permitir la instancia
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def block_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-26 19:50:03 +00:00
|
|
|
site.social_inbox.allowlist.delete(list: [instance.list_name]).ok? &&
|
2024-02-26 19:12:56 +00:00
|
|
|
site.social_inbox.blocklist.post(list: [instance.list_name]).ok?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Permite la instancia
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def allow_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-26 19:50:03 +00:00
|
|
|
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
|
2024-02-26 19:12:56 +00:00
|
|
|
site.social_inbox.allowlist.post(list: [instance.list_name]).ok?
|
|
|
|
end
|
2024-02-26 15:27:56 +00:00
|
|
|
end
|