From b79220e7111145a3f2258a19c5bc6486efdd334e Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 1 Jul 2019 16:16:40 +0200 Subject: [PATCH 1/4] UI --- app/assets/stylesheets/new_design/buttons.scss | 6 +++++- .../gestionnaires/dossiers_controller.rb | 6 ++++++ .../gestionnaires/dossiers/_state_button.html.haml | 14 ++++++++++++-- config/routes.rb | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/new_design/buttons.scss b/app/assets/stylesheets/new_design/buttons.scss index 16dc43c7b..6fe9cb876 100644 --- a/app/assets/stylesheets/new_design/buttons.scss +++ b/app/assets/stylesheets/new_design/buttons.scss @@ -183,7 +183,7 @@ color: $black; padding: $default-padding; - h4 { + .title { font-size: 24px; } @@ -266,6 +266,10 @@ color: $black; margin-bottom: $default-spacer; } + + &.with-top-border { + border-top: 1px solid $grey; + } } .dropdown-form { diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index 6dfd065d5..1a8f82132 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -93,6 +93,12 @@ module Gestionnaires render partial: 'state_button_refresh', locals: { dossier: dossier } end + def repasser_en_instruction + flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." + + render partial: 'state_button_refresh', locals: { dossier: dossier } + end + def terminer motivation = params[:dossier] && params[:dossier][:motivation] justificatif = params[:dossier] && params[:dossier][:justificatif_motivation] diff --git a/app/views/gestionnaires/dossiers/_state_button.html.haml b/app/views/gestionnaires/dossiers/_state_button.html.haml index 18d0a42be..e186ff2ee 100644 --- a/app/views/gestionnaires/dossiers/_state_button.html.haml +++ b/app/views/gestionnaires/dossiers/_state_button.html.haml @@ -58,14 +58,24 @@ = dossier_display_state(dossier, lower: true) .dropdown-content.fade-in-down.terminated - if dossier.motivation.present? - %h4 Motivation + %h4.title Motivation %p.dossier-motivation= dossier.motivation = render partial: 'users/dossiers/show/download_justificatif', locals: { dossier: dossier } - if dossier.attestation.present? - %h4 Attestation + %h4.title Attestation %p.attestation L'acceptation du dossier a envoyé automatiquement une attestation au demandeur = link_to "Voir l'attestation", attestation_gestionnaire_dossier_path(dossier.procedure, dossier), target: '_blank', rel: 'noopener', class: 'button' + + + - if dossier.refuse? || dossier.sans_suite? + %ul.dropdown-items.with-top-border + %li + = link_to repasser_en_instruction_gestionnaire_dossier_path(dossier.procedure, dossier), method: :post, data: { remote:true, confirm: "Voulez vous remettre le dossier #{dossier.id} en instruction ?" } do + %span.icon.in-progress + .dropdown-description + %h4 Repasser en instruction + L’usager sera notifié que son dossier est réexaminé. - else %span.label{ class: button_or_label_class(dossier) } = dossier_display_state(dossier, lower: true) diff --git a/config/routes.rb b/config/routes.rb index e6006507c..682ed5802 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -325,6 +325,7 @@ Rails.application.routes.draw do post 'commentaire' => 'dossiers#create_commentaire' post 'passer-en-instruction' => 'dossiers#passer_en_instruction' post 'repasser-en-construction' => 'dossiers#repasser_en_construction' + post 'repasser-en-instruction' => 'dossiers#repasser_en_instruction' post 'terminer' post 'send-to-instructeurs' => 'dossiers#send_to_instructeurs' post 'avis' => 'dossiers#create_avis' From b2c987ff0d368362c8a63413b62264d69ba43665 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 1 Jul 2019 17:45:03 +0200 Subject: [PATCH 2/4] [fix #3683] Dossier: add repasser_en_instruction! --- .../gestionnaires/dossiers_controller.rb | 1 + app/models/dossier.rb | 8 +++++++ app/models/dossier_operation_log.rb | 1 + spec/models/dossier_spec.rb | 24 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/app/controllers/gestionnaires/dossiers_controller.rb b/app/controllers/gestionnaires/dossiers_controller.rb index 1a8f82132..af0f42b6f 100644 --- a/app/controllers/gestionnaires/dossiers_controller.rb +++ b/app/controllers/gestionnaires/dossiers_controller.rb @@ -95,6 +95,7 @@ module Gestionnaires def repasser_en_instruction flash.notice = "Le dossier #{dossier.id} a été repassé en instruction." + dossier.repasser_en_instruction!(current_gestionnaire) render partial: 'state_button_refresh', locals: { dossier: dossier } end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b6ca39b40..965c39554 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -302,6 +302,14 @@ class Dossier < ApplicationRecord log_dossier_operation(gestionnaire, :repasser_en_construction) end + def repasser_en_instruction!(gestionnaire) + update(state: Dossier.states.fetch(:en_instruction), processed_at: nil, motivation: nil) + attestation&.destroy + DossierMailer.notify_revert_to_instruction(self).deliver_later + + log_dossier_operation(gestionnaire, :repasser_en_instruction) + end + def accepter!(gestionnaire, motivation, justificatif = nil) self.motivation = motivation self.en_instruction_at ||= Time.zone.now diff --git a/app/models/dossier_operation_log.rb b/app/models/dossier_operation_log.rb index a66492ace..a54f0718e 100644 --- a/app/models/dossier_operation_log.rb +++ b/app/models/dossier_operation_log.rb @@ -2,6 +2,7 @@ class DossierOperationLog < ApplicationRecord enum operation: { passer_en_instruction: 'passer_en_instruction', repasser_en_construction: 'repasser_en_construction', + repasser_en_instruction: 'repasser_en_instruction', accepter: 'accepter', refuser: 'refuser', classer_sans_suite: 'classer_sans_suite', diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 7f72f61e6..e9a5b49a8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -987,4 +987,28 @@ describe Dossier do it { expect(last_operation.operation).to eq('supprimer') } it { expect(last_operation.automatic_operation?).to be_falsey } end + + describe '#repasser_en_instruction!' do + let(:dossier) { create(:dossier, :refuse, :with_attestation) } + let!(:gestionnaire) { create(:gestionnaire) } + let(:last_operation) { dossier.dossier_operation_logs.last } + + before do + Timecop.freeze + allow(DossierMailer).to receive(:notify_revert_to_instruction) + .and_return(double(deliver_later: true)) + dossier.repasser_en_instruction!(gestionnaire) + dossier.reload + end + + it { expect(dossier.state).to eq('en_instruction') } + it { expect(dossier.processed_at).to be_nil } + it { expect(dossier.motivation).to be_nil } + it { expect(dossier.attestation).to be_nil } + it { expect(last_operation.operation).to eq('repasser_en_instruction') } + it { expect(JSON.parse(last_operation.serialized.download)['author']['email']).to eq(gestionnaire.email) } + it { expect(DossierMailer).to have_received(:notify_revert_to_instruction).with(dossier) } + + after { Timecop.return } + end end From c7e10fc43f76394d91305940e1c995fbe8814f65 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 1 Jul 2019 17:50:48 +0200 Subject: [PATCH 3/4] Manager: remove repasser_en_instruction --- app/controllers/manager/dossiers_controller.rb | 10 ---------- app/views/manager/dossiers/show.html.erb | 3 --- config/routes.rb | 1 - 3 files changed, 14 deletions(-) diff --git a/app/controllers/manager/dossiers_controller.rb b/app/controllers/manager/dossiers_controller.rb index 0372f579d..74170f17f 100644 --- a/app/controllers/manager/dossiers_controller.rb +++ b/app/controllers/manager/dossiers_controller.rb @@ -20,16 +20,6 @@ module Manager # Custom actions # - def change_state_to_instruction - dossier = Dossier.find(params[:id]) - dossier.update(state: Dossier.states.fetch(:en_instruction), processed_at: nil, motivation: nil) - dossier.attestation&.destroy - logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}") - flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction" - DossierMailer.notify_revert_to_instruction(dossier).deliver_later - redirect_to manager_dossier_path(dossier) - end - def hide dossier = Dossier.find(params[:id]) deleted_dossier = dossier.hide!(current_administration) diff --git a/app/views/manager/dossiers/show.html.erb b/app/views/manager/dossiers/show.html.erb index e2eacd19c..1dcae61cc 100644 --- a/app/views/manager/dossiers/show.html.erb +++ b/app/views/manager/dossiers/show.html.erb @@ -28,9 +28,6 @@ as well as a link to its edit page.
- <% if dossier.termine? %> - <%= link_to 'Repasser en instruction', change_state_to_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Repasser en instruction ?" } %> - <% end %> <% if dossier.hidden_at.nil? %> <%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 682ed5802..7b454fa57 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,7 +15,6 @@ Rails.application.routes.draw do end resources :dossiers, only: [:index, :show] do - post 'change_state_to_instruction', on: :member post 'hide', on: :member end From 522d7684ea4aba31da4aef98604b25dde4898114 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 2 Jul 2019 18:31:42 +0200 Subject: [PATCH 4/4] dossier state button in red when refused --- app/helpers/dossier_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/dossier_helper.rb b/app/helpers/dossier_helper.rb index 812eff956..db1ffa829 100644 --- a/app/helpers/dossier_helper.rb +++ b/app/helpers/dossier_helper.rb @@ -5,7 +5,7 @@ module DossierHelper elsif dossier.sans_suite? 'without-continuation' elsif dossier.refuse? - 'refuse' + 'refused' end end