Merge pull request #1393 from betagouv/fix_1012-envoyer_un_dossier_a_un_autre_accompagnateur

[Fix #1012] Send dossier to other accompagnateur
This commit is contained in:
Frederic Merizen 2018-02-01 17:04:26 +01:00 committed by GitHub
commit 3d31fcca4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 1 deletions

View file

@ -20,4 +20,8 @@
&.justify-center {
justify-content: center;
}
&.justify-start {
justify-content: flex-start;
}
}

View file

@ -0,0 +1,5 @@
@import "constants";
.gap-left {
margin-left: $default-spacer;
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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é" }

View file

@ -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

View file

@ -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 }