5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 14:56:22 +00:00

fix: los guards se ejecutan todo el tiempo

This commit is contained in:
f 2024-02-26 16:50:03 -03:00
parent 591d56581e
commit a1b5e385b0
No known key found for this signature in database

View file

@ -13,15 +13,27 @@ class InstanceModeration < ApplicationRecord
state :blocked
event :pause do
transitions from: %i[allowed blocked], to: :paused, guard: :pause_remotely!
transitions from: %i[allowed blocked], to: :paused
before do
pause_remotely!
end
end
event :allow do
transitions from: %i[paused blocked], to: :allowed, guard: :allow_remotely!
transitions from: %i[paused blocked], to: :allowed
before do
allow_remotely!
end
end
event :block do
transitions from: %i[paused allowed], to: :blocked, guard: :block_remotely!
transitions from: %i[paused allowed], to: :blocked
before do
block_remotely!
end
end
end
@ -29,7 +41,8 @@ class InstanceModeration < ApplicationRecord
#
# @return [Boolean]
def pause_remotely!
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
raise AASM::InvalidTransition unless
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
site.social_inbox.allowlist.delete(list: [instance.list_name]).ok?
end
@ -37,7 +50,8 @@ class InstanceModeration < ApplicationRecord
#
# @return [Boolean]
def block_remotely!
site.social_inbox.allowlist.delete(list: [instance.list_name]).ok? &&
raise AASM::InvalidTransition unless
site.social_inbox.allowlist.delete(list: [instance.list_name]).ok? &&
site.social_inbox.blocklist.post(list: [instance.list_name]).ok?
end
@ -45,7 +59,8 @@ class InstanceModeration < ApplicationRecord
#
# @return [Boolean]
def allow_remotely!
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
raise AASM::InvalidTransition unless
site.social_inbox.blocklist.delete(list: [instance.list_name]).ok? &&
site.social_inbox.allowlist.post(list: [instance.list_name]).ok?
end
end