From 45722dc224a349097b685134bf514b07c783e33d Mon Sep 17 00:00:00 2001 From: echarp <manu@echarp.org> Date: Sat, 6 May 2017 15:46:22 +0200 Subject: [PATCH] SPAM removal will not send an email or version data --- app/controllers/moderations_controller.rb | 9 ++++++++- app/views/moderations/refuse.html.haml | 4 ++++ config/locales/views/en.yml | 2 ++ config/locales/views/fr.yml | 2 ++ config/locales/views/pt-BR.yml | 2 ++ test/controllers/moderations_controller_test.rb | 11 +++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index f25c89465..4311be90b 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -45,7 +45,12 @@ class ModerationsController < ApplicationController # DELETE /events/1 # DELETE /events/1.json def destroy - @moderation.destroy! + if @moderation.reason == 'r_0' + logger.info 'SPAM! SPAM! SPAM!' + @moderation.paper_trail.without_versioning :destroy + else + @moderation.destroy! + end respond_to do |format| format.html { redirect_to :moderations, notice: t('.ok') } format.json { head :no_content } @@ -81,6 +86,8 @@ class ModerationsController < ApplicationController def generate_destroy_reason if params[:reason] == 'r_4' @moderation.reason = params[:event][:reason] + elsif params[:reason] == 'r_0' + @moderation.reason = 'r_0' else @moderation.reason = t "moderations.refuse.reason_#{params[:reason]}_long" end diff --git a/app/views/moderations/refuse.html.haml b/app/views/moderations/refuse.html.haml index 194a75ab0..a1cada24b 100644 --- a/app/views/moderations/refuse.html.haml +++ b/app/views/moderations/refuse.html.haml @@ -4,6 +4,10 @@ = form_for @moderation, url: { action: :destroy }, html: { method: :delete } do |f| + .field.closer{ title: t('.reason_r_0_long') } + = radio_button_tag :reason, :r_0, params[:event] == 'reason_r_0' + = label_tag :reason_r_0, t('.reason_r_0') + .field.closer{ title: t('.reason_r_1_long') } = radio_button_tag :reason, :r_1, params[:event] == 'reason_r_1' = label_tag :reason_r_1, t('.reason_r_1') diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 8f67ac8fd..bb6232a3e 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -193,10 +193,12 @@ it more readable or agreable. motif: Motive ok: Reject ko: Moderation + reason_r_0: SPAM! reason_r_1: Off-topic reason_r_2: Not enough information reason_r_3: Event already recorded reason_r_4: Specific reason (specify) + reason_r_0_long: SPAM! SPAM! SPAM! reason_r_1_long: Nonetheless, the proposed event hasn't yet retained the moderators' attention. As it were, the proposed event isn't about Free Software, or does not relate to Free Software, or the link with Free diff --git a/config/locales/views/fr.yml b/config/locales/views/fr.yml index ab3424f0d..734d51bb7 100644 --- a/config/locales/views/fr.yml +++ b/config/locales/views/fr.yml @@ -188,10 +188,12 @@ fr: motif: Motif ok: Rejeter ko: Modération + reason_r_0: SPAM! reason_r_1: Hors sujet reason_r_2: Pas assez d'informations reason_r_3: Événement déjà enregistré reason_r_4: Raison spécifique (précisez) + reason_r_0_long: SPAM! SPAM! SPAM! reason_r_1_long: Toutefois, l'événement proposé n'a pour l'instant pas retenu l'attention des modérateurs. En effet, l'événement proposé ne concerne pas le Logiciel Libre, ou bien le lien avec le Logiciel Libre diff --git a/config/locales/views/pt-BR.yml b/config/locales/views/pt-BR.yml index 005dcbc61..ac247e757 100644 --- a/config/locales/views/pt-BR.yml +++ b/config/locales/views/pt-BR.yml @@ -193,10 +193,12 @@ completa, deixando o texto mais legÃvel e agradável. motif: Motivo ok: Rejeitar ko: Moderação + reason_r_0: SPAM! reason_r_1: Off-topic reason_r_2: As informação não são suficientes reason_r_3: O evento já existe reason_r_4: Jutificativas especÃficas (especifique) + reason_r_0_long: SPAM! SPAM! SPAM! reason_r_1_long: O evento inscrito até agora não chamou a atenção dos moderadores. Na verdade, o evento proposto não é sobre Software Livre, ou a relação com Software Livre não é evidente considerando a diff --git a/test/controllers/moderations_controller_test.rb b/test/controllers/moderations_controller_test.rb index e33f04dee..75cda8c35 100644 --- a/test/controllers/moderations_controller_test.rb +++ b/test/controllers/moderations_controller_test.rb @@ -89,6 +89,17 @@ class ModerationsControllerTest < ActionController::TestCase assert_redirected_to edit_moderation_path @moderation end + test 'should reject spam' do + assert_difference 'Event.count', -1 do + delete :destroy, id: @moderation, reason: 'r_0', event: { reason: '' } + end + + assert_not_empty assigns(:moderation).reason + assert_empty assigns(:moderation).errors + + assert_redirected_to :moderations + end + test 'should reject event' do assert_difference 'Event.count', -1 do delete :destroy, id: @moderation, reason: 'r_1', event: { reason: '' } -- GitLab