5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-28 14:26:21 +00:00

feat: poder reportar comentarios

This commit is contained in:
f 2024-03-05 14:18:06 -03:00
parent 67a56c540a
commit ff428c6527
No known key found for this signature in database
10 changed files with 58 additions and 28 deletions

View file

@ -8,6 +8,7 @@ class ActivityPubsController < ApplicationController
define_method(event) do define_method(event) do
authorize activity_pub authorize activity_pub
activity_pub.update(remote_flag_params(activity_pub)) if event == :report
activity_pub.public_send(:"#{event}!") if activity_pub.public_send(:"may_#{event}?") activity_pub.public_send(:"#{event}!") if activity_pub.public_send(:"may_#{event}?")
redirect_to_moderation_queue! redirect_to_moderation_queue!
@ -29,7 +30,9 @@ class ActivityPubsController < ApplicationController
ActivityPub.transaction do ActivityPub.transaction do
activity_pubs.find_each do |activity_pub| activity_pubs.find_each do |activity_pub|
activity_pub.public_send(method) if activity_pub.public_send(may) next unless activity_pub.public_send(may)
activity_pub.public_send(method)
end end
end end
end end

View file

@ -9,7 +9,7 @@ class ActorModerationsController < ApplicationController
authorize actor_moderation authorize actor_moderation
# Crea una RemoteFlag si se envían los parámetros adecuados # Crea una RemoteFlag si se envían los parámetros adecuados
actor_moderation.update(actor_moderation_params(actor_moderation)) if actor_event == :report actor_moderation.update(remote_flag_params(actor_moderation)) if actor_event == :report
actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?") actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?")
@ -51,26 +51,4 @@ class ActorModerationsController < ApplicationController
def actor_moderation def actor_moderation
@actor_moderation ||= site.actor_moderations.find(params[:actor_moderation_id] || params[:id]) @actor_moderation ||= site.actor_moderations.find(params[:actor_moderation_id] || params[:id])
end end
# @return [String]
def panel_actor_mention
@panel_actor_mention ||= ENV.fetch('PANEL_ACTOR_MENTION', '@sutty@sutty.nl')
end
# @return [Hash]
def actor_moderation_params(actor_moderation)
{ remote_flag_attributes: { id: actor_moderation.remote_flag_id, message: '' } }.tap do |p|
p[:remote_flag_attributes][:site_id] = actor_moderation.site_id
p[:remote_flag_attributes][:actor_id] = actor_moderation.actor_id
I18n.available_locales.each do |locale|
p[:remote_flag_attributes][:message].tap do |m|
m += I18n.t(locale)
m += ': '
m += I18n.t('actor_moderations.report_message', locale: locale, panel_actor_mention: panel_actor_mention)
m += '\n\n'
end
end
end
end
end end

View file

@ -9,5 +9,26 @@ module ModerationConcern
def redirect_to_moderation_queue! def redirect_to_moderation_queue!
redirect_back fallback_location: site_moderation_queue_path(**(session[:moderation_queue_filters] || {})) redirect_back fallback_location: site_moderation_queue_path(**(session[:moderation_queue_filters] || {}))
end end
# @return [String]
def panel_actor_mention
@panel_actor_mention ||= ENV.fetch('PANEL_ACTOR_MENTION', '@sutty@sutty.nl')
end
def remote_flag_params(model)
{ remote_flag_attributes: { id: model.remote_flag_id, message: '' } }.tap do |p|
p[:remote_flag_attributes][:site_id] = model.site_id
p[:remote_flag_attributes][:actor_id] = model.actor_id
I18n.available_locales.each do |locale|
p[:remote_flag_attributes][:message].tap do |m|
m << I18n.t(locale)
m << ': '
m << I18n.t('remote_flags.report_message', locale: locale, panel_actor_mention: panel_actor_mention)
m << '\n\n'
end
end
end
end
end end
end end

View file

@ -13,7 +13,7 @@ class ActivityPub
self.priority = 30 self.priority = 30
def perform(remote_flag:) def perform(remote_flag:)
client = remote_flag.site.social_inbox.client_for(remote_flag.actor.content['inbox']) client = remote_flag.site.social_inbox.client_for(remote_flag.actor&.content['inbox'])
response = client.post(endpoint: '', body: remote_flag.content) response = client.post(endpoint: '', body: remote_flag.content)
raise 'No se pudo enviar el reporte' unless response.ok? raise 'No se pudo enviar el reporte' unless response.ok?

View file

