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

feat: cuando une actore es eliminade, hay que eliminar sus estados de moderación

This commit is contained in:
f 2024-03-07 17:17:58 -03:00
parent 66e59ee5ad
commit 5a7331e00e
No known key found for this signature in database
5 changed files with 46 additions and 4 deletions

View file

@ -16,10 +16,16 @@ class ActivityPub
ActivityPub.transaction do ActivityPub.transaction do
object = ActivityPub::Object.find_by(uri: ActivityPub.uri_from_object(content['object'])) object = ActivityPub::Object.find_by(uri: ActivityPub.uri_from_object(content['object']))
if object if object.present?
object.activity_pubs.find_each do |activity_pub| object.activity_pubs.find_each do |activity_pub|
activity_pub.remove! if activity_pub.may_remove? activity_pub.remove! if activity_pub.may_remove?
end end
# Encontrar todas las acciones de moderación de le actore
# eliminade y moverlas a eliminar.
if object.actor_type? && object.actor.present?
ActorModeration.where(actor_id: object.actor.id).remove_all!
end
end end
activity_pub.remove! if activity_pub.may_remove? activity_pub.remove! if activity_pub.may_remove?

View file

@ -14,7 +14,12 @@ class ActivityPub
# #
# @return [ActivityPub::Actor,nil] # @return [ActivityPub::Actor,nil]
def actor def actor
ActivityPub::Actor.find_by(uri: content['actor']) ActivityPub::Actor.find_by(uri: actor_uri)
end
# @return [String]
def actor_uri
content['attributedTo']
end end
def actor_type? def actor_type?

View file

@ -7,6 +7,13 @@ class ActivityPub
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
# La URI de le Actor en este caso es la misma id
#
# @return [String]
def actor_uri
uri
end
# El objeto referencia a une Actor # El objeto referencia a une Actor
# #
# @see {https://www.w3.org/TR/activitystreams-vocabulary/#actor-types} # @see {https://www.w3.org/TR/activitystreams-vocabulary/#actor-types}

View file

@ -5,8 +5,8 @@ class ActorModeration < ApplicationRecord
include AASM include AASM
include AasmEventsConcern include AasmEventsConcern
IGNORED_EVENTS = [] IGNORED_EVENTS = %i[remove]
IGNORED_STATES = [] IGNORED_STATES = %i[removed]
belongs_to :site belongs_to :site
belongs_to :remote_flag, optional: true, class_name: 'ActivityPub::RemoteFlag' belongs_to :remote_flag, optional: true, class_name: 'ActivityPub::RemoteFlag'
@ -23,11 +23,16 @@ class ActorModeration < ApplicationRecord
self.update_all(aasm_state: 'paused', updated_at: Time.now) self.update_all(aasm_state: 'paused', updated_at: Time.now)
end end
def self.remove_all!
self.update_all(aasm_state: 'removed', updated_at: Time.now)
end
aasm do aasm do
state :paused, initial: true state :paused, initial: true
state :allowed state :allowed
state :blocked state :blocked
state :reported state :reported
state :removed
event :pause do event :pause do
transitions from: %i[allowed blocked reported], to: :paused transitions from: %i[allowed blocked reported], to: :paused
@ -62,6 +67,12 @@ class ActorModeration < ApplicationRecord
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting? ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag) if remote_flag.waiting?
end end
end end
# Si un perfil es eliminado remotamente, tenemos que dejar de
# mostrarlo y todas sus actividades.
event :remove do
transitions to: :removed
end
end end
def pause_remotely! def pause_remotely!

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
# Mover todes les actores eliminades
class RemoveActorModerations < ActiveRecord::Migration[6.1]
def up
actor_ids =
ActivityPub.where(aasm_state: 'removed', object_type: 'ActivityPub::Object::Person').distinct.pluck(:actor_id)
ActorModeration.where(id: actor_ids).remove_all!
end
def down; end
end