diff --git a/app/mailers/decidim/spam_detection/spam_detection_mailer.rb b/app/mailers/decidim/spam_detection/spam_detection_mailer.rb index e2d58ff..ad772b2 100644 --- a/app/mailers/decidim/spam_detection/spam_detection_mailer.rb +++ b/app/mailers/decidim/spam_detection/spam_detection_mailer.rb @@ -3,6 +3,8 @@ module Decidim module SpamDetection class SpamDetectionMailer < Decidim::ApplicationMailer + helper_method :blocked_users_url, :reported_users_url + def notify_detection(user, results) with_user(user) do @reported_count = results[:reported_user] @@ -14,6 +16,24 @@ def notify_detection(user, results) mail(to: @user.email, subject: subject) end end + + private + + def blocked_users_url + decidim_admin.moderated_users_url(blocked: true, host: root_url) + end + + def reported_users_url + decidim_admin.moderated_users_url(blocked: false, host: root_url) + end + + def decidim_admin + Decidim::Admin::Engine.routes.url_helpers + end + + def root_url + decidim.root_url(host: @user.organization.host)[0..-2] + end end end end diff --git a/app/views/decidim/spam_detection/spam_detection_mailer/notify_detection.html.erb b/app/views/decidim/spam_detection/spam_detection_mailer/notify_detection.html.erb index b7a8672..ca6b528 100644 --- a/app/views/decidim/spam_detection/spam_detection_mailer/notify_detection.html.erb +++ b/app/views/decidim/spam_detection/spam_detection_mailer/notify_detection.html.erb @@ -5,10 +5,12 @@
<%= t(".reported_count", count: @reported_count) %>
+<%= link_to(t(".reported_link"), reported_users_url ) %>
<% end %> <% if @blocked_count.present? %><%= t(".blocked_count", count: @blocked_count) %>
+<%= link_to(t(".blocked_link"), blocked_users_url ) %>
<% end %> \ No newline at end of file diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index ad178d9..4363cd6 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -5,6 +5,8 @@ locales: [en, fr, es, ca] ignore_unused: - "decidim.components.spam_detection.name" + - blocked_user.* + - reported_user.* ignore_missing: - decidim.participatory_processes.scopes.global diff --git a/config/locales/ca.yml b/config/locales/ca.yml index c116097..eac0ea8 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1,16 +1,25 @@ --- ca: + blocked_user: + reason: L'usuari ha estat bloquejat a causa d'una alta probabilitat de spam per + la tasca de detecció automàtica de spam de Decidim amb una probabilitat de %{probability}% decidim: components: spam_detection: - name: SpamDetection + name: DeteccioSpam spam_detection: spam_detection_mailer: notify_detection: - blocked_count: blocked_count %{count} - hello: Hello %{name} - intro: Aquí teniu l'informe de la tasca de detecció de correu brossa - reported_count: reported_count %{count} + blocked_count: Comptes de spam bloquejats %{count} + blocked_link: Consulteu la llista de tots els comptes bloquejats + hello: Hola %{name} + intro: Aquí teniu l'informe de la tasca de detecció de spam + reported_count: Comptes blocs de %{count} + reported_link: Consulteu la llista de tots els comptes reportats al lloc spam_detection_mailer: notify_detection: - subject: Resum de detecció de correu brossa + subject: Informe de la tasca automàtica detecció de spam + reported_user: + details: L'usuari s'ha marcat com spam a causa d'una alta probabilitat de spam + per la tasca de detecció automàtica de spam de Decidim amb una probabilitat + de %{probability}% diff --git a/config/locales/en.yml b/config/locales/en.yml index 3e7fdbb..abd809e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,8 @@ --- en: + blocked_user: + reason: The user was blocked because of a high spam probability by the automated + spam detection task with a probability of %{probability}% decidim: components: spam_detection: @@ -7,10 +10,15 @@ en: spam_detection: spam_detection_mailer: notify_detection: - blocked_count: 'Blocked users count: %{count}' + blocked_count: 'Spam accounts blocked: %{count}' + blocked_link: See the list of all blocked accounts hello: Hello %{name} - intro: Here is the report of the spam detection task - reported_count: 'Reported users count: %{count}' + intro: Here is the report of the automated spam detection task. + reported_count: 'Spam accounts reported: %{count}' + reported_link: See the list of all reported accounts spam_detection_mailer: notify_detection: - subject: Spam detection digest + subject: Automated spam detection task digest + reported_user: + details: The user was reported because of a high spam probability by the automated + spam detection task with a probability of %{probability}% diff --git a/config/locales/es.yml b/config/locales/es.yml index 8b9324d..644ea4b 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,16 +1,24 @@ --- es: + blocked_user: + reason: El usuario fue bloqueado debido a una alta probabilidad de spam por la + tarea de detección automática de spam con una probabilidad de %{probability}% decidim: components: spam_detection: - name: SpamDetection + name: DeteccionSpam spam_detection: spam_detection_mailer: notify_detection: - blocked_count: blocked_count %{count} - hello: Hello %{name} - intro: Here is the report of the spam detection task - reported_count: reported_count %{count} + blocked_count: 'Cuentas de spam bloqueadas : %{count}' + blocked_link: Ver la lista de todas las cuentas bloqueadas + hello: Hola %{name} + intro: Aquí está el informe de la tarea de detección automática de spam. + reported_count: Cuentas de spam señaladas %{count} + reported_link: Ver la lista de cuentas señaladas spam_detection_mailer: notify_detection: - subject: Subject + subject: Informe de la tarea automática detección de spam + reported_user: + details: El usuario fue señalado debido a una alta probabilidad de spam por la + tarea de detección automática de spam con una probabilidad de %{probability}% diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 457d450..131b0f7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1,16 +1,24 @@ --- fr: + blocked_user: + reason: L'utilisateur a été bloqué en raison d'une forte probabilité de spam par + la tâche de détection automatique de spam avec une probabilité de %{probability}% decidim: components: spam_detection: - name: SpamDetection + name: DetectionSpam spam_detection: spam_detection_mailer: notify_detection: - blocked_count: blocked_count %{count} - hello: Hello %{name} - intro: Here is the report of the spam detection task - reported_count: reported_count %{count} + blocked_count: 'Comptes spam bloqués : %{count}' + blocked_link: Voir la liste de tous les comptes bloqués du site + hello: Bonjour %{name} + intro: Voici le rapport de la tâche de détection automatisée des spams. + reported_count: 'Comptes spam signalés : %{count}' + reported_link: Voir la liste de tous les comptes signalés spam_detection_mailer: notify_detection: - subject: Subject + subject: Rapport de la tâche de détection automatique de spam + reported_user: + details: L'utilisateur a été signalé en raison d'une forte probabilité de spam + par la tâche de détection automatique de spam avec une probabilité de %{probability}% diff --git a/lib/decidim/spam_detection/block_spam_user_command.rb b/lib/decidim/spam_detection/block_spam_user_command.rb index 9da992e..5e13f1f 100644 --- a/lib/decidim/spam_detection/block_spam_user_command.rb +++ b/lib/decidim/spam_detection/block_spam_user_command.rb @@ -62,7 +62,7 @@ def block! end def reason - "The user was blocked because of a high spam probability by Decidim spam detection bot with a probability of #{@probability}%" + I18n.t("blocked_user.reason", probability: @probability) end end end diff --git a/lib/decidim/spam_detection/report_spam_user_command.rb b/lib/decidim/spam_detection/report_spam_user_command.rb index ae5e5b8..0f34628 100644 --- a/lib/decidim/spam_detection/report_spam_user_command.rb +++ b/lib/decidim/spam_detection/report_spam_user_command.rb @@ -28,7 +28,7 @@ def reason end def details - "The user was marked as spam by Decidim spam detection bot with a probability of #{@probability}%" + I18n.t("reported_user.details", probability: @probability) end def find_or_create_moderation! diff --git a/spec/lib/decidim/spam_detection/block_spam_user_command_spec.rb b/spec/lib/decidim/spam_detection/block_spam_user_command_spec.rb index 352a432..5421a11 100644 --- a/spec/lib/decidim/spam_detection/block_spam_user_command_spec.rb +++ b/spec/lib/decidim/spam_detection/block_spam_user_command_spec.rb @@ -17,7 +17,7 @@ module SpamDetection it "creates a log" do expect { subject }.to change(Decidim::ActionLog, :count) - expect(Decidim::ActionLog.last.extra.dig("extra", "current_justification")).to eq("The user was blocked because of a high spam probability by Decidim spam detection bot with a probability of #{spam_probabilty}%") + expect(Decidim::ActionLog.last.extra.dig("extra", "current_justification")).to eq("The user was blocked because of a high spam probability by the automated spam detection task with a probability of #{spam_probabilty}%") end it "create a moderation entry" do diff --git a/spec/lib/decidim/spam_detection/report_spam_user_command_spec.rb b/spec/lib/decidim/spam_detection/report_spam_user_command_spec.rb index c36f2e0..e489fb3 100644 --- a/spec/lib/decidim/spam_detection/report_spam_user_command_spec.rb +++ b/spec/lib/decidim/spam_detection/report_spam_user_command_spec.rb @@ -14,7 +14,7 @@ module SpamDetection it "reports the user" do expect { subject }.to change(Decidim::UserReport, :count) expect(Decidim::UserReport.last.moderation.user).to eq(user) - expect(Decidim::UserReport.last.details).to eq("The user was marked as spam by Decidim spam detection bot with a probability of #{spam_probabilty}%") + expect(Decidim::UserReport.last.details).to eq("The user was reported because of a high spam probability by the automated spam detection task with a probability of #{spam_probabilty}%") end it "#add spam detection metadata" do diff --git a/spec/mailers/decidim/spam_detection/spam_detection_mailer_spec.rb b/spec/mailers/decidim/spam_detection/spam_detection_mailer_spec.rb index 0f0a792..729ecee 100644 --- a/spec/mailers/decidim/spam_detection/spam_detection_mailer_spec.rb +++ b/spec/mailers/decidim/spam_detection/spam_detection_mailer_spec.rb @@ -15,22 +15,30 @@ module SpamDetection let(:mail) { described_class.notify_detection(user, results) } describe "localisation" do - let(:subject) { "Resum de detecció de correu brossa" } - let(:default_subject) { "Spam detection digest" } + let(:subject) { "Informe de la tasca automàtica detecció de spam" } + let(:default_subject) { "Automated spam detection task digest" } - let(:body) { "Aquí teniu l'informe de la tasca de detecció de correu brossa" } - let(:default_body) { "Here is the report of the spam detection task" } + let(:body) { "Aquí teniu l'informe de la tasca de detecció de spam" } + let(:default_body) { "Here is the report of the automated spam detection task." } include_examples "localised email" end describe "email body" do it "includes reported_user count" do - expect(email_body(mail)).to include("Reported users count: #{results[:reported_user]}") + expect(email_body(mail)).to include("Spam accounts reported: #{results[:reported_user]}") + end + + it "includes reported_user link" do + expect(email_body(mail)).to include("See the list of all reported accounts") end it "includes blocked_user count" do - expect(email_body(mail)).to include("Blocked users count: #{results[:blocked_user]}") + expect(email_body(mail)).to include("Spam accounts blocked: #{results[:blocked_user]}") + end + + it "includes blocked_user link" do + expect(email_body(mail)).to include("See the list of all blocked accounts") end end end