From 157d1818b2917108b816402c310ecb80c22efaad Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 10 Apr 2017 12:29:14 +0200 Subject: [PATCH 1/4] DescriptionController: move instance var to local var --- .../users/description_controller.rb | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 49664c5b6..af105cdcc 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -24,41 +24,41 @@ class Users::DescriptionController < UsersController end def update - @dossier = current_user_dossier - @procedure = @dossier.procedure + dossier = current_user_dossier + procedure = dossier.procedure - return head :forbidden unless @dossier.can_be_initiated? + return head :forbidden unless dossier.can_be_initiated? - @champs = @dossier.ordered_champs + @champs = dossier.ordered_champs check_mandatory_fields = !draft_submission? if params[:champs] - champs_service_errors = ChampsService.save_champs @dossier.champs, + champs_service_errors = ChampsService.save_champs dossier.champs, params, check_mandatory_fields - return redirect_to_description_with_errors(@dossier, champs_service_errors) if champs_service_errors.any? + return redirect_to_description_with_errors(dossier, champs_service_errors) if champs_service_errors.any? end - if @procedure.cerfa_flag? && params[:cerfa_pdf] - cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier, user: current_user) - return redirect_to_description_with_errors(@dossier, cerfa.errors.full_messages) unless cerfa.save + if procedure.cerfa_flag? && params[:cerfa_pdf] + cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: dossier, user: current_user) + return redirect_to_description_with_errors(dossier, cerfa.errors.full_messages) unless cerfa.save end - errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params) - return redirect_to_description_with_errors(@dossier, errors_upload) if errors_upload.any? + errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params) + return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any? if draft_submission? flash.notice = 'Votre brouillon a bien été sauvegardé.' redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon) else - if @dossier.draft? - @dossier.initiated! - NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail).deliver_now! + if dossier.draft? + dossier.initiated! + NotificationMailer.send_notification(dossier, procedure.initiated_mail).deliver_now! end flash.notice = 'Félicitations, votre demande a bien été enregistrée.' - redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id) + redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id) end end From 866a54085c09d3c4094655709b8deb1d91f0d179 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 30 Mar 2017 10:41:20 +0200 Subject: [PATCH 2/4] DescriptionController: cosmetic --- app/controllers/users/description_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index af105cdcc..9b7fba56d 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -34,10 +34,8 @@ class Users::DescriptionController < UsersController check_mandatory_fields = !draft_submission? if params[:champs] - champs_service_errors = ChampsService.save_champs dossier.champs, - params, - check_mandatory_fields - + champs_service_errors = + ChampsService.save_champs(dossier.champs, params, check_mandatory_fields) return redirect_to_description_with_errors(dossier, champs_service_errors) if champs_service_errors.any? end From eb3bb63a8f2fab2e36d041e49ce9f65158a9098c Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 30 Mar 2017 10:41:39 +0200 Subject: [PATCH 3/4] DescriptionController: remove useless @champs --- app/controllers/users/description_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 9b7fba56d..7c42c3cdd 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -28,9 +28,6 @@ class Users::DescriptionController < UsersController procedure = dossier.procedure return head :forbidden unless dossier.can_be_initiated? - - @champs = dossier.ordered_champs - check_mandatory_fields = !draft_submission? if params[:champs] From 4cd21580fb4e9706940ec36add36379a9ebfcfb7 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 30 Mar 2017 11:17:22 +0200 Subject: [PATCH 4/4] DescriptionController: move html_safe to the view html_safe could not work upon redirection as stated here : https://groups.google.com/forum/#!topic/rubyonrails-core/z52zgDgUmbs --- app/controllers/users/description_controller.rb | 2 +- app/views/layouts/_flash_messages.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 7c42c3cdd..69e17b4a8 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -98,7 +98,7 @@ class Users::DescriptionController < UsersController private def redirect_to_description_with_errors(dossier, errors) - flash.alert = errors.join('
').html_safe + flash.alert = errors.join('
') redirect_to users_dossier_description_path(dossier_id: dossier.id) end diff --git a/app/views/layouts/_flash_messages.html.haml b/app/views/layouts/_flash_messages.html.haml index 2ed1b4013..a661dcdbd 100644 --- a/app/views/layouts/_flash_messages.html.haml +++ b/app/views/layouts/_flash_messages.html.haml @@ -4,4 +4,4 @@ = flash.notice - if flash.alert .alert.alert-danger - = flash.alert + = flash.alert.html_safe