diff --git a/app/assets/images/icons/close.svg b/app/assets/images/icons/refuse.svg similarity index 100% rename from app/assets/images/icons/close.svg rename to app/assets/images/icons/refuse.svg diff --git a/app/assets/stylesheets/new_design/icons.scss b/app/assets/stylesheets/new_design/icons.scss index 40a1780c4..0dfbb1ec5 100644 --- a/app/assets/stylesheets/new_design/icons.scss +++ b/app/assets/stylesheets/new_design/icons.scss @@ -29,8 +29,8 @@ background-image: image-url("icons/accept.svg"); } - &.close { - background-image: image-url("icons/close.svg"); + &.refuse { + background-image: image-url("icons/refuse.svg"); } &.without-continuation { diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 4a9412636..5acaa4fa8 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -101,7 +101,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController current_gestionnaire.follow(dossier) flash.notice = 'Dossier passé en instruction.' - redirect_to_dossier(dossier) + redirect_to backoffice_dossier_path(id: dossier.id) end def process_dossier @@ -143,7 +143,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now! - redirect_to_dossier(dossier) + redirect_to backoffice_dossier_path(id: dossier.id) end def reload_smartlisting @@ -182,19 +182,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController @facade.dossier.initiated! flash.notice = 'Dossier repassé en construction.' - redirect_to_dossier(@facade.dossier) + redirect_to backoffice_dossier_path(id: @facade.dossier.id) end private - def redirect_to_dossier(dossier) - if params[:new_ui] # TODO delete new_ui when old UI is no longer used - redirect_to dossier_path(dossier.procedure, dossier) - else - redirect_to backoffice_dossier_path(id: dossier.id) - end - end - def check_attestation_emailable(dossier) if dossier&.attestation&.emailable? == false human_size = number_to_human_size(dossier.attestation.pdf.size) diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index d82d80407..a3c35a178 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -1,5 +1,6 @@ module NewGestionnaire class DossiersController < ProceduresController + include ActionView::Helpers::NumberHelper include ActionView::Helpers::TextHelper def attestation @@ -52,6 +53,59 @@ module NewGestionnaire redirect_back(fallback_location: procedures_url) end + def passer_en_instruction + dossier.received! + current_gestionnaire.follow(dossier) + flash.notice = 'Dossier passé en instruction.' + + redirect_to dossier_path(procedure, dossier) + end + + def repasser_en_construction + dossier.initiated! + flash.notice = 'Dossier repassé en construction.' + + redirect_to dossier_path(procedure, dossier) + end + + def terminer + if params[:dossier] && params[:dossier][:motivation].present? + motivation = params[:dossier][:motivation] + end + + case params[:process_action] + when "refuser" + next_step = "refuse" + notice = "Dossier considéré comme refusé." + template = procedure.refused_mail_template + when "classer_sans_suite" + next_step = "without_continuation" + notice = "Dossier considéré comme sans suite." + template = procedure.without_continuation_mail_template + when "accepter" + next_step = "close" + notice = "Dossier traité avec succès." + template = procedure.closed_mail_template + end + + dossier.next_step!('gestionnaire', next_step, motivation) + + # needed to force Carrierwave to provide dossier.attestation.pdf.read + # when the Feature.remote_storage is true, otherwise pdf.read is a closed stream. + dossier.reload + + attestation_pdf = nil + if check_attestation_emailable + attestation_pdf = dossier.attestation.pdf.read + end + + flash.notice = notice + + NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now! + + redirect_to dossier_path(procedure, dossier) + end + def create_commentaire commentaire_hash = commentaire_params.merge(email: current_gestionnaire.email, dossier: dossier) @@ -122,5 +176,15 @@ module NewGestionnaire def champs_private_params params.require(:dossier).permit(champs_private_attributes: [:id, :value, value: []]) end + + def check_attestation_emailable + if dossier&.attestation&.emailable? == false + human_size = number_to_human_size(dossier.attestation.pdf.size) + msg = "the attestation of the dossier #{dossier.id} cannot be mailed because it is too heavy: #{human_size}" + capture_message(msg, level: 'error') + end + + dossier&.attestation&.emailable? + end end end diff --git a/app/views/new_gestionnaire/dossiers/_state_button.html.haml b/app/views/new_gestionnaire/dossiers/_state_button.html.haml index c1115697e..d7fa22108 100644 --- a/app/views/new_gestionnaire/dossiers/_state_button.html.haml +++ b/app/views/new_gestionnaire/dossiers/_state_button.html.haml @@ -10,7 +10,7 @@ %h4 En construction Vous permettez à l'usager de modifier ses réponses au formulaire %li - = link_to backoffice_dossier_receive_path(dossier, new_ui: true), method: :post, data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do + = link_to passer_en_instruction_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } do .icon.in-progress .description %h4 Passer en instruction @@ -18,7 +18,7 @@ - if dossier.en_instruction? %li - = link_to backoffice_dossier_reopen_path(dossier, new_ui: true), method: :post, data: { confirm: "Confirmer vous la réouverture de ce dossier ?" } do + = link_to repasser_en_construction_dossier_path(dossier.procedure, dossier), method: :post, data: { confirm: "Confirmer vous le passage en construction de ce dossier ?" } do .icon.edit .description %h4 Repasser en construction @@ -38,14 +38,14 @@ .description %h4 Classer sans suite L'usager ne recevra aucune notification - %li{ onclick: "TPS.showMotivation('close');" } - .icon.close + %li{ onclick: "TPS.showMotivation('refuse');" } + .icon.refuse .description %h4 Refuser L'usager sera notifié que son dossier a été refusé - = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Accepter le dossier', popup_class: 'accept', process_action: 'close', title: 'Accepter', confirm: 'Accepter ce dossier ?' } - = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Classer le dossier sans suite', popup_class: 'without-continuation', process_action: 'without_continuation', title: 'Classer sans suite', confirm: 'Confirmer vous le classement sans suite de ce dossier ?' } - = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Refuser le dossier', popup_class: 'close', process_action: 'refuse', title: 'Refuser', confirm: 'Confirmer vous le refus de ce dossier ?' } + = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Accepter le dossier', popup_class: 'accept', process_action: 'accepter', title: 'Accepter', confirm: 'Accepter ce dossier ?' } + = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Classer le dossier sans suite', popup_class: 'without-continuation', process_action: 'classer_sans_suite', title: 'Classer sans suite', confirm: 'Confirmer vous le classement sans suite de ce dossier ?' } + = render partial: 'new_gestionnaire/dossiers/state_button_motivation', locals: { dossier: dossier, popup_title: 'Refuser le dossier', popup_class: 'refuse', process_action: 'refuser', title: 'Refuser', confirm: 'Confirmer vous le refus de ce dossier ?' } - else - if dossier.motivation.present? || dossier.attestation.present? diff --git a/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml b/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml index 2dfadaaf0..8dc3e716b 100644 --- a/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml +++ b/app/views/new_gestionnaire/dossiers/_state_button_motivation.html.haml @@ -3,7 +3,7 @@ .icon{ class: popup_class } #{popup_title} nº #{dossier.id} - = form_tag(backoffice_dossier_process_dossier_url(dossier.id, new_ui: true), method: :post, class: 'form') do + = form_tag(terminer_dossier_path(dossier.procedure, dossier), method: :post, class: 'form') do = text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: 'Rédigez votre motivation ici (facultative)' - if title == 'Accepter' %p.help diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index 3a86f8a2b..0b60bab49 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -8,7 +8,7 @@ .icon.unarchive .icon.folder .icon.accept - .icon.close + .icon.refuse .icon.without-continuation .icon.edit .icon.in-progress diff --git a/config/routes.rb b/config/routes.rb index 9930412c5..3f83c1b52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -254,6 +254,9 @@ Rails.application.routes.draw do patch 'unarchive' patch 'annotations' => 'dossiers#update_annotations' post 'commentaire' => 'dossiers#create_commentaire' + post 'passer-en-instruction' => 'dossiers#passer_en_instruction' + post 'repasser-en-construction' => 'dossiers#repasser_en_construction' + post 'terminer' scope :carte do get 'position' end diff --git a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb index 9360189d8..d734b5c57 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -77,6 +77,156 @@ describe NewGestionnaire::DossiersController, type: :controller do it { expect(response).to redirect_to(procedures_url) } end + describe '#passer_en_instruction' do + before do + dossier.initiated! + sign_in gestionnaire + post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id } + dossier.reload + end + + it { expect(dossier.state).to eq('received') } + it { is_expected.to redirect_to dossier_path(procedure, dossier) } + it { expect(gestionnaire.follow?(dossier)).to be true } + end + + describe '#repasser_en_construction' do + before do + dossier.received! + sign_in gestionnaire + end + + subject { post :repasser_en_construction, params: { procedure_id: procedure.id, dossier_id: dossier.id} } + + it 'change state to initiated' do + subject + + dossier.reload + expect(dossier.state).to eq('initiated') + end + + it { is_expected.to redirect_to dossier_path(procedure, dossier) } + end + + describe '#terminer' do + context "with refuser" do + before do + dossier.received! + sign_in gestionnaire + end + + subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id} } + + it 'change state to refused' do + subject + + dossier.reload + expect(dossier.state).to eq('refused') + end + + it 'Notification email is sent' do + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::RefusedMail), nil).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + subject + end + + it { is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) } + end + + context "with classer_sans_suite" do + before do + dossier.received! + sign_in gestionnaire + end + + subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id} } + + it 'change state to without_continuation' do + subject + + dossier.reload + expect(dossier.state).to eq('without_continuation') + end + + it 'Notification email is sent' do + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::WithoutContinuationMail), nil).and_return(NotificationMailer) + expect(NotificationMailer).to receive(:deliver_now!) + + subject + end + + it { is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) } + end + + context "with accepter" do + let(:expected_attestation) { nil } + + before do + dossier.received! + sign_in gestionnaire + + expect(NotificationMailer).to receive(:send_notification) + .with(dossier, kind_of(Mails::ClosedMail), expected_attestation) + .and_return(NotificationMailer) + + expect(NotificationMailer).to receive(:deliver_now!) + end + + subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id} } + + it 'change state to closed' do + subject + + dossier.reload + expect(dossier.state).to eq('closed') + end + + context 'when the dossier does not have any attestation' do + it 'Notification email is sent' do + subject + end + end + + context 'when the dossier has an attestation' do + before do + attestation = Attestation.new + allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes)) + allow(attestation).to receive(:emailable?).and_return(emailable) + + expect_any_instance_of(Dossier).to receive(:reload) + allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation) + end + + context 'emailable' do + let(:emailable) { true } + let(:expected_attestation) { 'pdf' } + + it 'Notification email is sent with the attestation' do + subject + + is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) + end + end + + context 'when the dossier has an attestation not emailable' do + let(:emailable) { false } + let(:expected_attestation) { nil } + + it 'Notification email is sent without the attestation' do + expect(controller).to receive(:capture_message) + + subject + + is_expected.to redirect_to redirect_to dossier_path(procedure, dossier) + end + end + end + end + end + describe '#show #messagerie #annotations_privees #avis' do before do dossier.notifications = %w(champs annotations_privees avis commentaire).map{ |type| Notification.create!(type_notif: type) }