From 3a382390b1e82f78df79b6910cfd6d4ecdee8c1c Mon Sep 17 00:00:00 2001 From: f Date: Thu, 22 Feb 2024 18:42:20 -0300 Subject: [PATCH 1/2] fix: la social inbox no confirma acciones! --- .../v1/webhooks/social_inbox_controller.rb | 24 ++++++++++++++----- app/models/activity_pub.rb | 8 +++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index c71c4922..1ffc1596 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -38,21 +38,33 @@ module Api head :accepted end - # Cuando aprobamos una actividad, recibimos la confirmación y - # cambiamos el estado. + # Cuando la Social Inbox acepta una actividad, la recibimos + # igual y la guardamos por si cambiamos de idea. + # + # @todo DRY def onapproved ActivityPub.transaction do - activity_pub.approve! if activity_pub.waiting? + actor.present? + instance.present? + object.present? + activity.present? + activity_pub.approve! end head :accepted end - # Cuando rechazamos una actividad, recibimos la confirmación y - # cambiamos el estado + # Cuando la Social Inbox rechaza una actividad, la recibimos + # igual y la guardamos por si cambiamos de idea. + # + # @todo DRY def onrejected ActivityPub.transaction do - activity_pub.reject! if activity_pub.waiting? + actor.present? + instance.present? + object.present? + activity.present? + activity_pub.reject! end head :accepted diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index df8e5c5c..07754b87 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -21,8 +21,6 @@ class ActivityPub < ApplicationRecord aasm do # Todavía no hay una decisión sobre el objeto state :paused, initial: true - # Estamos esperando respuesta desde la Social Inbox - state :waiting # Le usuarie aprobó el objeto state :approved # Le usuarie rechazó el objeto @@ -46,17 +44,17 @@ class ActivityPub < ApplicationRecord # Si un objeto previamente aprobado fue actualizado, volvemos a # pausarlo. event :pause do - transitions from: %i[waiting approved rejected], to: :paused + transitions from: %i[approved rejected], to: :paused end # La actividad se aprueba event :approve do - transitions from: :waiting, to: :approved + transitions from: %i[paused rejected], to: :approved end # La actividad fue rechazada event :reject do - transitions from: :waiting, to: :rejected + transitions from: %i[paused approved], to: :rejected end end end From fd1d2382fa481ec45888bb036bc8aac27e3d50b4 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 22 Feb 2024 18:42:36 -0300 Subject: [PATCH 2/2] feat: luego de rechazar podemos reportar --- app/models/activity_pub.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index 07754b87..217c15a1 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -56,5 +56,10 @@ class ActivityPub < ApplicationRecord event :reject do transitions from: %i[paused approved], to: :rejected end + + # Solo podemos reportarla luego de rechazarla + event :report do + transitions from: :rejected, to: :reported + end end end