2024-02-28 20:34:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Mantiene la relación entre Site y Actor
|
|
|
|
class ActorModeration < ApplicationRecord
|
|
|
|
include AASM
|
2024-03-04 16:49:07 +00:00
|
|
|
include AasmEventsConcern
|
|
|
|
|
|
|
|
IGNORED_EVENTS = []
|
2024-03-04 16:59:01 +00:00
|
|
|
IGNORED_STATES = []
|
2024-02-28 20:34:34 +00:00
|
|
|
|
|
|
|
belongs_to :site
|
2024-03-06 18:47:27 +00:00
|
|
|
belongs_to :remote_flag, optional: true, class_name: 'ActivityPub::RemoteFlag'
|
2024-02-28 20:34:34 +00:00
|
|
|
belongs_to :actor, class_name: 'ActivityPub::Actor'
|
|
|
|
|
2024-03-01 18:51:54 +00:00
|
|
|
accepts_nested_attributes_for :remote_flag
|
|
|
|
|
2024-02-29 19:45:06 +00:00
|
|
|
# Bloquea todes les Actores bloqueables
|
|
|
|
def self.block_all!
|
|
|
|
self.update_all(aasm_state: 'blocked', updated_at: Time.now)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pause_all!
|
|
|
|
self.update_all(aasm_state: 'paused', updated_at: Time.now)
|
|
|
|
end
|
|
|
|
|
2024-02-28 20:34:34 +00:00
|
|
|
aasm do
|
|
|
|
state :paused, initial: true
|
|
|
|
state :allowed
|
|
|
|
state :blocked
|
|
|
|
state :reported
|
|
|
|
|
|
|
|
event :pause do
|
|
|
|
transitions from: %i[allowed blocked reported], to: :paused
|
2024-02-28 20:58:00 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
pause_remotely!
|
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|
|
|
|
|
2024-02-28 20:58:00 +00:00
|
|
|
event :allow do
|
2024-02-28 20:34:34 +00:00
|
|
|
transitions from: %i[paused blocked reported], to: :allowed
|
2024-02-28 20:58:00 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
allow_remotely!
|
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|
|
|
|
|
2024-02-28 20:58:00 +00:00
|
|
|
event :block do
|
2024-02-28 20:34:34 +00:00
|
|
|
transitions from: %i[paused allowed], to: :blocked
|
2024-02-28 20:58:00 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
block_remotely!
|
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|
|
|
|
|
2024-03-01 18:51:54 +00:00
|
|
|
# Al reportar, necesitamos asociar una RemoteFlag para poder
|
|
|
|
# enviarla.
|
2024-02-28 22:10:37 +00:00
|
|
|
event :report do
|
2024-02-28 20:34:34 +00:00
|
|
|
transitions from: %i[blocked], to: :reported
|
2024-03-01 18:51:54 +00:00
|
|
|
|
|
|
|
before do
|
2024-03-05 19:00:47 +00:00
|
|
|
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting?
|
2024-03-01 18:51:54 +00:00
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|
|
|
|
end
|
2024-02-28 20:58:00 +00:00
|
|
|
|
|
|
|
def pause_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-28 20:58:00 +00:00
|
|
|
actor.mention &&
|
|
|
|
site.social_inbox.allowlist.delete(list: [actor.mention]).ok? &&
|
|
|
|
site.social_inbox.blocklist.delete(list: [actor.mention]).ok?
|
|
|
|
end
|
|
|
|
|
|
|
|
def allow_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-28 20:58:00 +00:00
|
|
|
actor.mention &&
|
|
|
|
site.social_inbox.allowlist.post(list: [actor.mention]).ok? &&
|
|
|
|
site.social_inbox.blocklist.delete(list: [actor.mention]).ok?
|
|
|
|
end
|
|
|
|
|
|
|
|
def block_remotely!
|
2024-03-06 17:31:32 +00:00
|
|
|
raise unless
|
2024-02-28 20:58:00 +00:00
|
|
|
actor.mention &&
|
|
|
|
site.social_inbox.allowlist.delete(list: [actor.mention]).ok? &&
|
|
|
|
site.social_inbox.blocklist.post(list: [actor.mention]).ok?
|
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|