diff --git a/app/mailers/activity_pub/actor_flagged_mailer.rb b/app/mailers/activity_pub/actor_flagged_mailer.rb new file mode 100644 index 00000000..ccf24568 --- /dev/null +++ b/app/mailers/activity_pub/actor_flagged_mailer.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ActivityPub + # Notifica a les moderadores cuando un sitio fue reportado. + class ActorFlaggedMailer < ::ApplicationMailer + # Envía correo a cada moderadore en su idioma + # + # @param :site_id [String,Integer] + # @param :site_name [String] + # @param :content [String] + def notify_moderators + Usuarie.moderators.pluck(:lang, :email).group_by(&:first).transform_values do |value| + value.last + end.each_pair do |lang, emails| + I18n.with_locale(lang) do + emails.each do |email| + mail to: email, subject: I18n.t('activity_pub.actor_flagged_mailer.notify_moderators.subject') + end + end + end + end + end +end diff --git a/app/models/activity_pub/activity/flag.rb b/app/models/activity_pub/activity/flag.rb index ffbc374b..f54b1d27 100644 --- a/app/models/activity_pub/activity/flag.rb +++ b/app/models/activity_pub/activity/flag.rb @@ -2,6 +2,16 @@ class ActivityPub class Activity - class Flag < ActivityPub::Activity; end + class Flag < ActivityPub::Activity + # Notifica a todes les moderadores + def update_activity_pub_state! + ActivityPub::ActorFlaggedMailer.with( + content: content['content'], + object: content['object'], + actor: content['actor'], + site_id: activity_pub.site_id + ).notify_moderators.deliver_later + end + end end end diff --git a/app/models/concerns/activity_pub/moderator_concern.rb b/app/models/concerns/activity_pub/moderator_concern.rb new file mode 100644 index 00000000..ed0cf245 --- /dev/null +++ b/app/models/concerns/activity_pub/moderator_concern.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ActivityPub + module ModeratorConcern + extend ActiveSupport::Concern + + included do + scope :moderators, ->() { where(moderator: true) } + end + end +end diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 4856f17f..b9a5bf94 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -3,6 +3,7 @@ # Usuarie de la plataforma class Usuarie < ApplicationRecord include Usuarie::Consent + include ActivityPub::ModeratorConcern devise :invitable, :database_authenticatable, :recoverable, :rememberable, :validatable, diff --git a/app/views/activity_pub/actor_flagged_mailer/notify_moderators.text.haml b/app/views/activity_pub/actor_flagged_mailer/notify_moderators.text.haml new file mode 100644 index 00000000..afe984f7 --- /dev/null +++ b/app/views/activity_pub/actor_flagged_mailer/notify_moderators.text.haml @@ -0,0 +1,18 @@ += t('.content', site_id: params[:site_id]) + += Terminal::Table.new do |table| + - if (actor = params[:actor].presence).present? + - table << [ t('.actor') ] + - table.add_separator + - table << [ actor ] + - table.add_separator + + - if (content = sanitize(params[:content])).present? + - table << [ word_wrap(content, line_width: 50) ] + - table.add_separator + + - if (uris = [params[:object]].flatten).present? + - table << [ t('.uris') ] + - table.add_separator + - uris.each do |uri| + - table << [ uri ] diff --git a/config/locales/en.yml b/config/locales/en.yml index b717c666..2b0f7946 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -120,6 +120,13 @@ en: confirm_report: "Send report to the remote instance? This action will also block the account." 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}." + activity_pub: + actor_flagged_mailer: + notify_moderators: + subject: "A site has been reported" + content: "The site with id %{site_id} has been reported. Please review the report ASAP." + actor: "Site" + uris: "Reported activities" activity_pubs: action_on_several: success: "Several comments have changed moderation state. You can find them using the filters on the Comments section." diff --git a/config/locales/es.yml b/config/locales/es.yml index e41c8a41..da9facb6 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -119,6 +119,13 @@ es: confirm_report: "¿Enviar el reporte a la instancia remota? Esta acción también bloqueará la cuenta." 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}." + activity_pub: + actor_flagged_mailer: + notify_moderators: + subject: "Un sitio ha sido reportado" + content: "El sitio con id %{site_id} ha sido reportado. Por favor revisa el reporte a la brevedad." + actor: "Sitio" + uris: "Actividades reportadas" activity_pubs: action_on_several: success: "Se ha modificado el estado de moderación de varios comentarios. Podés encontrarlos usando los filtros en la sección Comentarios." diff --git a/db/migrate/20241113183226_add_moderator_to_usuaries.rb b/db/migrate/20241113183226_add_moderator_to_usuaries.rb new file mode 100644 index 00000000..073e3c70 --- /dev/null +++ b/db/migrate/20241113183226_add_moderator_to_usuaries.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# Agrega el campo moderator para saber quiénes son moderadores +class AddModeratorToUsuaries < ActiveRecord::Migration[6.1] + def change + add_column :usuaries, :moderator, :boolean, default: false + end +end diff --git a/db/structure.sql b/db/structure.sql index fa1caf34..032425f1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1497,7 +1497,8 @@ CREATE TABLE public.usuaries ( privacy_policy_accepted_at timestamp without time zone, terms_of_service_accepted_at timestamp without time zone, code_of_conduct_accepted_at timestamp without time zone, - available_for_feedback_accepted_at timestamp without time zone + available_for_feedback_accepted_at timestamp without time zone, + moderator boolean DEFAULT false ); @@ -2734,6 +2735,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240318183846'), ('20240319124212'), ('20240319144735'), -('20240614191548'); +('20240614191548'), +('20241113183226');