Better management of a textual reason when destroying moderated events

filter
echarp 6 years ago
parent 19d8cb73f9
commit a2dc4144e7
  1. 2
      app/assets/stylesheets/form.sass
  2. 1
      app/controllers/events_controller.rb
  3. 17
      app/controllers/moderations_controller.rb
  4. 4
      app/views/events/cancel.html.haml
  5. 4
      app/views/moderations/refuse.html.haml
  6. 1
      config/locales/models/en.yml
  7. 1
      config/locales/models/fr.yml
  8. 9
      test/controllers/events_controller_test.rb
  9. 2
      test/controllers/moderations_controller_test.rb

@ -82,6 +82,8 @@
content: $fa-var-tags
.field.active label:before
content: $fa-var-heartbeat
.field.reason label:before
content: $fa-var-comment
.field.kind > label:before, th.kind:before
content: $fa-var-cubes

@ -74,6 +74,7 @@ class EventsController < ApplicationController
# DELETE /events/1
# DELETE /events/1.json
def destroy
@event.reason = params[:event][:reason]
@event.destroy
respond_to do |format|
format.html { redirect_to :root, notice: t('.ok') }

@ -3,6 +3,7 @@ class ModerationsController < ApplicationController
before_action :authenticate_user!
before_action :set_moderation, :set_mailer_host, only:
[:show, :edit, :preview, :update, :validate, :accept, :refuse, :destroy]
before_action :generate_destroy_reason, only: :destroy
rescue_from ActiveRecord::StaleObjectError, with: :locked
def index
@ -44,7 +45,6 @@ class ModerationsController < ApplicationController
# DELETE /events/1
# DELETE /events/1.json
def destroy
@moderation.reason = generate_destroy_reason(params)
@moderation.destroy!
respond_to do |format|
format.html { redirect_to :moderations, notice: t('.ok') }
@ -54,14 +54,6 @@ class ModerationsController < ApplicationController
private
def generate_destroy_reason(params)
if params[:reason] == 'r_4'
params[:event][:reason]
else
t "moderations.refuse.reason_#{params[:reason]}_long"
end
end
# Use callbacks to share common setup or constraints between actions.
def set_moderation
@event = Event.find params[:id]
@ -85,4 +77,11 @@ class ModerationsController < ApplicationController
def locked
redirect_to edit_moderation_url(@moderation), alert: t('staleObjectError')
end
def generate_destroy_reason
@moderation.reason = params[:event][:reason]
if params[:reason] != 'r_4'
@moderation.reason = t "moderations.refuse.reason_#{params[:reason]}_long"
end
end
end

@ -10,6 +10,10 @@
= hidden_field_tag :secret, params[:secret]
%h2= t '.confirm'
.field.reason
= f.label :reason
= f.text_area :reason, cols: 40, rows: 5
= f.submit t('.ok'), name: :yes
= link_to t('.ko'), @event, class: :button

@ -21,8 +21,8 @@
params[:event] == 'reason_r_4' || !params[:event]
= label_tag :reason_r_4, t('.reason_r_4')
.field
= label_tag :reason
.field.reason
= f.label :reason
= f.text_area :reason, cols: 40, rows: 5
= link_to moderations_path do

@ -82,6 +82,7 @@ en:
submitter: Submitter
submission_time: Waiting for
tags: Tags
reason: Reason
region:
name_values:
all: All regions

@ -82,6 +82,7 @@ fr:
submitter: Soumetteur
submission_time: En attente depuis
tags: Mots-clés
reason: Raison
region:
name_values:
all: Toutes les régions

@ -26,9 +26,7 @@ class EventsControllerTest < ActionController::TestCase
start_time: @event.start_time, end_time: @event.end_time,
description: @event.description,
city: @event.city, region_id: @event.region.id,
url: @event.url,
contact: @event.contact,
tags: @event.tags
url: @event.url, contact: @event.contact, tags: @event.tags
}
assert_empty assigns(:event).errors
@ -122,9 +120,12 @@ class EventsControllerTest < ActionController::TestCase
test 'should destroy event' do
assert_difference('Event.count', -1) do
delete :destroy, id: @event, secret: @event.secret
delete :destroy, id: @event, secret: @event.secret, event: {
reason: 'bye'
}
end
assert_equal 'bye', assigns(:event).reason
assert_redirected_to :root
end
end

@ -106,7 +106,7 @@ class ModerationsControllerTest < ActionController::TestCase
delete :destroy, id: @moderation, reason: 'r_4', event: { reason: 'bye' }
end
assert_not_empty assigns(:moderation).reason
assert_equal 'bye', assigns(:moderation).reason
assert_empty assigns(:moderation).errors
assert_redirected_to :moderations

Loading…
Cancel
Save