2024-02-20 17:44:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# = ActivityPub =
|
|
|
|
#
|
|
|
|
# El registro de actividades recibidas y su estado. Cuando recibimos
|
|
|
|
# una actividad, puede estar destinada a varies actores dentro de Sutty,
|
|
|
|
# con lo que generamos una cola para cada une.
|
|
|
|
#
|
|
|
|
# @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions}
|
|
|
|
class ActivityPub < ApplicationRecord
|
|
|
|
include AASM
|
|
|
|
|
|
|
|
belongs_to :site
|
|
|
|
belongs_to :object, polymorphic: true
|
|
|
|
has_many :activities
|
|
|
|
|
|
|
|
validates :site_id, presence: true
|
|
|
|
validates :object_id, presence: true
|
2024-02-21 20:04:39 +00:00
|
|
|
validates :aasm_state, presence: true, inclusion: { in: %w[paused approved rejected reported removed] }
|
2024-02-20 17:44:52 +00:00
|
|
|
|
|
|
|
aasm do
|
|
|
|
# Todavía no hay una decisión sobre el objeto
|
|
|
|
state :paused, initial: true
|
|
|
|
# Le usuarie aprobó el objeto
|
|
|
|
state :approved
|
|
|
|
# Le usuarie rechazó el objeto
|
|
|
|
state :rejected
|
|
|
|
# Le usuarie reportó el objeto
|
|
|
|
state :reported
|
|
|
|
# Le actore eliminó el objeto
|
2024-02-21 18:44:41 +00:00
|
|
|
state :removed
|
2024-02-20 20:15:57 +00:00
|
|
|
|
|
|
|
# Recibir una acción de eliminación, eliminar el contenido de la
|
|
|
|
# base de datos. Esto elimina el contenido para todos los sitios
|
|
|
|
# porque estamos respetando lo que pidió le actore.
|
2024-02-21 18:44:41 +00:00
|
|
|
event :remove do
|
|
|
|
transitions to: :removed
|
2024-02-20 20:15:57 +00:00
|
|
|
|
2024-02-21 19:42:28 +00:00
|
|
|
before do
|
2024-02-21 20:05:17 +00:00
|
|
|
object.update(content: {}) unless object.content.empty?
|
2024-02-20 20:15:57 +00:00
|
|
|
end
|
|
|
|
end
|
2024-02-20 20:18:15 +00:00
|
|
|
|
|
|
|
# Si un objeto previamente aprobado fue actualizado, volvemos a
|
|
|
|
# pausarlo.
|
|
|
|
event :pause do
|
2024-02-22 21:42:20 +00:00
|
|
|
transitions from: %i[approved rejected], to: :paused
|
2024-02-21 16:04:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# La actividad se aprueba
|
|
|
|
event :approve do
|
2024-02-22 21:42:20 +00:00
|
|
|
transitions from: %i[paused rejected], to: :approved
|
2024-02-20 20:18:15 +00:00
|
|
|
end
|
2024-02-21 16:06:06 +00:00
|
|
|
|
|
|
|
# La actividad fue rechazada
|
|
|
|
event :reject do
|
2024-02-22 21:42:20 +00:00
|
|
|
transitions from: %i[paused approved], to: :rejected
|
2024-02-21 16:06:06 +00:00
|
|
|
end
|
2024-02-22 21:42:36 +00:00
|
|
|
|
|
|
|
# Solo podemos reportarla luego de rechazarla
|
|
|
|
event :report do
|
|
|
|
transitions from: :rejected, to: :reported
|
|
|
|
end
|
2024-02-20 17:44:52 +00:00
|
|
|
end
|
|
|
|
end
|