5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 19:36:21 +00:00

feat: acciones en masa para actividades

This commit is contained in:
f 2024-03-08 15:55:01 -03:00
parent 071102fa3b
commit 522cef8c9a
No known key found for this signature in database
3 changed files with 42 additions and 12 deletions

View file

@ -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

View file

@ -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

View file

@ -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