From 6c3bfba86729163be4cbb44d4baeafcd2ee3b02f Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 19 Aug 2026 17:33:15 +0200 Subject: [PATCH] Add mailing for new moderation suggestions --- app/mailers/admin_mailer.rb | 4 ++++ app/models/user_settings.rb | 1 + .../new_moderation_suggestions.text.erb | 3 +++ .../preferences/notifications/show.html.haml | 3 ++- .../moderation_list_synchronization_scheduler.rb | 14 +++++++++++++- config/locales/en.yml | 3 +++ config/locales/simple_form.en.yml | 1 + 7 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/views/admin_mailer/new_moderation_suggestions.text.erb diff --git a/app/mailers/admin_mailer.rb b/app/mailers/admin_mailer.rb index 9735004c803..680a8a86687 100644 --- a/app/mailers/admin_mailer.rb +++ b/app/mailers/admin_mailer.rb @@ -79,6 +79,10 @@ class AdminMailer < ApplicationMailer mail subject: default_i18n_subject(instance: @instance) end + def new_moderation_suggestions + mail subject: default_i18n_subject(instance: @instance) + end + private def process_params diff --git a/app/models/user_settings.rb b/app/models/user_settings.rb index 6e1537fdbce..964be5313f5 100644 --- a/app/models/user_settings.rb +++ b/app/models/user_settings.rb @@ -55,6 +55,7 @@ class UserSettings setting :appeal, default: true setting :software_updates, default: 'critical', in: %w(none critical patch all) setting :end_of_support, default: true + setting :moderation_suggestions, default: true end namespace :interactions do diff --git a/app/views/admin_mailer/new_moderation_suggestions.text.erb b/app/views/admin_mailer/new_moderation_suggestions.text.erb new file mode 100644 index 00000000000..c81b7b3d7f8 --- /dev/null +++ b/app/views/admin_mailer/new_moderation_suggestions.text.erb @@ -0,0 +1,3 @@ +<%= raw t('admin_mailer.new_moderation_suggestions.body') %> + +<%= raw t('application_mailer.view')%> <%= admin_moderation_suggestions_url %> diff --git a/app/views/settings/preferences/notifications/show.html.haml b/app/views/settings/preferences/notifications/show.html.haml index ac5d3335197..66985702fd2 100644 --- a/app/views/settings/preferences/notifications/show.html.haml +++ b/app/views/settings/preferences/notifications/show.html.haml @@ -23,7 +23,7 @@ .fields-group = ff.input :always_send_emails, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_always_send_emails'), hint: I18n.t('simple_form.hints.defaults.setting_always_send_emails') - - if current_user.can?(:manage_reports, :manage_appeals, :manage_users, :manage_taxonomies) + - if current_user.can?(:manage_reports, :manage_appeals, :manage_users, :manage_taxonomies, :manage_federation) %h2= t 'notifications.moderation_emails' .fields-group @@ -31,6 +31,7 @@ = ff.input :'notification_emails.appeal', as: :boolean, wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.appeal') if current_user.can?(:manage_appeals) = ff.input :'notification_emails.pending_account', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.pending_account') if current_user.can?(:manage_users) = ff.input :'notification_emails.trends', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.trending_tag') if current_user.can?(:manage_taxonomies) + = ff.input :'notification_emails.moderation_suggestions', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.moderation_suggestions') if current_user.can?(:manage_federation) - if SoftwareUpdate.check_enabled? && current_user.can?(:view_devops) %h2= t 'notifications.administration_emails' diff --git a/app/workers/scheduler/moderation_list_synchronization_scheduler.rb b/app/workers/scheduler/moderation_list_synchronization_scheduler.rb index 30e17b89374..abc6f0e5eed 100644 --- a/app/workers/scheduler/moderation_list_synchronization_scheduler.rb +++ b/app/workers/scheduler/moderation_list_synchronization_scheduler.rb @@ -10,7 +10,7 @@ class Scheduler::ModerationListSynchronizationScheduler ProcessModerationListsService.new.call - # TODO: mail suggestions + mail_suggestions! end private @@ -20,4 +20,16 @@ class Scheduler::ModerationListSynchronizationScheduler ModerationSubscriptionSyncService.new.call(subscription) end.any? end + + def mail_suggestions! + return unless ModerationSuggestion.exists?(state: :new) + + User.those_who_can(:manage_federation).includes(:account).find_each do |user| + next unless user.settings['notification_emails.moderation_suggestions'] + + AdminMailer.with(recipient: user.account).new_moderation_suggestions.deliver_later + end + + ModerationSuggestion.where(state: :new).in_batches.update_all(state: :mailed) + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index d647a8100d0..fb1bfd397fe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1425,6 +1425,9 @@ en: new_critical_software_updates: body: New critical versions of Mastodon have been released, you may want to update as soon as possible! subject: Critical Mastodon updates are available for %{instance}! + new_moderation_suggestions: + body: The moderation lists your server is subscribed to have published new suggestions. + subject: New moderation suggestions available on %{instance}! new_pending_account: body: The details of the new account are below. You can approve or reject this application. subject: New account up for review on %{instance} (%{username}) diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 82c4f42bcf8..5b0c2513a7e 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -350,6 +350,7 @@ en: follow: Someone followed you follow_request: Someone requested to follow you mention: Someone mentioned you + moderation_suggestions: Automatic moderation suggestions are available pending_account: New account needs review quote: Someone quoted you reblog: Someone boosted your post