diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index 33cd4d45..fce340db 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -38,6 +38,28 @@ class ActivityPub < ApplicationRecord end end + # Permite todos los comentarios. No podemos hacer acciones en masa + # sobre comentarios en la Social Inbox, con lo que tenemos que + # comunicarnos individualmente. + def self.allow_all! + self.find_each do |activity_pub| + activity_pub.allow! if activity_pub.may_allow? + rescue Exception => e + notify_exception!(e, activity_pub) + end + end + + # Rechaza todos los comentarios. No podemos hacer acciones en masa + # sobre comentarios en la Social Inbox, con lo que tenemos que + # comunicarnos individualmente. + def self.reject_all! + self.find_each do |activity_pub| + activity_pub.reject! if activity_pub.may_reject? + rescue Exception => e + notify_exception!(e, activity_pub) + end + end + aasm do # Todavía no hay una decisión sobre el objeto state :paused, initial: true @@ -68,7 +90,7 @@ class ActivityPub < ApplicationRecord transitions from: %i[paused], to: :approved before do - raise unless site.social_inbox.inbox.accept(id: object.uri).ok? + allow_remotely! end end @@ -77,7 +99,7 @@ class ActivityPub < ApplicationRecord transitions from: %i[paused approved], to: :rejected before do - raise unless site.social_inbox.inbox.reject(id: object.uri).ok? + reject_remotely! end end @@ -90,4 +112,12 @@ class ActivityPub < ApplicationRecord end end end + + def reject_remotely! + raise unless site.social_inbox.inbox.reject(id: object.uri).ok? + end + + def allow_remotely! + raise unless site.social_inbox.inbox.accept(id: object.uri).ok? + end end diff --git a/app/models/actor_moderation.rb b/app/models/actor_moderation.rb index 4b220a58..a510f1eb 100644 --- a/app/models/actor_moderation.rb +++ b/app/models/actor_moderation.rb @@ -50,11 +50,7 @@ class ActorModeration < ApplicationRecord before do allow_remotely! - site.activity_pubs.paused.where(actor_id: self.actor_id).find_each do |activity_pub| - activity_pub.allow! if activity_pub.may_allow? - rescue Exception => e - ExceptionNotifier.notify_exception(e, data: { site: site.name, activity_pub: activity_pub_id }) - end + site.activity_pubs.paused.where(actor_id: self.actor_id).allow_all! end end @@ -66,11 +62,7 @@ class ActorModeration < ApplicationRecord before do block_remotely! - site.activity_pubs.paused.where(actor_id: self.actor_id).find_each do |activity_pub| - activity_pub.reject! if activity_pub.may_reject? - rescue Exception => e - ExceptionNotifier.notify_exception(e, data: { site: site.name, activity_pub: activity_pub_id }) - end + site.activity_pubs.paused.where(actor_id: self.actor_id).reject_all! end end diff --git a/app/models/concerns/aasm_events_concern.rb b/app/models/concerns/aasm_events_concern.rb index 418368d8..b189dbe4 100644 --- a/app/models/concerns/aasm_events_concern.rb +++ b/app/models/concerns/aasm_events_concern.rb @@ -27,5 +27,13 @@ module AasmEventsConcern def self.states aasm.states.map(&:name) - self::IGNORED_STATES end + + # Envía notificación de errores + # + # @param exception [Exception] + # @param record [ApplicationRecord] + def notify_exception!(exception, record) + ExceptionNotifier.notify_exception(exception, data: { site: site.name, record_type: record.class.name, record_id: record.id }) + end end end