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

52 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# Mantiene el registro de relaciones entre sitios e instancias
class InstanceModeration < ApplicationRecord
include AASM
belongs_to :site
belongs_to :instance, class_name: 'ActivityPub::Instance'
aasm do
state :paused, initial: true
state :allowed
state :blocked
event :pause do
transitions from: %i[allowed blocked], to: :paused, guard: :pause_remotely!
end
event :allow do
transitions from: %i[paused blocked], to: :allowed, guard: :allow_remotely!
end
event :block do
transitions from: %i[paused allowed], to: :blocked, guard: :block_remotely!
end
end
# Elimina la instancia de todas las listas
#
# @return [Boolean]
def pause_remotely!
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!
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!
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
site.social_inbox.allowlist.post(list: [instance.list_name]).ok?
end
end