diff --git a/app/assets/stylesheets/new_design/flex.scss b/app/assets/stylesheets/new_design/flex.scss index 0689c004c..a204355e1 100644 --- a/app/assets/stylesheets/new_design/flex.scss +++ b/app/assets/stylesheets/new_design/flex.scss @@ -20,4 +20,8 @@ &.justify-center { justify-content: center; } + + &.justify-start { + justify-content: flex-start; + } } diff --git a/app/assets/stylesheets/new_design/gaps.scss b/app/assets/stylesheets/new_design/gaps.scss new file mode 100644 index 000000000..0d2dc2226 --- /dev/null +++ b/app/assets/stylesheets/new_design/gaps.scss @@ -0,0 +1,5 @@ +@import "constants"; + +.gap-left { + margin-left: $default-spacer; +} diff --git a/app/controllers/new_gestionnaire/dossiers_controller.rb b/app/controllers/new_gestionnaire/dossiers_controller.rb index 59809566a..e00b6859a 100644 --- a/app/controllers/new_gestionnaire/dossiers_controller.rb +++ b/app/controllers/new_gestionnaire/dossiers_controller.rb @@ -33,6 +33,14 @@ module NewGestionnaire @following_accompagnateurs_emails = dossier.followers_gestionnaires.pluck(:email) @avis_emails = dossier.avis.includes(:gestionnaire).map(&:email_to_display) @invites_emails = dossier.invites.map(&:email) + @potential_recipients = procedure.gestionnaires.reject { |g| g == current_gestionnaire } + end + + def envoyer_a_accompagnateur + recipient = Gestionnaire.find(params[:recipient]) + GestionnaireMailer.send_dossier(current_gestionnaire, dossier, recipient).deliver_later + flash.notice = "Dossier envoyé" + redirect_to(personnes_impliquees_dossier_path(procedure, dossier)) end def follow diff --git a/app/mailers/gestionnaire_mailer.rb b/app/mailers/gestionnaire_mailer.rb index ac8124191..24718a766 100644 --- a/app/mailers/gestionnaire_mailer.rb +++ b/app/mailers/gestionnaire_mailer.rb @@ -10,6 +10,14 @@ class GestionnaireMailer < ApplicationMailer send_mail gestionnaire.email, overview, 'Vos activités sur TPS' end + def send_dossier(sender, dossier, recipient) + @sender = sender + @dossier = dossier + subject = "#{sender.email} vous a envoyé le dossier nº #{dossier.id}" + + mail(to: recipient.email, subject: subject) + end + private def vars_mailer email, args diff --git a/app/views/gestionnaire_mailer/send_dossier.text.erb b/app/views/gestionnaire_mailer/send_dossier.text.erb new file mode 100644 index 000000000..029fb2b4b --- /dev/null +++ b/app/views/gestionnaire_mailer/send_dossier.text.erb @@ -0,0 +1,9 @@ +Bonjour, + +<%= @sender.email %> vous a envoyé le dossier nº <%= @dossier.id %>, cliquez sur le lien ci-dessous pour y accéder : + +<%= dossier_url(@dossier.procedure, @dossier) %> + +Bonne journée, + +L'équipe Téléprocédures Simplifiées diff --git a/app/views/new_gestionnaire/dossiers/_envoyer_dossier_block.html.haml b/app/views/new_gestionnaire/dossiers/_envoyer_dossier_block.html.haml new file mode 100644 index 000000000..cf5d33eac --- /dev/null +++ b/app/views/new_gestionnaire/dossiers/_envoyer_dossier_block.html.haml @@ -0,0 +1,6 @@ +.tab-title= "Envoyer ce dossier à un autre accompagnateur" + += form_for dossier, url: envoyer_a_accompagnateur_dossier_path(dossier.procedure, dossier), method: :post, html: { class: 'form' } do |f| + .flex.justify-start.align-baseline + = select_tag(:recipient, options_from_collection_for_select(potential_recipients, :id, :email)) + = f.submit "Envoyer", class: "button large send gap-left" diff --git a/app/views/new_gestionnaire/dossiers/personnes_impliquees.html.haml b/app/views/new_gestionnaire/dossiers/personnes_impliquees.html.haml index 857c99692..571279a48 100644 --- a/app/views/new_gestionnaire/dossiers/personnes_impliquees.html.haml +++ b/app/views/new_gestionnaire/dossiers/personnes_impliquees.html.haml @@ -3,6 +3,8 @@ = render partial: "header", locals: { dossier: @dossier } .personnes-impliquees.container + = render partial: 'new_gestionnaire/dossiers/envoyer_dossier_block', locals: { dossier: @dossier, potential_recipients: @potential_recipients } + = render partial: 'new_gestionnaire/dossiers/personnes_impliquees_block', locals: { emails_collection: @following_accompagnateurs_emails, title: "Accompagnateurs qui suivent le dossier", blank: "Aucun accompagnateur ne suit ce dossier" } = render partial: 'new_gestionnaire/dossiers/personnes_impliquees_block', locals: { emails_collection: @avis_emails, title: "Personnes à qui un avis a été demandé", blank: "Aucun avis n'a été demandé" } diff --git a/config/routes.rb b/config/routes.rb index cfb615098..c29bbe3b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -231,6 +231,7 @@ Rails.application.routes.draw do post 'passer-en-instruction' => 'dossiers#passer_en_instruction' post 'repasser-en-construction' => 'dossiers#repasser_en_construction' post 'terminer' + post 'envoyer-a-accompagnateur' => 'dossiers#envoyer_a_accompagnateur' 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 ab9a861fa..326812ed9 100644 --- a/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb +++ b/spec/controllers/new_gestionnaire/dossiers_controller_spec.rb @@ -4,7 +4,8 @@ describe NewGestionnaire::DossiersController, type: :controller do render_views let(:gestionnaire) { create(:gestionnaire) } - let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) } + let(:gestionnaires) { [gestionnaire] } + let(:procedure) { create(:procedure, :published, gestionnaires: gestionnaires) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } before { sign_in(gestionnaire) } @@ -30,6 +31,32 @@ describe NewGestionnaire::DossiersController, type: :controller do end end + describe '#envoyer_a_accompagnateur' do + let(:recipient) { create(:gestionnaire) } + let(:gestionnaires) { [gestionnaire, recipient] } + let(:mail) { double("mail") } + + before do + expect(mail).to receive(:deliver_later) + + expect(GestionnaireMailer) + .to receive(:send_dossier) + .with(gestionnaire, dossier, recipient) + .and_return(mail) + + post( + :envoyer_a_accompagnateur, + params: { + recipient: recipient, + procedure_id: procedure.id, + dossier_id: dossier.id + } + ) + end + + it { expect(response).to redirect_to(personnes_impliquees_dossier_url) } + end + describe '#follow' do before do patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id }