# frozen_string_literal: true # Mantiene el registro de relaciones entre sitios e instancias class InstanceModeration < ApplicationRecord IGNORED_EVENTS = [].freeze IGNORED_STATES = [].freeze include AASM belongs_to :site belongs_to :instance, class_name: 'ActivityPub::Instance' aasm do 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 # Al volver la instancia a pausa no cambiamos el estado de # moderaciĆ³n de actores pre-existente. event :pause do transitions from: %i[allowed blocked], to: :paused end # Al permitir, solo bloqueamos la instancia, sin modificar el estado # de les actores y comentarios retroactivamente. event :allow do transitions from: %i[paused blocked], to: :allowed end # Al bloquear, solo bloqueamos la instancia, sin modificar el estado # de les actores y comentarios retroactivamente. event :block do transitions from: %i[paused allowed], to: :blocked end end # Definir eventos en masa include AasmEventsConcern # @return [Array] def actor_ids ActivityPub::Actor.where(instance_id: instance_id).ids end # Elimina la instancia de todas las listas # # @return [Boolean] def pause_remotely! raise unless site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? && site.social_inbox.allowlist.delete(list: [instance.list_name]).ok? end # Deja de permitir la instancia # # @return [Boolean] def block_remotely! raise unless site.social_inbox.allowlist.delete(list: [instance.list_name]).ok? && site.social_inbox.blocklist.post(list: [instance.list_name]).ok? end # Permite la instancia # # @return [Boolean] def allow_remotely! raise unless site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? && site.social_inbox.allowlist.post(list: [instance.list_name]).ok? end end