mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-19 04:16:22 +00:00
chore: rubocop
This commit is contained in:
parent
fb4401fd53
commit
091d5ac41d
20 changed files with 132 additions and 70 deletions
|
@ -27,7 +27,9 @@ module Api
|
||||||
activity.update_activity_pub_state!
|
activity.update_activity_pub_state!
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
ExceptionNotifier.notify_exception(e, data: { site: site.name, usuarie: usuarie.email, activity: original_activity })
|
ExceptionNotifier.notify_exception(e,
|
||||||
|
data: { site: site.name, usuarie: usuarie.email,
|
||||||
|
activity: original_activity })
|
||||||
ensure
|
ensure
|
||||||
head :accepted
|
head :accepted
|
||||||
end
|
end
|
||||||
|
@ -59,11 +61,9 @@ module Api
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def object_uri
|
def object_uri
|
||||||
@object_uri ||=
|
@object_uri ||=
|
||||||
begin
|
case original_activity[:object]
|
||||||
case original_activity[:object]
|
when String then original_activity[:object]
|
||||||
when String then original_activity[:object]
|
when Hash then original_activity.dig(:object, :id)
|
||||||
when Hash then original_activity.dig(:object, :id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
raise ActiveRecord::RecordNotFound, 'object id missing' unless @object_uri
|
raise ActiveRecord::RecordNotFound, 'object id missing' unless @object_uri
|
||||||
|
@ -82,7 +82,8 @@ module Api
|
||||||
#
|
#
|
||||||
# @return [ActivityPub::Object]
|
# @return [ActivityPub::Object]
|
||||||
def object
|
def object
|
||||||
@object ||= ActivityPub::Object.type_from(original_object).find_or_initialize_by(actor: actor, uri: object_uri).tap do |o|
|
@object ||= ActivityPub::Object.type_from(original_object).find_or_initialize_by(actor: actor,
|
||||||
|
uri: object_uri).tap do |o|
|
||||||
if object_embedded?
|
if object_embedded?
|
||||||
o.content = original_object
|
o.content = original_object
|
||||||
else
|
else
|
||||||
|
@ -104,7 +105,8 @@ module Api
|
||||||
#
|
#
|
||||||
# @return [ActivityPub::Activity]
|
# @return [ActivityPub::Activity]
|
||||||
def activity
|
def activity
|
||||||
@activity ||= ActivityPub::Activity.type_from(original_activity).new(uri: original_activity[:id], activity_pub: activity_pub).tap do |a|
|
@activity ||= ActivityPub::Activity.type_from(original_activity).new(uri: original_activity[:id],
|
||||||
|
activity_pub: activity_pub).tap do |a|
|
||||||
a.content = original_activity.dup
|
a.content = original_activity.dup
|
||||||
a.content[:object] = object.uri
|
a.content[:object] = object.uri
|
||||||
a.save!
|
a.save!
|
||||||
|
|
|
@ -7,16 +7,18 @@
|
||||||
# disponible para todo el CMS. Asumimos que el objeto devuelto es el
|
# disponible para todo el CMS. Asumimos que el objeto devuelto es el
|
||||||
# mismo para todo el mundo y las credenciales solo son para
|
# mismo para todo el mundo y las credenciales solo son para
|
||||||
# autenticación.
|
# autenticación.
|
||||||
class ActivityPub::FetchJob < ApplicationJob
|
class ActivityPub
|
||||||
def perform(site:, object:)
|
class FetchJob < ApplicationJob
|
||||||
ActivityPub::Object.transaction do
|
def perform(site:, object:)
|
||||||
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
ActivityPub::Object.transaction do
|
||||||
|
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
||||||
|
|
||||||
# @todo Fallar cuando la respuesta no funcione?
|
# @todo Fallar cuando la respuesta no funcione?
|
||||||
return unless response.ok?
|
return unless response.ok?
|
||||||
return unless response.miss?
|
return unless response.miss?
|
||||||
|
|
||||||
object.update(content: FastJsonparser.parse(response.body))
|
object.update(content: FastJsonparser.parse(response.body))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,19 +11,21 @@
|
||||||
# envía como referencia en lugar de anidarlo.
|
# envía como referencia en lugar de anidarlo.
|
||||||
#
|
#
|
||||||
# @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions}
|
# @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions}
|
||||||
class ActivityPub::Activity < ApplicationRecord
|
class ActivityPub
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
class Activity < ApplicationRecord
|
||||||
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :activity_pub
|
belongs_to :activity_pub
|
||||||
has_one :object, through: :activity_pub
|
has_one :object, through: :activity_pub
|
||||||
|
|
||||||
validates :activity_pub_id, presence: true
|
validates :activity_pub_id, presence: true
|
||||||
|
|
||||||
# Siempre en orden descendiente para saber el último estado
|
# Siempre en orden descendiente para saber el último estado
|
||||||
default_scope -> { order(created_at: :desc) }
|
default_scope -> { order(created_at: :desc) }
|
||||||
|
|
||||||
# Cambia la máquina de estados según el tipo de actividad
|
# Cambia la máquina de estados según el tipo de actividad
|
||||||
def update_activity_pub_state!
|
def update_activity_pub_state!
|
||||||
nil
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Create < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Create < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Delete < ActivityPub::Activity
|
class ActivityPub
|
||||||
# Si estamos eliminando el objeto, tenemos que vaciar su contenido y
|
module Activity
|
||||||
# cambiar el estado a borrado
|
class Delete < ActivityPub::Activity
|
||||||
def update_activity_pub_state!
|
# Si estamos eliminando el objeto, tenemos que vaciar su contenido y
|
||||||
activity_pub.deleted!
|
# cambiar el estado a borrado
|
||||||
|
def update_activity_pub_state!
|
||||||
|
activity_pub.deleted!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Flag < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Flag < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,4 +4,8 @@
|
||||||
#
|
#
|
||||||
# Una actividad de seguimiento se refiere siempre a une actore (el
|
# Una actividad de seguimiento se refiere siempre a une actore (el
|
||||||
# sitio) y proviene de otre actore.
|
# sitio) y proviene de otre actore.
|
||||||
class ActivityPub::Activity::Follow < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Follow < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Generic < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Generic < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,5 +4,9 @@
|
||||||
#
|
#
|
||||||
# Deshace una actividad, dependiendo de la actividad a la que se
|
# Deshace una actividad, dependiendo de la actividad a la que se
|
||||||
# refiere.
|
# refiere.
|
||||||
class ActivityPub::Activity::Undo < ActivityPub::Activity
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Undo < ActivityPub::Activity
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Update < ActivityPub::Activity
|
class ActivityPub
|
||||||
# Si estamos actualizando el objeto, tenemos que devolverlo a estado
|
module Activity
|
||||||
# de moderación
|
class Update < ActivityPub::Activity
|
||||||
def update_activity_pub_state!
|
# Si estamos actualizando el objeto, tenemos que devolverlo a estado
|
||||||
activity_pub.pause! if activity_pub.approved?
|
# de moderación
|
||||||
|
def update_activity_pub_state!
|
||||||
|
activity_pub.pause! if activity_pub.approved?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
# Actor es la entidad que realiza acciones en ActivityPub
|
# Actor es la entidad que realiza acciones en ActivityPub
|
||||||
#
|
#
|
||||||
# @todo Obtener el perfil dinámicamente
|
# @todo Obtener el perfil dinámicamente
|
||||||
class ActivityPub::Actor < ApplicationRecord
|
class ActivityPub
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
class Actor < ApplicationRecord
|
||||||
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :instance
|
belongs_to :instance
|
||||||
has_many :activity_pubs, as: :object
|
has_many :activity_pubs, as: :object
|
||||||
has_many :objects
|
has_many :objects
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,18 +4,20 @@
|
||||||
#
|
#
|
||||||
# Representa cada instancia del fediverso que interactúa con la Social
|
# Representa cada instancia del fediverso que interactúa con la Social
|
||||||
# Inbox.
|
# Inbox.
|
||||||
class ActivityPub::Instance < ApplicationRecord
|
class ActivityPub
|
||||||
include AASM
|
class Instance < ApplicationRecord
|
||||||
|
include AASM
|
||||||
|
|
||||||
validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] }
|
validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] }
|
||||||
validates :hostname, uniqueness: true, hostname: true
|
validates :hostname, uniqueness: true, hostname: true
|
||||||
|
|
||||||
has_many :activity_pubs
|
has_many :activity_pubs
|
||||||
has_many :actors
|
has_many :actors
|
||||||
|
|
||||||
aasm do
|
aasm do
|
||||||
state :paused, initial: true
|
state :paused, initial: true
|
||||||
state :allowed
|
state :allowed
|
||||||
state :blocked
|
state :blocked
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Almacena objetos de ActivityPub, como Note, Article, etc.
|
# Almacena objetos de ActivityPub, como Note, Article, etc.
|
||||||
class ActivityPub::Object < ApplicationRecord
|
class ActivityPub
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
class Object < ApplicationRecord
|
||||||
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :actor
|
belongs_to :actor
|
||||||
has_many :activity_pubs, as: :object
|
has_many :activity_pubs, as: :object
|
||||||
|
|
||||||
validates :actor_id, presence: true
|
validates :actor_id, presence: true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Application =
|
# = Application =
|
||||||
#
|
#
|
||||||
# Una aplicación o instancia
|
# Una aplicación o instancia
|
||||||
class ActivityPub::Object::Application < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Application < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Article =
|
# = Article =
|
||||||
#
|
#
|
||||||
# Representa artículos
|
# Representa artículos
|
||||||
class ActivityPub::Object::Article < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Article < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# = Generic =
|
# = Generic =
|
||||||
class ActivityPub::Object::Generic < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Generic < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Note =
|
# = Note =
|
||||||
#
|
#
|
||||||
# Representa notas, el tipo más común de objeto del Fediverso.
|
# Representa notas, el tipo más común de objeto del Fediverso.
|
||||||
class ActivityPub::Object::Note < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Note < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Organization =
|
# = Organization =
|
||||||
#
|
#
|
||||||
# Una organización
|
# Una organización
|
||||||
class ActivityPub::Object::Organization < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Organization < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Person =
|
# = Person =
|
||||||
#
|
#
|
||||||
# Una persona, el perfil de une actore
|
# Una persona, el perfil de une actore
|
||||||
class ActivityPub::Object::Person < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Person < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -69,8 +69,6 @@ class SocialInbox
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def generate_uri(&block)
|
def generate_uri(&block)
|
||||||
@public_key_url ||= URI("https://#{hostname}").tap do |uri|
|
@public_key_url ||= URI("https://#{hostname}").tap(&block).to_s
|
||||||
yield uri
|
|
||||||
end.to_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue