5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 00:46:23 +00:00
panel/app/models/actor_moderation.rb

70 lines
1.5 KiB
Ruby
Raw Normal View History

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
belongs_to :site
belongs_to :actor, class_name: 'ActivityPub::Actor'
def self.events
aasm.events.map(&:name)
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
event :report do
2024-02-28 20:34:34 +00:00
transitions from: %i[blocked], to: :reported
end
end
2024-02-28 20:58:00 +00:00
def pause_remotely!
raise AASM::InvalidTransition unless
actor.mention &&
site.social_inbox.allowlist.delete(list: [actor.mention]).ok? &&
site.social_inbox.blocklist.delete(list: [actor.mention]).ok?
end
def allow_remotely!
raise AASM::InvalidTransition unless
actor.mention &&
site.social_inbox.allowlist.post(list: [actor.mention]).ok? &&
site.social_inbox.blocklist.delete(list: [actor.mention]).ok?
end
def block_remotely!
raise AASM::InvalidTransition unless
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