2024-02-28 20:34:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Mantiene la relación entre Site y Actor
|
|
|
|
class ActorModeration < ApplicationRecord
|
2024-03-16 18:12:55 +00:00
|
|
|
IGNORED_EVENTS = %i[remove].freeze
|
|
|
|
IGNORED_STATES = %i[removed].freeze
|
2024-02-28 20:34:34 +00:00
|
|
|
|
2024-03-12 17:24:38 +00:00
|
|
|
include AASM
|
|
|
|
|
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-28 20:34:34 +00:00
|
|
|
aasm do
|
2024-03-16 18:12:55 +00:00
|
|
|
state :paused, initial: true, before_enter: :pause_remotely!
|
|
|
|
state :allowed, before_enter: :allow_remotely!
|
|
|
|
state :blocked, before_enter: :block_remotely!
|
2024-02-28 20:34:34 +00:00
|
|
|
state :reported
|
2024-03-07 20:17:58 +00:00
|
|
|
state :removed
|
2024-02-28 20:34:34 +00:00
|
|
|
|
2024-03-16 18:12:55 +00:00
|
|
|
error_on_all_events do |e|
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, actor: actor.uri, actor_moderation: id })
|
|
|
|
end
|
|
|
|
|
2024-02-28 20:34:34 +00:00
|
|
|
event :pause do
|
|
|
|
transitions from: %i[allowed blocked reported], to: :paused
|
|
|
|
end
|
|
|
|
|
2024-03-13 18:29:34 +00:00
|
|
|
# Al permitir una cuenta no se permiten todos los comentarios
|
2024-03-08 18:31:41 +00:00
|
|
|
# pendientes de moderación que ya hizo.
|
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
|
|
|
|
end
|
|
|
|
|
2024-03-13 18:29:34 +00:00
|
|
|
# Al bloquear una cuenta no se bloquean todos los comentarios
|
2024-03-08 18:31:41 +00:00
|
|
|
# pendientes de moderación que hizo.
|
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
|
|
|
|
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
|
|
|
|
2024-03-16 18:12:55 +00:00
|
|
|
after 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
|
2024-03-07 20:17:58 +00:00
|
|
|
|
|
|
|
# Si un perfil es eliminado remotamente, tenemos que dejar de
|
|
|
|
# mostrarlo y todas sus actividades.
|
|
|
|
event :remove do
|
|
|
|
transitions to: :removed
|
2024-03-12 17:30:43 +00:00
|
|
|
|
2024-03-16 18:12:55 +00:00
|
|
|
after do
|
|
|
|
site.activity_pubs.where(actor_id: actor_id).remove_all!
|
2024-03-12 17:30:43 +00:00
|
|
|
end
|
2024-03-07 20:17:58 +00:00
|
|
|
end
|
2024-02-28 20:34:34 +00:00
|
|
|
end
|
2024-02-28 20:58:00 +00:00
|
|
|
|
2024-03-13 14:15:31 +00:00
|
|
|
# Definir eventos en masa
|
|
|
|
include AasmEventsConcern
|
|
|
|
|
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
|