5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 20:26:22 +00:00
panel/app/models/instance_moderation.rb

86 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Mantiene el registro de relaciones entre sitios e instancias
class InstanceModeration < ApplicationRecord
include AASM
include AasmEventsConcern
IGNORED_EVENTS = []
IGNORED_STATES = []
belongs_to :site
belongs_to :instance, class_name: 'ActivityPub::Instance'
aasm do
state :paused, initial: true
state :allowed
state :blocked
# 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
before do
pause_remotely!
end
end
# Al permitir, también permitimos todes les actores que no hayan
# tenido acciones de moderación.
event :allow do
transitions from: %i[paused blocked], to: :allowed
before do
allow_remotely!
site.actor_moderations.paused.where(actor_id: actor_ids).allow_all!
end
end
# Al bloquear, también bloqueamos a todes les actores que no hayan
# tenido acciones de moderación.
event :block do
transitions from: %i[paused allowed], to: :blocked
before do
block_remotely!
site.actor_moderations.paused.where(actor_id: actor_ids).block_all!
end
end
end
# @return [Array<String>]
def actor_ids
ActivityPub::Actor.where(instance_id: self.instance_id).ids
end
# Elimina la instancia de todas las listas
#
# @return [Boolean]
def pause_remotely!
2024-03-06 17:31:32 +00:00
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!
2024-03-06 17:31:32 +00:00
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!
2024-03-06 17:31:32 +00:00
raise unless
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
site.social_inbox.allowlist.post(list: [instance.list_name]).ok?
end
end