@ -18,12 +18,15 @@ class ActivityPub < ApplicationRecord
belongs_to :site belongs_to :site
belongs_to :object, polymorphic: true belongs_to :object, polymorphic: true
belongs_to :actor belongs_to :actor
belongs_to :remote_flag, class_name: 'ActivityPub::RemoteFlag'
has_many :activities has_many :activities
validates :site_id, presence: true validates :site_id, presence: true
validates :object_id, presence: true validates :object_id, presence: true
validates :aasm_state, presence: true, inclusion: { in: %w[paused approved rejected reported removed] } validates :aasm_state, presence: true, inclusion: { in: %w[paused approved rejected reported removed] }
accepts_nested_attributes_for :remote_flag
# Encuentra la URI de un objeto # Encuentra la URI de un objeto
# #
# @return [String, nil] # @return [String, nil]
@ -83,6 +86,10 @@ class ActivityPub < ApplicationRecord
# Solo podemos reportarla luego de rechazarla # Solo podemos reportarla luego de rechazarla
event :report do event :report do
transitions from: :rejected, to: :reported transitions from: :rejected, to: :reported
before do
ActivityPub::RemoteFlagJob.perform_later(remote_flag: remote_flag)
end
end end
end end
end end

View file

@ -5,6 +5,11 @@ class ActivityPub
belongs_to :actor belongs_to :actor
belongs_to :site belongs_to :site
has_one :actor_moderation
has_many :activity_pubs
# XXX: source_type es obligatorio para el `through`
has_many :objects, through: :activity_pubs, source_type: 'ActivityPub::Object::Note'
# Genera la actividad a enviar # Genera la actividad a enviar
def content def content
{ {
@ -13,7 +18,7 @@ class ActivityPub
'type' => 'Flag', 'type' => 'Flag',
'actor' => ENV.fetch('PANEL_ACTOR_ID') { "https://#{ENV['SUTTY']}/about.jsonld" }, 'actor' => ENV.fetch('PANEL_ACTOR_ID') { "https://#{ENV['SUTTY']}/about.jsonld" },
'content' => message.to_s, 'content' => message.to_s,
'object' => [ actor.uri ] 'object' => [ actor.uri ] + objects.pluck(:uri)
} }
end end
end end

View file

@ -116,6 +116,7 @@ en:
profile_id: ID profile_id: ID
profile_published: Published profile_published: Published
profile_summary: Summary profile_summary: Summary
remote_flags:
report_message: "Hi! Someone using Sutty CMS reported this account on your instance. We don't have support for customized report messages yet, but we will soon. You can reach us at %{panel_actor_mention}." report_message: "Hi! Someone using Sutty CMS reported this account on your instance. We don't have support for customized report messages yet, but we will soon. You can reach us at %{panel_actor_mention}."
moderation_queue: moderation_queue:
everything: 'Select all' everything: 'Select all'

View file

@ -115,6 +115,7 @@ es:
profile_id: ID profile_id: ID
profile_published: Publicada profile_published: Publicada
profile_summary: Presentación profile_summary: Presentación
remote_flags:
report_message: "¡Hola! Une usuarie de Sutty CMS reportó esta cuenta en tu instancia. Todavía no tenemos soporte para mensajes personalizados. Podés contactarnos en %{panel_actor_mention}." report_message: "¡Hola! Une usuarie de Sutty CMS reportó esta cuenta en tu instancia. Todavía no tenemos soporte para mensajes personalizados. Podés contactarnos en %{panel_actor_mention}."
moderation_queue: moderation_queue:
everything: 'Seleccionar todo' everything: 'Seleccionar todo'

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
# Agrega relaciones en las remote flags
class ChangeRemoteFlags < ActiveRecord::Migration[6.1]
def up
add_column :activity_pubs, :remote_flag_id, :uuid, index: true, null: true
end
def down
remove_column :activity_pubs, :remote_flag_id
end
end

View file

@ -573,7 +573,8 @@ CREATE TABLE public.activity_pubs (
object_type character varying NOT NULL, object_type character varying NOT NULL,
aasm_state character varying NOT NULL, aasm_state character varying NOT NULL,
instance_id uuid, instance_id uuid,
actor_id uuid actor_id uuid,
remote_flag_id uuid
); );
@ -2695,6 +2696,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240229201155'), ('20240229201155'),
('20240301181224'), ('20240301181224'),
('20240301194154'), ('20240301194154'),
('20240301202955'); ('20240301202955'),
('20240305164653');