mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-29 21:16:22 +00:00
feat: poder cambiar el estado de moderación a instancias
This commit is contained in:
parent
dc11e6efc7
commit
ffdcb5fae8
3 changed files with 45 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue