From a1b5e385b0ff97a079d60fb689fa05757002269e Mon Sep 17 00:00:00 2001 From: f Date: Mon, 26 Feb 2024 16:50:03 -0300 Subject: [PATCH] fix: los guards se ejecutan todo el tiempo --- app/models/instance_moderation.rb | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/models/instance_moderation.rb b/app/models/instance_moderation.rb index 17b38fb7..735ec387 100644 --- a/app/models/instance_moderation.rb +++ b/app/models/instance_moderation.rb @@ -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