From 995c80fed1d3eb837122e1656a41261c544aaae3 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 8 Mar 2024 14:42:27 -0300 Subject: [PATCH] fix: no colgar toda la cola si algo falla en la api --- app/controllers/fediblock_states_controller.rb | 13 ++++++++++++- app/jobs/activity_pub/instance_moderation_job.rb | 7 +++++++ config/locales/en.yml | 6 ++++++ config/locales/es.yml | 7 +++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/controllers/fediblock_states_controller.rb b/app/controllers/fediblock_states_controller.rb index 6d9737c3..4d9cc968 100644 --- a/app/controllers/fediblock_states_controller.rb +++ b/app/controllers/fediblock_states_controller.rb @@ -11,11 +11,22 @@ class FediblockStatesController < ApplicationController elsif fediblock_state.may_disable? fediblock_state.disable! end + + flash[:success] = I18n.t('fediblock_states.action_on_several.success') + rescue Exception => e + ExceptionNotifier.notify_exception(e, data: { site: site.name }) + + flash.delete(:success) + flash[:error] = I18n.t('fediblock_states.action_on_several.error') end # Bloquear otras instancias if custom_blocklist.present? - ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: custom_blocklist) + if ActivityPub::InstanceModerationJob.perform_now(site: site, hostnames: custom_blocklist) + flash[:success] = I18n.t('fediblock_states.action_on_several.custom_blocklist_success') + else + flash[:error] = I18n.t('fediblock_states.action_on_several.custom_blocklist_error') + end end redirect_to site_moderation_queue_path diff --git a/app/jobs/activity_pub/instance_moderation_job.rb b/app/jobs/activity_pub/instance_moderation_job.rb index b205e68f..17def46e 100644 --- a/app/jobs/activity_pub/instance_moderation_job.rb +++ b/app/jobs/activity_pub/instance_moderation_job.rb @@ -14,6 +14,7 @@ class ActivityPub end instances = ActivityPub::Instance.where(hostname: hostnames) + success = true Site.transaction do # Crea todas las moderaciones de instancia con un estado por @@ -23,9 +24,15 @@ class ActivityPub # idealmente son pocas instancias las que aparecen. site.instance_moderations.find_or_create_by(instance: instance).tap do |instance_moderation| instance_moderation.block! if instance_moderation.may_block? + # Notificar todos los errores sin detener la ejecución + rescue Exception => e + ExceptionNotifier.notify_exception(e, data: { site: site.name, instance_moderation: instance_moderation.id }) + success = false end end end + + success end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 0f010c89..565f0218 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -117,6 +117,12 @@ en: text_report: Report 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}." + fediblock_states: + action_on_several: + success: "Blocklists have been enabled, you can find their instances by filtering by Blocked. Any pending account from these instances has also been blocked. You can approve them individually on the Accounts section." + error: "There was an error while enabling or disabling blocklists. We received a report and will be acting on it soon." + custom_blocklist_success: "Custom blocklist has been added, you can find the instances by filtering by Blocked. Any pending account from these instances has also been blocked. You can approve them individually on the Accounts section." + custom_blocklist_error: "There was an error while adding a custom blocklist. We received a report and will be acting on it soon." moderation_queue: everything: 'Select all' nothing: "There's nothing for this filter" diff --git a/config/locales/es.yml b/config/locales/es.yml index 0a2538a7..175ca661 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -116,6 +116,13 @@ es: text_report: Reportar 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}." + fediblock_states: + action_on_several: + success: "Se habilitaron las listas de bloqueo, podés encontrar las instancias filtrando por Bloqueadas. Todas las cuentas de estas instancias pendientes de moderación han sido bloqueadas. Podés activarlas individualmente en la sección Cuentas." + error: "Hubo un error al activar o desactivar listas de bloqueo, ya recibimos el reporte y lo estaremos verificando." + custom_blocklist_success: "Se agregaron las instancias personalizadas a la lista de bloqueo, podés encontrarlas filtrando por Bloqueadas. Todas las cuentas de estas instancias pendientes de moderación han sido bloqueadas. Podés aprobarlas individualmente en la sección Cuentas." + custom_blocklist_error: "Hubo un error al agregar instancias personalizadas a la lista de bloqueo, ya recibimos el reporte y lo estaremos verificando." + actor_moderations: moderation_queue: everything: 'Seleccionar todo' nothing: 'No hay nada para este filtro'