diff --git a/app/models/activity_pub/instance.rb b/app/models/activity_pub/instance.rb index 627ccb10..42cd2695 100644 --- a/app/models/activity_pub/instance.rb +++ b/app/models/activity_pub/instance.rb @@ -15,12 +15,18 @@ class ActivityPub has_many :actors has_many :instance_moderations + # XXX: Mantenemos esto por si queremos bloquear una instancia a + # nivel general aasm do state :paused, initial: true state :allowed state :blocked end + def list_name + "@*@#{hostname}" + end + def uri @uri ||= "https://#{hostname}/" end diff --git a/app/models/instance_moderation.rb b/app/models/instance_moderation.rb index 3c092958..17b38fb7 100644 --- a/app/models/instance_moderation.rb +++ b/app/models/instance_moderation.rb @@ -13,15 +13,39 @@ class InstanceModeration < ApplicationRecord state :blocked event :pause do - transitions from: %i[allowed blocked], to: :paused + transitions from: %i[allowed blocked], to: :paused, guard: :pause_remotely! end event :allow do - transitions from: %i[paused blocked], to: :allowed + transitions from: %i[paused blocked], to: :allowed, guard: :allow_remotely! end event :block do - transitions from: %i[paused allowed], to: :blocked + 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 diff --git a/app/models/social_inbox.rb b/app/models/social_inbox.rb index 03612779..6677a320 100644 --- a/app/models/social_inbox.rb +++ b/app/models/social_inbox.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require 'distributed_press/v1/social/client' +require 'distributed_press/v1/social/allowlist' +require 'distributed_press/v1/social/blocklist' require 'distributed_press/v1/social/hook' require 'distributed_press/v1/social/inbox' require 'distributed_press/v1/social/dereferencer' @@ -59,6 +61,16 @@ class SocialInbox @hook ||= DistributedPress::V1::Social::Hook.new(client: client, actor: actor) end + # @return [DistributedPress::V1::Social::Allowlist] + def allowlist + @allowlist ||= DistributedPress::V1::Social::Allowlist.new(client: client, actor: actor) + end + + # @return [DistributedPress::V1::Social::Blocklist] + def blocklist + @blocklist ||= DistributedPress::V1::Social::Blocklist.new(client: client, actor: actor) + end + # @return [String] def public_key_url @public_key_url ||= SocialInbox.generate_uri(hostname) do |uri|