From d5fce6f7b6dd2091423250900f7e32f9d94b4d3f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:09:08 +0200 Subject: [PATCH 001/131] Remove the 3 dashes from the emails signature --- app/views/devise/mailer/reset_password_instructions.html.erb | 1 - app/views/gestionnaire_mailer/new_assignement.text.erb | 1 - app/views/gestionnaire_mailer/new_gestionnaire.text.erb | 1 - app/views/invite_mailer/invite_guest.text.erb | 1 - app/views/invite_mailer/invite_user.text.erb | 1 - app/views/new_admin_mailer/new_admin_email.text.erb | 1 - app/views/notification_mailer/new_answer.text.erb | 1 - app/views/welcome_mailer/welcome_email.text.erb | 1 - 8 files changed, 8 deletions(-) diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index 80466e643..d92d8cc07 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -10,6 +10,5 @@

- ---
L'équipe Téléprocédures Simplifiées

diff --git a/app/views/gestionnaire_mailer/new_assignement.text.erb b/app/views/gestionnaire_mailer/new_assignement.text.erb index 694f454b8..cf9571c58 100644 --- a/app/views/gestionnaire_mailer/new_assignement.text.erb +++ b/app/views/gestionnaire_mailer/new_assignement.text.erb @@ -7,5 +7,4 @@ Vous venez d'être assigné à un administrateur sur la plateforme TPS. Voici qu Bonne journée, ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/gestionnaire_mailer/new_gestionnaire.text.erb b/app/views/gestionnaire_mailer/new_gestionnaire.text.erb index f7472cb9e..31cf76418 100644 --- a/app/views/gestionnaire_mailer/new_gestionnaire.text.erb +++ b/app/views/gestionnaire_mailer/new_gestionnaire.text.erb @@ -8,5 +8,4 @@ Vous venez d'être nommé accompagnateur sur la plateforme TPS. Pour mémoire, v Bonne journée, ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/invite_mailer/invite_guest.text.erb b/app/views/invite_mailer/invite_guest.text.erb index 73894115d..3b0773e7c 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -8,5 +8,4 @@ Afin de répondre à cette invitation, merci de vous inscrit avec l'adresse emai Bonne journée. ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/invite_mailer/invite_user.text.erb b/app/views/invite_mailer/invite_user.text.erb index 53e98e30c..b3be9f06f 100644 --- a/app/views/invite_mailer/invite_user.text.erb +++ b/app/views/invite_mailer/invite_user.text.erb @@ -6,5 +6,4 @@ Pour le consulter, merci de suivre ce lien : <%= users_dossiers_invite_url(@invi Bonne journée. ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/new_admin_mailer/new_admin_email.text.erb b/app/views/new_admin_mailer/new_admin_email.text.erb index 547713f13..407566622 100644 --- a/app/views/new_admin_mailer/new_admin_email.text.erb +++ b/app/views/new_admin_mailer/new_admin_email.text.erb @@ -5,5 +5,4 @@ Plateforme : <%= TPS::Application::URL %> Login : <%= @admin.email %> Password : <%= @password %> ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index 039d306de..7f1e9f44c 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -10,5 +10,4 @@ Bonne journée Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. --- ---- L'équipe Téléprocédures Simplifiées diff --git a/app/views/welcome_mailer/welcome_email.text.erb b/app/views/welcome_mailer/welcome_email.text.erb index 90b547ce5..cfd119663 100644 --- a/app/views/welcome_mailer/welcome_email.text.erb +++ b/app/views/welcome_mailer/welcome_email.text.erb @@ -11,5 +11,4 @@ Oubli de mot de passe, pas de problème : Bonne journée, ---- L'équipe Téléprocédures Simplifiées From d8c5db4ac55aa08f68b1bf2ff0a808e2f4856384 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:11:24 +0200 Subject: [PATCH 002/131] End the email parting phrase with a comma --- app/views/devise/mailer/reset_password_instructions.html.erb | 2 +- app/views/invite_mailer/invite_guest.text.erb | 2 +- app/views/invite_mailer/invite_user.text.erb | 2 +- app/views/mails/closed_mail.html.haml | 2 +- app/views/mails/initiated_mail.html.haml | 2 +- app/views/mails/received_mail.html.haml | 2 +- app/views/mails/refused_mail.html.haml | 2 +- app/views/mails/without_continuation_mail.html.haml | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index d92d8cc07..cbe2d8193 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -6,7 +6,7 @@

Si vous n'avez pas effectué une telle demande, merci d'ignorer ce mail. Votre mot de passe ne sera pas changé.

-

Bonne journée

+

Bonne journée,

diff --git a/app/views/invite_mailer/invite_guest.text.erb b/app/views/invite_mailer/invite_guest.text.erb index 3b0773e7c..90cf95d0a 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -6,6 +6,6 @@ Cette plateforme permet à ses utilisateurs d'établir des dossiers 100% en lign Afin de répondre à cette invitation, merci de vous inscrit avec l'adresse email <%= @invite.email %> sur <%= users_dossiers_invite_url(@invite.id)+"?email=#{@invite.email}" %>. -Bonne journée. +Bonne journée, L'équipe Téléprocédures Simplifiées diff --git a/app/views/invite_mailer/invite_user.text.erb b/app/views/invite_mailer/invite_user.text.erb index b3be9f06f..507c6f44b 100644 --- a/app/views/invite_mailer/invite_user.text.erb +++ b/app/views/invite_mailer/invite_user.text.erb @@ -4,6 +4,6 @@ L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'él Pour le consulter, merci de suivre ce lien : <%= users_dossiers_invite_url(@invite.id) %> -Bonne journée. +Bonne journée, L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml index 5870fc1cf..c8961445d 100644 --- a/app/views/mails/closed_mail.html.haml +++ b/app/views/mails/closed_mail.html.haml @@ -7,7 +7,7 @@ Votre dossier nº --numero_dossier-- a été accepté le --date_de_decision--. A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier-- %br %br -Bonne journée +Bonne journée, %br %br \--- diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml index ce3ae6324..4868daacb 100644 --- a/app/views/mails/initiated_mail.html.haml +++ b/app/views/mails/initiated_mail.html.haml @@ -7,7 +7,7 @@ Votre administration vous confirme la bonne réception de votre dossier nº --n A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier-- %br %br -Bonne journée +Bonne journée, %br %br \--- diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml index 113139052..60b13c8a4 100644 --- a/app/views/mails/received_mail.html.haml +++ b/app/views/mails/received_mail.html.haml @@ -4,7 +4,7 @@ Bonjour Votre administration vous confirme la bonne réception de votre dossier nº --numero_dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur. %br %br -Bonne journée +Bonne journée, %br %br \--- diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml index b2796bf3c..d6f1f5774 100644 --- a/app/views/mails/refused_mail.html.haml +++ b/app/views/mails/refused_mail.html.haml @@ -7,7 +7,7 @@ Votre dossier nº --numero_dossier-- a été refusé le --date_de_decision--. Pour en savoir plus sur le motif du refus, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier-- %br %br -Bonne journée +Bonne journée, %br %br \--- diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml index ddac75477..7431bf367 100644 --- a/app/views/mails/without_continuation_mail.html.haml +++ b/app/views/mails/without_continuation_mail.html.haml @@ -7,7 +7,7 @@ Votre dossier nº --numero_dossier-- a été classé sans suite le --date_de_de Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez consulter le contenu de vos dossiers et les éventuels commentaires de l'administration à cette adresse : --lien_dossier-- %br %br -Bonne journée +Bonne journée, %br %br \--- diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index 7f1e9f44c..e76018657 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -4,7 +4,7 @@ Un nouveau message est disponible dans votre espace TPS. Pour le consulter, merci de vous rendre sur <%=users_dossier_recapitulatif_url(dossier_id: @dossier.id)%> -Bonne journée +Bonne journée, --- Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. From 2984c495e63498f53fc506ef5368f4a83b560b73 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:11:43 +0200 Subject: [PATCH 003/131] =?UTF-8?q?Add=20a=20parting=20phrase=20to=20email?= =?UTF-8?q?s=20which=20don=E2=80=99t=20have=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/new_admin_mailer/new_admin_email.text.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/new_admin_mailer/new_admin_email.text.erb b/app/views/new_admin_mailer/new_admin_email.text.erb index 407566622..678123a26 100644 --- a/app/views/new_admin_mailer/new_admin_email.text.erb +++ b/app/views/new_admin_mailer/new_admin_email.text.erb @@ -5,4 +5,6 @@ Plateforme : <%= TPS::Application::URL %> Login : <%= @admin.email %> Password : <%= @password %> +Bonne journée, + L'équipe Téléprocédures Simplifiées From 2796eea39a20d24a1067a5c905edb812143baa17 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:12:20 +0200 Subject: [PATCH 004/131] Improve the formatting of reset_password_instructions.html.erb --- app/views/devise/mailer/reset_password_instructions.html.erb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index cbe2d8193..62ee8f44c 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -8,7 +8,4 @@

Bonne journée,

- -

-
- L'équipe Téléprocédures Simplifiées

+

L'équipe Téléprocédures Simplifiées

From b77c63605a8473a6f476d78406e944571f9ac60e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:14:06 +0200 Subject: [PATCH 005/131] =?UTF-8?q?Add=20a=20signature=20to=20the=20emails?= =?UTF-8?q?=20which=20don=E2=80=99t=20have=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/mails/closed_mail.html.haml | 3 +++ app/views/mails/initiated_mail.html.haml | 3 +++ app/views/mails/received_mail.html.haml | 3 +++ app/views/mails/refused_mail.html.haml | 3 +++ app/views/mails/without_continuation_mail.html.haml | 3 +++ 5 files changed, 15 insertions(+) diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml index c8961445d..b67bbca8c 100644 --- a/app/views/mails/closed_mail.html.haml +++ b/app/views/mails/closed_mail.html.haml @@ -15,3 +15,6 @@ Bonne journée, Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. %br \--- +%br +%br +L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml index 4868daacb..9763bda5c 100644 --- a/app/views/mails/initiated_mail.html.haml +++ b/app/views/mails/initiated_mail.html.haml @@ -15,3 +15,6 @@ Bonne journée, Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. %br \--- +%br +%br +L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml index 60b13c8a4..f37229927 100644 --- a/app/views/mails/received_mail.html.haml +++ b/app/views/mails/received_mail.html.haml @@ -12,3 +12,6 @@ Bonne journée, Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. %br \--- +%br +%br +L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml index d6f1f5774..34efc02de 100644 --- a/app/views/mails/refused_mail.html.haml +++ b/app/views/mails/refused_mail.html.haml @@ -15,3 +15,6 @@ Bonne journée, Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. %br \--- +%br +%br +L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml index 7431bf367..1690267e1 100644 --- a/app/views/mails/without_continuation_mail.html.haml +++ b/app/views/mails/without_continuation_mail.html.haml @@ -15,3 +15,6 @@ Bonne journée, Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. %br \--- +%br +%br +L'équipe Téléprocédures Simplifiées From ae7cea369dd7f5492a9252f92f8405e5759ef387 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:18:07 +0200 Subject: [PATCH 006/131] =?UTF-8?q?Move=20the=20=E2=80=9Cplease=20do=20not?= =?UTF-8?q?=20reply=E2=80=9D=20message=20below=20the=20signature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/mails/closed_mail.html.haml | 11 +++++------ app/views/mails/initiated_mail.html.haml | 11 +++++------ app/views/mails/received_mail.html.haml | 11 +++++------ app/views/mails/refused_mail.html.haml | 11 +++++------ app/views/mails/without_continuation_mail.html.haml | 11 +++++------ app/views/notification_mailer/new_answer.text.erb | 8 ++++---- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml index b67bbca8c..b608f00eb 100644 --- a/app/views/mails/closed_mail.html.haml +++ b/app/views/mails/closed_mail.html.haml @@ -10,11 +10,10 @@ A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuel Bonne journée, %br %br -\--- +L'équipe Téléprocédures Simplifiées +%br +%br +— +%br %br Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. -%br -\--- -%br -%br -L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml index 9763bda5c..14173126d 100644 --- a/app/views/mails/initiated_mail.html.haml +++ b/app/views/mails/initiated_mail.html.haml @@ -10,11 +10,10 @@ A tout moment, vous pouvez consulter le contenu de vos dossiers et les éventuel Bonne journée, %br %br -\--- +L'équipe Téléprocédures Simplifiées +%br +%br +— +%br %br Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. -%br -\--- -%br -%br -L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml index f37229927..376838226 100644 --- a/app/views/mails/received_mail.html.haml +++ b/app/views/mails/received_mail.html.haml @@ -7,11 +7,10 @@ Votre administration vous confirme la bonne réception de votre dossier nº --n Bonne journée, %br %br -\--- +L'équipe Téléprocédures Simplifiées +%br +%br +— +%br %br Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. -%br -\--- -%br -%br -L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml index 34efc02de..77c5b7c55 100644 --- a/app/views/mails/refused_mail.html.haml +++ b/app/views/mails/refused_mail.html.haml @@ -10,11 +10,10 @@ Pour en savoir plus sur le motif du refus, vous pouvez consulter le contenu de v Bonne journée, %br %br -\--- +L'équipe Téléprocédures Simplifiées +%br +%br +— +%br %br Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. -%br -\--- -%br -%br -L'équipe Téléprocédures Simplifiées diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml index 1690267e1..c164e8d0d 100644 --- a/app/views/mails/without_continuation_mail.html.haml +++ b/app/views/mails/without_continuation_mail.html.haml @@ -10,11 +10,10 @@ Pour en savoir plus sur les raisons de ce classement sans suite, vous pouvez con Bonne journée, %br %br -\--- +L'équipe Téléprocédures Simplifiées +%br +%br +— +%br %br Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. -%br -\--- -%br -%br -L'équipe Téléprocédures Simplifiées diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index e76018657..27fbe729d 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -6,8 +6,8 @@ Pour le consulter, merci de vous rendre sur <%=users_dossier_recapitulatif_url(d Bonne journée, ---- -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. ---- - L'équipe Téléprocédures Simplifiées + +— + +Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. From 536591078e3073a855dfd05277a8f61184b40780 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:19:54 +0200 Subject: [PATCH 007/131] In emails, add a comma after the salutation phrase --- app/views/devise/mailer/reset_password_instructions.html.erb | 2 +- app/views/gestionnaire_mailer/new_assignement.text.erb | 2 +- app/views/gestionnaire_mailer/new_gestionnaire.text.erb | 2 +- app/views/invite_mailer/invite_guest.text.erb | 2 +- app/views/invite_mailer/invite_user.text.erb | 2 +- app/views/mails/closed_mail.html.haml | 2 +- app/views/mails/initiated_mail.html.haml | 2 +- app/views/mails/received_mail.html.haml | 2 +- app/views/mails/refused_mail.html.haml | 2 +- app/views/mails/without_continuation_mail.html.haml | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- app/views/welcome_mailer/welcome_email.text.erb | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index 62ee8f44c..9c1be2c7d 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -1,4 +1,4 @@ -

Bonjour <%= @resource.email %>!

+

Bonjour <%= @resource.email %>!

,

Vous avez demandé à regénérer votre mot de passe sur la plateforme TPS. Pour ceci, merci de suivre le lien suivant :

diff --git a/app/views/gestionnaire_mailer/new_assignement.text.erb b/app/views/gestionnaire_mailer/new_assignement.text.erb index cf9571c58..9af14a3e6 100644 --- a/app/views/gestionnaire_mailer/new_assignement.text.erb +++ b/app/views/gestionnaire_mailer/new_assignement.text.erb @@ -1,4 +1,4 @@ -Bienvenue sur la plateforme TPS +Bienvenue sur la plateforme TPS, Vous venez d'être assigné à un administrateur sur la plateforme TPS. Voici quelques informations utiles : diff --git a/app/views/gestionnaire_mailer/new_gestionnaire.text.erb b/app/views/gestionnaire_mailer/new_gestionnaire.text.erb index 31cf76418..7fdcce89d 100644 --- a/app/views/gestionnaire_mailer/new_gestionnaire.text.erb +++ b/app/views/gestionnaire_mailer/new_gestionnaire.text.erb @@ -1,4 +1,4 @@ -Bienvenue sur la plateforme TPS +Bienvenue sur la plateforme TPS, Vous venez d'être nommé accompagnateur sur la plateforme TPS. Pour mémoire, voici quelques informations utiles : diff --git a/app/views/invite_mailer/invite_guest.text.erb b/app/views/invite_mailer/invite_guest.text.erb index 90cf95d0a..6d18aafcb 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @invite.email %> +Bonjour <%= @invite.email %>, L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'élaboration d'un dossier sur la plateforme TPS. diff --git a/app/views/invite_mailer/invite_user.text.erb b/app/views/invite_mailer/invite_user.text.erb index 507c6f44b..0612d74fa 100644 --- a/app/views/invite_mailer/invite_user.text.erb +++ b/app/views/invite_mailer/invite_user.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @invite.email %> +Bonjour <%= @invite.email %>, L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'élaboration d'un dossier sur la plateforme TPS. diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml index b608f00eb..57c2876d3 100644 --- a/app/views/mails/closed_mail.html.haml +++ b/app/views/mails/closed_mail.html.haml @@ -1,4 +1,4 @@ -Bonjour +Bonjour, %br %br Votre dossier nº --numero_dossier-- a été accepté le --date_de_decision--. diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml index 14173126d..cada6be78 100644 --- a/app/views/mails/initiated_mail.html.haml +++ b/app/views/mails/initiated_mail.html.haml @@ -1,4 +1,4 @@ -Bonjour +Bonjour, %br %br Votre administration vous confirme la bonne réception de votre dossier nº --numero_dossier--. diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml index 376838226..8fa2133bc 100644 --- a/app/views/mails/received_mail.html.haml +++ b/app/views/mails/received_mail.html.haml @@ -1,4 +1,4 @@ -Bonjour +Bonjour, %br %br Votre administration vous confirme la bonne réception de votre dossier nº --numero_dossier--. Celui-ci sera instruit dans le délai légal déclaré par votre interlocuteur. diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml index 77c5b7c55..23c6f2b9c 100644 --- a/app/views/mails/refused_mail.html.haml +++ b/app/views/mails/refused_mail.html.haml @@ -1,4 +1,4 @@ -Bonjour +Bonjour, %br %br Votre dossier nº --numero_dossier-- a été refusé le --date_de_decision--. diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml index c164e8d0d..966238454 100644 --- a/app/views/mails/without_continuation_mail.html.haml +++ b/app/views/mails/without_continuation_mail.html.haml @@ -1,4 +1,4 @@ -Bonjour +Bonjour, %br %br Votre dossier nº --numero_dossier-- a été classé sans suite le --date_de_decision--. diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index 27fbe729d..e95a1a6dd 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @user.email %> +Bonjour <%= @user.email %>, Un nouveau message est disponible dans votre espace TPS. diff --git a/app/views/welcome_mailer/welcome_email.text.erb b/app/views/welcome_mailer/welcome_email.text.erb index cfd119663..ccec462b8 100644 --- a/app/views/welcome_mailer/welcome_email.text.erb +++ b/app/views/welcome_mailer/welcome_email.text.erb @@ -1,4 +1,4 @@ -Bienvenue sur la plateforme TPS +Bienvenue sur la plateforme TPS, Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles : From e6f866d99e21b34dc9c2072b82f14b72fcf854f9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:20:37 +0200 Subject: [PATCH 008/131] Do not use the email address in emails --- app/views/devise/mailer/reset_password_instructions.html.erb | 2 +- app/views/invite_mailer/invite_guest.text.erb | 2 +- app/views/invite_mailer/invite_user.text.erb | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb index 9c1be2c7d..f83f30336 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -1,4 +1,4 @@ -

Bonjour <%= @resource.email %>!

, +

Bonjour,

Vous avez demandé à regénérer votre mot de passe sur la plateforme TPS. Pour ceci, merci de suivre le lien suivant :

diff --git a/app/views/invite_mailer/invite_guest.text.erb b/app/views/invite_mailer/invite_guest.text.erb index 6d18aafcb..bfcfcc932 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @invite.email %>, +Bonjour, L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'élaboration d'un dossier sur la plateforme TPS. diff --git a/app/views/invite_mailer/invite_user.text.erb b/app/views/invite_mailer/invite_user.text.erb index 0612d74fa..3c1b9abee 100644 --- a/app/views/invite_mailer/invite_user.text.erb +++ b/app/views/invite_mailer/invite_user.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @invite.email %>, +Bonjour, L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'élaboration d'un dossier sur la plateforme TPS. diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index e95a1a6dd..8ae262b36 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -1,4 +1,4 @@ -Bonjour <%= @user.email %>, +Bonjour, Un nouveau message est disponible dans votre espace TPS. From cd19c17df50eb294474c9e5bb463352a897207a5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 16 May 2017 12:23:22 +0200 Subject: [PATCH 009/131] mail -> email --- app/views/mails/closed_mail.html.haml | 2 +- app/views/mails/initiated_mail.html.haml | 2 +- app/views/mails/received_mail.html.haml | 2 +- app/views/mails/refused_mail.html.haml | 2 +- app/views/mails/without_continuation_mail.html.haml | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/mails/closed_mail.html.haml b/app/views/mails/closed_mail.html.haml index 57c2876d3..2acc43fa7 100644 --- a/app/views/mails/closed_mail.html.haml +++ b/app/views/mails/closed_mail.html.haml @@ -16,4 +16,4 @@ L'équipe Téléprocédures Simplifiées — %br %br -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/mails/initiated_mail.html.haml b/app/views/mails/initiated_mail.html.haml index cada6be78..b2e170224 100644 --- a/app/views/mails/initiated_mail.html.haml +++ b/app/views/mails/initiated_mail.html.haml @@ -16,4 +16,4 @@ L'équipe Téléprocédures Simplifiées — %br %br -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/mails/received_mail.html.haml b/app/views/mails/received_mail.html.haml index 8fa2133bc..acd67a6a6 100644 --- a/app/views/mails/received_mail.html.haml +++ b/app/views/mails/received_mail.html.haml @@ -13,4 +13,4 @@ L'équipe Téléprocédures Simplifiées — %br %br -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/mails/refused_mail.html.haml b/app/views/mails/refused_mail.html.haml index 23c6f2b9c..83415496b 100644 --- a/app/views/mails/refused_mail.html.haml +++ b/app/views/mails/refused_mail.html.haml @@ -16,4 +16,4 @@ L'équipe Téléprocédures Simplifiées — %br %br -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/mails/without_continuation_mail.html.haml b/app/views/mails/without_continuation_mail.html.haml index 966238454..7882763f2 100644 --- a/app/views/mails/without_continuation_mail.html.haml +++ b/app/views/mails/without_continuation_mail.html.haml @@ -16,4 +16,4 @@ L'équipe Téléprocédures Simplifiées — %br %br -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/app/views/notification_mailer/new_answer.text.erb b/app/views/notification_mailer/new_answer.text.erb index 8ae262b36..240df0b81 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -10,4 +10,4 @@ L'équipe Téléprocédures Simplifiées — -Merci de ne pas répondre à ce mail. Postez directement vos questions dans votre dossier sur la plateforme. +Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. From a213032f281714b815d18b2bdf345e83b7cc05df Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 17 May 2017 11:18:01 +0200 Subject: [PATCH 010/131] Refactor: use select block to select stuff --- app/controllers/admin/previsualisations_controller.rb | 5 +---- app/controllers/backoffice/dossiers_controller.rb | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/previsualisations_controller.rb b/app/controllers/admin/previsualisations_controller.rb index f3a78abf5..a2cb7efac 100644 --- a/app/controllers/admin/previsualisations_controller.rb +++ b/app/controllers/admin/previsualisations_controller.rb @@ -10,9 +10,6 @@ class Admin::PrevisualisationsController < AdminController @champs = @dossier.ordered_champs - @headers = @champs.inject([]) do |acc, champ| - acc.push(champ) if champ.type_champ == 'header_section' - acc - end + @headers = @champs.select { |champ| champ.type_champ == 'header_section' } end end diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 1c421a6de..c2dc2b89c 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -25,10 +25,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController unless @facade.nil? @champs_private = @facade.champs_private - @headers_private = @champs_private.inject([]) do |acc, champ| - acc.push(champ) if champ.type_champ == 'header_section' - acc - end + @headers_private = @champs_private.select { |champ| champ.type_champ == 'header_section' } end Notification.where(dossier_id: params[:id].to_i).update_all already_read: true From 14bfda2e2650c62fb22be9f0a0dac9337fc24f8d Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 17 May 2017 18:06:25 +0200 Subject: [PATCH 011/131] [Fix #251] Fix landing page design on mobile (and add responsive) --- app/assets/stylesheets/_constants.scss | 2 + app/assets/stylesheets/_placeholders.scss | 15 ++- app/assets/stylesheets/landing.scss | 130 ++++++++++++++------ app/assets/stylesheets/new_footer.scss | 16 +-- app/assets/stylesheets/new_header.scss | 6 +- app/views/layouts/_new_header.haml | 6 +- app/views/layouts/new_application.html.haml | 1 + app/views/root/landing.html.haml | 82 ++++++------ 8 files changed, 162 insertions(+), 96 deletions(-) diff --git a/app/assets/stylesheets/_constants.scss b/app/assets/stylesheets/_constants.scss index 1208ef340..bfd996878 100644 --- a/app/assets/stylesheets/_constants.scss +++ b/app/assets/stylesheets/_constants.scss @@ -5,3 +5,5 @@ $light-blue: #F2F6FA; $font-size-base: 16px; $page-width: 1040px; + +$default-padding: 15px; diff --git a/app/assets/stylesheets/_placeholders.scss b/app/assets/stylesheets/_placeholders.scss index 71870ccec..fbb5bf9d5 100644 --- a/app/assets/stylesheets/_placeholders.scss +++ b/app/assets/stylesheets/_placeholders.scss @@ -1,14 +1,21 @@ +@import "constants"; +@import "mixins"; + %horizontal-list { list-style-type: none; margin: 0; padding: 0; font-size: 0px; + display: flex; + flex-wrap: wrap; } %horizontal-list-item { display: inline-block; - - &:last-of-type { - margin-right: 0; - } +} + +%page-width-container { + @include horizontal-padding($default-padding); + max-width: $page-width + 2 * $default-padding; + margin: 0 auto; } diff --git a/app/assets/stylesheets/landing.scss b/app/assets/stylesheets/landing.scss index e5f6b2251..b5fa9cb12 100644 --- a/app/assets/stylesheets/landing.scss +++ b/app/assets/stylesheets/landing.scss @@ -12,12 +12,30 @@ } .landing-panel-inner-content { - width: $page-width; - margin: 0 auto; + @extend %page-width-container; +} + +$landing-breakpoint: 1040px; + +.hero-wrapper { + display: flex; + flex-wrap: wrap; + justify-content: space-between; + + @media (max-width: $landing-breakpoint) { + justify-content: center; + } +} + +.hero-text { + max-width: 500px; + + @media (max-width: $landing-breakpoint) { + margin: auto; + } } .hero-tagline { - width: 500px; font-size: 30px; margin-bottom: 0px; } @@ -29,12 +47,16 @@ font-weight: bold; } -.hero-text { - width: 500px; -} - .hero-illustration { - width: 500px; + max-width: 500px; + + img { + max-width: 100%; + } + + @media (max-width: 1030px) { + margin: auto; + } } .hero-button { @@ -69,6 +91,7 @@ } .landing-panel-title { + width: 100%; font-size: 30px; font-weight: normal; text-align: center; @@ -86,15 +109,22 @@ .features { @extend %horizontal-list; -} + width: 100%; + align-items: baseline; + justify-content: space-between; -$feature-width: 320px; -$features-count: 3; + @media (max-width: $landing-breakpoint) { + justify-content: center; + } +} .feature { @extend %horizontal-list-item; - width: $feature-width; - margin-right: calc((#{$page-width} - (#{$feature-width} * #{$features-count})) / (#{$features-count} - 1)); + width: 320px; + + @media (max-width: $landing-breakpoint) { + margin: 15px 20px; + } } .feature-text { @@ -116,18 +146,27 @@ $features-count: 3; .quotes { @extend %horizontal-list; -} + width: 100%; + justify-content: space-between; -$quote-width: 500px; -$quote-count: 2; + @media (max-width: $landing-breakpoint) { + justify-content: center; + } +} .quote { @extend %horizontal-list-item; - width: $quote-width; - margin-right: calc((#{$page-width} - (#{$quote-width} * #{$quote-count}))/ (#{$quote-count} - 1)); + max-width: 500px; background-color: #FFFFFF; box-shadow: 0 4px 16px 0 rgba(153, 153, 153, 0.2); padding: 24px; + display: flex; + justify-content: flex-start; + align-items: flex-start; + + @media (max-width: $landing-breakpoint) { + margin: 15px 0; + } } .quote-quotation-mark { @@ -136,13 +175,16 @@ $quote-count: 2; .quote-content { font-size: 18px; - width: 388px; margin-bottom: 24px; } +.quote-content-wrapper { + margin-left: 20px; + width: 100%; +} + .quote-author { font-size: 14px; - margin-left: 64px; } .quote-author-name { @@ -155,16 +197,18 @@ $quote-count: 2; .numbers { @extend %horizontal-list; + justify-content: space-around; + width: 100%; } -$number-width: 320px; -$number-count: 3; - .number { @extend %horizontal-list-item; - width: $number-width; - margin-right: calc((#{$page-width} - (#{$number-width} * #{$number-count}))/ (#{$number-count} - 1)); + width: 320px; text-align: center; + + @media (max-width: $landing-breakpoint) { + margin-bottom: 15px; + } } .number-value { @@ -178,25 +222,33 @@ $number-count: 3; font-size: 20px; } +$users-breakpoint: 950px; + .users { @extend %horizontal-list; -} + justify-content: space-between; + width: 100%; -$image-width: 170px; -$images-total-width: $image-width * 5; -$images-count: 5; + @media (max-width: $users-breakpoint) { + justify-content: space-around; + } +} .user { @extend %horizontal-list-item; - margin-right: calc((#{$page-width} - (#{$images-total-width}))/ (#{$images-count} - 1)); + width: 170px; &:hover { opacity: 0.6; } + + @media (max-width: $users-breakpoint) { + margin: 0 15px 15px; + } } .user-image { - width: $image-width; + width: 170px; } .cta-panel { @@ -204,6 +256,13 @@ $images-count: 5; color: #FFFFFF; } +.cta-panel-wrapper { + width: 100%; + display: flex; + flex-wrap: wrap; + justify-content: space-between; +} + .cta-panel-title { font-size: 24px; font-weight: bold; @@ -212,22 +271,21 @@ $images-count: 5; .cta-panel-explanation { font-size: 24px; - margin-bottom: 0; + margin-bottom: 10px; } -$cta-panel-button-height: 60px; $cta-panel-button-border-size: 2px; .cta-panel-button { @include horizontal-padding(30px); display: block; - height: $cta-panel-button-height; - line-height: $cta-panel-button-height - (2 * $cta-panel-button-border-size); - border-radius: $cta-panel-button-height; + padding: 10px; + border-radius: 100px; border: $cta-panel-button-border-size solid #FFFFFF; color: #FFFFFF; font-size: 24px; + text-align: center; &:hover { color: #FFFFFF; diff --git a/app/assets/stylesheets/new_footer.scss b/app/assets/stylesheets/new_footer.scss index ccfab7146..c88b853cd 100644 --- a/app/assets/stylesheets/new_footer.scss +++ b/app/assets/stylesheets/new_footer.scss @@ -10,23 +10,25 @@ } .footer-inner-content { - width: $page-width; - margin: 0 auto; + @extend %page-width-container; } .footer-columns { @extend %horizontal-list; + justify-content: flex-start; } -$footer-column-width: 320px; -$footer-column-count: 3; - .footer-column { @extend %horizontal-list-item; - width: $footer-column-width; - margin-right: calc((#{$page-width} - (#{$footer-column-width} * #{$footer-column-count})) / (#{$footer-column-count} - 1)); font-size: 14px; vertical-align: top; + flex-grow: 1; + min-width: 320px; + + @media (max-width: 1000px) { + width: 100%; + margin-bottom: 14px; + } } .footer-logos, diff --git a/app/assets/stylesheets/new_header.scss b/app/assets/stylesheets/new_header.scss index a76bbf9a1..aa542550e 100644 --- a/app/assets/stylesheets/new_header.scss +++ b/app/assets/stylesheets/new_header.scss @@ -1,6 +1,7 @@ @import "constants"; @import "colors"; @import "mixins"; +@import "placeholders"; // FIXME: Rename when the header is generalized .new-header { @@ -13,8 +14,9 @@ } .header-inner-content { - width: $page-width; - margin: 0 auto; + @extend %page-width-container; + display: flex; + justify-content: space-between; } .header-logo { diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 82554fd60..de45e2ef1 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -1,7 +1,5 @@ .new-header{ class: current_page?(root_path) ? nil : 'new-header-with-border' } .header-inner-content - %img.header-logo.pull-left{ src: image_url("header/logo-tps.svg") } + %img.header-logo{ src: image_url("header/logo-tps.svg") } - = link_to "Connexion", new_user_session_path, :class => "header-login-button pull-right" - - .clear-fix + = link_to "Connexion", new_user_session_path, class: "header-login-button" diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index ba6539661..e76072c71 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -3,6 +3,7 @@ %meta{ "http-equiv" => "Content-Type", :content => "text/html; charset=UTF-8" } %meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge" } %meta{ :name => "turbolinks-cache-control", :content => "no-cache" } + %meta{ name: "viewport", content: "width=device-width, initial-scale=1" } = csrf_meta_tags = action_cable_meta_tag diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 561246170..61c4ed7c4 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -1,23 +1,22 @@ .landing .landing-panel.hero-panel .landing-panel-inner-content - .hero-text.pull-left - %p.hero-tagline - %em.hero-tagline-em Dématérialisez - %br - vos procédures administratives en quelques minutes + .hero-wrapper + .hero-text + %p.hero-tagline + %em.hero-tagline-em Dématérialisez + %br + vos procédures administratives en quelques minutes - = link_to "Demander une démo", - "mailto:#{t("dynamics.contact_email")}?subject=Demande de démo TPS", - :class => "hero-button" + = link_to "Demander une démo", + "mailto:#{t("dynamics.contact_email")}?subject=Demande de démo TPS", + :class => "hero-button" - %p.hero-phone-cta - ou nous appeler au 01 40 15 68 49 + %p.hero-phone-cta + ou nous appeler au 01 40 15 68 49 - .hero-illustration.pull-right - %img{ :src => image_url("landing/hero/dematerialiser.svg") } - - .clearfix + .hero-illustration + %img{ :src => image_url("landing/hero/dematerialiser.svg") } .landing-panel.features-panel .landing-panel-inner-content @@ -55,28 +54,26 @@ %ul.quotes %li.quote - %img.quote-quotation-mark.pull-left{ :src => image_url("landing/testimonials/quotation-mark.svg") } - %p.quote-content.pull-right - TPS est un outil de dématérialisation adapté au dépôt de dossiers de demande d’inscription au registre des transporteurs routiers en Ile-de-France. Les échanges avec les usagers sont facilités, ce qui permet de réduire les délais d’instructions et de gagner en efficacité. - .clearfix + %img.quote-quotation-mark{ :src => image_url("landing/testimonials/quotation-mark.svg") } + .quote-content-wrapper + %p.quote-content + TPS est un outil de dématérialisation adapté au dépôt de dossiers de demande d’inscription au registre des transporteurs routiers en Ile-de-France. Les échanges avec les usagers sont facilités, ce qui permet de réduire les délais d’instructions et de gagner en efficacité. - %p.quote-author.pull-left - %span.quote-author-name Elodie Le Rhun - %br - Chef de bureau, DRIEA Ile-de-France - .clearfix + %p.quote-author + %span.quote-author-name Elodie Le Rhun + %br + Chef de bureau, DRIEA Ile-de-France %li.quote - %img.quote-quotation-mark.pull-left{ :src => image_url("landing/testimonials/quotation-mark.svg") } - %p.quote-content.pull-right - TPS c’est surtout l’assurance d’un dialogue en toute fluidité et en toute transparence entre les porteurs de projet et l’administration. Un service qui garantit une économie de temps et beaucoup moins de manipulations des dossiers. - .clearfix + %img.quote-quotation-mark{ :src => image_url("landing/testimonials/quotation-mark.svg") } + .quote-content-wrapper + %p.quote-content + TPS c’est surtout l’assurance d’un dialogue en toute fluidité et en toute transparence entre les porteurs de projet et l’administration. Un service qui garantit une économie de temps et beaucoup moins de manipulations des dossiers. - %p.quote-author.pull-left - %span.quote-author-name Nadja Briki - %br - Déléguée de la Préfète du Pas-de-Calais - .clearfix + %p.quote-author + %span.quote-author-name Nadja Briki + %br + Déléguée de la Préfète du Pas-de-Calais - cache "numbers-panel", :expires_in => 3.hours do .landing-panel.numbers-panel @@ -128,14 +125,13 @@ .landing-panel.cta-panel .landing-panel-inner-content - .pull-right - = link_to "Demander une démo", - "mailto:#{t('dynamics.contact_email')}?subject=Demande de démo TPS", - :class => "cta-panel-button" - %p.cta-panel-phone-cta - ou nous appeler au 01 40 15 68 49 - .pull-left - %h1.cta-panel-title Commencez à dématerialiser vos procédures - %p.cta-panel-explanation Nous vous accompagnons dans la prise en main de l’outil - .clearfix - + .cta-panel-wrapper + %div + %h1.cta-panel-title Commencez à dématerialiser vos procédures + %p.cta-panel-explanation Nous vous accompagnons dans la prise en main de l’outil + %div + = link_to "Demander une démo", + "mailto:#{t('dynamics.contact_email')}?subject=Demande de démo TPS", + :class => "cta-panel-button" + %p.cta-panel-phone-cta + ou nous appeler au 01 40 15 68 49 From 8af72f7b9a9a59eaa900903347c63704bc46fc0c Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 17 May 2017 15:11:35 +0200 Subject: [PATCH 012/131] Isolate new design stylesheets --- .scss-lint.yml | 2 +- app/assets/stylesheets/_constants.scss | 4 ---- app/assets/stylesheets/application.scss | 7 ------- app/assets/stylesheets/new_application.scss | 10 ---------- .../stylesheets/{ => new_design}/_colors.scss | 0 app/assets/stylesheets/new_design/_constants.scss | 3 +++ .../stylesheets/{ => new_design}/_mixins.scss | 0 .../{ => new_design}/_placeholders.scss | 0 .../stylesheets/{ => new_design}/_typography.scss | 0 app/assets/stylesheets/new_design/beta.scss | 15 +++++++++++++++ .../stylesheets/{ => new_design}/common.scss | 0 .../{ => new_design}/custom_reset.scss | 0 .../stylesheets/{ => new_design}/fonts.scss | 0 .../stylesheets/{ => new_design}/landing.scss | 0 .../stylesheets/{ => new_design}/new_alert.scss | 0 .../stylesheets/new_design/new_application.scss | 6 ++++++ .../stylesheets/{ => new_design}/new_footer.scss | 0 .../stylesheets/{ => new_design}/new_header.scss | 0 .../stylesheets/{ => new_design}/reset.scss | 0 .../stylesheets/{ => new_design}/utils.scss | 0 app/views/layouts/new_application.html.haml | 2 +- config/initializers/assets.rb | 2 +- 22 files changed, 27 insertions(+), 24 deletions(-) delete mode 100644 app/assets/stylesheets/new_application.scss rename app/assets/stylesheets/{ => new_design}/_colors.scss (100%) create mode 100644 app/assets/stylesheets/new_design/_constants.scss rename app/assets/stylesheets/{ => new_design}/_mixins.scss (100%) rename app/assets/stylesheets/{ => new_design}/_placeholders.scss (100%) rename app/assets/stylesheets/{ => new_design}/_typography.scss (100%) create mode 100644 app/assets/stylesheets/new_design/beta.scss rename app/assets/stylesheets/{ => new_design}/common.scss (100%) rename app/assets/stylesheets/{ => new_design}/custom_reset.scss (100%) rename app/assets/stylesheets/{ => new_design}/fonts.scss (100%) rename app/assets/stylesheets/{ => new_design}/landing.scss (100%) rename app/assets/stylesheets/{ => new_design}/new_alert.scss (100%) create mode 100644 app/assets/stylesheets/new_design/new_application.scss rename app/assets/stylesheets/{ => new_design}/new_footer.scss (100%) rename app/assets/stylesheets/{ => new_design}/new_header.scss (100%) rename app/assets/stylesheets/{ => new_design}/reset.scss (100%) rename app/assets/stylesheets/{ => new_design}/utils.scss (100%) diff --git a/.scss-lint.yml b/.scss-lint.yml index 7ee185bb3..835a46690 100644 --- a/.scss-lint.yml +++ b/.scss-lint.yml @@ -1,4 +1,4 @@ -exclude: 'app/assets/stylesheets/reset.scss' +exclude: 'app/assets/stylesheets/new_design/reset.scss' linters: BangFormat: diff --git a/app/assets/stylesheets/_constants.scss b/app/assets/stylesheets/_constants.scss index bfd996878..119b9eaea 100644 --- a/app/assets/stylesheets/_constants.scss +++ b/app/assets/stylesheets/_constants.scss @@ -3,7 +3,3 @@ $light-blue: #F2F6FA; // Bootstrap constants $font-size-base: 16px; - -$page-width: 1040px; - -$default-padding: 15px; diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 33338dbdb..5b64692b7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -13,13 +13,8 @@ // file per style scope. // // = require _card -// = require _colors -// = require _constants // = require _helpers -// = require _mixins -// = require _placeholders // = require _turbolinks -// = require _typography // = require admin_procedures_modal // = require admin_type_de_champ // = require backoffice @@ -31,9 +26,7 @@ // = require dossier_show // = require dossiers // = require etapes -// = require fonts // = require france_connect_particulier -// = require landing // = require left_panel // = require login // = require main_container diff --git a/app/assets/stylesheets/new_application.scss b/app/assets/stylesheets/new_application.scss deleted file mode 100644 index db2e8c65c..000000000 --- a/app/assets/stylesheets/new_application.scss +++ /dev/null @@ -1,10 +0,0 @@ -// = require reset -// = require custom_reset -// = require common -// = require utils -// = require fonts -// = require new_alert -// = require new_header -// = require new_footer -// = require landing -// = require navbar diff --git a/app/assets/stylesheets/_colors.scss b/app/assets/stylesheets/new_design/_colors.scss similarity index 100% rename from app/assets/stylesheets/_colors.scss rename to app/assets/stylesheets/new_design/_colors.scss diff --git a/app/assets/stylesheets/new_design/_constants.scss b/app/assets/stylesheets/new_design/_constants.scss new file mode 100644 index 000000000..897512e1d --- /dev/null +++ b/app/assets/stylesheets/new_design/_constants.scss @@ -0,0 +1,3 @@ +$page-width: 1040px; + +$default-padding: 15px; diff --git a/app/assets/stylesheets/_mixins.scss b/app/assets/stylesheets/new_design/_mixins.scss similarity index 100% rename from app/assets/stylesheets/_mixins.scss rename to app/assets/stylesheets/new_design/_mixins.scss diff --git a/app/assets/stylesheets/_placeholders.scss b/app/assets/stylesheets/new_design/_placeholders.scss similarity index 100% rename from app/assets/stylesheets/_placeholders.scss rename to app/assets/stylesheets/new_design/_placeholders.scss diff --git a/app/assets/stylesheets/_typography.scss b/app/assets/stylesheets/new_design/_typography.scss similarity index 100% rename from app/assets/stylesheets/_typography.scss rename to app/assets/stylesheets/new_design/_typography.scss diff --git a/app/assets/stylesheets/new_design/beta.scss b/app/assets/stylesheets/new_design/beta.scss new file mode 100644 index 000000000..c8480d52d --- /dev/null +++ b/app/assets/stylesheets/new_design/beta.scss @@ -0,0 +1,15 @@ +#beta { + text-align: center; + text-transform: uppercase; + position: fixed; + bottom: 26px; + right: -35px; + transform: rotate(-45deg); + width: 150px; + background-color: #008CBA; + color: #FFFFFF; + padding: 5px; + font-size: 15px; + font-weight: 700; + z-index: 10; +} diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/new_design/common.scss similarity index 100% rename from app/assets/stylesheets/common.scss rename to app/assets/stylesheets/new_design/common.scss diff --git a/app/assets/stylesheets/custom_reset.scss b/app/assets/stylesheets/new_design/custom_reset.scss similarity index 100% rename from app/assets/stylesheets/custom_reset.scss rename to app/assets/stylesheets/new_design/custom_reset.scss diff --git a/app/assets/stylesheets/fonts.scss b/app/assets/stylesheets/new_design/fonts.scss similarity index 100% rename from app/assets/stylesheets/fonts.scss rename to app/assets/stylesheets/new_design/fonts.scss diff --git a/app/assets/stylesheets/landing.scss b/app/assets/stylesheets/new_design/landing.scss similarity index 100% rename from app/assets/stylesheets/landing.scss rename to app/assets/stylesheets/new_design/landing.scss diff --git a/app/assets/stylesheets/new_alert.scss b/app/assets/stylesheets/new_design/new_alert.scss similarity index 100% rename from app/assets/stylesheets/new_alert.scss rename to app/assets/stylesheets/new_design/new_alert.scss diff --git a/app/assets/stylesheets/new_design/new_application.scss b/app/assets/stylesheets/new_design/new_application.scss new file mode 100644 index 000000000..82fb5fc2a --- /dev/null +++ b/app/assets/stylesheets/new_design/new_application.scss @@ -0,0 +1,6 @@ +// = require ./reset +// = require ./custom_reset +// = require ./common +// = require ./utils +// = require ./fonts +// = require_tree . diff --git a/app/assets/stylesheets/new_footer.scss b/app/assets/stylesheets/new_design/new_footer.scss similarity index 100% rename from app/assets/stylesheets/new_footer.scss rename to app/assets/stylesheets/new_design/new_footer.scss diff --git a/app/assets/stylesheets/new_header.scss b/app/assets/stylesheets/new_design/new_header.scss similarity index 100% rename from app/assets/stylesheets/new_header.scss rename to app/assets/stylesheets/new_design/new_header.scss diff --git a/app/assets/stylesheets/reset.scss b/app/assets/stylesheets/new_design/reset.scss similarity index 100% rename from app/assets/stylesheets/reset.scss rename to app/assets/stylesheets/new_design/reset.scss diff --git a/app/assets/stylesheets/utils.scss b/app/assets/stylesheets/new_design/utils.scss similarity index 100% rename from app/assets/stylesheets/utils.scss rename to app/assets/stylesheets/new_design/utils.scss diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index e76072c71..7a90a8c78 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -14,7 +14,7 @@ = favicon_link_tag(image_url("favicons/32x32.png"), type: "image/png", sizes: "32x32") = favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96") - = stylesheet_link_tag "new_application", :media => "all", "data-turbolinks-track" => true + = stylesheet_link_tag "new_design/new_application", :media => "all", "data-turbolinks-track" => true = stylesheet_link_tag "print", :media => "print", "data-turbolinks-track" => true %body diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 882590de7..c20bc1259 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,4 +8,4 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w(print.css new_application.css) +Rails.application.config.assets.precompile += %w(print.css new_design/new_application.css) From ca1a61cd7f7576894ea1275360daaaf39ed33e4c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 22 May 2017 16:56:37 +0200 Subject: [PATCH 013/131] Remove an extra character in welcome_email.text.erb --- app/views/welcome_mailer/welcome_email.text.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/welcome_mailer/welcome_email.text.erb b/app/views/welcome_mailer/welcome_email.text.erb index ccec462b8..5fb3d1d8a 100644 --- a/app/views/welcome_mailer/welcome_email.text.erb +++ b/app/views/welcome_mailer/welcome_email.text.erb @@ -2,7 +2,7 @@ Bienvenue sur la plateforme TPS, Nous vous remercions de vous être inscrit sur TPS. Pour mémoire, voici quelques informations utiles : - URL : <%= root_url %>> + URL : <%= root_url %> Login : <%= @user.email %> Oubli de mot de passe, pas de problème : From b30cb34fa2b8a45b58499cbb6c9f13d4ca342be6 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 22 May 2017 17:11:41 +0200 Subject: [PATCH 014/131] LeftPanelBackofficeDossier: fix a typo --- .../_left_panel_backoffice_dossierscontroller_show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml index ccc0aaa36..a78fa8241 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml @@ -51,12 +51,12 @@ - if notification.liste.size > 1 .type= "Plusieurs attributs ont été changés, dont: #{notification.liste.join(" ")}" - else - .type= "Un attribut à été changé: #{notification.liste.last}" + .type= "Un attribut a été changé: #{notification.liste.last}" - elsif ['piece_justificative'].include?(notification.type_notif) - if notification.liste.size > 1 .type= "Plusieurs pièces jointes ont été changés, dont: #{notification.liste.join(" ")}" - else - .type= "Une pièce jointe à été changée: #{notification.liste.last}" + .type= "Une pièce jointe a été changée: #{notification.liste.last}" - else .type= notification.liste.last .split-hr From f1b923e30fdcb038a8800e896cd1304f966276f1 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 23 May 2017 10:46:37 +0200 Subject: [PATCH 015/131] ApiControllers: remove useless meta data --- app/controllers/api/v1/dossiers_controller.rb | 7 ------- app/controllers/api/v1/procedures_controller.rb | 4 ---- 2 files changed, 11 deletions(-) diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index e77e11351..b2010c0f9 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -6,9 +6,6 @@ class API::V1::DossiersController < APIController error code: 401, desc: "Non authorisé" error code: 404, desc: "Procédure inconnue" - meta champs: { - } - def index procedure = current_administrateur.procedures.find(params[:procedure_id]) dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page]) @@ -25,10 +22,6 @@ class API::V1::DossiersController < APIController error code: 401, desc: "Non authorisé" error code: 404, desc: "Procédure ou dossier inconnu" - meta champs: { - - } - def show procedure = current_administrateur.procedures.find(params[:procedure_id]) dossier = procedure.dossiers.find(params[:id]) diff --git a/app/controllers/api/v1/procedures_controller.rb b/app/controllers/api/v1/procedures_controller.rb index b8a9fbdaa..cf370a8ff 100644 --- a/app/controllers/api/v1/procedures_controller.rb +++ b/app/controllers/api/v1/procedures_controller.rb @@ -5,10 +5,6 @@ class API::V1::ProceduresController < APIController error code: 401, desc: "Non authorisé" error code: 404, desc: "Procédure inconnue" - meta champs: { - - } - def show procedure = current_administrateur.procedures.find(params[:id]).decorate From 14dd75d0d2131d18579f5668b1b26bf1dc91802c Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 23 May 2017 10:29:09 +0200 Subject: [PATCH 016/131] Procedure: set archive_date to datetime to allow localtime And fix /issues/1562/ sentry bug --- ...220_change_procedure_auto_archive_date_to_datetime.rb | 9 +++++++++ db/schema.rb | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb diff --git a/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb b/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb new file mode 100644 index 000000000..b0d8deef3 --- /dev/null +++ b/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb @@ -0,0 +1,9 @@ +class ChangeProcedureAutoArchiveDateToDatetime < ActiveRecord::Migration[5.0] + def up + change_column :procedures, :auto_archive_on, :datetime + end + + def down + change_column :procedures, :auto_archive_on, :date + end +end diff --git a/db/schema.rb b/db/schema.rb index 140dccaf6..4af90d2e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170414095411) do +ActiveRecord::Schema.define(version: 20170523081220) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -344,7 +344,7 @@ ActiveRecord::Schema.define(version: 20170414095411) do t.string "lien_notice" t.boolean "for_individual", default: false t.boolean "individual_with_siret", default: false - t.date "auto_archive_on" + t.datetime "auto_archive_on" end create_table "quartier_prioritaires", force: :cascade do |t| From e7d39ca65078a55b268961b498e6d452d8dd08a9 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 12 May 2017 15:47:05 +0200 Subject: [PATCH 017/131] ProcedureOverview: add object to contain overview logic --- app/models/procedure.rb | 3 + app/models/procedure_overview.rb | 82 ++++++++++++++++++++++++ spec/models/procedure_overview_spec.rb | 87 ++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 app/models/procedure_overview.rb create mode 100644 spec/models/procedure_overview_spec.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2e910acd3..8c863697c 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -141,4 +141,7 @@ class Procedure < ActiveRecord::Base } end + def procedure_overview(start_date, notifications_count) + ProcedureOverview.new(self, start_date, notifications_count) + end end diff --git a/app/models/procedure_overview.rb b/app/models/procedure_overview.rb new file mode 100644 index 000000000..5bce9e5b5 --- /dev/null +++ b/app/models/procedure_overview.rb @@ -0,0 +1,82 @@ +class ProcedureOverview + include Rails.application.routes.url_helpers + attr_accessor :libelle, :notifications_count, :received_dossiers_count, :created_dossiers_count, :processed_dossiers_count, :date + + def initialize(procedure, start_date, notifications_count) + @libelle = procedure.libelle + @procedure_url = backoffice_dossiers_procedure_path(procedure) + @notifications_count = notifications_count + + @received_dossiers_count = procedure.dossiers.where(state: :received).count + @created_dossiers_count = procedure.dossiers + .where(created_at: start_date..DateTime.now) + .where.not(state: :draft) + .count + @processed_dossiers_count = procedure.dossiers.where(processed_at: start_date..DateTime.now).count + end + + def had_some_activities? + [received_dossiers_count, + created_dossiers_count, + processed_dossiers_count, + notifications_count].reduce(:+) > 0 + end + + def to_html + [libelle_description, + dossiers_en_instruction_description, + created_dossier_description, + processed_dossier_description, + notifications_description].compact.join('
') + end + + private + + def libelle_description + "#{libelle}" + end + + def dossiers_en_instruction_description + case received_dossiers_count + when 0 + nil + when 1 + "1 dossier est en cours d'instruction" + else + "#{received_dossiers_count} dossiers sont en cours d'instruction" + end + end + + def created_dossier_description + case created_dossiers_count + when 0 + nil + when 1 + '1 nouveau dossier a été déposé' + else + "#{created_dossiers_count} nouveaux dossiers ont été déposés" + end + end + + def processed_dossier_description + case processed_dossiers_count + when 0 + nil + when 1 + '1 dossier a été instruit' + else + "#{processed_dossiers_count} dossiers ont été instruits" + end + end + + def notifications_description + case notifications_count + when 0 + nil + when 1 + '1 notification en attente sur les dossiers que vous suivez' + else + "#{notifications_count} notifications en attente sur les dossiers que vous suivez" + end + end +end diff --git a/spec/models/procedure_overview_spec.rb b/spec/models/procedure_overview_spec.rb new file mode 100644 index 000000000..c6670d730 --- /dev/null +++ b/spec/models/procedure_overview_spec.rb @@ -0,0 +1,87 @@ +require 'spec_helper' + +describe ProcedureOverview, type: :model do + let(:procedure) { create(:procedure, libelle: 'libelle') } + let(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai + let(:monday) { DateTime.new(2017, 5, 8) } + + before :each do + Timecop.freeze(friday) + end + + let(:procedure_overview) { ProcedureOverview.new(procedure, monday, 0) } + + describe 'received_dossiers_count' do + let!(:received_dossier) do + dossier = create(:dossier, procedure: procedure, state: :received, created_at: monday) + end + + it { expect(procedure_overview.received_dossiers_count).to eq(1) } + end + + describe 'created_dossiers_count' do + let!(:created_dossier_during_the_week) do + create(:dossier, procedure: procedure, created_at: monday, state: :received) + end + + let!(:created_dossier_during_the_week_but_in_draft) do + create(:dossier, procedure: procedure, created_at: monday, state: :draft) + end + + let!(:created_dossier_before_the_week) do + create(:dossier, procedure: procedure, created_at: (monday - 1.week), state: :received) + end + + it { expect(procedure_overview.created_dossiers_count).to eq(1) } + end + + describe 'processed_dossiers_count' do + let!(:processed_dossier_during_the_week) do + create(:dossier, procedure: procedure, created_at: monday, processed_at: monday) + end + + let!(:processed_dossier_before_the_week) do + create(:dossier, procedure: procedure, created_at: (monday - 1.week), processed_at: (monday - 1.week)) + end + + it { expect(procedure_overview.processed_dossiers_count).to eq(1) } + end + + describe 'to_html' do + subject { procedure_overview.to_html } + + context 'when the different count are equal to 0' do + it { is_expected.to match(/^libelle<\/strong><\/a>$/) } + end + + context 'when the different counts are equal to 1' do + before :each do + procedure_overview.notifications_count = 1 + procedure_overview.received_dossiers_count = 1 + procedure_overview.created_dossiers_count = 1 + procedure_overview.processed_dossiers_count = 1 + end + + it { is_expected.to match(/^libelle<\/strong><\/a>/) } + it { is_expected.to include("1 dossier est en cours d'instruction") } + it { is_expected.to include('1 nouveau dossier a été déposé') } + it { is_expected.to include('1 dossier a été instruit') } + it { is_expected.to include('1 notification en attente sur les dossiers que vous suivez') } + end + + context 'when the different counts are equal to 2' do + before :each do + procedure_overview.notifications_count = 2 + procedure_overview.received_dossiers_count = 3 + procedure_overview.created_dossiers_count = 4 + procedure_overview.processed_dossiers_count = 5 + end + + it { is_expected.to match(/^libelle<\/strong><\/a>/) } + it { is_expected.to include("3 dossiers sont en cours d'instruction") } + it { is_expected.to include('4 nouveaux dossiers ont été déposés') } + it { is_expected.to include('5 dossiers ont été instruits') } + it { is_expected.to include('2 notifications en attente sur les dossiers que vous suivez') } + end + end +end From e6305481102321d85f95f2e4c4d6e00ad3e7a854 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 12 May 2017 16:47:18 +0200 Subject: [PATCH 018/131] Gestionnaire: add last_week_overview method --- app/models/gestionnaire.rb | 20 +++++++++++++ spec/models/gestionnaire_spec.rb | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index b5e84bcdd..f4cb1578b 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -92,6 +92,26 @@ class Gestionnaire < ActiveRecord::Base notifications.pluck(:dossier_id).uniq.count end + def last_week_overview + start_date = DateTime.now.beginning_of_week + + active_procedure_overviews = procedures + .where(published: true) + .all + .map { |procedure| procedure.procedure_overview(start_date, dossiers_with_notifications_count_for_procedure(procedure)) } + .select(&:had_some_activities?) + + if active_procedure_overviews.count == 0 && notifications.count == 0 + nil + else + { + start_date: start_date, + procedure_overviews: active_procedure_overviews, + notifications: notifications + } + end + end + private def valid_couple_table_attr? table, column diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 8525b2e86..27cb3502e 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -347,4 +347,52 @@ describe Gestionnaire, type: :model do end end end + + describe 'last_week_overview' do + let!(:gestionnaire2) { create(:gestionnaire) } + subject { gestionnaire2.last_week_overview } + let(:friday) { DateTime.new(2017, 5, 12) } + let(:monday) { DateTime.now.beginning_of_week } + + before :each do + Timecop.freeze(friday) + end + + context 'when no procedure published was active last week' do + let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) } + context 'when the gestionnaire has no notifications' do + it { is_expected.to eq(nil) } + end + + context 'when the gestionnaire has one notification' do + before :each do + expect(gestionnaire2).to receive(:notifications).twice.and_return([1]) + end + + it { is_expected.to eq({ start_date: monday, procedure_overviews: [], notifications: [1] }) } + end + end + + context 'when a procedure published was active' do + let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: true) } + let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) } + + before :each do + expect_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview) + end + + it { expect(gestionnaire.last_week_overview[:procedure_overviews]).to match([procedure_overview]) } + end + + context 'when a procedure not published was active with no notifications' do + let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire2], libelle: 'procedure', published: false) } + let(:procedure_overview) { double('procedure_overview', 'had_some_activities?'.to_sym => true) } + + before :each do + allow_any_instance_of(Procedure).to receive(:procedure_overview).and_return(procedure_overview) + end + + it { is_expected.to eq(nil) } + end + end end From 8dabdcc6c41c3fed13d29e44ea3bf05a4cd55546 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 12 May 2017 16:56:46 +0200 Subject: [PATCH 019/131] GestionnaireMailer: add a last week report --- .../mailer/gestionnaire_mailer/logo.png | Bin 0 -> 4188 bytes app/mailers/gestionnaire_mailer.rb | 4 +++ .../last_week_overview.html.haml | 26 ++++++++++++++++++ .../previews/gestionnaire_mailer_preview.rb | 6 ++++ 4 files changed, 36 insertions(+) create mode 100755 app/assets/images/mailer/gestionnaire_mailer/logo.png create mode 100644 app/views/gestionnaire_mailer/last_week_overview.html.haml create mode 100644 spec/mailers/previews/gestionnaire_mailer_preview.rb diff --git a/app/assets/images/mailer/gestionnaire_mailer/logo.png b/app/assets/images/mailer/gestionnaire_mailer/logo.png new file mode 100755 index 0000000000000000000000000000000000000000..b8c63e7c3dca4cc45340be7a41b8ad3707a22cb7 GIT binary patch literal 4188 zcmV-i5ToyjP)B*E400001b5ch_0Itp) z=>Px_7D+@wRCodHTnTtoRhB;Iy{bx5Rcy){91$0Kk>0d%92;mc2?10@TXb3hNkEV+ zVh?Kf%=k%cyY05^QG_a1Ljo@NX}g061VwSh=}qw)!Iq^*L1-XAsw$PLdhgDEU-Dkw zt5l#;RXW<~`+b#r?z!ijyPUh6d+vQ<${>^mqi5@sxIzfJfJhWVM4=Eoh?rbV)JQ^n zM9l9J@fLD>w=~S=V;L0VU=iizg%sx^B7G#W_%1RBlAu#j4kO+N+&&{#_$_iN&v9+- zUWb5xB&;5Qj?xR`9}zuc$0Bo~&};EKH$5(>owxoa-AOxf)-vJV6${-YnC`?(>YGicK;iGJ zidwm$qG0RE9AlhAgH>=P=zG|+S|dg*B_ zq5zCL~P_O~>VE7H=^Pa*Bwx-NbQ#g$^fd?T6P zNHZOR@~_`i>ECGPi)qs2nfr0t06jud1ta;=50(gVM(?4v*J0v9_avXoX<^zi+PM!5|9= zT0&n6x!<$%_it&W`#*fJX<*CY9(H^i{48elTwcBWuPO3QiV`zt4xm`#KCB*7oy1VQ zi%Pk!?qw&wd!!snAGbLAwS*pj2TO7tz8|!eQJB}4)2CuIBT~-CQF^j3?x4+n$#>RJ^F^;%^=Q_^G=-T7F6o&3T%Nv1f-ziCvy+ zgG<~{K9O|&Y1G=LczTa6n{Zxtv+Auq`;F}poQ3TQM@r$jxmLIwDx2P&>$?BL1qI0p z-*U?L=&JMY?OifrSt=t;vSu83)yn75p4%J(1bv&jnv9reD5Hc$;J4zhJ)| zWVM;Oesh(-%u4475M^Z-Q9?+I-C~N@eXT-fu z^*23v4X0f%$SXL0Bs@$csJ|{mT=955yJ(hYXAQG%FTg%1!}1@svC{j$CO#)|zWY{+#wS7XUPGRs z!F0HB4&eK{D!(ZdehfV0yUKTz!wbPPxA9P%SK?JUGS4b?ri zq@p!!F)e;~$p4bRW+BveZgrE z=G(Df0@#?0LX^Ns@d}R8al z4MhQQai&K_M|oyKc%k(0&yZ|2>I9vSgiD>a0C+f4cmpncE=kuRWb$?v^XlMX z?Cr0kBYtSn#5LIuORRJnfZ6$W(vqdobM$!JP&ztUYpC|iqhiXy3TmLWW}*E@8>)QI zr662UvMBtfPNKDLtW5)rp>)xrRiS_KBo7q624y9$SnH8>pWz@A+P$iqjR~e;IE|D{ zW`Je)ya{I;i;4wfCMAt4QpGd;ekm?AIO^Dz6*j~xv^D=&ZS z_^e2cUIY17B@I!`kI<@>m7R%QKAYp7GkudWa^>pK9)uY4aXh@d z9g!uZQ*t{Cvy^DCD{?{4afrr31(rx5!WPWpmrNHC60;|p&jw~Uj7YCZM_6!;_RXno{|<@o}y{Won|Kb?oT#&n+antzpEq=dJxwBw=7&IfD7CEAp6+t zt>tB{bX<>~O);&?Stef6t#ZBqnOn&|5G>hM81=XTgtOyJ3#E zy}@Q?S7NVsKQ-CBfdc*T1qb_{j#)4m3j38+1uS)d`@J3vjf8%T_5;Ag%}8>wOjg0Yau%BIFwkq;U@o|%_h~CaTF7y zRBI030bGS?)FGAwcp8kvX`xWKr8p4!ol8~kcxg_-9?7dfm}8kcB3iOu=8Rjh4rgI; z9vwXV6!v}ZYDa5m@_Z+xP5}~-Wo$`&{|6{-`#zf&gNx%0n z-=D$n=LH`BS(_^Sk0e)d!%RK`tNq`+`7}gTl$mg7J|zc;Nhb#aR)Oo|ILj9Yn+>BK zGo8^`G0Y@#aeOe~on|`Yc<7MZY1iI!Fxw|uGK44v?s4(N6O&JL$$?5T&g?5t;cG2k z2{65ON`K#M2QJfu0t2?~xMYZsk1KN!q#>tgB8TaHxV^uh39ICJ{zm@+MDQC>t#Ntw zLGuXs5PpQi`Alqyy)b!tkkD2mZoYHN%blo z7SBT|mf3)JZx>Doh6b8M*~U=(A-sk!#^BoJkR`-yaYLEITU8tk{S3qLKkRfErTbm% zD$eD_i}9j{_+M=0z(MKGnN!Lp_j3hHgQ072net*$AZl&T$py+6OSrl`+rZ;NOhJCZ zPS=Z-{?BmseH&UgIsr3Xi3{W2+42J?3+if`SFYR#|9cVq@0d;EG>cys^Tf3B5U*ZY zgNGH>LKp2v77)QGIjoW>*-)AP7mFtsKuo(8GhJ?NZGpEL7cpk?D-y$X53i>D@FOv< zC=l9$srx5ZcnA9JuXys-2YEk8XolO?Xe(~&>gDmRH9=&#`DA;s@mG#p(tJiP+s^e% z_mEr8cyiv}34Q*ys{3BWpj&7!PghXacpDiq=%{m=2svUBe9qo7IbusaI zc;r%5q17cV-ZEBc<1$5z!G!$@9-%JPH2p=ukD^cI>tes;hf`-WP5`$^*id@!{{9sh z9oF&-hP=3@Elg+6kV4W8nDIM^T_vD*TFv2c%f_eXIAan4i zwLS3#7}a@}IHo<+%eUN0X9;{!d%AR2!=GN^ak+=%4dX&-=o$mSQGYxDCEAMoX?WvU zA{|~b+cE^k2Acj=6ST(8gAsA}rs^Jd+Htvn@p|T;aa`Jf&hKTH_fGF~>7KL8nj`M~ zi47J0276vEU@^4}Z4q}lWGTuNJf+InOn1osf)mBdL@yC<8Q>z#uPN$L`7J`Kmp7Ku ztDJoJm_mjc5STLxomi!M93jJs^sm?SL4N46|9xV zL6Bhr4UyocI8# ze06tIxa`LEQQy|7MZxe0EW5AaXS}j7`x-~5b)>p(Zm7u5Xa?f(W#33F{A-k04%t?@ zed0}c`@T4GX5-yy}bPxX2B`8^bGY>f6(bukd~mX@=~BPcEf1Ap?n4u|0^ufeLJH|6TcfX{|;E`Yr3P+ma31^ zQo3Z69-!TcNI9P2PQem;5ga%jm(Nrs7&!g}4uTb|>Px%wp5FN6I1;@POZ6-afU`Ok z-!TL42l;LM9;KnDufUC;am&<^tb1b8R=T}=#;+9p;*kiR42z2~`v>FBwh;M+=xH|u z{tYt=u2!)Zih33AuV2oED^*OpaTxA{FTst`7|0!p^7^Bkeu(8$MEs*6<39XT49M3= m&3}RG7t0qn{|G61;Qs*r>O{Y^LLWE)0000 Date: Fri, 12 May 2017 17:41:03 +0200 Subject: [PATCH 020/131] WeeklyOverviewWorker: add worker to send the week overview --- app/workers/weekly_overview_worker.rb | 10 +++++++ spec/workers/weekly_overview_worker_spec.rb | 30 +++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 app/workers/weekly_overview_worker.rb create mode 100644 spec/workers/weekly_overview_worker_spec.rb diff --git a/app/workers/weekly_overview_worker.rb b/app/workers/weekly_overview_worker.rb new file mode 100644 index 000000000..226bc8fc6 --- /dev/null +++ b/app/workers/weekly_overview_worker.rb @@ -0,0 +1,10 @@ +class WeeklyOverviewWorker + include Sidekiq::Worker + + def perform(*args) + Gestionnaire.all + .map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] } + .reject { |_, overview| overview.nil? } + .each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now } + end +end diff --git a/spec/workers/weekly_overview_worker_spec.rb b/spec/workers/weekly_overview_worker_spec.rb new file mode 100644 index 000000000..c19a3e184 --- /dev/null +++ b/spec/workers/weekly_overview_worker_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe WeeklyOverviewWorker, type: :worker do + describe 'perform' do + let!(:gestionnaire) { create(:gestionnaire) } + let(:overview) { double('overview') } + let(:mailer_double) { double('mailer', deliver_now: true) } + + context 'with one gestionnaire with one overview' do + before :each do + expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(overview) + allow(GestionnaireMailer).to receive(:last_week_overview).and_return(mailer_double) + WeeklyOverviewWorker.new.perform + end + + it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) } + it { expect(mailer_double).to have_received(:deliver_now) } + end + + context 'with one gestionnaire with no overviews' do + before :each do + expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil) + allow(GestionnaireMailer).to receive(:last_week_overview) + WeeklyOverviewWorker.new.perform + end + + it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) } + end + end +end From b043effcc53d1958e3983170b9947da1c919688a Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 15 May 2017 15:31:39 +0200 Subject: [PATCH 021/131] Sidekiq: run weekly_overview_worker every sunday at 8:00 --- config/schedule.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/schedule.yml b/config/schedule.yml index 79dbdefc9..9a2979d42 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -1,3 +1,6 @@ auto_archive_procedure: cron: "* * * * *" class: "AutoArchiveProcedureWorker" +weekly_overview_worker: + cron: "0 8 * * 0" + class: "WeeklyOverviewWorker" From 5a794a8b9a81ef86cdda98c969a9f057e2fb0364 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 17 May 2017 10:27:08 +0200 Subject: [PATCH 022/131] GestionnaireMailer: add mailjet campaign tag --- app/mailers/gestionnaire_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/gestionnaire_mailer.rb b/app/mailers/gestionnaire_mailer.rb index 530e0614c..118537a8d 100644 --- a/app/mailers/gestionnaire_mailer.rb +++ b/app/mailers/gestionnaire_mailer.rb @@ -9,6 +9,7 @@ class GestionnaireMailer < ApplicationMailer end def last_week_overview(gestionnaire, overview) + headers['X-mailjet-campaign'] = 'last_week_overview' send_mail gestionnaire.email, overview, 'Résumé de la semaine' end From 45209619a460b4ca470ece76ee8a987aa496f3a4 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 19 May 2017 16:20:07 +0200 Subject: [PATCH 023/131] Config: add action_mailer.asset_host var to send image in email --- config/environments/development.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/environments/development.rb b/config/environments/development.rb index acb324db7..a03dda8e0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -42,6 +42,7 @@ Rails.application.configure do # Action Mailer settings config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + config.action_mailer.asset_host = 'http://localhost:3000' # Config for mailcatcher https://mailcatcher.me/ config.action_mailer.smtp_settings = { :address => "localhost", From b48549d7658c409804db625e2eb9c7c45ede4e39 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 19 May 2017 16:21:11 +0200 Subject: [PATCH 024/131] WeeklyOverviewWorker: add feature flip on worker The main objective is to avoid batch mail sent in staging --- app/workers/weekly_overview_worker.rb | 11 ++++--- config/initializers/features.yml | 1 + spec/workers/weekly_overview_worker_spec.rb | 36 ++++++++++++++------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/workers/weekly_overview_worker.rb b/app/workers/weekly_overview_worker.rb index 226bc8fc6..8f15194a7 100644 --- a/app/workers/weekly_overview_worker.rb +++ b/app/workers/weekly_overview_worker.rb @@ -2,9 +2,12 @@ class WeeklyOverviewWorker include Sidekiq::Worker def perform(*args) - Gestionnaire.all - .map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] } - .reject { |_, overview| overview.nil? } - .each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now } + # Feature flipped to avoid mails in staging due to unprocessed dossier + if Features.weekly_overview + Gestionnaire.all + .map { |gestionnaire| [gestionnaire, gestionnaire.last_week_overview] } + .reject { |_, overview| overview.nil? } + .each { |gestionnaire, overview| GestionnaireMailer.last_week_overview(gestionnaire, overview).deliver_now } + end end end diff --git a/config/initializers/features.yml b/config/initializers/features.yml index e91fb5346..7776e7e30 100644 --- a/config/initializers/features.yml +++ b/config/initializers/features.yml @@ -1 +1,2 @@ remote_storage: false +weekly_overview: false diff --git a/spec/workers/weekly_overview_worker_spec.rb b/spec/workers/weekly_overview_worker_spec.rb index c19a3e184..e2bff3e80 100644 --- a/spec/workers/weekly_overview_worker_spec.rb +++ b/spec/workers/weekly_overview_worker_spec.rb @@ -6,25 +6,39 @@ RSpec.describe WeeklyOverviewWorker, type: :worker do let(:overview) { double('overview') } let(:mailer_double) { double('mailer', deliver_now: true) } - context 'with one gestionnaire with one overview' do - before :each do - expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(overview) - allow(GestionnaireMailer).to receive(:last_week_overview).and_return(mailer_double) - WeeklyOverviewWorker.new.perform + context 'if the feature is enabled' do + before { allow(Features).to receive(:weekly_overview).and_return(true) } + + context 'with one gestionnaire with one overview' do + before :each do + expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(overview) + allow(GestionnaireMailer).to receive(:last_week_overview).and_return(mailer_double) + WeeklyOverviewWorker.new.perform + end + + it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) } + it { expect(mailer_double).to have_received(:deliver_now) } end - it { expect(GestionnaireMailer).to have_received(:last_week_overview).with(gestionnaire, overview) } - it { expect(mailer_double).to have_received(:deliver_now) } + context 'with one gestionnaire with no overviews' do + before :each do + expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil) + allow(GestionnaireMailer).to receive(:last_week_overview) + WeeklyOverviewWorker.new.perform + end + + it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) } + end end - context 'with one gestionnaire with no overviews' do + context 'if the feature is disabled' do + before { allow(Features).to receive(:weekly_overview).and_return(false) } before :each do - expect_any_instance_of(Gestionnaire).to receive(:last_week_overview).and_return(nil) - allow(GestionnaireMailer).to receive(:last_week_overview) + allow(Gestionnaire).to receive(:all) WeeklyOverviewWorker.new.perform end - it { expect(GestionnaireMailer).not_to have_received(:last_week_overview) } + it { expect(Gestionnaire).not_to receive(:all) } end end end From 5cc486298397c095cf75421915cd795f878cc475 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 23 May 2017 17:28:34 +0200 Subject: [PATCH 025/131] [Fix #349] NewHeader: the logo is a link to root_path --- app/views/layouts/_new_header.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index de45e2ef1..6e656bbc4 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -1,5 +1,6 @@ .new-header{ class: current_page?(root_path) ? nil : 'new-header-with-border' } .header-inner-content - %img.header-logo{ src: image_url("header/logo-tps.svg") } + = link_to root_path do + %img.header-logo{ src: image_url("header/logo-tps.svg") } = link_to "Connexion", new_user_session_path, class: "header-login-button" From 72494de76f8d1927abfbdad5d7b119e4172eb019 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 25 Apr 2017 12:09:11 +0200 Subject: [PATCH 026/131] Create new model Avis --- app/models/avis.rb | 4 ++++ app/models/dossier.rb | 1 + app/models/gestionnaire.rb | 1 + config/initializers/inflections.rb | 2 ++ db/migrate/20170425100757_create_avis.rb | 13 +++++++++++++ db/schema.rb | 14 +++++++++++++- 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/models/avis.rb create mode 100644 db/migrate/20170425100757_create_avis.rb diff --git a/app/models/avis.rb b/app/models/avis.rb new file mode 100644 index 000000000..2e6c622a2 --- /dev/null +++ b/app/models/avis.rb @@ -0,0 +1,4 @@ +class Avis < ApplicationRecord + belongs_to :dossier + belongs_to :gestionnaire +end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c6eee566f..71506ee9c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -25,6 +25,7 @@ class Dossier < ActiveRecord::Base has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy has_many :follows has_many :notifications, dependent: :destroy + has_many :avis, dependent: :destroy belongs_to :procedure belongs_to :user diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index f4cb1578b..0457deacb 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -12,6 +12,7 @@ class Gestionnaire < ActiveRecord::Base has_many :followed_dossiers, through: :follows, source: :dossier has_many :follows has_many :preference_list_dossiers + has_many :avis after_create :build_default_preferences_list_dossier after_create :build_default_preferences_smart_listing_page diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index a3bd49fb8..864ba4221 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -15,6 +15,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.irregular 'type_de_champ', 'types_de_champ' inflect.irregular 'type_de_champ_private', 'types_de_champ_private' inflect.irregular 'assign_to', 'assign_tos' + inflect.irregular('avis', 'avis') end # These inflection rules are supported but not enabled by default: @@ -24,4 +25,5 @@ end ActiveSupport::Inflector.inflections(:fr) do |inflect| inflect.plural(/$/, 's') inflect.plural(/(hib|ch|bij|caill|p|gen|jouj)ou$/i, '\1oux') + inflect.irregular('avis', 'avis') end diff --git a/db/migrate/20170425100757_create_avis.rb b/db/migrate/20170425100757_create_avis.rb new file mode 100644 index 000000000..229be2178 --- /dev/null +++ b/db/migrate/20170425100757_create_avis.rb @@ -0,0 +1,13 @@ +class CreateAvis < ActiveRecord::Migration[5.0] + def change + create_table :avis do |t| + t.string :email + t.text :introduction + t.text :answer + t.references :gestionnaire + t.references :dossier + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4af90d2e2..55f008b87 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170523081220) do +ActiveRecord::Schema.define(version: 20170425100757) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -71,6 +71,18 @@ ActiveRecord::Schema.define(version: 20170523081220) do t.index ["procedure_id"], name: "index_assign_tos_on_procedure_id", using: :btree end + create_table "avis", force: :cascade do |t| + t.string "email" + t.text "introduction" + t.text "answer" + t.integer "gestionnaire_id" + t.integer "dossier_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["dossier_id"], name: "index_avis_on_dossier_id", using: :btree + t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id", using: :btree + end + create_table "cadastres", force: :cascade do |t| t.string "surface_intersection" t.float "surface_parcelle" From c3bf15d49f77eac516c0a54b161f49e09aa186d1 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 25 Apr 2017 17:02:54 +0200 Subject: [PATCH 027/131] Create and list Avis on Dossier detail page --- app/controllers/backoffice/avis_controller.rb | 21 ++++++++ .../backoffice/dossiers_controller.rb | 2 + app/models/avis.rb | 4 ++ app/views/dossiers/_avis.html.haml | 52 +++++++++++++++++++ app/views/dossiers/_dossier_show.html.haml | 3 +- config/routes.rb | 1 + spec/models/avis_spec.rb | 20 +++++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 app/controllers/backoffice/avis_controller.rb create mode 100644 app/views/dossiers/_avis.html.haml create mode 100644 spec/models/avis_spec.rb diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb new file mode 100644 index 000000000..3d1559f6e --- /dev/null +++ b/app/controllers/backoffice/avis_controller.rb @@ -0,0 +1,21 @@ +class Backoffice::AvisController < ApplicationController + + def create + avis = Avis.new(create_params) + avis.dossier = dossier + avis.save + + redirect_to backoffice_dossier_path(dossier) + end + + private + + def dossier + current_gestionnaire.dossiers.find(params[:dossier_id]) + end + + def create_params + params.require(:avis).permit(:email, :introduction) + end + +end diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index c2dc2b89c..11ff0d7a6 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -29,6 +29,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController end Notification.where(dossier_id: params[:id].to_i).update_all already_read: true + + @new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.") end def filter diff --git a/app/models/avis.rb b/app/models/avis.rb index 2e6c622a2..5bbe6244f 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -1,4 +1,8 @@ class Avis < ApplicationRecord belongs_to :dossier belongs_to :gestionnaire + + def email_to_display + gestionnaire.try(:email) || email + end end diff --git a/app/views/dossiers/_avis.html.haml b/app/views/dossiers/_avis.html.haml new file mode 100644 index 000000000..feeedd37c --- /dev/null +++ b/app/views/dossiers/_avis.html.haml @@ -0,0 +1,52 @@ +- if @current_gestionnaire + + .default-data-block.default_visible + .row.show-block.infos + .header + .col-xs-12.title + .carret-right + .carret-down + AVIS EXTERNES + .body + .display-block-on-print + - dossier_facade.dossier.avis.order(updated_at: :desc).each do |avis| + - if avis.answer + .panel.panel-success + .panel-heading + %strong= avis.email_to_display + a donné son avis le + = avis.updated_at.localtime.strftime('%d/%m/%Y à %H:%M') + .panel-body + %strong Vous : + = avis.introduction + %hr + %strong= "#{avis.email_to_display} :" + = avis.answer + - else + .panel.panel-info + .panel-heading + Avis demandé à + %strong= avis.email_to_display + le + = avis.created_at.localtime.strftime('%d/%m/%Y à %H:%M') + .panel-body + %strong Vous : + = avis.introduction + %hr + .center + %em Avis en attente + .hidden-print + .panel.panel-default + .panel-heading + Demander un avis externe + .panel-body + .help-block + Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci. + %br + Cette personne pourra également contribuer au fil de messagerie, mais ne pourra pas modifier le dossier. + = simple_form_for @new_avis, url: backoffice_dossier_avis_index_path(dossier_facade.dossier.object.id) do |f| + + = f.input 'email', label: "Email de la personne qui doit donner un avis" + = f.input 'introduction', label: "Message" + + = f.submit "Envoyer la demande d'avis", class: 'btn btn-default' diff --git a/app/views/dossiers/_dossier_show.html.haml b/app/views/dossiers/_dossier_show.html.haml index 632a32f20..f4accd099 100644 --- a/app/views/dossiers/_dossier_show.html.haml +++ b/app/views/dossiers/_dossier_show.html.haml @@ -51,7 +51,6 @@ = render partial: '/users/carte/map', locals: { dossier: @facade.dossier } = render partial: 'users/carte/init_carto', locals: { dossier: @facade.dossier } - - if @current_gestionnaire && gestionnaire_signed_in? && @champs_private.count > 0 .default-data-block.default_visible .row.show-block#private-fields @@ -65,3 +64,5 @@ = (private_fields_count == 1) ? "1 champ" : "#{private_fields_count} champs" .body = render partial: '/dossiers/infos_private_fields' + += render partial: 'dossiers/avis', locals: { dossier_facade: @facade } diff --git a/config/routes.rb b/config/routes.rb index 16b0b090a..c11e135e0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,6 +179,7 @@ Rails.application.routes.draw do post 'reopen' => 'dossiers#reopen' put 'follow' => 'dossiers#follow' resources :commentaires, only: [:index] + resources :avis, only: [:create] end namespace :dossiers do diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb new file mode 100644 index 000000000..fbb731329 --- /dev/null +++ b/spec/models/avis_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe Avis, type: :model do + describe '.email_to_display' do + let(:invited_email) { 'invited@avis.com' } + let!(:avis) { Avis.create(email: invited_email, dossier: create(:dossier)) } + + subject { avis.email_to_display } + + context 'when gestionnaire is not known' do + it{ is_expected.to eq(invited_email) } + end + + context 'when gestionnaire is known' do + let!(:avis) { Avis.create(email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) } + + it{ is_expected.to eq(avis.gestionnaire.email) } + end + end +end From e831442cbd667b09a89cb17bca36c72dbab23da4 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 2 May 2017 16:20:16 +0200 Subject: [PATCH 028/131] Associate gestionnaire to avis if gestionnaire is known --- app/controllers/backoffice/avis_controller.rb | 9 +++++ .../backoffice/avis_controller_spec.rb | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 spec/controllers/backoffice/avis_controller_spec.rb diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 3d1559f6e..8b20f69ad 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -1,8 +1,17 @@ class Backoffice::AvisController < ApplicationController + before_action :authenticate_gestionnaire! + def create avis = Avis.new(create_params) avis.dossier = dossier + + gestionnaire = Gestionnaire.find_by(email: create_params[:email]) + if gestionnaire + avis.gestionnaire = gestionnaire + avis.email = nil + end + avis.save redirect_to backoffice_dossier_path(dossier) diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb new file mode 100644 index 000000000..041f0f03d --- /dev/null +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Backoffice::AvisController, type: :controller do + + describe '#POST create' do + let(:gestionnaire){ create(:gestionnaire) } + let!(:dossier){ create(:dossier, state: 'received') } + let!(:assign_to){ create(:assign_to, gestionnaire: gestionnaire, procedure: dossier.procedure )} + + subject { post :create, params: { dossier_id: dossier.id, avis: { email: gestionnaire.email, introduction: "Bonjour, regardez ce joli dossier." } } } + + context 'when gestionnaire is not authenticated' do + it { is_expected.to redirect_to new_user_session_path } + it { expect{ subject }.to_not change(Avis, :count) } + end + + context 'when gestionnaire is authenticated' do + before do + sign_in gestionnaire + end + + context 'When gestionnaire is known' do + it { is_expected.to redirect_to backoffice_dossier_path(dossier.id) } + it { expect{ subject }.to change(Avis, :count).by(1) } + it do + subject + expect(gestionnaire.avis.last).to_not eq(nil) + expect(gestionnaire.avis.last.email).to eq(nil) + expect(gestionnaire.avis.last.dossier_id).to eq(dossier.id) + end + end + end + end + +end From 43f481b7ff2176d679018516df97f59d40e9e636 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 27 Apr 2017 12:17:50 +0200 Subject: [PATCH 029/131] Gestionnaire can list dossiers where he is invited for avis --- .../dossiers/procedure_controller.rb | 1 + .../backoffice/dossiers_controller.rb | 3 ++ app/controllers/backoffice_controller.rb | 19 ++++++++ app/models/avis.rb | 3 ++ app/models/procedure.rb | 1 - .../dossiers/_list_invitations.html.haml | 20 +++++++++ app/views/backoffice/invitations.html.haml | 22 +++++++++ app/views/backoffice/invitations.js.erb | 4 ++ ...koffice_dossierscontroller_index.html.haml | 4 ++ ...backofficecontroller_invitations.html.haml | 1 + ...backofficecontroller_invitations.html.haml | 2 + config/routes.rb | 2 + .../controllers/backoffice_controller_spec.rb | 45 ++++++++++++++++++- spec/factories/avis.rb | 17 +++++++ 14 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 app/views/backoffice/dossiers/_list_invitations.html.haml create mode 100644 app/views/backoffice/invitations.html.haml create mode 100644 app/views/backoffice/invitations.js.erb create mode 100644 app/views/layouts/left_panels/_left_panel_backofficecontroller_invitations.html.haml create mode 100644 app/views/layouts/navbars/_navbar_backofficecontroller_invitations.html.haml create mode 100644 spec/factories/avis.rb diff --git a/app/controllers/backoffice/dossiers/procedure_controller.rb b/app/controllers/backoffice/dossiers/procedure_controller.rb index 76b96bf66..88bcf6536 100644 --- a/app/controllers/backoffice/dossiers/procedure_controller.rb +++ b/app/controllers/backoffice/dossiers/procedure_controller.rb @@ -22,4 +22,5 @@ class Backoffice::Dossiers::ProcedureController < Backoffice::DossiersListContro def retrieve_procedure current_gestionnaire.procedures.find params[:id] end + end diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 11ff0d7a6..ac7135587 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -4,10 +4,13 @@ class Backoffice::DossiersController < Backoffice::DossiersListController before_action :ensure_gestionnaire_is_authorized, only: :show def index + return redirect_to backoffice_invitations_path if current_gestionnaire.avis.any? + procedure = current_gestionnaire.procedure_filter if procedure.nil? procedure_list = dossiers_list_facade.gestionnaire_procedures_name_and_id_list + if procedure_list.count == 0 flash.alert = "Vous n'avez aucune procédure d'affectée." return redirect_to root_path diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb index 7cad9b2a4..fa77609d3 100644 --- a/app/controllers/backoffice_controller.rb +++ b/app/controllers/backoffice_controller.rb @@ -1,4 +1,8 @@ class BackofficeController < ApplicationController + include SmartListing::Helper::ControllerExtensions + helper SmartListing::Helper + + before_action :authenticate_gestionnaire!, only: [:invitations] def index if !gestionnaire_signed_in? @@ -7,4 +11,19 @@ class BackofficeController < ApplicationController redirect_to(:backoffice_dossiers) end end + + def invitations + pending_avis = current_gestionnaire.avis.without_answer.includes(dossier: [:procedure]).by_latest + @pending_avis = smart_listing_create :pending_avis, + pending_avis, + partial: 'backoffice/dossiers/list_invitations', + array: true + + avis_with_answer = current_gestionnaire.avis.with_answer.includes(dossier: [:procedure]).by_latest + @avis_with_answer = smart_listing_create :avis_with_answer, + avis_with_answer, + partial: 'backoffice/dossiers/list_invitations', + array: true + end + end diff --git a/app/models/avis.rb b/app/models/avis.rb index 5bbe6244f..e81c91ac8 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -2,6 +2,9 @@ class Avis < ApplicationRecord belongs_to :dossier belongs_to :gestionnaire + scope :with_answer, -> { where.not(answer: nil) } + scope :without_answer, -> { where(answer: nil) } + def email_to_display gestionnaire.try(:email) || email end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 8c863697c..864b3fcc3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -3,7 +3,6 @@ class Procedure < ActiveRecord::Base has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy has_many :types_de_champ_private, dependent: :destroy has_many :dossiers - has_many :notifications, through: :dossiers has_one :procedure_path, dependent: :destroy diff --git a/app/views/backoffice/dossiers/_list_invitations.html.haml b/app/views/backoffice/dossiers/_list_invitations.html.haml new file mode 100644 index 000000000..526bc5415 --- /dev/null +++ b/app/views/backoffice/dossiers/_list_invitations.html.haml @@ -0,0 +1,20 @@ +- if smart_listing.collection.any? + %table#dossiers-list.table + %thead + %th + Nº + %th + Procédure + %th + Invité le + %tbody + - smart_listing.collection.each do |avis| + %tr.dossier-row{ id: "tr_dossier_#{avis.dossier.id}", 'data-dossier_url' => backoffice_dossier_url(id: avis.dossier.id) } + %td= avis.dossier.id + %td= avis.dossier.procedure.libelle + %td= avis.created_at.strftime('%d/%m/%Y %H:%M') + = smart_listing.paginate + +- else + .center{ colspan: 2 } + %em Aucun dossier diff --git a/app/views/backoffice/invitations.html.haml b/app/views/backoffice/invitations.html.haml new file mode 100644 index 000000000..b9ffaad00 --- /dev/null +++ b/app/views/backoffice/invitations.html.haml @@ -0,0 +1,22 @@ +.col-md-12 + .default-data-block.default_visible + .row.show-block + .header + .title + .carret-right + .carret-down + = "#{@pending_avis.count} avis à rendre" + .body + = smart_listing_render :pending_avis + + %br + + .default-data-block + .row.show-block + .header + .title + .carret-right + .carret-down + = "#{@avis_with_answer.count} avis #{"rendu".pluralize(@avis_with_answer.count)}" + .body + = smart_listing_render :avis_with_answer diff --git a/app/views/backoffice/invitations.js.erb b/app/views/backoffice/invitations.js.erb new file mode 100644 index 000000000..a56437328 --- /dev/null +++ b/app/views/backoffice/invitations.js.erb @@ -0,0 +1,4 @@ +<%= smart_listing_update :pending_avis %> +<%= smart_listing_update :avis_with_answer %> + +link_init(); diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml index c1dfe2bd7..d2ea6ea5b 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml @@ -20,6 +20,10 @@ #infos-block .split-hr-left #procedure-list + - if current_gestionnaire.avis.any? + = link_to backoffice_invitations_path do + .procedure-list-element{ class: ('active' if request.path == backoffice_invitations_path) } + Invitations - current_gestionnaire.procedures.by_libelle.each do |procedure| = link_to backoffice_dossiers_procedure_path(procedure.id), { title: procedure.libelle } do .procedure-list-element{ class: ('active' if procedure.id.to_s == params[:id]) } diff --git a/app/views/layouts/left_panels/_left_panel_backofficecontroller_invitations.html.haml b/app/views/layouts/left_panels/_left_panel_backofficecontroller_invitations.html.haml new file mode 100644 index 000000000..b4114cab1 --- /dev/null +++ b/app/views/layouts/left_panels/_left_panel_backofficecontroller_invitations.html.haml @@ -0,0 +1 @@ += render partial: 'layouts/left_panels/left_panel_backoffice_dossierscontroller_index' diff --git a/app/views/layouts/navbars/_navbar_backofficecontroller_invitations.html.haml b/app/views/layouts/navbars/_navbar_backofficecontroller_invitations.html.haml new file mode 100644 index 000000000..eb80c1517 --- /dev/null +++ b/app/views/layouts/navbars/_navbar_backofficecontroller_invitations.html.haml @@ -0,0 +1,2 @@ +.col-xs-10.main-info + INVITATIONS diff --git a/config/routes.rb b/config/routes.rb index c11e135e0..39c5ec5fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -167,6 +167,8 @@ Rails.application.routes.draw do resource :private_formulaire + get 'invitations' + resources :dossiers do post 'receive' => 'dossiers#receive' post 'refuse' => 'dossiers#refuse' diff --git a/spec/controllers/backoffice_controller_spec.rb b/spec/controllers/backoffice_controller_spec.rb index 00db207ae..540f8db82 100644 --- a/spec/controllers/backoffice_controller_spec.rb +++ b/spec/controllers/backoffice_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe BackofficeController, type: :controller do describe 'GET #index' do - context 'when gestionnaire is not connected'do + context 'when gestionnaire is not connected' do before do get :index end @@ -10,7 +10,7 @@ describe BackofficeController, type: :controller do it { expect(response).to redirect_to :new_gestionnaire_session } end - context 'when gestionnaire is connected'do + context 'when gestionnaire is connected' do before do sign_in create(:gestionnaire) get :index @@ -19,4 +19,45 @@ describe BackofficeController, type: :controller do it { expect(response).to redirect_to :backoffice_dossiers } end end + + describe 'GET #invitations' do + context 'when gestionnaire is not invited on any dossiers' do + render_views + + before do + sign_in create(:gestionnaire) + get :invitations + end + + it { expect(response.status).to eq(200) } + it { expect(response.body).to include("INVITATIONS") } + it { expect(response.body).to include("0 avis à rendre") } + it { expect(response.body).to include("0 avis rendus") } + end + + context 'when gestionnaire is invited on a dossier' do + let(:dossier){ create(:dossier) } + let(:gestionnaire){ create(:gestionnaire) } + let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) } + render_views + + before do + sign_in gestionnaire + get :invitations + end + + it { expect(response.status).to eq(200) } + it { expect(response.body).to include("1 avis à rendre") } + it { expect(response.body).to include("0 avis rendus") } + it { expect(response.body).to include(dossier.procedure.libelle) } + + context 'when avis is already sent' do + let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire, answer: "Voici mon avis.") } + + it { expect(response.body).to include("0 avis à rendre") } + it { expect(response.body).to include("1 avis rendu") } + it { expect(response.body).to include(dossier.procedure.libelle) } + end + end + end end diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb new file mode 100644 index 000000000..c69371734 --- /dev/null +++ b/spec/factories/avis.rb @@ -0,0 +1,17 @@ +FactoryGirl.define do + factory :avis do + introduction 'Bonjour, merci de me donner votre avis sur ce dossier' + + before(:create) do |avis, _evaluator| + unless avis.gestionnaire + avis.gestionnaire = create :gestionnaire + end + end + + before(:create) do |avis, _evaluator| + unless avis.dossier + avis.dossier = create :dossier + end + end + end +end From 7c662aa7b29d8a8cfbc983c038c4f0a52f17ffc9 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 27 Apr 2017 16:29:04 +0200 Subject: [PATCH 030/131] Gestionnaire invited on dossier for avis, cannot see private form / change dossier state / follow dossier / see invited people / see others avis --- app/controllers/root_controller.rb | 2 + app/models/gestionnaire.rb | 4 + app/views/dossiers/_avis.html.haml | 2 +- app/views/dossiers/_dossier_show.html.haml | 2 +- ...ckoffice_dossierscontroller_show.html.haml | 4 +- ...ckoffice_dossierscontroller_show.html.haml | 73 ++++++++++--------- ...backoffice_dossierscontroller_show_spec.rb | 1 + 7 files changed, 48 insertions(+), 40 deletions(-) diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index ec123d601..fec3780b4 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -14,6 +14,8 @@ class RootController < ApplicationController return redirect_to admin_procedures_path elsif gestionnaire_signed_in? + return redirect_to backoffice_invitations_path if current_gestionnaire.avis.any? + procedure_id = current_gestionnaire.procedure_filter if procedure_id.nil? procedure_list = current_gestionnaire.procedures diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 0457deacb..3c12cf790 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -42,6 +42,10 @@ class Gestionnaire < ActiveRecord::Base Follow.where(gestionnaire_id: id, dossier_id: dossier_id).any? end + def assigned_on_procedure?(procedure_id) + procedures.find_by(id: procedure_id).present? + end + def build_default_preferences_list_dossier procedure_id=nil PreferenceListDossier.available_columns_for(procedure_id).each do |table| diff --git a/app/views/dossiers/_avis.html.haml b/app/views/dossiers/_avis.html.haml index feeedd37c..319b5e2ac 100644 --- a/app/views/dossiers/_avis.html.haml +++ b/app/views/dossiers/_avis.html.haml @@ -1,4 +1,4 @@ -- if @current_gestionnaire +- if current_gestionnaire && current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id) .default-data-block.default_visible .row.show-block.infos diff --git a/app/views/dossiers/_dossier_show.html.haml b/app/views/dossiers/_dossier_show.html.haml index f4accd099..09c63d506 100644 --- a/app/views/dossiers/_dossier_show.html.haml +++ b/app/views/dossiers/_dossier_show.html.haml @@ -51,7 +51,7 @@ = render partial: '/users/carte/map', locals: { dossier: @facade.dossier } = render partial: 'users/carte/init_carto', locals: { dossier: @facade.dossier } -- if @current_gestionnaire && gestionnaire_signed_in? && @champs_private.count > 0 +- if @current_gestionnaire && gestionnaire_signed_in? && current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id) && @champs_private.count > 0 .default-data-block.default_visible .row.show-block#private-fields .header diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml index a78fa8241..2560a0bb8 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.html.haml @@ -2,8 +2,8 @@ .infos #dossier_id= t('dynamics.dossiers.numéro') + @facade.dossier.id.to_s -#action-block - - if gestionnaire_signed_in? +- if current_gestionnaire && current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id) + #action-block - if !@facade.dossier.read_only? || @facade.dossier.initiated? = link_to 'Passer en instruction', backoffice_dossier_receive_path(@facade.dossier), method: :post, class: 'btn btn-danger btn-block', data: { confirm: "Confirmer vous le passage en instruction de ce dossier ?" } diff --git a/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml index 97027181d..2c72a80fe 100644 --- a/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml @@ -1,40 +1,41 @@ .col-xs-7.main-info = @facade.dossier.procedure.libelle .col-xs-3.options - .row - .col-xs-12 - - if current_gestionnaire.follow?(@facade.dossier.id) - = link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), "data-method" => :put, class: "button-navbar-action", id: "suivre_dossier_#{@facade.dossier.id}" do - %i.fa.fa-user-times - Ne plus suivre - - else - = link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'button-navbar-action', id: "suivre_dossier_#{@facade.dossier.id}" do - %i.fa.fa-user-plus - Suivre le dossier - .row - .col-xs-12 - #invitations.dropdown-toggle{ 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false } - %i.fa.fa-user - = t('utils.involved') - .badge.progress-bar-info - = @facade.dossier.invites.count - .dropdown-menu.dropdown-menu-right.dropdown-pannel - %h4= t('dynamics.dossiers.followers.title') - %ul - - unless @facade.followers.empty? - - @facade.followers.each do |follower| - %li= follower.email - - else - = t('dynamics.dossiers.followers.empty') - %h4= t('dynamics.dossiers.invites.title') - %ul - - unless @facade.invites.empty? - - @facade.invites.each do |invite| - %li= invite.email - - else - = t('dynamics.dossiers.invites.empty') + - if current_gestionnaire.assigned_on_procedure?(@facade.dossier.procedure_id) + .row + .col-xs-12 + - if current_gestionnaire.follow?(@facade.dossier.id) + = link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), "data-method" => :put, class: "button-navbar-action", id: "suivre_dossier_#{@facade.dossier.id}" do + %i.fa.fa-user-times + Ne plus suivre + - else + = link_to backoffice_dossier_follow_path(dossier_id: @facade.dossier.id), 'data-method' => :put, class: 'button-navbar-action', id: "suivre_dossier_#{@facade.dossier.id}" do + %i.fa.fa-user-plus + Suivre le dossier + .row + .col-xs-12 + #invitations.dropdown-toggle{ 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false } + %i.fa.fa-user + = t('utils.involved') + .badge.progress-bar-info + = @facade.dossier.invites.count + .dropdown-menu.dropdown-menu-right.dropdown-pannel + %h4= t('dynamics.dossiers.followers.title') + %ul + - unless @facade.followers.empty? + - @facade.followers.each do |follower| + %li= follower.email + - else + = t('dynamics.dossiers.followers.empty') + %h4= t('dynamics.dossiers.invites.title') + %ul + - unless @facade.invites.empty? + - @facade.invites.each do |invite| + %li= invite.email + - else + = t('dynamics.dossiers.invites.empty') - %li - = form_tag invites_dossier_path(dossier_id: @facade.dossier.id), method: :post, class: 'form-inline', id: 'send-invitation' do - = text_field_tag :email, '', class: 'form-control', placeholder: 'Envoyer une invitation', id: 'invitation-email' - = submit_tag 'Ajouter', class: 'btn btn-success', data: { confirm: "Envoyer l'invitation ?" } + %li + = form_tag invites_dossier_path(dossier_id: @facade.dossier.id), method: :post, class: 'form-inline', id: 'send-invitation' do + = text_field_tag :email, '', class: 'form-control', placeholder: 'Envoyer une invitation', id: 'invitation-email' + = submit_tag 'Ajouter', class: 'btn btn-success', data: { confirm: "Envoyer l'invitation ?" } diff --git a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb index dd61a7578..308acb09c 100644 --- a/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb +++ b/spec/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_show_spec.rb @@ -6,6 +6,7 @@ describe 'layouts/left_panels/_left_panel_backoffice_dossierscontroller_show.htm let(:state) { 'draft' } let(:archived) { false } let(:gestionnaire) { create(:gestionnaire) } + let!(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: dossier.procedure) } before do sign_in gestionnaire From d07943a55db9e11699459cdc8a7c8b6dee528ab8 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 2 May 2017 13:54:57 +0200 Subject: [PATCH 031/131] Add by_latest scope in Avis --- app/models/avis.rb | 1 + app/views/dossiers/_avis.html.haml | 2 +- spec/models/avis_spec.rb | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/avis.rb b/app/models/avis.rb index e81c91ac8..129175673 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -4,6 +4,7 @@ class Avis < ApplicationRecord scope :with_answer, -> { where.not(answer: nil) } scope :without_answer, -> { where(answer: nil) } + scope :by_latest, -> { order(updated_at: :desc) } def email_to_display gestionnaire.try(:email) || email diff --git a/app/views/dossiers/_avis.html.haml b/app/views/dossiers/_avis.html.haml index 319b5e2ac..80c896070 100644 --- a/app/views/dossiers/_avis.html.haml +++ b/app/views/dossiers/_avis.html.haml @@ -9,7 +9,7 @@ AVIS EXTERNES .body .display-block-on-print - - dossier_facade.dossier.avis.order(updated_at: :desc).each do |avis| + - dossier_facade.dossier.avis.by_latest.each do |avis| - if avis.answer .panel.panel-success .panel-heading diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index fbb731329..7f10efcf2 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -17,4 +17,16 @@ RSpec.describe Avis, type: :model do it{ is_expected.to eq(avis.gestionnaire.email) } end end + + describe '.by_latest' do + context 'with 3 avis' do + let!(:avis){ create(:avis) } + let!(:avis2){ create(:avis, updated_at: 4.hours.ago) } + let!(:avis3){ create(:avis, updated_at: 3.hours.ago) } + + subject { Avis.by_latest } + + it { expect(subject).to eq([avis, avis3, avis2])} + end + end end From f24e4a77d3d386a380e598014cb4c1450930f220 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 16 May 2017 15:20:38 +0200 Subject: [PATCH 032/131] Gestionnaire can view dossier if he is invited on dossier --- .../backoffice/dossiers_controller.rb | 9 ++++---- app/models/gestionnaire.rb | 5 ++++ spec/models/gestionnaire_spec.rb | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index ac7135587..14f04fe45 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -190,11 +190,10 @@ class Backoffice::DossiersController < Backoffice::DossiersListController private def ensure_gestionnaire_is_authorized - current_gestionnaire.dossiers.find(params[:id]) - - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(controller: '/backoffice') + unless current_gestionnaire.can_view_dossier?(params[:id]) + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: '/backoffice') + end end def create_dossier_facade dossier_id diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 3c12cf790..6492cca64 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -25,6 +25,11 @@ class Gestionnaire < ActiveRecord::Base self[:procedure_filter] end + def can_view_dossier?(dossier_id) + avis.where(dossier_id: dossier_id).any? || + dossiers.where(id: dossier_id).any? + end + def toggle_follow_dossier dossier_id dossier = dossier_id dossier = Dossier.find(dossier_id) unless dossier_id.class == Dossier diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 27cb3502e..fbfbfd76f 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -395,4 +395,27 @@ describe Gestionnaire, type: :model do it { is_expected.to eq(nil) } end end + + describe '.can_view_dossier?' do + subject{ gestionnaire.can_view_dossier?(dossier.id) } + + context 'when gestionnaire is assigned on dossier' do + let!(:dossier){ create(:dossier, procedure: procedure, state: 'received') } + + it { expect(subject).to be true } + end + + context 'when gestionnaire is invited on dossier' do + let(:dossier){ create(:dossier) } + let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) } + + it { expect(subject).to be true } + end + + context 'when gestionnaire is neither assigned nor invited on dossier' do + let(:dossier){ create(:dossier) } + + it { expect(subject).to be false } + end + end end From f6359cb7aa6781ecb79d84db5db2635534e1a6ce Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 18:45:31 +0200 Subject: [PATCH 033/131] gestionnaire invited on dossier for avis, can update Avis --- app/controllers/backoffice/avis_controller.rb | 16 +++++++++ app/models/avis.rb | 1 + app/views/dossiers/_dossier_show.html.haml | 2 ++ app/views/dossiers/_edit_avis.html.haml | 13 +++++++ config/routes.rb | 2 +- .../backoffice/avis_controller_spec.rb | 34 +++++++++++++++++++ .../backoffice/dossiers_controller_spec.rb | 19 +++++++++++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 app/views/dossiers/_edit_avis.html.haml diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 8b20f69ad..2bd8a23b9 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -17,14 +17,30 @@ class Backoffice::AvisController < ApplicationController redirect_to backoffice_dossier_path(dossier) end + def update + if avis.update(update_params) + flash[:notice] = 'Merci, votre avis a été enregistré.' + end + + redirect_to backoffice_dossier_path(avis.dossier_id) + end + private def dossier current_gestionnaire.dossiers.find(params[:dossier_id]) end + def avis + current_gestionnaire.avis.find(params[:id]) + end + def create_params params.require(:avis).permit(:email, :introduction) end + def update_params + params.require(:avis).permit(:answer) + end + end diff --git a/app/models/avis.rb b/app/models/avis.rb index 129175673..b63ca92ff 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -4,6 +4,7 @@ class Avis < ApplicationRecord scope :with_answer, -> { where.not(answer: nil) } scope :without_answer, -> { where(answer: nil) } + scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) } scope :by_latest, -> { order(updated_at: :desc) } def email_to_display diff --git a/app/views/dossiers/_dossier_show.html.haml b/app/views/dossiers/_dossier_show.html.haml index 09c63d506..cfbe4ee02 100644 --- a/app/views/dossiers/_dossier_show.html.haml +++ b/app/views/dossiers/_dossier_show.html.haml @@ -1,3 +1,5 @@ += render partial: 'dossiers/edit_avis', locals: { dossier_facade: @facade } + = render partial: 'dossiers/messagerie', locals: { dossier_facade: @facade } - if @facade.procedure.individual_with_siret diff --git a/app/views/dossiers/_edit_avis.html.haml b/app/views/dossiers/_edit_avis.html.haml new file mode 100644 index 000000000..491291793 --- /dev/null +++ b/app/views/dossiers/_edit_avis.html.haml @@ -0,0 +1,13 @@ +- if current_gestionnaire + - avis_for_dossier = current_gestionnaire.avis.for_dossier(dossier_facade.dossier.id).by_latest + - if avis_for_dossier.any? + .panel.panel-default + .panel-body + %h4 Votre avis est sollicité sur le dossier : + - avis_for_dossier.each do |avis| + %hr + %p= avis.introduction + = simple_form_for avis, url: backoffice_dossier_avis_path(dossier_facade.dossier, avis) do |f| + = f.input 'answer', label: "Votre avis" + - submit_label = if avis.answer then "Modifier votre avis" else "Enregistrer votre avis" end + = f.submit submit_label, class: 'btn btn-default' diff --git a/config/routes.rb b/config/routes.rb index 39c5ec5fd..16fadf98d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,7 +181,7 @@ Rails.application.routes.draw do post 'reopen' => 'dossiers#reopen' put 'follow' => 'dossiers#follow' resources :commentaires, only: [:index] - resources :avis, only: [:create] + resources :avis, only: [:create, :update] end namespace :dossiers do diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 041f0f03d..d3731e63c 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -32,4 +32,38 @@ describe Backoffice::AvisController, type: :controller do end end + describe '#POST update' do + let(:gestionnaire){ create(:gestionnaire) } + let(:dossier){ create(:dossier, state: 'received') } + let(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire )} + + subject { post :update, params: { dossier_id: dossier.id, id: avis.id, avis: { answer: "Ok ce dossier est valide." } } } + + context 'when gestionnaire is not authenticated' do + it { is_expected.to redirect_to new_user_session_path } + it { expect(avis.answer).to be_nil } + end + + context 'when gestionnaire is authenticated' do + before do + sign_in gestionnaire + end + + context 'and is invited on dossier' do + it { is_expected.to redirect_to backoffice_dossier_path(dossier.id) } + it do + subject + expect(avis.reload.answer).to eq("Ok ce dossier est valide.") + end + end + + context 'but is not invited on dossier' do + let(:gestionnaire2) { create(:gestionnaire) } + let(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire2 )} + + it { expect{ subject }.to raise_error(ActiveRecord::RecordNotFound) } + end + end + end + end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 7ba92db57..169e976d6 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -109,6 +109,25 @@ describe Backoffice::DossiersController, type: :controller do it { expect(subject).to redirect_to('/backoffice') } end + + describe 'he can invite somebody for avis' do + render_views + + it { expect(subject.body).to include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") } + end + + context 'and is invited on a dossier' do + let(:dossier_invited){ create(:dossier, procedure: create(:procedure)) } + let!(:avis){ create(:avis, dossier: dossier_invited, gestionnaire: gestionnaire) } + + subject { get :show, params: { id: dossier_invited.id } } + + render_views + + it { expect(subject.status).to eq(200) } + it { expect(subject.body).to include("Votre avis est sollicité sur le dossier") } + it { expect(subject.body).to_not include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") } + end end context 'gestionnaire does not connected but dossier id is correct' do From efdac753c6f04a8764f1eadbbed959cd423d7579 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 2 May 2017 15:37:06 +0200 Subject: [PATCH 034/131] When an Avis is created an email is sent to the Gestionnaire --- app/mailers/avis_mailer.rb | 9 +++++++ app/models/avis.rb | 6 +++++ .../you_are_invited_on_dossier.html.haml | 24 +++++++++++++++++++ spec/mailers/avis_mailer_spec.rb | 13 ++++++++++ spec/mailers/previews/avis_mailer_preview.rb | 8 +++++++ 5 files changed, 60 insertions(+) create mode 100644 app/mailers/avis_mailer.rb create mode 100644 app/views/avis_mailer/you_are_invited_on_dossier.html.haml create mode 100644 spec/mailers/avis_mailer_spec.rb create mode 100644 spec/mailers/previews/avis_mailer_preview.rb diff --git a/app/mailers/avis_mailer.rb b/app/mailers/avis_mailer.rb new file mode 100644 index 000000000..601ee464d --- /dev/null +++ b/app/mailers/avis_mailer.rb @@ -0,0 +1,9 @@ +class AvisMailer < ApplicationMailer + + def you_are_invited_on_dossier(avis) + @avis = avis + email = @avis.gestionnaire.try(:email) || @avis.email + mail(to: email, subject: "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})") + end + +end diff --git a/app/models/avis.rb b/app/models/avis.rb index b63ca92ff..4a2b8520d 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -2,6 +2,8 @@ class Avis < ApplicationRecord belongs_to :dossier belongs_to :gestionnaire + after_create :notify_gestionnaire + scope :with_answer, -> { where.not(answer: nil) } scope :without_answer, -> { where(answer: nil) } scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) } @@ -10,4 +12,8 @@ class Avis < ApplicationRecord def email_to_display gestionnaire.try(:email) || email end + + def notify_gestionnaire + AvisMailer.you_are_invited_on_dossier(self).deliver_now + end end diff --git a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml new file mode 100644 index 000000000..ac2403812 --- /dev/null +++ b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml @@ -0,0 +1,24 @@ +%html + %body + %p + Bonjour, + %br + = "Vous avez été invité à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}." + %br + Message de votre interlocuteur : + + %p{ style: 'border: 1px solid grey' } + = @avis.introduction + + %p + = link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url + + Bonne journée, + %br + %br + L'équipe Téléprocédures Simplifiées + %br + %br + %hr + %br + Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme. diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb new file mode 100644 index 000000000..657a327a6 --- /dev/null +++ b/spec/mailers/avis_mailer_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +RSpec.describe AvisMailer, type: :mailer do + describe '.you_are_invited_on_dossier' do + let(:avis) { create(:avis) } + + subject { described_class.you_are_invited_on_dossier(avis) } + + it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } + it { expect(subject.body).to include("Vous avez été invité à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") } + it { expect(subject.body).to include(avis.introduction) } + end +end diff --git a/spec/mailers/previews/avis_mailer_preview.rb b/spec/mailers/previews/avis_mailer_preview.rb new file mode 100644 index 000000000..c911615e6 --- /dev/null +++ b/spec/mailers/previews/avis_mailer_preview.rb @@ -0,0 +1,8 @@ +# Preview all emails at http://localhost:3000/rails/mailers/avis_mailer +class AvisMailerPreview < ActionMailer::Preview + + def you_are_invited_on_dossier + AvisMailer.you_are_invited_on_dossier(Avis.last) + end + +end From 4e064dbaeda7fcf88040488611fdf9595289945b Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 2 May 2017 16:13:09 +0200 Subject: [PATCH 035/131] Add a method to link multiple avis to a gestionnaire by his email --- app/models/avis.rb | 4 ++++ spec/models/avis_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/models/avis.rb b/app/models/avis.rb index 4a2b8520d..248d0c130 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -16,4 +16,8 @@ class Avis < ApplicationRecord def notify_gestionnaire AvisMailer.you_are_invited_on_dossier(self).deliver_now end + + def self.link_avis_to_gestionnaire(gestionnaire) + Avis.where(email: gestionnaire.email).update_all(email: nil, gestionnaire_id: gestionnaire.id) + end end diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index 7f10efcf2..f870d9e79 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -29,4 +29,26 @@ RSpec.describe Avis, type: :model do it { expect(subject).to eq([avis, avis3, avis2])} end end + + describe ".link_avis_to_gestionnaire" do + let(:gestionnaire){ create(:gestionnaire) } + + subject{ Avis.link_avis_to_gestionnaire(gestionnaire) } + + context 'when there are 2 avis linked by email to a gestionnaire' do + let!(:avis){ create(:avis, email: gestionnaire.email, gestionnaire: nil) } + let!(:avis2){ create(:avis, email: gestionnaire.email, gestionnaire: nil) } + + before do + subject + avis.reload + avis2.reload + end + + it { expect(avis.email).to be_nil } + it { expect(avis.gestionnaire).to eq(gestionnaire) } + it { expect(avis2.email).to be_nil } + it { expect(avis2.gestionnaire).to eq(gestionnaire) } + end + end end From aaf155df7232225338388f7ea355952c96d5b975 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 12 May 2017 10:22:18 +0200 Subject: [PATCH 036/131] Avis: add sign_up logic for new tps gestionnaire --- .../stylesheets/new_design/avis_sign_up.scss | 92 +++++++++++++++++++ app/controllers/backoffice/avis_controller.rb | 15 ++- app/models/avis.rb | 5 + app/views/backoffice/avis/sign_up.html.haml | 15 +++ config/routes.rb | 2 + .../backoffice/avis_controller_spec.rb | 26 ++++++ spec/models/avis_spec.rb | 29 ++++++ 7 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/new_design/avis_sign_up.scss create mode 100644 app/views/backoffice/avis/sign_up.html.haml diff --git a/app/assets/stylesheets/new_design/avis_sign_up.scss b/app/assets/stylesheets/new_design/avis_sign_up.scss new file mode 100644 index 000000000..10d6d64ee --- /dev/null +++ b/app/assets/stylesheets/new_design/avis_sign_up.scss @@ -0,0 +1,92 @@ +@import "typography"; +@import "colors"; + +.avis-sign-up { + display: flex; + + .left, + .right { + width: 50%; + padding: 60px 86px; + } + + .left { + p { + margin: auto; + max-width: 410px; + text-align: center; + } + + .description { + font-size: 30px; + line-height: 1.3; + } + + .dossier { + font-size: 18px; + font-weight: bold; + margin-top: 15px; + } + } + + .right { + background-color: $light-grey; + + h1 { + font-size: 36px; + font-weight: bold; + margin-bottom: 60px; + } + + form { + max-width: 420px; + } + + label, + input { + display: block; + width: 100%; + } + + label { + font-size: 14px; + line-height: 1.57; + margin: 24px 0 8px; + } + + input { + border: solid 1px $border-grey; + border-radius: 4px; + height: 56px; + padding: 0 15px; + font-family: Muli; + font-size: 14px; + + &:disabled { + background-color: $border-grey; + } + } + + button { + display: inline-block; + height: 60px; + line-height: 60px; + border: none; + border-radius: 60px; + background-color: $blue; + color: #FFFFFF; + font-size: 16px; + font-weight: bold; + text-align: center; + width: 100%; + margin: 55px 0; + + &:hover { + color: #FFFFFF; + text-decoration: none; + background-color: $light-blue; + cursor: pointer; + } + } + } +} diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 2bd8a23b9..50cab0e5d 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -1,6 +1,7 @@ class Backoffice::AvisController < ApplicationController - before_action :authenticate_gestionnaire! + before_action :authenticate_gestionnaire!, except: [:sign_up] + before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up] def create avis = Avis.new(create_params) @@ -25,6 +26,13 @@ class Backoffice::AvisController < ApplicationController redirect_to backoffice_dossier_path(avis.dossier_id) end + def sign_up + @email = params[:email] + @dossier = Avis.includes(:dossier).find(params[:id]).dossier + + render layout: 'new_application' + end + private def dossier @@ -43,4 +51,9 @@ class Backoffice::AvisController < ApplicationController params.require(:avis).permit(:answer) end + def check_avis_exists_and_email_belongs_to_avis + if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email]) + redirect_to url_for(root_path) + end + end end diff --git a/app/models/avis.rb b/app/models/avis.rb index 248d0c130..afc6ec285 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -20,4 +20,9 @@ class Avis < ApplicationRecord def self.link_avis_to_gestionnaire(gestionnaire) Avis.where(email: gestionnaire.email).update_all(email: nil, gestionnaire_id: gestionnaire.id) end + + def self.avis_exists_and_email_belongs_to_avis?(avis_id, email) + avis = Avis.find_by(id: avis_id) + avis.present? && avis.email == email + end end diff --git a/app/views/backoffice/avis/sign_up.html.haml b/app/views/backoffice/avis/sign_up.html.haml new file mode 100644 index 000000000..c02191ce7 --- /dev/null +++ b/app/views/backoffice/avis/sign_up.html.haml @@ -0,0 +1,15 @@ +.avis-sign-up + .left + %p.description= @dossier.procedure.libelle + %p.dossier Dossier n°#{@dossier.id} + .right + %h1 Créez-vous un compte + + = form_for(Gestionnaire.new, url: { controller: 'backoffice/avis', action: :create_gestionnaire }, method: :post) do |f| + = f.label :email, 'Email' + = f.email_field :email, value: @email, disabled: true + + = f.label :password, 'Mot de passe' + = f.password_field :password, autofocus: true, required: true, placeholder: '8 caractères minimum' + + %button Créer un compte diff --git a/config/routes.rb b/config/routes.rb index 16fadf98d..3911fd3a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,8 @@ Rails.application.routes.draw do put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration' end + get 'avis/:id/sign_up/email/:email' => 'backoffice/avis#sign_up', constraints: { email: /.*/ }, as: 'avis_sign_up' + devise_scope :administrateur do get '/administrateurs/sign_in/demo' => 'administrateurs/sessions#demo' end diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index d3731e63c..055fb8be8 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -66,4 +66,30 @@ describe Backoffice::AvisController, type: :controller do end end + describe '.sign_up' do + let(:invited_email) { 'invited@avis.com' } + let(:dossier) { create(:dossier) } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let(:invitations_email) { true } + + before do + expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) + .with(avis.id.to_s, invited_email) + .and_return(invitations_email) + get :sign_up, params: { id: avis.id, email: invited_email } + end + + context 'when the email belongs to the invitation' do + it { expect(subject.status).to eq(200) } + it { expect(assigns(:email)).to eq(invited_email) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + + context 'when the email does not belong to the invitation' do + let(:invitations_email) { false } + + it { is_expected.to redirect_to root_path } + end + end + end diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index f870d9e79..47a39c82e 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -51,4 +51,33 @@ RSpec.describe Avis, type: :model do it { expect(avis2.gestionnaire).to eq(gestionnaire) } end end + + describe '.avis_exists_and_email_belongs_to_avis' do + let(:dossier) { create(:dossier) } + let(:invited_email) { 'invited@avis.com' } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + + subject { Avis.avis_exists_and_email_belongs_to_avis?(avis_id, email) } + + context 'when the avis is unknown' do + let(:avis_id) { 666 } + let(:email) { 'unknown@mystery.com' } + + it { is_expected.to be false } + end + + context 'when the avis is known' do + let(:avis_id) { avis.id } + + context 'when the email belongs to the invitation' do + let(:email) { invited_email } + it { is_expected.to be true } + end + + context 'when the email is unknown' do + let(:email) { 'unknown@mystery.com' } + it { is_expected.to be false } + end + end + end end From 842999d229e82902f37d229e69eee8a41f75d3c3 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 12 May 2017 10:22:53 +0200 Subject: [PATCH 037/131] Avis: add create_gestionnaire logic --- app/controllers/backoffice/avis_controller.rb | 21 +++++++- config/routes.rb | 1 + .../backoffice/avis_controller_spec.rb | 48 +++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 50cab0e5d..69e481dba 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -1,7 +1,7 @@ class Backoffice::AvisController < ApplicationController - before_action :authenticate_gestionnaire!, except: [:sign_up] - before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up] + before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire] + before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire] def create avis = Avis.new(create_params) @@ -33,6 +33,23 @@ class Backoffice::AvisController < ApplicationController render layout: 'new_application' end + def create_gestionnaire + email = params[:email] + password = params['gestionnaire']['password'] + + gestionnaire = Gestionnaire.new(email: email, password: password) + + if gestionnaire.save + sign_in(gestionnaire, scope: :gestionnaire) + Avis.link_avis_to_gestionnaire(gestionnaire) + avis = Avis.find(params[:id]) + redirect_to url_for(backoffice_dossier_path(avis.dossier_id)) + else + flash[:alert] = gestionnaire.errors.full_messages.join('
') + redirect_to url_for(avis_sign_up_path(params[:id], email)) + end + end + private def dossier diff --git a/config/routes.rb b/config/routes.rb index 3911fd3a1..8e2c90217 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,7 @@ Rails.application.routes.draw do end get 'avis/:id/sign_up/email/:email' => 'backoffice/avis#sign_up', constraints: { email: /.*/ }, as: 'avis_sign_up' + post 'avis/:id/sign_up/email/:email' => 'backoffice/avis#create_gestionnaire', constraints: { email: /.*/ } devise_scope :administrateur do get '/administrateurs/sign_in/demo' => 'administrateurs/sessions#demo' diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 055fb8be8..6823e9a00 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -92,4 +92,52 @@ describe Backoffice::AvisController, type: :controller do end end + describe '.create_gestionnaire' do + let(:invited_email) { 'invited@avis.com' } + let(:dossier) { create(:dossier) } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let(:avis_id) { avis.id } + let(:password) { '12345678' } + let(:created_gestionnaire) { Gestionnaire.find_by(email: invited_email) } + let(:invitations_email) { true } + + before do + allow(Avis).to receive(:link_avis_to_gestionnaire) + expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) + .with(avis_id.to_s, invited_email) + .and_return(invitations_email) + + post :create_gestionnaire, params: { id: avis_id, + email: invited_email, + gestionnaire: { + password: password + } } + end + + context 'when the email does not belong to the invitation' do + let(:invitations_email) { false } + + it { is_expected.to redirect_to root_path } + end + + context 'when the email belongs to the invitation' do + context 'when the gestionnaire creation succeeds' do + it { expect(created_gestionnaire).to be_present } + it { expect(created_gestionnaire.valid_password?(password)).to be true } + + it { expect(Avis).to have_received(:link_avis_to_gestionnaire) } + + it { expect(subject.current_gestionnaire).to eq(created_gestionnaire) } + it { is_expected.to redirect_to backoffice_dossier_path(dossier) } + end + + context 'when the gestionnaire creation fails' do + let(:password) { '' } + + it { expect(created_gestionnaire).to be_nil } + it { is_expected.to redirect_to avis_sign_up_path(avis_id, invited_email) } + it { expect(flash.alert).to eq('Password : Le mot de passe est vide') } + end + end + end end From 516a8c28c5074dab3568102a22afbb691b424b52 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 5 May 2017 16:02:20 +0200 Subject: [PATCH 038/131] Avis: change invitation mail when the recipient is not tps --- .../avis_mailer/you_are_invited_on_dossier.html.haml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml index ac2403812..76c9f4149 100644 --- a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml +++ b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml @@ -10,8 +10,12 @@ %p{ style: 'border: 1px solid grey' } = @avis.introduction - %p - = link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url + - if @avis.gestionnaire.present? + %p + = link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url + - else + %p + = link_to "Inscrivez-vous pour donner votre avis", avis_sign_up_url(@avis.id, @avis.email) Bonne journée, %br From f9aee06040d64288ebbe3b5a70a4a2239480149c Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Fri, 5 May 2017 17:38:43 +0200 Subject: [PATCH 039/131] AvisController: add redirection logic for various login cases --- app/controllers/backoffice/avis_controller.rb | 15 +++++ .../backoffice/avis_controller_spec.rb | 61 +++++++++++++++---- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 69e481dba..ded272fae 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -1,6 +1,7 @@ class Backoffice::AvisController < ApplicationController before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire] + before_action :redirect_if_no_sign_up_needed, only: [:sign_up] before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire] def create @@ -68,6 +69,20 @@ class Backoffice::AvisController < ApplicationController params.require(:avis).permit(:answer) end + def redirect_if_no_sign_up_needed + avis = Avis.find(params[:id]) + + if current_gestionnaire.present? + # a gestionnaire is authenticated ... lets see if it can view the dossier + + redirect_to backoffice_dossier_url(avis.dossier) + elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email] + # the avis gestionnaire has already signed up and it sould sign in + + redirect_to new_gestionnaire_session_url + end + end + def check_avis_exists_and_email_belongs_to_avis if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email]) redirect_to url_for(root_path) diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 6823e9a00..08f1d5e82 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -72,23 +72,60 @@ describe Backoffice::AvisController, type: :controller do let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } let(:invitations_email) { true } - before do - expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) - .with(avis.id.to_s, invited_email) - .and_return(invitations_email) - get :sign_up, params: { id: avis.id, email: invited_email } + context 'when the new gestionnaire has never signed up' do + before do + expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) + .with(avis.id.to_s, invited_email) + .and_return(invitations_email) + get :sign_up, params: { id: avis.id, email: invited_email } + end + + context 'when the email belongs to the invitation' do + it { expect(subject.status).to eq(200) } + it { expect(assigns(:email)).to eq(invited_email) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + + context 'when the email does not belong to the invitation' do + let(:invitations_email) { false } + + it { is_expected.to redirect_to root_path } + end end - context 'when the email belongs to the invitation' do - it { expect(subject.status).to eq(200) } - it { expect(assigns(:email)).to eq(invited_email) } - it { expect(assigns(:dossier)).to eq(dossier) } + context 'when the gestionnaire has already signed up and belongs to the invitation' do + let(:gestionnaire) { create(:gestionnaire, email: invited_email) } + let!(:avis) { Avis.create(dossier: dossier, gestionnaire: gestionnaire) } + + context 'when the gestionnaire is authenticated' do + before do + sign_in gestionnaire + get :sign_up, params: { id: avis.id, email: invited_email } + end + + it { is_expected.to redirect_to backoffice_dossier_url(avis.dossier) } + end + + context 'when the gestionnaire is not authenticated' do + before do + get :sign_up, params: { id: avis.id, email: invited_email } + end + + it { is_expected.to redirect_to new_gestionnaire_session_url } + end end - context 'when the email does not belong to the invitation' do - let(:invitations_email) { false } + context 'when the gestionnaire has already signed up / is authenticated and does not belong to the invitation' do + let(:gestionnaire) { create(:gestionnaire, email: 'other@gmail.com') } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } - it { is_expected.to redirect_to root_path } + before do + sign_in gestionnaire + get :sign_up, params: { id: avis.id, email: invited_email } + end + + # redirected to dossier but then the gestionnaire gonna be banished ! + it { is_expected.to redirect_to backoffice_dossier_url(avis.dossier) } end end From 612a8c4b91fbd04e59564e69e618539274ff5045 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 18 May 2017 16:14:26 +0200 Subject: [PATCH 040/131] Confirm with flash after avis is sent --- app/controllers/backoffice/avis_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index ded272fae..ed59a671b 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -8,13 +8,16 @@ class Backoffice::AvisController < ApplicationController avis = Avis.new(create_params) avis.dossier = dossier - gestionnaire = Gestionnaire.find_by(email: create_params[:email]) + email = create_params[:email] + gestionnaire = Gestionnaire.find_by(email: email) if gestionnaire avis.gestionnaire = gestionnaire avis.email = nil end - avis.save + if avis.save + flash[:notice] = "Votre demande d'avis a bien été envoyée à #{email}" + end redirect_to backoffice_dossier_path(dossier) end From 3483ec075b468f67ae4df8abd2ba569fad2e9713 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 17:51:43 +0200 Subject: [PATCH 041/131] DossierController: extract dossier_id from params[:id] --- app/controllers/backoffice/dossiers_controller.rb | 5 +++-- spec/controllers/backoffice/dossiers_controller_spec.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 14f04fe45..5c9b7f4ca 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -23,7 +23,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController end def show - create_dossier_facade params[:id] + dossier_id = params[:id] + create_dossier_facade dossier_id unless @facade.nil? @champs_private = @facade.champs_private @@ -31,7 +32,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController @headers_private = @champs_private.select { |champ| champ.type_champ == 'header_section' } end - Notification.where(dossier_id: params[:id].to_i).update_all already_read: true + Notification.where(dossier_id: dossier_id).update_all already_read: true @new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.") end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 169e976d6..7a647f51c 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -97,7 +97,7 @@ describe Backoffice::DossiersController, type: :controller do describe 'all notifications unread are changed' do it do - expect(Notification).to receive(:where).with(dossier_id: dossier_id).and_return(Notification::ActiveRecord_Relation) + expect(Notification).to receive(:where).with(dossier_id: dossier_id.to_s).and_return(Notification::ActiveRecord_Relation) expect(Notification::ActiveRecord_Relation).to receive(:update_all).with(already_read: true).and_return(true) subject From 34a7905828f133082be2305095dc927428b43a18 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 17:55:00 +0200 Subject: [PATCH 042/131] DossierController: giving an advice does not remove the notifications --- app/controllers/backoffice/dossiers_controller.rb | 6 +++++- spec/controllers/backoffice/dossiers_controller_spec.rb | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 5c9b7f4ca..8cc2260ae 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -32,7 +32,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController @headers_private = @champs_private.select { |champ| champ.type_champ == 'header_section' } end - Notification.where(dossier_id: dossier_id).update_all already_read: true + # if the current_gestionnaire does not own the dossier, it is here to give an advice + # and it should not remove the notifications + if current_gestionnaire.dossiers.find_by(id: dossier_id).present? + Notification.where(dossier_id: dossier_id).update_all(already_read: true) + end @new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.") end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 7a647f51c..a5889ec9f 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -127,6 +127,13 @@ describe Backoffice::DossiersController, type: :controller do it { expect(subject.status).to eq(200) } it { expect(subject.body).to include("Votre avis est sollicité sur le dossier") } it { expect(subject.body).to_not include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") } + + describe 'the notifications are not marked as read' do + it do + expect(Notification).not_to receive(:where) + subject + end + end end end From cdcd5b951f1175a9c16d39d22d752b1baee4d92d Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 22 May 2017 17:10:17 +0200 Subject: [PATCH 043/131] AvisController: add a notification when a avis has been received --- app/controllers/backoffice/avis_controller.rb | 1 + app/models/notification.rb | 3 ++- app/services/notification_service.rb | 2 ++ spec/controllers/backoffice/avis_controller_spec.rb | 6 ++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index ed59a671b..650bce8be 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -24,6 +24,7 @@ class Backoffice::AvisController < ApplicationController def update if avis.update(update_params) + NotificationService.new('avis', params[:dossier_id]).notify flash[:notice] = 'Merci, votre avis a été enregistré.' end diff --git a/app/models/notification.rb b/app/models/notification.rb index af36da06e..0740ee823 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -5,7 +5,8 @@ class Notification < ActiveRecord::Base cerfa: 'cerfa', piece_justificative: 'piece_justificative', champs: 'champs', - submitted: 'submitted' + submitted: 'submitted', + avis: 'avis' } scope :unread, -> { where(already_read: false) } end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 18415ebbd..a401064cf 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -35,6 +35,8 @@ class NotificationService attribut when 'submitted' "Le dossier nº #{@dossier_id} a été déposé." + when 'avis' + 'Un nouvel avis a été rendu' else 'Notification par défaut' end diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 08f1d5e82..60fba087b 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -39,6 +39,11 @@ describe Backoffice::AvisController, type: :controller do subject { post :update, params: { dossier_id: dossier.id, id: avis.id, avis: { answer: "Ok ce dossier est valide." } } } + before :each do + notification = double('notification', notify: true) + allow(NotificationService).to receive(:new).and_return(notification) + end + context 'when gestionnaire is not authenticated' do it { is_expected.to redirect_to new_user_session_path } it { expect(avis.answer).to be_nil } @@ -54,6 +59,7 @@ describe Backoffice::AvisController, type: :controller do it do subject expect(avis.reload.answer).to eq("Ok ce dossier est valide.") + expect(NotificationService).to have_received(:new).at_least(:once) end end From 23e57f5cc469ac0c5c60632178f10b83d95bacf3 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 22 May 2017 17:45:49 +0200 Subject: [PATCH 044/131] Navbar: add deprecation warning for invitations --- .../_navbar_backoffice_dossierscontroller_show.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml b/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml index 2c72a80fe..6604a98c1 100644 --- a/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml @@ -28,6 +28,8 @@ - else = t('dynamics.dossiers.followers.empty') %h4= t('dynamics.dossiers.invites.title') + %p + %b Attention, les invitations sur les dossiers vont disparaître en faveur des avis externes situés en bas de la page %ul - unless @facade.invites.empty? - @facade.invites.each do |invite| From 64f7cab3cf7ff6b61536e3af2e8f456c3b72bd59 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 23 May 2017 13:28:17 +0200 Subject: [PATCH 045/131] Avis: add claimant gestionnaire to track who asks for an avis --- app/controllers/backoffice/avis_controller.rb | 2 +- app/models/avis.rb | 1 + .../avis_mailer/you_are_invited_on_dossier.html.haml | 2 +- db/migrate/20170523092900_add_claimant_to_avis.rb | 5 +++++ db/schema.rb | 5 ++++- spec/controllers/backoffice/avis_controller_spec.rb | 8 ++++---- spec/factories/avis.rb | 6 ++++++ spec/mailers/avis_mailer_spec.rb | 3 ++- spec/models/avis_spec.rb | 12 +++++++++--- 9 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20170523092900_add_claimant_to_avis.rb diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 650bce8be..4d77496d2 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -5,7 +5,7 @@ class Backoffice::AvisController < ApplicationController before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire] def create - avis = Avis.new(create_params) + avis = Avis.new(create_params.merge(claimant: current_gestionnaire)) avis.dossier = dossier email = create_params[:email] diff --git a/app/models/avis.rb b/app/models/avis.rb index afc6ec285..59eff74fc 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -1,6 +1,7 @@ class Avis < ApplicationRecord belongs_to :dossier belongs_to :gestionnaire + belongs_to :claimant, class_name: 'Gestionnaire' after_create :notify_gestionnaire diff --git a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml index 76c9f4149..26b129266 100644 --- a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml +++ b/app/views/avis_mailer/you_are_invited_on_dossier.html.haml @@ -3,7 +3,7 @@ %p Bonjour, %br - = "Vous avez été invité à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}." + = "Vous avez été invité par #{@avis.claimant.email} à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}." %br Message de votre interlocuteur : diff --git a/db/migrate/20170523092900_add_claimant_to_avis.rb b/db/migrate/20170523092900_add_claimant_to_avis.rb new file mode 100644 index 000000000..c8a34e182 --- /dev/null +++ b/db/migrate/20170523092900_add_claimant_to_avis.rb @@ -0,0 +1,5 @@ +class AddClaimantToAvis < ActiveRecord::Migration[5.0] + def change + add_reference :avis, :claimant, foreign_key: { to_table: :gestionnaires }, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 55f008b87..796086d82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170425100757) do +ActiveRecord::Schema.define(version: 20170523092900) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -79,6 +79,8 @@ ActiveRecord::Schema.define(version: 20170425100757) do t.integer "dossier_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "claimant_id", null: false + t.index ["claimant_id"], name: "index_avis_on_claimant_id", using: :btree t.index ["dossier_id"], name: "index_avis_on_dossier_id", using: :btree t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id", using: :btree end @@ -446,6 +448,7 @@ ActiveRecord::Schema.define(version: 20170425100757) do t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id", using: :btree end + add_foreign_key "avis", "gestionnaires", column: "claimant_id" add_foreign_key "cerfas", "dossiers" add_foreign_key "closed_mails", "procedures" add_foreign_key "commentaires", "dossiers" diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index 60fba087b..c1af9658b 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -75,7 +75,7 @@ describe Backoffice::AvisController, type: :controller do describe '.sign_up' do let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } - let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:invitations_email) { true } context 'when the new gestionnaire has never signed up' do @@ -101,7 +101,7 @@ describe Backoffice::AvisController, type: :controller do context 'when the gestionnaire has already signed up and belongs to the invitation' do let(:gestionnaire) { create(:gestionnaire, email: invited_email) } - let!(:avis) { Avis.create(dossier: dossier, gestionnaire: gestionnaire) } + let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) } context 'when the gestionnaire is authenticated' do before do @@ -123,7 +123,7 @@ describe Backoffice::AvisController, type: :controller do context 'when the gestionnaire has already signed up / is authenticated and does not belong to the invitation' do let(:gestionnaire) { create(:gestionnaire, email: 'other@gmail.com') } - let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } before do sign_in gestionnaire @@ -138,7 +138,7 @@ describe Backoffice::AvisController, type: :controller do describe '.create_gestionnaire' do let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } - let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:avis_id) { avis.id } let(:password) { '12345678' } let(:created_gestionnaire) { Gestionnaire.find_by(email: invited_email) } diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index c69371734..7568cdfe9 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -13,5 +13,11 @@ FactoryGirl.define do avis.dossier = create :dossier end end + + before(:create) do |avis, _evaluator| + unless avis.claimant + avis.claimant = create :gestionnaire + end + end end end diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index 657a327a6..cc5320d7a 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -7,7 +7,8 @@ RSpec.describe AvisMailer, type: :mailer do subject { described_class.you_are_invited_on_dossier(avis) } it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } - it { expect(subject.body).to include("Vous avez été invité à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") } + it { expect(subject.body).to include("Vous avez été invité par #{avis.claimant.email} à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") } it { expect(subject.body).to include(avis.introduction) } + end end diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index 47a39c82e..231210158 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -1,9 +1,15 @@ require 'rails_helper' RSpec.describe Avis, type: :model do + let(:claimant) { create(:gestionnaire) } + describe '.email_to_display' do let(:invited_email) { 'invited@avis.com' } - let!(:avis) { Avis.create(email: invited_email, dossier: create(:dossier)) } + let!(:avis) do + avis = create(:avis, email: invited_email, dossier: create(:dossier)) + avis.gestionnaire = nil + avis + end subject { avis.email_to_display } @@ -12,7 +18,7 @@ RSpec.describe Avis, type: :model do end context 'when gestionnaire is known' do - let!(:avis) { Avis.create(email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) } + let!(:avis) { create(:avis, email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) } it{ is_expected.to eq(avis.gestionnaire.email) } end @@ -55,7 +61,7 @@ RSpec.describe Avis, type: :model do describe '.avis_exists_and_email_belongs_to_avis' do let(:dossier) { create(:dossier) } let(:invited_email) { 'invited@avis.com' } - let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } subject { Avis.avis_exists_and_email_belongs_to_avis?(avis_id, email) } From e0c253eee1501191033323fef8c9e2de0cce2d49 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 11:56:31 +0200 Subject: [PATCH 046/131] Revert "Procedure: set archive_date to datetime to allow localtime" This reverts commit 14dd75d0d2131d18579f5668b1b26bf1dc91802c. --- ...220_change_procedure_auto_archive_date_to_datetime.rb | 9 --------- db/schema.rb | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb diff --git a/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb b/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb deleted file mode 100644 index b0d8deef3..000000000 --- a/db/migrate/20170523081220_change_procedure_auto_archive_date_to_datetime.rb +++ /dev/null @@ -1,9 +0,0 @@ -class ChangeProcedureAutoArchiveDateToDatetime < ActiveRecord::Migration[5.0] - def up - change_column :procedures, :auto_archive_on, :datetime - end - - def down - change_column :procedures, :auto_archive_on, :date - end -end diff --git a/db/schema.rb b/db/schema.rb index 796086d82..81476287a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -358,7 +358,7 @@ ActiveRecord::Schema.define(version: 20170523092900) do t.string "lien_notice" t.boolean "for_individual", default: false t.boolean "individual_with_siret", default: false - t.datetime "auto_archive_on" + t.date "auto_archive_on" end create_table "quartier_prioritaires", force: :cascade do |t| From 7ac6c81154d519b0bc72aedd017d23dc5035deb4 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 12:41:42 +0200 Subject: [PATCH 047/131] AdminProceduresInfoHaml: remove localtime to date --- app/views/admin/procedures/_informations.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index cb2c4aa2e..253ee6729 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -84,7 +84,7 @@ %h4 Options avancées %label{ for: :auto_archive_on } Archivage automatique le - = f.text_field :auto_archive_on, id: 'auto_archive_on', value: @procedure.auto_archive_on.try{ |d| d.localtime.strftime("%d-%m-%Y") }, data: { provide: 'datepicker', 'date-language' => 'fr', 'date-format' => 'dd/mm/yyyy' } + = f.text_field :auto_archive_on, id: 'auto_archive_on', value: @procedure.auto_archive_on.try{ |d| d.strftime("%d-%m-%Y") }, data: { provide: 'datepicker', 'date-language' => 'fr', 'date-format' => 'dd/mm/yyyy' } (à 00h00) %p.help-block %i.fa.fa-info-circle From 627ce150a75fdcf5aebd213b3292de5d42b48a36 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 22 May 2017 16:55:53 +0200 Subject: [PATCH 048/131] Capture the Chartkick JS and yield it in the layout So that we can include all the JS at the bottom of the page without error --- app/views/layouts/new_application.html.haml | 1 + config/initializers/chartkick.rb | 1 + 2 files changed, 2 insertions(+) create mode 100644 config/initializers/chartkick.rb diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index 7a90a8c78..19c5bc700 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -37,6 +37,7 @@ = render partial: "layouts/mailjet_newsletter" = javascript_include_tag "application", "data-turbolinks-track" => true + = yield :charts_js - if Rails.env == "test" %script{ :type => "text/javascript" } (typeof jQuery !== "undefined") && (jQuery.fx.off = true); diff --git a/config/initializers/chartkick.rb b/config/initializers/chartkick.rb new file mode 100644 index 000000000..20cc32bc9 --- /dev/null +++ b/config/initializers/chartkick.rb @@ -0,0 +1 @@ +Chartkick.options[:content_for] = :charts_js From f82533be192d4998db3921c580c0de5bbdde7253 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 22 May 2017 16:56:09 +0200 Subject: [PATCH 049/131] Use the new_application layout for the Stats page --- app/assets/stylesheets/application.scss | 1 - app/assets/stylesheets/{ => new_design}/stats.scss | 8 ++++---- app/assets/stylesheets/new_design/utils.scss | 4 ++++ app/controllers/stats_controller.rb | 1 + app/views/stats/index.html.haml | 8 ++++---- 5 files changed, 13 insertions(+), 9 deletions(-) rename app/assets/stylesheets/{ => new_design}/stats.scss (96%) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5b64692b7..aac24c497 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -40,7 +40,6 @@ // = require recapitulatif // = require search // = require siret -// = require stats // = require support_navigator_banner // = require switch_menu // = require typeahead diff --git a/app/assets/stylesheets/stats.scss b/app/assets/stylesheets/new_design/stats.scss similarity index 96% rename from app/assets/stylesheets/stats.scss rename to app/assets/stylesheets/new_design/stats.scss index 42fef6ac1..5b32a7a24 100644 --- a/app/assets/stylesheets/stats.scss +++ b/app/assets/stylesheets/new_design/stats.scss @@ -1,5 +1,3 @@ -@import "card"; - $dark-grey: #333333; $light-grey: #999999; $blue: rgba(61, 149, 236, 1); @@ -12,8 +10,9 @@ $new-h1-margin-bottom: 4 * $default-space; .new-h1 { color: $dark-grey; text-align: center; - margin-top: 0; margin-bottom: $new-h1-margin-bottom; + font-weight: bold; + font-size: 41px; } $statistiques-padding-top: $default-space * 2; @@ -33,6 +32,7 @@ $statistiques-padding-top: $default-space * 2; $stat-card-margin-bottom: 3 * $default-space; .stat-card { + padding: 15px; margin-bottom: $stat-card-margin-bottom; border-radius: 5px; box-shadow: none; @@ -49,7 +49,7 @@ $stat-card-half-horizontal-spacing: 4 * $default-space; .stat-card-title { color: $dark-grey; font-size: 26px; - font-weight: 500; + font-weight: bold; width: 200px; } diff --git a/app/assets/stylesheets/new_design/utils.scss b/app/assets/stylesheets/new_design/utils.scss index 04a4559bf..958f8ff9c 100644 --- a/app/assets/stylesheets/new_design/utils.scss +++ b/app/assets/stylesheets/new_design/utils.scss @@ -13,3 +13,7 @@ .center { text-align: center; } + +.hidden { + display: none; +} diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 66d1bf202..629b2dad7 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -1,4 +1,5 @@ class StatsController < ApplicationController + layout "new_application" def index procedures = Procedure.where(:published => true) diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index c3d40561a..9b0a389b1 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -4,7 +4,7 @@ .stat-cards - .card.stat-card.stat-card-half.pull-left + .stat-card.stat-card-half.pull-left %ul.segmented-control.pull-right %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.cumulative-procedures-chart');" } Cumul @@ -21,7 +21,7 @@ = line_chart @procedures_30_days_flow, :colors => ["rgba(61, 149, 236, 1)"] - .card.stat-card.stat-card-half.pull-left + .stat-card.stat-card-half.pull-left %ul.segmented-control.pull-right %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.cumulative-dossiers-chart');" } Cumul @@ -38,12 +38,12 @@ = line_chart @dossiers_30_days_flow, :colors => ["rgba(61, 149, 236, 1)"] - .card.stat-card.stat-card-half.big-number-card.pull-left + .stat-card.stat-card-half.big-number-card.pull-left %span.big-number-card-title TOTAL PROCÉDURES DÉMATÉRIALISÉES %span.big-number-card-number = number_with_delimiter(@procedures_count) - .card.stat-card.stat-card-half.big-number-card.pull-left + .stat-card.stat-card-half.big-number-card.pull-left %span.big-number-card-title TOTAL DOSSIERS DÉPOSÉS %span.big-number-card-number = number_with_delimiter(@dossiers_count) From b820f9d39cf9819d94381251ee2db83415df861e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 15:26:56 +0200 Subject: [PATCH 050/131] Move a test in the right describe section --- spec/controllers/stats_controller_spec.rb | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 6cbaf91bd..1b5753fc0 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -66,22 +66,22 @@ describe StatsController, type: :controller do 15.days.ago.beginning_of_month => 3 }) } end - end - context "with a date attribute" do - before do - FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 20.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago) + context "with a date attribute" do + before do + FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago) + FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 20.days.ago) + FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago) + end + + let (:association) { Procedure.all } + + subject { StatsController.new.send(:cumulative_hash, association, :updated_at) } + + it { expect(subject).to eq({ + 20.days.ago.beginning_of_month => 2, + 10.days.ago.beginning_of_month => 3 + }) } end - - let (:association) { Procedure.all } - - subject { StatsController.new.send(:cumulative_hash, association, :updated_at) } - - it { expect(subject).to eq({ - 20.days.ago.beginning_of_month => 2, - 10.days.ago.beginning_of_month => 3 - }) } end end From 0cc5d85f131dc1323a87cc33e922a08044c3d145 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 17:22:54 +0200 Subject: [PATCH 051/131] Improve the Procedure factory We can now specify how many types_de_champ a procedure has --- spec/factories/procedure.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index f38629fc7..9e0b76e7b 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -30,10 +30,16 @@ FactoryGirl.define do end trait :with_type_de_champ do - after(:build) do |procedure, _evaluator| - type_de_champ = create(:type_de_champ_public) + transient do + types_de_champ_count 1 + end - procedure.types_de_champ << type_de_champ + after(:build) do |procedure, evaluator| + evaluator.types_de_champ_count.times do + type_de_champ = create(:type_de_champ_public) + + procedure.types_de_champ << type_de_champ + end end end From ed7ba60cf0cb7b13612d883480239f91d5f839dd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 17:29:31 +0200 Subject: [PATCH 052/131] [Fix #264] Add the last 4 months evolution graphs to Stats --- app/controllers/stats_controller.rb | 16 ++++++++++ app/views/stats/index.html.haml | 16 ++++++++++ spec/controllers/stats_controller_spec.rb | 38 +++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 629b2dad7..9b4131f1a 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -5,6 +5,9 @@ class StatsController < ApplicationController procedures = Procedure.where(:published => true) dossiers = Dossier.where.not(:state => :draft) + @procedures_in_the_last_4_months = last_four_months_hash(procedures) + @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) + @procedures_30_days_flow = thirty_days_flow_hash(procedures) @dossiers_30_days_flow = thirty_days_flow_hash(dossiers, :initiated_at) @@ -17,6 +20,19 @@ class StatsController < ApplicationController private + def last_four_months_hash(association, date_attribute = :created_at) + min_date = 3.months.ago.beginning_of_month.to_date + max_date = Time.now.to_date + + association + .where(date_attribute => min_date..max_date) + .group("DATE_TRUNC('month', #{date_attribute.to_s})") + .count + .to_a + .sort{ |x, y| x[0] <=> y[0] } + .map { |e| [I18n.l(e.first, format: "%B %Y"), e.last] } + end + def thirty_days_flow_hash(association, date_attribute = :created_at) min_date = 30.days.ago.to_date max_date = Time.now.to_date diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 9b0a389b1..ce252935d 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -4,6 +4,22 @@ .stat-cards + .stat-card.stat-card-half.pull-left + %span.stat-card-title Procédures dématérialisées / mois + + .chart-container + .chart + = column_chart @procedures_in_the_last_4_months, + :colors => ["rgba(61, 149, 236, 1)"] + + .stat-card.stat-card-half.pull-left + %span.stat-card-title Dossiers déposés / mois + + .chart-container + .chart + = column_chart @dossiers_in_the_last_4_months, + :colors => ["rgba(61, 149, 236, 1)"] + .stat-card.stat-card-half.pull-left %ul.segmented-control.pull-right %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.cumulative-procedures-chart');" } diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 1b5753fc0..54c48be7a 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -1,6 +1,44 @@ require 'spec_helper' describe StatsController, type: :controller do + describe "#last_four_months_hash" do + context "without a date attribute" do + before do + FactoryGirl.create(:procedure, :created_at => 6.months.ago) + FactoryGirl.create(:procedure, :created_at => 45.days.ago) + FactoryGirl.create(:procedure, :created_at => 1.days.ago) + FactoryGirl.create(:procedure, :created_at => 1.days.ago) + end + + let (:association) { Procedure.all } + + subject { StatsController.new.send(:last_four_months_hash, association) } + + it { expect(subject).to eq([ + [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1], + [I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 2] + ] ) } + end + + context "with a date attribute" do + before do + FactoryGirl.create(:procedure, :created_at => 6.months.ago, :updated_at => 6.months.ago) + FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 45.days.ago) + FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 45.days.ago) + FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 1.days.ago) + end + + let (:association) { Procedure.all } + + subject { StatsController.new.send(:last_four_months_hash, association, :updated_at) } + + it { expect(subject).to eq([ + [I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 2], + [I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 1] + ] ) } + end + end + describe '#thirty_days_flow_hash' do context "without a date_attribut" do before do From faa547e891d315fc6e64454d52445ab3c9ade01c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 17:19:50 +0200 Subject: [PATCH 053/131] [Fix #264] Add the mean instruction time graph to Stats --- app/controllers/stats_controller.rb | 44 +++++++++++++++++++++ app/views/stats/index.html.haml | 9 +++++ spec/controllers/stats_controller_spec.rb | 48 +++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 9b4131f1a..d0e4cc437 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -16,6 +16,8 @@ class StatsController < ApplicationController @procedures_count = procedures.count @dossiers_count = dossiers.count + + @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) end private @@ -70,4 +72,46 @@ class StatsController < ApplicationController .reduce({}, :merge) end + def mean(collection) + (collection.sum.to_f / collection.size).round(2) + end + + def dossier_instruction_mean_time(dossiers) + # In the 12 last months, we compute for each month + # the average time it took to instruct a dossier + # We compute monthly averages by first making an average per procedure + # and then computing the average for all the procedures + + min_date = 11.months.ago + max_date = Time.now.to_date + + processed_dossiers = dossiers + .where(:processed_at => min_date..max_date) + .pluck(:procedure_id, :initiated_at, :processed_at) + + # Group dossiers by month + processed_dossiers_by_month = processed_dossiers + .group_by do |dossier| + dossier[2].beginning_of_month.to_s + end + + processed_dossiers_by_month.map do |month, value| + # Group the dossiers for this month by procedure + dossiers_grouped_by_procedure = value.group_by { |dossier| dossier[0] } + + # Compute the mean time for this procedure + procedure_processing_times = dossiers_grouped_by_procedure.map do |procedure_id, procedure_dossiers| + procedure_dossiers_processing_time = procedure_dossiers.map do |dossier| + (dossier[2] - dossier[1]).to_f / (3600 * 24) + end + + mean(procedure_dossiers_processing_time) + end + + # Compute the average mean time for all the procedures of this month + month_average = mean(procedure_processing_times) + + [month, month_average] + end.to_h + end end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index ce252935d..a4e6bfffb 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -64,4 +64,13 @@ %span.big-number-card-number = number_with_delimiter(@dossiers_count) + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de traitement moyen d'un dossier + + .chart-container + .chart + = line_chart @dossier_instruction_mean_time, + :ytitle => "Jours", + :colors => ["rgba(61, 149, 236, 1)"] + .clearfix diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 54c48be7a..de5834c5b 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -122,4 +122,52 @@ describe StatsController, type: :controller do }) } end end + + describe "#dossier_instruction_mean_time" do + # Month-2: mean 3 days + # procedure_1: mean 2 days + # dossier_p1_a: 3 days + # dossier_p1_b: 1 days + # procedure_2: mean 4 days + # dossier_p2_a: 4 days + # + # Month-1: mean 5 days + # procedure_1: mean 5 days + # dossier_p1_c: 5 days + + before do + procedure_1 = FactoryGirl.create(:procedure) + procedure_2 = FactoryGirl.create(:procedure) + dossier_p1_a = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :initiated_at => 2.months.ago.beginning_of_month, + :processed_at => 2.months.ago.beginning_of_month + 3.days) + dossier_p1_b = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :initiated_at => 2.months.ago.beginning_of_month, + :processed_at => 2.months.ago.beginning_of_month + 1.days) + dossier_p1_c = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :initiated_at => 1.months.ago.beginning_of_month, + :processed_at => 1.months.ago.beginning_of_month + 5.days) + dossier_p2_a = FactoryGirl.create(:dossier, + :procedure => procedure_2, + :initiated_at => 2.month.ago.beginning_of_month, + :processed_at => 2.month.ago.beginning_of_month + 4.days) + + # Write directly in the DB to avoid the before_validation hook + Dossier.update_all(state: "closed") + + @expected_hash = { + "#{2.months.ago.beginning_of_month}" => 3.0, + "#{1.months.ago.beginning_of_month}" => 5.0 + } + end + + let (:association) { Dossier.where.not(:state => :draft) } + + subject { StatsController.new.send(:dossier_instruction_mean_time, association) } + + it { expect(subject).to eq(@expected_hash) } + end end From 711f21c458cf0e01445a7874436608f78736ebe7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 17:27:23 +0200 Subject: [PATCH 054/131] [Fix #264] Add the mean filling time graph to Stats --- app/controllers/stats_controller.rb | 48 +++++++++++++++++++++ app/views/stats/index.html.haml | 9 ++++ spec/controllers/stats_controller_spec.rb | 52 +++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index d0e4cc437..7c44c8e0c 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -1,6 +1,8 @@ class StatsController < ApplicationController layout "new_application" + MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0 + def index procedures = Procedure.where(:published => true) dossiers = Dossier.where.not(:state => :draft) @@ -18,6 +20,7 @@ class StatsController < ApplicationController @dossiers_count = dossiers.count @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) + @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) end private @@ -114,4 +117,49 @@ class StatsController < ApplicationController [month, month_average] end.to_h end + + def dossier_filling_mean_time(dossiers) + # In the 12 last months, we compute for each month + # the average time it took to fill a dossier + # We compute monthly averages by first making an average per procedure + # and then computing the average for all the procedures + # For each procedure, we normalize the data: the time is calculated + # for a 24 champs form (the current form mean length) + + min_date = 11.months.ago + max_date = Time.now.to_date + + processed_dossiers = dossiers + .where(:processed_at => min_date..max_date) + .pluck(:procedure_id, :created_at, :initiated_at, :processed_at) + + # Group dossiers by month + processed_dossiers_by_month = processed_dossiers + .group_by do |e| + e[3].beginning_of_month.to_s + end + + processed_dossiers_by_month.map do |month, value| + # Group the dossiers for this month by procedure + dossiers_grouped_by_procedure = value.group_by { |dossier| dossier[0] } + + # Compute the mean time for this procedure + procedure_processing_times = dossiers_grouped_by_procedure.map do |procedure_id, procedure_dossiers| + procedure_dossiers_processing_time = procedure_dossiers.map do |dossier| + (dossier[2] - dossier[1]).to_f / 60 + end + + procedure_mean = mean(procedure_dossiers_processing_time) + + # We normalize the data for 24 fields + procedure_fields_count = Procedure.find(procedure_id).types_de_champ.count + procedure_mean * (MEAN_NUMBER_OF_CHAMPS_IN_A_FORM / procedure_fields_count) + end + + # Compute the average mean time for all the procedures of this month + month_average = mean(procedure_processing_times) + + [month, month_average] + end.to_h + end end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index a4e6bfffb..65287a397 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -73,4 +73,13 @@ :ytitle => "Jours", :colors => ["rgba(61, 149, 236, 1)"] + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de remplissage moyen d'un dossier + + .chart-container + .chart + = line_chart @dossier_filling_mean_time, + :ytitle => "Minutes", + :colors => ["rgba(61, 149, 236, 1)"] + .clearfix diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index de5834c5b..36c7928b1 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -170,4 +170,56 @@ describe StatsController, type: :controller do it { expect(subject).to eq(@expected_hash) } end + + describe "#dossier_filling_mean_time" do + # Month-2: mean 30 minutes + # procedure_1: mean 20 minutes + # dossier_p1_a: 30 minutes + # dossier_p1_b: 10 minutes + # procedure_2: mean 40 minutes + # dossier_p2_a: 80 minutes, for twice the fields + # + # Month-1: mean 50 minutes + # procedure_1: mean 50 minutes + # dossier_p1_c: 50 minutes + + before do + procedure_1 = FactoryGirl.create(:procedure, :with_type_de_champ, :types_de_champ_count => 24) + procedure_2 = FactoryGirl.create(:procedure, :with_type_de_champ, :types_de_champ_count => 48) + dossier_p1_a = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :created_at => 2.months.ago.beginning_of_month, + :initiated_at => 2.months.ago.beginning_of_month + 30.minutes, + :processed_at => 2.months.ago.beginning_of_month + 1.day) + dossier_p1_b = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :created_at => 2.months.ago.beginning_of_month, + :initiated_at => 2.months.ago.beginning_of_month + 10.minutes, + :processed_at => 2.months.ago.beginning_of_month + 1.day) + dossier_p1_c = FactoryGirl.create(:dossier, + :procedure => procedure_1, + :created_at => 1.months.ago.beginning_of_month, + :initiated_at => 1.months.ago.beginning_of_month + 50.minutes, + :processed_at => 1.months.ago.beginning_of_month + 1.day) + dossier_p2_a = FactoryGirl.create(:dossier, + :procedure => procedure_2, + :created_at => 2.month.ago.beginning_of_month, + :initiated_at => 2.month.ago.beginning_of_month + 80.minutes, + :processed_at => 2.month.ago.beginning_of_month + 1.day) + + # Write directly in the DB to avoid the before_validation hook + Dossier.update_all(state: "closed") + + @expected_hash = { + "#{2.months.ago.beginning_of_month}" => 30.0, + "#{1.months.ago.beginning_of_month}" => 50.0 + } + end + + let (:association) { Dossier.where.not(:state => :draft) } + + subject { StatsController.new.send(:dossier_filling_mean_time, association) } + + it { expect(subject).to eq(@expected_hash) } + end end From e242c5d74254a5e74271426f73eec596e1260fc3 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 17:36:17 +0200 Subject: [PATCH 055/131] Add caching to the Stats page --- app/views/stats/index.html.haml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 65287a397..f318a2483 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -64,22 +64,23 @@ %span.big-number-card-number = number_with_delimiter(@dossiers_count) - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de traitement moyen d'un dossier + - cache "computation-heavy-stats", :expires_in => 1.day do + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de traitement moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_instruction_mean_time, - :ytitle => "Jours", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_instruction_mean_time, + :ytitle => "Jours", + :colors => ["rgba(61, 149, 236, 1)"] - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de remplissage moyen d'un dossier + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de remplissage moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_filling_mean_time, - :ytitle => "Minutes", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_filling_mean_time, + :ytitle => "Minutes", + :colors => ["rgba(61, 149, 236, 1)"] .clearfix From e19fb43f016b81a36bbdd8ae04c22698b8fa8c82 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 17:37:05 +0200 Subject: [PATCH 056/131] Only show the mean charts to logged in users --- app/views/stats/index.html.haml | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index f318a2483..db4c1c42b 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -64,23 +64,24 @@ %span.big-number-card-number = number_with_delimiter(@dossiers_count) - - cache "computation-heavy-stats", :expires_in => 1.day do - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de traitement moyen d'un dossier + - if administration_signed_in? + - cache "computation-heavy-stats", :expires_in => 1.day do + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de traitement moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_instruction_mean_time, - :ytitle => "Jours", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_instruction_mean_time, + :ytitle => "Jours", + :colors => ["rgba(61, 149, 236, 1)"] - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de remplissage moyen d'un dossier + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de remplissage moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_filling_mean_time, - :ytitle => "Minutes", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_filling_mean_time, + :ytitle => "Minutes", + :colors => ["rgba(61, 149, 236, 1)"] .clearfix From 58aa94359c3a33e617ba2e8ac4721bca340985ab Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 17:16:26 +0200 Subject: [PATCH 057/131] On the Stats page, move the total numbers at the top of the page --- app/controllers/stats_controller.rb | 6 +++--- app/views/stats/index.html.haml | 19 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 7c44c8e0c..1614295ad 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -7,6 +7,9 @@ class StatsController < ApplicationController procedures = Procedure.where(:published => true) dossiers = Dossier.where.not(:state => :draft) + @procedures_count = procedures.count + @dossiers_count = dossiers.count + @procedures_in_the_last_4_months = last_four_months_hash(procedures) @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) @@ -16,9 +19,6 @@ class StatsController < ApplicationController @procedures_cumulative = cumulative_hash(procedures) @dossiers_cumulative = cumulative_hash(dossiers, :initiated_at) - @procedures_count = procedures.count - @dossiers_count = dossiers.count - @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index db4c1c42b..286745d4b 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -3,6 +3,15 @@ %h1.new-h1 Statistiques .stat-cards + .stat-card.stat-card-half.big-number-card.pull-left + %span.big-number-card-title TOTAL PROCÉDURES DÉMATÉRIALISÉES + %span.big-number-card-number + = number_with_delimiter(@procedures_count) + + .stat-card.stat-card-half.big-number-card.pull-left + %span.big-number-card-title TOTAL DOSSIERS DÉPOSÉS + %span.big-number-card-number + = number_with_delimiter(@dossiers_count) .stat-card.stat-card-half.pull-left %span.stat-card-title Procédures dématérialisées / mois @@ -54,16 +63,6 @@ = line_chart @dossiers_30_days_flow, :colors => ["rgba(61, 149, 236, 1)"] - .stat-card.stat-card-half.big-number-card.pull-left - %span.big-number-card-title TOTAL PROCÉDURES DÉMATÉRIALISÉES - %span.big-number-card-number - = number_with_delimiter(@procedures_count) - - .stat-card.stat-card-half.big-number-card.pull-left - %span.big-number-card-title TOTAL DOSSIERS DÉPOSÉS - %span.big-number-card-number - = number_with_delimiter(@dossiers_count) - - if administration_signed_in? - cache "computation-heavy-stats", :expires_in => 1.day do .stat-card.stat-card-half.pull-left From 3215411547c779da5074aba098e8522e5d131982 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 17:46:31 +0200 Subject: [PATCH 058/131] Delete the 30 days flows graphs --- app/controllers/stats_controller.rb | 29 -------------- app/views/stats/index.html.haml | 22 +---------- spec/controllers/stats_controller_spec.rb | 48 ----------------------- 3 files changed, 2 insertions(+), 97 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 1614295ad..3654e0238 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -13,9 +13,6 @@ class StatsController < ApplicationController @procedures_in_the_last_4_months = last_four_months_hash(procedures) @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) - @procedures_30_days_flow = thirty_days_flow_hash(procedures) - @dossiers_30_days_flow = thirty_days_flow_hash(dossiers, :initiated_at) - @procedures_cumulative = cumulative_hash(procedures) @dossiers_cumulative = cumulative_hash(dossiers, :initiated_at) @@ -38,32 +35,6 @@ class StatsController < ApplicationController .map { |e| [I18n.l(e.first, format: "%B %Y"), e.last] } end - def thirty_days_flow_hash(association, date_attribute = :created_at) - min_date = 30.days.ago.to_date - max_date = Time.now.to_date - - thirty_days_flow_hash = association - .where(date_attribute => min_date..max_date) - .group("date_trunc('day', #{date_attribute.to_s})") - .count - - clean_hash(thirty_days_flow_hash, min_date, max_date) - end - - def clean_hash(h, min_date, max_date) - # Convert keys to date - h = Hash[h.map { |(k, v)| [k.to_date, v] }] - - # Add missing vales where count is 0 - (min_date..max_date).each do |date| - if h[date].nil? - h[date] = 0 - end - end - - h - end - def cumulative_hash(association, date_attribute = :created_at) sum = 0 association diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 286745d4b..6527de814 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -30,38 +30,20 @@ :colors => ["rgba(61, 149, 236, 1)"] .stat-card.stat-card-half.pull-left - %ul.segmented-control.pull-right - %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.cumulative-procedures-chart');" } - Cumul - %li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.flux-procedures-chart');" } - Flux (30 jours) - %span.stat-card-title.pull-left Procédures dématérialisées - .clearfix + %span.stat-card-title Procédures dématérialisées .chart-container .chart.cumulative-procedures-chart = area_chart @procedures_cumulative, :colors => ["rgba(61, 149, 236, 1)"] - .chart.flux-procedures-chart.hidden - = line_chart @procedures_30_days_flow, - :colors => ["rgba(61, 149, 236, 1)"] .stat-card.stat-card-half.pull-left - %ul.segmented-control.pull-right - %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.cumulative-dossiers-chart');" } - Cumul - %li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.flux-dossiers-chart');" } - Flux (30 jours) - %span.stat-card-title.pull-left Dossiers déposés - .clearfix + %span.stat-card-title Dossiers déposés .chart-container .chart.cumulative-dossiers-chart = area_chart @dossiers_cumulative, :colors => ["rgba(61, 149, 236, 1)"] - .chart.flux-dossiers-chart.hidden - = line_chart @dossiers_30_days_flow, - :colors => ["rgba(61, 149, 236, 1)"] - if administration_signed_in? - cache "computation-heavy-stats", :expires_in => 1.day do diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 36c7928b1..99516aeba 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -39,54 +39,6 @@ describe StatsController, type: :controller do end end - describe '#thirty_days_flow_hash' do - context "without a date_attribut" do - before do - FactoryGirl.create(:procedure, :created_at => 45.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago) - FactoryGirl.create(:procedure, :created_at => 1.day.ago) - - @expected_hash = {} - (30.days.ago.to_date..Time.now.to_date).each do |day| - if [15.days.ago.to_date, 1.day.ago.to_date].include?(day) - @expected_hash[day] = 1 - else - @expected_hash[day] = 0 - end - end - end - - let (:association) { Procedure.all } - - subject { StatsController.new.send(:thirty_days_flow_hash, association) } - - it { expect(subject).to eq(@expected_hash) } - end - - context "with a date_attribut" do - before do - FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 50.days.ago) - FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago) - FactoryGirl.create(:procedure, :created_at => 1.day.ago, :updated_at => 3.days.ago) - - @expected_hash = {} - (30.days.ago.to_date..Time.now.to_date).each do |day| - if [10.days.ago.to_date, 3.day.ago.to_date].include?(day) - @expected_hash[day] = 1 - else - @expected_hash[day] = 0 - end - end - end - - let (:association) { Procedure.all } - - subject { StatsController.new.send(:thirty_days_flow_hash, association, :updated_at) } - - it { expect(subject).to eq(@expected_hash) } - end - end - describe '#cumulative_hash' do context "without a date attribute" do before do From 95851424682d9ce1e48af39a5ab700280e8ceb22 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 17:47:55 +0200 Subject: [PATCH 059/131] Group the cumulative and monthly charts --- app/controllers/stats_controller.rb | 6 ++--- app/views/stats/index.html.haml | 38 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 3654e0238..14a85b789 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -10,11 +10,11 @@ class StatsController < ApplicationController @procedures_count = procedures.count @dossiers_count = dossiers.count - @procedures_in_the_last_4_months = last_four_months_hash(procedures) - @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) - @procedures_cumulative = cumulative_hash(procedures) + @procedures_in_the_last_4_months = last_four_months_hash(procedures) + @dossiers_cumulative = cumulative_hash(dossiers, :initiated_at) + @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 6527de814..5b7d74076 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -14,34 +14,36 @@ = number_with_delimiter(@dossiers_count) .stat-card.stat-card-half.pull-left - %span.stat-card-title Procédures dématérialisées / mois + %ul.segmented-control.pull-right + %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.monthly-procedures-chart');" } + Par mois + %li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.cumulative-procedures-chart');" } + Cumul + %span.stat-card-title.pull-left Procédures dématérialisées + .clearfix .chart-container - .chart + .chart.monthly-procedures-chart = column_chart @procedures_in_the_last_4_months, :colors => ["rgba(61, 149, 236, 1)"] - - .stat-card.stat-card-half.pull-left - %span.stat-card-title Dossiers déposés / mois - - .chart-container - .chart - = column_chart @dossiers_in_the_last_4_months, - :colors => ["rgba(61, 149, 236, 1)"] - - .stat-card.stat-card-half.pull-left - %span.stat-card-title Procédures dématérialisées - - .chart-container - .chart.cumulative-procedures-chart + .chart.cumulative-procedures-chart.hidden = area_chart @procedures_cumulative, :colors => ["rgba(61, 149, 236, 1)"] .stat-card.stat-card-half.pull-left - %span.stat-card-title Dossiers déposés + %ul.segmented-control.pull-right + %li.segmented-control-item.segmented-control-item-active{ :onclick => "TPS.toggleChart(event, '.monthly-dossiers-chart');" } + Par mois + %li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.cumulative-dossiers-chart');" } + Cumul + %span.stat-card-title.pull-left Dossiers déposés + .clearfix .chart-container - .chart.cumulative-dossiers-chart + .chart.monthly-dossiers-chart + = column_chart @dossiers_in_the_last_4_months, + :colors => ["rgba(61, 149, 236, 1)"] + .chart.cumulative-dossiers-chart.hidden = area_chart @dossiers_cumulative, :colors => ["rgba(61, 149, 236, 1)"] From ae8b12659466878cccef71fb9ea6a14d84fc0414 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 30 May 2017 15:03:51 +0200 Subject: [PATCH 060/131] ProcedureOverview: use procedure_url to link with absolute path in email --- app/models/procedure_overview.rb | 2 +- spec/models/procedure_overview_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/procedure_overview.rb b/app/models/procedure_overview.rb index 5bce9e5b5..464001cf2 100644 --- a/app/models/procedure_overview.rb +++ b/app/models/procedure_overview.rb @@ -4,7 +4,7 @@ class ProcedureOverview def initialize(procedure, start_date, notifications_count) @libelle = procedure.libelle - @procedure_url = backoffice_dossiers_procedure_path(procedure) + @procedure_url = backoffice_dossiers_procedure_url(procedure) @notifications_count = notifications_count @received_dossiers_count = procedure.dossiers.where(state: :received).count diff --git a/spec/models/procedure_overview_spec.rb b/spec/models/procedure_overview_spec.rb index c6670d730..defe51345 100644 --- a/spec/models/procedure_overview_spec.rb +++ b/spec/models/procedure_overview_spec.rb @@ -51,7 +51,7 @@ describe ProcedureOverview, type: :model do subject { procedure_overview.to_html } context 'when the different count are equal to 0' do - it { is_expected.to match(/^
libelle<\/strong><\/a>$/) } + it { is_expected.to match(/^libelle<\/strong><\/a>$/) } end context 'when the different counts are equal to 1' do From 69a5857322da965174dd51e5ef3d413c1cd29da7 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 30 May 2017 15:11:18 +0200 Subject: [PATCH 061/131] [Fix #264] Add pie chart to count administrations --- app/controllers/stats_controller.rb | 11 +++++++ app/views/stats/index.html.haml | 9 ++++++ spec/controllers/stats_controller_spec.rb | 36 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 14a85b789..817c39ee3 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -16,6 +16,8 @@ class StatsController < ApplicationController @dossiers_cumulative = cumulative_hash(dossiers, :initiated_at) @dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at) + @procedures_count_per_administrateur = procedures_count_per_administrateur(procedures) + @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) end @@ -46,6 +48,15 @@ class StatsController < ApplicationController .reduce({}, :merge) end + def procedures_count_per_administrateur(procedures) + count_per_administrateur = procedures.group(:administrateur_id).count.values + { + 'Une procédure' => count_per_administrateur.select { |count| count == 1 }.count, + 'Entre deux et cinq procédures' => count_per_administrateur.select { |count| 2 <= count && count <= 5 }.count, + 'Plus de cinq procédures' => count_per_administrateur.select { |count| 5 < count }.count + } + end + def mean(collection) (collection.sum.to_f / collection.size).round(2) end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 5b7d74076..fe01a39cd 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -47,6 +47,15 @@ = area_chart @dossiers_cumulative, :colors => ["rgba(61, 149, 236, 1)"] + .stat-card.stat-card-half.pull-left + %span.stat-card-title + Nombre d'administrations ayant dématérialisé N procédures + + .chart-container + .chart + = pie_chart @procedures_count_per_administrateur, + :colors => ["rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"] + - if administration_signed_in? - cache "computation-heavy-stats", :expires_in => 1.day do .stat-card.stat-card-half.pull-left diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 99516aeba..4a475fb30 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -75,6 +75,42 @@ describe StatsController, type: :controller do end end + describe "#procedures_count_per_administrateur" do + let!(:administrateur_1) { create(:administrateur) } + let!(:administrateur_2) { create(:administrateur) } + let!(:administrateur_3) { create(:administrateur) } + let!(:administrateur_4) { create(:administrateur) } + let!(:administrateur_5) { create(:administrateur) } + + before do + 3.times do + create(:procedure, published: true, administrateur: administrateur_1) + end + + 2.times do + create(:procedure, published: true, administrateur: administrateur_2) + end + + 8.times do + create(:procedure, published: true, administrateur: administrateur_3) + end + + create(:procedure, published: true, administrateur: administrateur_4) + end + + let(:association){ Procedure.all } + + subject { StatsController.new.send(:procedures_count_per_administrateur, association) } + + it do + is_expected.to eq({ + 'Une procédure' => 1, + 'Entre deux et cinq procédures' => 2, + 'Plus de cinq procédures' => 1 + }) + end + end + describe "#dossier_instruction_mean_time" do # Month-2: mean 3 days # procedure_1: mean 2 days From f2fe06e86f47725ec9b01dfe8692b9d7c3f8e11d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:09:19 +0200 Subject: [PATCH 062/131] Add the not_brouillon scope on Dossier --- app/models/dossier.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 71506ee9c..b38b261ca 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -54,7 +54,6 @@ class Dossier < ActiveRecord::Base EN_INSTRUCTION = %w(received) A_INSTRUIRE = %w(received) TERMINE = %w(closed refused without_continuation) - ALL_STATE = %w(initiated updated replied received closed refused without_continuation) def unreaded_notifications @unreaded_notif ||= notifications.where(already_read: false) @@ -160,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - where(state: ALL_STATE, archived: false).order("updated_at #{order}") + not_brouillon.where(archived: false).order("updated_at #{order}") end def brouillon? @@ -168,6 +167,7 @@ class Dossier < ActiveRecord::Base end scope :brouillon, -> { where(state: BROUILLON) } + scope :not_brouillon, -> { where.not(state: BROUILLON) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } From 7eed44d4302f6fab559bf59045f715c2b7353745 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:10:38 +0200 Subject: [PATCH 063/131] Use the not_archived scope in Dossier --- app/models/dossier.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b38b261ca..a919aec27 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -159,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.where(archived: false).order("updated_at #{order}") + not_brouillon.not_archived.order("updated_at #{order}") end def brouillon? @@ -172,25 +172,25 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } def self.nouveaux order = 'ASC' - where(state: NOUVEAUX, archived: false).order("updated_at #{order}") + not_archived.where(state: NOUVEAUX).order("updated_at #{order}") end def self.waiting_for_gestionnaire order = 'ASC' - where(state: WAITING_FOR_GESTIONNAIRE, archived: false).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order("updated_at #{order}") end def self.waiting_for_user order = 'ASC' - where(state: WAITING_FOR_USER, archived: false).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_USER).order("updated_at #{order}") end scope :en_construction, -> { where(state: EN_CONSTRUCTION) } def self.ouvert order = 'ASC' - where(state: OUVERT, archived: false).order("updated_at #{order}") + not_archived.where(state: OUVERT).order("updated_at #{order}") end def self.a_instruire order = 'ASC' - where(state: A_INSTRUIRE, archived: false).order("updated_at #{order}") + not_archived.where(state: A_INSTRUIRE).order("updated_at #{order}") end scope :en_instruction, -> { where(state: EN_INSTRUCTION) } From 5253f07b69b7ee09add6ad78e4143709d6f5e0cb Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:12:25 +0200 Subject: [PATCH 064/131] Use the order_by_updated_at scope in Dossier --- app/models/dossier.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a919aec27..607254391 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -159,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.not_archived.order("updated_at #{order}") + not_brouillon.not_archived.order_by_updated_at(order) end def brouillon? @@ -172,25 +172,25 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } def self.nouveaux order = 'ASC' - not_archived.where(state: NOUVEAUX).order("updated_at #{order}") + not_archived.where(state: NOUVEAUX).order_by_updated_at(order) end def self.waiting_for_gestionnaire order = 'ASC' - not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) end def self.waiting_for_user order = 'ASC' - not_archived.where(state: WAITING_FOR_USER).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) end scope :en_construction, -> { where(state: EN_CONSTRUCTION) } def self.ouvert order = 'ASC' - not_archived.where(state: OUVERT).order("updated_at #{order}") + not_archived.where(state: OUVERT).order_by_updated_at(order) end def self.a_instruire order = 'ASC' - not_archived.where(state: A_INSTRUIRE).order("updated_at #{order}") + not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) end scope :en_instruction, -> { where(state: EN_INSTRUCTION) } From 4655707eb5d28dc49329930ef7c813c04e3cdc1f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:14:00 +0200 Subject: [PATCH 065/131] [Fix #319] Include archived dossiers in the export --- app/models/dossier.rb | 2 +- spec/models/dossier_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 607254391..3fd21c1c0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -200,7 +200,7 @@ class Dossier < ActiveRecord::Base scope :archived, -> { where(archived: true) } scope :not_archived, -> { where(archived: false) } - scope :downloadable, -> { all_state } + scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e964e4b0d..8b9c8244a 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -911,11 +911,13 @@ describe Dossier do let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) } let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) } let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received) } + let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true) } subject { procedure.dossiers.downloadable } it { is_expected.not_to include(dossier)} it { is_expected.to include(dossier2)} it { is_expected.to include(dossier3)} + it { is_expected.to include(dossier4)} end end From 9d478609d071db68998b27b7d1eadfe5fbef4909 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:30:11 +0200 Subject: [PATCH 066/131] Move the Procedure scopes at the top --- app/models/procedure.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 864b3fcc3..412a9ff9b 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -24,6 +24,9 @@ class Procedure < ActiveRecord::Base mount_uploader :logo, ProcedureLogoUploader + scope :not_archived, -> { where(archived: false) } + scope :by_libelle, -> { order(libelle: :asc) } + validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false @@ -46,10 +49,6 @@ class Procedure < ActiveRecord::Base alias_method_chain "#{name.underscore.to_sym}".to_s, :override end - scope :not_archived, -> { where(archived: false) } - scope :by_libelle, -> { order(libelle: :asc) } - - def path procedure_path.path unless procedure_path.nil? end From 258a80b0d77bbedaec72e4bec0556e95fc3cadd6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:31:31 +0200 Subject: [PATCH 067/131] Use the Procedure not_archived scope --- app/models/procedure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 412a9ff9b..6e31a70ad 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -66,7 +66,7 @@ class Procedure < ActiveRecord::Base end def self.active id - Procedure.where(archived: false, published: true).find(id) + not_archived.where(published: true).find(id) end def switch_types_de_champ index_of_first_element From 843bb9fd2cc6c655d2e8f7fcdac998a3b8119fbe Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:31:51 +0200 Subject: [PATCH 068/131] Format the User loged_in_with_france_connect enum correctly --- app/models/user.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7ea29d260..3c7574789 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,8 @@ class User < ActiveRecord::Base - enum loged_in_with_france_connect: {particulier: 'particulier', - entreprise: 'entreprise'} + enum loged_in_with_france_connect: { + particulier: 'particulier', + entreprise: 'entreprise' + } # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable From 9f6edc5d1ec71399a744604e20a15639e9885228 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:35:36 +0200 Subject: [PATCH 069/131] Format the TypeDeChamp type_champs enum correctly --- app/models/type_de_champ.rb | 42 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index dcdf0a102..86747bc5a 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -1,26 +1,26 @@ class TypeDeChamp < ActiveRecord::Base enum type_champs: { - text: 'text', - textarea: 'textarea', - date: 'date', - datetime: 'datetime', - number: 'number', - checkbox: 'checkbox', - civilite: 'civilite', - email: 'email', - phone: 'phone', - address: 'address', - yes_no: 'yes_no', - drop_down_list: 'drop_down_list', - multiple_drop_down_list: 'multiple_drop_down_list', - pays: 'pays', - regions: 'regions', - departements: 'departements', - engagement: 'engagement', - header_section: 'header_section', - explication: 'explication', - dossier_link: 'dossier_link' - } + text: 'text', + textarea: 'textarea', + date: 'date', + datetime: 'datetime', + number: 'number', + checkbox: 'checkbox', + civilite: 'civilite', + email: 'email', + phone: 'phone', + address: 'address', + yes_no: 'yes_no', + drop_down_list: 'drop_down_list', + multiple_drop_down_list: 'multiple_drop_down_list', + pays: 'pays', + regions: 'regions', + departements: 'departements', + engagement: 'engagement', + header_section: 'header_section', + explication: 'explication', + dossier_link: 'dossier_link' + } belongs_to :procedure From d47e8b370298ec6ad9b6f47be98d03882b755f72 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:32:43 +0200 Subject: [PATCH 070/131] Reformat Notification correctly --- app/models/notification.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 0740ee823..53d8af02d 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,12 +1,14 @@ class Notification < ActiveRecord::Base - belongs_to :dossier enum type_notif: { - commentaire: 'commentaire', - cerfa: 'cerfa', - piece_justificative: 'piece_justificative', - champs: 'champs', - submitted: 'submitted', - avis: 'avis' - } + commentaire: 'commentaire', + cerfa: 'cerfa', + piece_justificative: 'piece_justificative', + champs: 'champs', + submitted: 'submitted', + avis: 'avis' + } + + belongs_to :dossier + scope :unread, -> { where(already_read: false) } end From 04845efdfc7b6d5a245a849b2d5d87e94ade878b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:34:50 +0200 Subject: [PATCH 071/131] Remove inconsistent and useless blank lines in models --- app/models/administrateur.rb | 1 - app/models/entreprise.rb | 1 - app/models/etablissement.rb | 1 - app/models/exercice.rb | 1 - app/models/france_connect_particulier_client.rb | 1 - app/models/user.rb | 1 - 6 files changed, 6 deletions(-) diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index ab69d0339..731e5df5c 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -27,5 +27,4 @@ class Administrateur < ActiveRecord::Base break token unless Administrateur.find_by(api_token: token) end end - end diff --git a/app/models/entreprise.rb b/app/models/entreprise.rb index 8e14d7640..5e24a31bb 100644 --- a/app/models/entreprise.rb +++ b/app/models/entreprise.rb @@ -1,5 +1,4 @@ class Entreprise < ActiveRecord::Base - belongs_to :dossier has_one :etablissement, dependent: :destroy has_one :rna_information, dependent: :destroy diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 1e80b4bad..44e840205 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -1,5 +1,4 @@ class Etablissement < ActiveRecord::Base - belongs_to :dossier belongs_to :entreprise diff --git a/app/models/exercice.rb b/app/models/exercice.rb index e6ec6a4cb..6b002c092 100644 --- a/app/models/exercice.rb +++ b/app/models/exercice.rb @@ -2,5 +2,4 @@ class Exercice < ActiveRecord::Base belongs_to :etablissement validates :ca, presence: true, allow_blank: false, allow_nil: false - end diff --git a/app/models/france_connect_particulier_client.rb b/app/models/france_connect_particulier_client.rb index 967ab84bd..bc0e99e9c 100644 --- a/app/models/france_connect_particulier_client.rb +++ b/app/models/france_connect_particulier_client.rb @@ -1,5 +1,4 @@ class FranceConnectParticulierClient < OpenIDConnect::Client - def initialize params={} super( identifier: FRANCE_CONNECT.particulier_identifier, diff --git a/app/models/user.rb b/app/models/user.rb index 3c7574789..c4dab2a5f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -37,5 +37,4 @@ class User < ActiveRecord::Base def invite? dossier_id invites.pluck(:dossier_id).include?(dossier_id.to_i) end - end From d54fe12a9c88abe30876a466ed713b27fdeb9612 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:39:09 +0200 Subject: [PATCH 072/131] Remove inconsistent and useless blank lines in controllers --- app/controllers/api/statistiques_controller.rb | 1 - app/controllers/api/v1/dossiers_controller.rb | 1 - app/controllers/backoffice/dossiers/procedure_controller.rb | 1 - app/controllers/backoffice_controller.rb | 1 - app/controllers/france_connect/particulier_controller.rb | 1 - app/controllers/ping_controller.rb | 2 -- app/controllers/root_controller.rb | 1 - app/controllers/sessions/sessions_controller.rb | 1 - app/controllers/users/carte_controller.rb | 1 - app/controllers/users/dossiers/invites_controller.rb | 1 - app/controllers/users/recapitulatif_controller.rb | 1 - 11 files changed, 12 deletions(-) diff --git a/app/controllers/api/statistiques_controller.rb b/app/controllers/api/statistiques_controller.rb index b920f47c6..fe12ffa2a 100644 --- a/app/controllers/api/statistiques_controller.rb +++ b/app/controllers/api/statistiques_controller.rb @@ -1,5 +1,4 @@ class API::StatistiquesController < ApplicationController - def dossiers_stats render json: { total: total_dossiers, diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index b2010c0f9..ddafcf82c 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -1,5 +1,4 @@ class API::V1::DossiersController < APIController - api :GET, '/procedures/:procedure_id/dossiers/', 'Liste de tous les dossiers d\'une procédure' param :procedure_id, Integer, desc: "L'identifiant de la procédure", required: true param :token, String, desc: "Token administrateur", required: true diff --git a/app/controllers/backoffice/dossiers/procedure_controller.rb b/app/controllers/backoffice/dossiers/procedure_controller.rb index 88bcf6536..5f96c1508 100644 --- a/app/controllers/backoffice/dossiers/procedure_controller.rb +++ b/app/controllers/backoffice/dossiers/procedure_controller.rb @@ -1,5 +1,4 @@ class Backoffice::Dossiers::ProcedureController < Backoffice::DossiersListController - def index super diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb index fa77609d3..5f426be36 100644 --- a/app/controllers/backoffice_controller.rb +++ b/app/controllers/backoffice_controller.rb @@ -25,5 +25,4 @@ class BackofficeController < ApplicationController partial: 'backoffice/dossiers/list_invitations', array: true end - end diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index a625d0440..1fd9e507f 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -1,5 +1,4 @@ class FranceConnect::ParticulierController < ApplicationController - def login client = FranceConnectParticulierClient.new diff --git a/app/controllers/ping_controller.rb b/app/controllers/ping_controller.rb index 361adb56c..5848f722c 100644 --- a/app/controllers/ping_controller.rb +++ b/app/controllers/ping_controller.rb @@ -1,5 +1,4 @@ class PingController < ApplicationController - def index Rails.logger.silence do if (ActiveRecord::Base.connected?) @@ -9,5 +8,4 @@ class PingController < ApplicationController end end end - end diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index fec3780b4..70684f99e 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -1,6 +1,5 @@ class RootController < ApplicationController def index - begin route = Rails.application.routes.recognize_path(request.referrer) rescue ActionController::RoutingError diff --git a/app/controllers/sessions/sessions_controller.rb b/app/controllers/sessions/sessions_controller.rb index d288616c3..e30c51fc8 100644 --- a/app/controllers/sessions/sessions_controller.rb +++ b/app/controllers/sessions/sessions_controller.rb @@ -1,5 +1,4 @@ class Sessions::SessionsController < Devise::SessionsController - before_action :before_sign_in, only: [:create] def before_sign_in diff --git a/app/controllers/users/carte_controller.rb b/app/controllers/users/carte_controller.rb index f38f52ab5..3c10c7df9 100644 --- a/app/controllers/users/carte_controller.rb +++ b/app/controllers/users/carte_controller.rb @@ -1,5 +1,4 @@ class Users::CarteController < UsersController - before_action only: [:show] do authorized_routes? self.class end diff --git a/app/controllers/users/dossiers/invites_controller.rb b/app/controllers/users/dossiers/invites_controller.rb index c10f93d0a..c890dc6c8 100644 --- a/app/controllers/users/dossiers/invites_controller.rb +++ b/app/controllers/users/dossiers/invites_controller.rb @@ -1,5 +1,4 @@ class Users::Dossiers::InvitesController < UsersController - def authenticate_user! session["user_return_to"] = request.fullpath return redirect_to new_user_registration_path(user_email: params[:email]) if !params[:email].blank? && User.find_by_email(params[:email]).nil? diff --git a/app/controllers/users/recapitulatif_controller.rb b/app/controllers/users/recapitulatif_controller.rb index 8315380c8..88dd4d2f8 100644 --- a/app/controllers/users/recapitulatif_controller.rb +++ b/app/controllers/users/recapitulatif_controller.rb @@ -1,5 +1,4 @@ class Users::RecapitulatifController < UsersController - before_action only: [:show] do authorized_routes? self.class end From 9268da82362842b2c7cf9a013bfafd1ae5d2ecad Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:43:44 +0200 Subject: [PATCH 073/131] Refactor Procedure#switch_list_order --- app/models/procedure.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 6e31a70ad..0c33a5e94 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -82,12 +82,17 @@ class Procedure < ActiveRecord::Base end def switch_list_order(list, index_of_first_element) - return false if index_of_first_element < 0 - return false if index_of_first_element == list.count - 1 - return false if list.count < 1 - list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1) - list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element) - true + if index_of_first_element < 0 || + index_of_first_element == list.count - 1 || + list.count < 1 + + false + else + list[index_of_first_element].update_attributes(order_place: index_of_first_element + 1) + list[index_of_first_element + 1].update_attributes(order_place: index_of_first_element) + + true + end end def locked? From b5f1b898c7384bf86b273642aee8e3cff8cc14fe Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 9 May 2017 17:09:35 +0200 Subject: [PATCH 074/131] Add the weekly avis usage to Stats --- app/assets/stylesheets/new_design/stats.scss | 14 +++++++++++-- app/controllers/stats_controller.rb | 21 ++++++++++++++++++++ app/views/stats/index.html.haml | 10 ++++++++++ spec/controllers/stats_controller_spec.rb | 14 +++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/new_design/stats.scss b/app/assets/stylesheets/new_design/stats.scss index 5b32a7a24..2f0b4f37a 100644 --- a/app/assets/stylesheets/new_design/stats.scss +++ b/app/assets/stylesheets/new_design/stats.scss @@ -6,15 +6,25 @@ $blue-hover: rgba(61, 149, 236, 0.8); $default-space: 15px; $new-h1-margin-bottom: 4 * $default-space; +$new-h2-margin-bottom: 3 * $default-space; -.new-h1 { +.new-h1, +.new-h2 { color: $dark-grey; text-align: center; - margin-bottom: $new-h1-margin-bottom; font-weight: bold; +} + +.new-h1 { + margin-bottom: $new-h1-margin-bottom; font-size: 41px; } +.new-h2 { + margin-bottom: $new-h2-margin-bottom; + font-size: 36px; +} + $statistiques-padding-top: $default-space * 2; .statistiques { diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 817c39ee3..d2810536d 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -20,6 +20,8 @@ class StatsController < ApplicationController @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) + + @avis_usage = avis_usage end private @@ -144,4 +146,23 @@ class StatsController < ApplicationController [month, month_average] end.to_h end + + def avis_usage + [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + max_date = min_date + 1.week + + weekly_dossiers = Dossier.includes(:avis).where(created_at: min_date..max_date).to_a + + weekly_dossiers_count = weekly_dossiers.count + + if weekly_dossiers_count == 0 + result = 0 + else + weekly_dossier_with_avis_count = weekly_dossiers.select { |dossier| dossier.avis.present? }.count + result = ((weekly_dossier_with_avis_count.to_f / weekly_dossiers_count) * 100).round(2) + end + + [min_date.to_i, result] + end + end end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index fe01a39cd..3467b94a6 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -77,3 +77,13 @@ :colors => ["rgba(61, 149, 236, 1)"] .clearfix + + - if administration_signed_in? + %h2.new-h2 Avis + + .stat-cards + .stat-card.stat-card-half.pull-left + %span.stat-card-title Taux d'utilisation des avis + = line_chart @avis_usage, ytitle: 'dossiers avec avis / total dossiers', xtitle: 'semaines' + + .clearfix diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 4a475fb30..57e198195 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -210,4 +210,18 @@ describe StatsController, type: :controller do it { expect(subject).to eq(@expected_hash) } end + + describe '#avis_usage' do + let!(:dossier) { create(:dossier) } + let!(:avis_with_dossier) { create(:avis) } + let!(:dossier2) { create(:dossier) } + + before do + Timecop.freeze(Time.now) + end + + subject { StatsController.new.send(:avis_usage) } + + it { expect(subject).to match([[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 33.33]]) } + end end From 068b635b7cfe9b601ae8ff359ac021dd7af115bb Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 9 May 2017 18:11:58 +0200 Subject: [PATCH 075/131] Add the weekly avis answer time average to Stats --- app/controllers/stats_controller.rb | 15 ++++++++++++++ app/models/avis.rb | 2 +- app/views/stats/index.html.haml | 4 ++++ spec/controllers/stats_controller_spec.rb | 25 +++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index d2810536d..cb5fe18fd 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -22,6 +22,7 @@ class StatsController < ApplicationController @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) @avis_usage = avis_usage + @avis_average_answer_time = avis_average_answer_time end private @@ -165,4 +166,18 @@ class StatsController < ApplicationController [min_date.to_i, result] end end + + def avis_average_answer_time + [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + max_date = min_date + 1.week + + average = Avis.with_answer + .where(created_at: min_date..max_date) + .average("EXTRACT(EPOCH FROM updated_at - created_at) / 86400") + + result = average ? average.to_f.round(2) : 0 + + [min_date.to_i, result] + end + end end diff --git a/app/models/avis.rb b/app/models/avis.rb index 59eff74fc..dfbebbc23 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -22,7 +22,7 @@ class Avis < ApplicationRecord Avis.where(email: gestionnaire.email).update_all(email: nil, gestionnaire_id: gestionnaire.id) end - def self.avis_exists_and_email_belongs_to_avis?(avis_id, email) + def self.avis_exists_and_email_belongs_to_avis?(avis_id, email) avis = Avis.find_by(id: avis_id) avis.present? && avis.email == email end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 3467b94a6..47ab748b4 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -86,4 +86,8 @@ %span.stat-card-title Taux d'utilisation des avis = line_chart @avis_usage, ytitle: 'dossiers avec avis / total dossiers', xtitle: 'semaines' + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de réponse moyen par avis + = line_chart @avis_average_answer_time, ytitle: 'jours', xtitle: 'semaines' + .clearfix diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 57e198195..f5fcffe5c 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -224,4 +224,29 @@ describe StatsController, type: :controller do it { expect(subject).to match([[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 33.33]]) } end + + describe "#avis_average_answer_time" do + before do + # 1 week ago + create(:avis, answer: "voila ma réponse", created_at: 1.week.ago + 1.day, updated_at: 1.week.ago + 2.days) # 1 day + create(:avis, created_at: 1.week.ago + 2.days) + + # 2 weeks ago + create(:avis, answer: "voila ma réponse", created_at: 2.week.ago + 1.day, updated_at: 2.week.ago + 2.days) # 1 day + create(:avis, answer: "voila ma réponse2", created_at: 2.week.ago + 3.days, updated_at: 1.week.ago + 6.days) # 10 days + create(:avis, answer: "voila ma réponse2", created_at: 2.week.ago + 2.days, updated_at: 1.week.ago + 6.days) # 11 days + create(:avis, created_at: 2.week.ago + 1.day, updated_at: 2.week.ago + 2.days) + + # 3 weeks ago + create(:avis, answer: "voila ma réponse2", created_at: 3.weeks.ago + 1.day, updated_at: 3.weeks.ago + 2.days) # 1 day + create(:avis, answer: "voila ma réponse2", created_at: 3.weeks.ago + 1.day, updated_at: 1.week.ago + 5.days) # 18 day + end + + subject { StatsController.new.send(:avis_average_answer_time) } + + it { expect(subject.count).to eq(3) } + it { is_expected.to include [1.week.ago.to_i, 1.0] } + it { is_expected.to include [2.week.ago.to_i, 7.33] } + it { is_expected.to include [3.week.ago.to_i, 9.5] } + end end From 9e6098dc096699bf9082310e6565e344b339fbdc Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 10 May 2017 11:07:38 +0200 Subject: [PATCH 076/131] Add the weekly avis answer percentage to Stats --- app/controllers/stats_controller.rb | 20 ++++++++++++++++++++ app/views/stats/index.html.haml | 4 ++++ spec/controllers/stats_controller_spec.rb | 14 ++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index cb5fe18fd..36a95df9b 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -23,6 +23,7 @@ class StatsController < ApplicationController @avis_usage = avis_usage @avis_average_answer_time = avis_average_answer_time + @avis_answer_percentages = avis_answer_percentages end private @@ -180,4 +181,23 @@ class StatsController < ApplicationController [min_date.to_i, result] end end + + def avis_answer_percentages + [3.week.ago, 2.week.ago, 1.week.ago].map do |min_date| + max_date = min_date + 1.week + + weekly_avis = Avis.where(created_at: min_date..max_date) + + weekly_avis_count = weekly_avis.count + + if weekly_avis_count == 0 + [min_date.to_i, 0] + else + answered_weekly_avis_count = weekly_avis.with_answer.count + result = ((answered_weekly_avis_count.to_f / weekly_avis_count) * 100).round(2) + + [min_date.to_i, result] + end + end + end end diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 47ab748b4..753a893ae 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -90,4 +90,8 @@ %span.stat-card-title Temps de réponse moyen par avis = line_chart @avis_average_answer_time, ytitle: 'jours', xtitle: 'semaines' + .stat-card.stat-card-half.pull-left + %span.stat-card-title Pourcentage d'avis rempli + = line_chart @avis_answer_percentages, ytitle: 'avis avec reponse / total avis', xtitle: 'semaines' + .clearfix diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index f5fcffe5c..d574fde07 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -249,4 +249,18 @@ describe StatsController, type: :controller do it { is_expected.to include [2.week.ago.to_i, 7.33] } it { is_expected.to include [3.week.ago.to_i, 9.5] } end + + describe '#avis_answer_percentages' do + let!(:avis) { create(:avis, created_at: 2.days.ago) } + let!(:avis2) { create(:avis, answer: 'answer', created_at: 2.days.ago) } + let!(:avis3) { create(:avis, answer: 'answer', created_at: 2.days.ago) } + + subject { StatsController.new.send(:avis_answer_percentages) } + + before do + Timecop.freeze(Time.now) + end + + it { is_expected.to match [[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 66.67]] } + end end From c185f60dd2ff2c3488bb2f679bddb79f049ce933 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 31 May 2017 14:10:16 +0200 Subject: [PATCH 077/131] Avis: ugly workaround for #375 --- app/views/dossiers/_avis.html.haml | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/views/dossiers/_avis.html.haml b/app/views/dossiers/_avis.html.haml index 80c896070..489130448 100644 --- a/app/views/dossiers/_avis.html.haml +++ b/app/views/dossiers/_avis.html.haml @@ -35,18 +35,22 @@ %hr .center %em Avis en attente - .hidden-print - .panel.panel-default - .panel-heading - Demander un avis externe - .panel-body - .help-block - Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci. - %br - Cette personne pourra également contribuer au fil de messagerie, mais ne pourra pas modifier le dossier. - = simple_form_for @new_avis, url: backoffice_dossier_avis_index_path(dossier_facade.dossier.object.id) do |f| - = f.input 'email', label: "Email de la personne qui doit donner un avis" - = f.input 'introduction', label: "Message" + -# FIXME prevent bug when the user is also a gestionnaire on the procedure #375 + - if @new_avis.present? + .hidden-print + .panel.panel-default + .panel-heading + Demander un avis externe + .panel-body + .help-block + Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci. + %br + Cette personne pourra également contribuer au fil de messagerie, mais ne pourra pas modifier le dossier. - = f.submit "Envoyer la demande d'avis", class: 'btn btn-default' + = simple_form_for @new_avis, url: backoffice_dossier_avis_index_path(dossier_facade.dossier.object.id) do |f| + + = f.input 'email', label: "Email de la personne qui doit donner un avis" + = f.input 'introduction', label: "Message" + + = f.submit "Envoyer la demande d'avis", class: 'btn btn-default' From a348d95057112d120885542f5b95e26f3566e0a9 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 31 May 2017 17:03:51 +0200 Subject: [PATCH 078/131] [Fix #77] Staging is dead => change the CI and deploy info Use develop instead --- .circleci/config.yml | 2 +- config/deploy.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 90725ad32..45417e72c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: - "0a:67:42:7d:7e:b7:e1:3c:48:8f:bf:68:10:51:a8:44" - deploy: command: | - if [ "${CIRCLE_BRANCH}" == "staging" ]; then + if [ "${CIRCLE_BRANCH}" == "develop" ]; then bundle exec rake deploy_ha fi diff --git a/config/deploy.rb b/config/deploy.rb index eae817ea8..68315835c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -27,7 +27,7 @@ set :deploy_to, '/var/www/tps_dev' case ENV["to"] when "staging" if ENV['branch'].nil? - set :branch, 'staging' + set :branch, 'develop' else set :branch, ENV['branch'] end From 46c0e04b0c7a5f4442e4a091512811bff637c963 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 31 May 2017 17:22:30 +0200 Subject: [PATCH 079/131] Save 8 lines of code --- config/deploy.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 68315835c..24bcfe12e 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -26,20 +26,12 @@ set :deploy_to, '/var/www/tps_dev' case ENV["to"] when "staging" - if ENV['branch'].nil? - set :branch, 'develop' - else - set :branch, ENV['branch'] - end + set :branch, ENV['branch'] || 'develop' set :deploy_to, '/var/www/tps_dev' set :user, 'tps_dev' # Username in the server to SSH to. appname = 'tps_dev' when "production" - if ENV['branch'].nil? - set :branch, 'master' - else - set :branch, ENV['branch'] - end + set :branch, ENV['branch'] || 'master' set :deploy_to, '/var/www/tps' set :user, 'tps' # Username in the server to SSH to. appname = 'tps' From a7969e550782764d38fe3530502144f619bcb051 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 31 May 2017 17:24:16 +0200 Subject: [PATCH 080/131] Branch value in log is now correct --- config/deploy.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 24bcfe12e..ef1d6b4e1 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -15,7 +15,6 @@ raise "Bad to=#{+ENV['to']}" unless ["staging", "production"].include?(ENV['to'] raise "missing domain, run with 'rake deploy domain=37.187.154.237'" if ENV['domain'].nil? -print "Deploy to #{ENV['to']} environment branch #{branch}\n" # set :domain, '5.135.190.60' set :domain, ENV['domain'] @@ -37,6 +36,8 @@ when "production" appname = 'tps' end +print "Deploy to #{ENV['to']} environment branch #{branch}\n" + set :rails_env, ENV["to"] # For system-wide RVM install. From 705a3f3e1bf564ea8672a5ea56f0d257c1e745f0 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 1 Jun 2017 09:44:22 +0200 Subject: [PATCH 081/131] Fix cache bug on stats page --- app/controllers/stats_controller.rb | 9 +++++++-- app/views/stats/index.html.haml | 31 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 36a95df9b..eb96939c1 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -18,8 +18,13 @@ class StatsController < ApplicationController @procedures_count_per_administrateur = procedures_count_per_administrateur(procedures) - @dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers) - @dossier_filling_mean_time = dossier_filling_mean_time(dossiers) + @dossier_instruction_mean_time = Rails.cache.fetch("dossier_instruction_mean_time", expires_in: 1.day) do + dossier_instruction_mean_time(dossiers) + end + + @dossier_filling_mean_time = Rails.cache.fetch("dossier_filling_mean_time", expires_in: 1.day) do + dossier_filling_mean_time(dossiers) + end @avis_usage = avis_usage @avis_average_answer_time = avis_average_answer_time diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 753a893ae..8a63be266 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -57,24 +57,23 @@ :colors => ["rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"] - if administration_signed_in? - - cache "computation-heavy-stats", :expires_in => 1.day do - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de traitement moyen d'un dossier + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de traitement moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_instruction_mean_time, - :ytitle => "Jours", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_instruction_mean_time, + :ytitle => "Jours", + :colors => ["rgba(61, 149, 236, 1)"] - .stat-card.stat-card-half.pull-left - %span.stat-card-title Temps de remplissage moyen d'un dossier + .stat-card.stat-card-half.pull-left + %span.stat-card-title Temps de remplissage moyen d'un dossier - .chart-container - .chart - = line_chart @dossier_filling_mean_time, - :ytitle => "Minutes", - :colors => ["rgba(61, 149, 236, 1)"] + .chart-container + .chart + = line_chart @dossier_filling_mean_time, + :ytitle => "Minutes", + :colors => ["rgba(61, 149, 236, 1)"] .clearfix @@ -92,6 +91,6 @@ .stat-card.stat-card-half.pull-left %span.stat-card-title Pourcentage d'avis rempli - = line_chart @avis_answer_percentages, ytitle: 'avis avec reponse / total avis', xtitle: 'semaines' + = line_chart @avis_answer_percentages, ytitle: 'avis avec réponse / total avis', xtitle: 'semaines' .clearfix From d2d2c7846142cb47f59383cd44067dfa0b2adb02 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 31 May 2017 14:30:26 +0200 Subject: [PATCH 082/131] Remove unused code --- app/controllers/root_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 70684f99e..6af19d477 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -38,8 +38,6 @@ class RootController < ApplicationController return redirect_to administrations_path end - @demo_environment_host = "https://tps-dev.apientreprise.fr" unless Rails.env.development? - render 'landing', :layout => 'new_application' end end From 8e9144f565d7b90cd2365818d4ed754e7328dc30 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 31 May 2017 15:27:20 +0200 Subject: [PATCH 083/131] [Fix #378] Remove redirect based on referrer --- app/controllers/root_controller.rb | 14 +------------- spec/controllers/root_controller_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 6af19d477..6736fc88c 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -1,15 +1,6 @@ class RootController < ApplicationController def index - begin - route = Rails.application.routes.recognize_path(request.referrer) - rescue ActionController::RoutingError - route = Rails.application.routes.recognize_path(new_user_session_path) - end - - if user_signed_in? && !route[:controller].match('users').nil? - return redirect_to users_dossiers_path - - elsif administrateur_signed_in? && !route[:controller].match('admin').nil? + if administrateur_signed_in? return redirect_to admin_procedures_path elsif gestionnaire_signed_in? @@ -31,9 +22,6 @@ class RootController < ApplicationController elsif user_signed_in? return redirect_to users_dossiers_path - elsif administrateur_signed_in? - return redirect_to admin_procedures_path - elsif administration_signed_in? return redirect_to administrations_path end diff --git a/spec/controllers/root_controller_spec.rb b/spec/controllers/root_controller_spec.rb index 474f03dfd..9b0b7ed56 100644 --- a/spec/controllers/root_controller_spec.rb +++ b/spec/controllers/root_controller_spec.rb @@ -45,6 +45,14 @@ describe RootController, type: :controller do it { expect(subject).to redirect_to(admin_procedures_path) } end + context 'when Administration is connected' do + before do + sign_in create(:administration) + end + + it { expect(subject).to redirect_to(administrations_path) } + end + context 'when nobody is connected' do render_views From 6731f28e23fea24d4ef114e47338a7d8f26db3e4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:22:31 +0200 Subject: [PATCH 084/131] Move the state constants below the state enum --- app/models/dossier.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 3fd21c1c0..aa40a5410 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -9,6 +9,16 @@ class Dossier < ActiveRecord::Base without_continuation: 'without_continuation' } + BROUILLON = %w(draft) + NOUVEAUX = %w(initiated) + OUVERT = %w(updated replied) + WAITING_FOR_GESTIONNAIRE = %w(updated) + WAITING_FOR_USER = %w(replied) + EN_CONSTRUCTION = %w(initiated updated replied) + EN_INSTRUCTION = %w(received) + A_INSTRUIRE = %w(received) + TERMINE = %w(closed refused without_continuation) + has_one :etablissement, dependent: :destroy has_one :entreprise, dependent: :destroy has_one :individual, dependent: :destroy @@ -45,16 +55,6 @@ class Dossier < ActiveRecord::Base validates :user, presence: true - BROUILLON = %w(draft) - NOUVEAUX = %w(initiated) - OUVERT = %w(updated replied) - WAITING_FOR_GESTIONNAIRE = %w(updated) - WAITING_FOR_USER = %w(replied) - EN_CONSTRUCTION = %w(initiated updated replied) - EN_INSTRUCTION = %w(received) - A_INSTRUIRE = %w(received) - TERMINE = %w(closed refused without_continuation) - def unreaded_notifications @unreaded_notif ||= notifications.where(already_read: false) end From 1816aef7d0280f27c902dee91506f0c654701622 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:23:16 +0200 Subject: [PATCH 085/131] Group the Dossier scopes and move them at the top --- app/models/dossier.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index aa40a5410..12b46bf33 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -40,6 +40,19 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user + scope :brouillon, -> { where(state: BROUILLON) } + scope :not_brouillon, -> { where.not(state: BROUILLON) } + scope :en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :termine, -> { where(state: TERMINE) } + + scope :archived, -> { where(archived: true) } + scope :not_archived, -> { where(archived: false) } + + scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } + + scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } + accepts_nested_attributes_for :individual delegate :siren, to: :entreprise @@ -166,11 +179,6 @@ class Dossier < ActiveRecord::Base BROUILLON.include?(state) end - scope :brouillon, -> { where(state: BROUILLON) } - scope :not_brouillon, -> { where.not(state: BROUILLON) } - - scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - def self.nouveaux order = 'ASC' not_archived.where(state: NOUVEAUX).order_by_updated_at(order) end @@ -183,8 +191,6 @@ class Dossier < ActiveRecord::Base not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) end - scope :en_construction, -> { where(state: EN_CONSTRUCTION) } - def self.ouvert order = 'ASC' not_archived.where(state: OUVERT).order_by_updated_at(order) end @@ -193,15 +199,6 @@ class Dossier < ActiveRecord::Base not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) end - scope :en_instruction, -> { where(state: EN_INSTRUCTION) } - - scope :termine, -> { where(state: TERMINE) } - - scope :archived, -> { where(archived: true) } - scope :not_archived, -> { where(archived: false) } - - scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } - def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 end From 51dd6df1c0e99a1f217ba50573f900b9946f8ba8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:27:51 +0200 Subject: [PATCH 086/131] Improve the formatting of the Dossier state enum --- app/models/dossier.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 12b46bf33..ab75d7608 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,13 +1,14 @@ class Dossier < ActiveRecord::Base - enum state: {draft: 'draft', - initiated: 'initiated', - replied: 'replied', #action utilisateur demandé - updated: 'updated', #etude par l'administration en cours - received: 'received', - closed: 'closed', - refused: 'refused', - without_continuation: 'without_continuation' - } + enum state: { + draft: 'draft', + initiated: 'initiated', + replied: 'replied', # action utilisateur demandé + updated: 'updated', # etude par l'administration en cours + received: 'received', + closed: 'closed', + refused: 'refused', + without_continuation: 'without_continuation' + } BROUILLON = %w(draft) NOUVEAUX = %w(initiated) From ab1c19c09bf1691a1e2570b25b90cb310f1f281c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:59:21 +0200 Subject: [PATCH 087/131] Rename some Dossier scopes --- app/controllers/users/dossiers_controller.rb | 8 ++++---- app/models/dossier.rb | 14 +++++++------- app/services/dossiers_list_gestionnaire_service.rb | 2 +- ..._panel_users_dossierscontroller_index.html.haml | 8 ++++---- app/workers/auto_archive_procedure_worker.rb | 2 +- spec/models/dossier_spec.rb | 4 ++-- .../dossiers_list_gestionnaire_service_spec.rb | 2 +- spec/views/users/dossiers/index_html.haml_spec.rb | 7 +++---- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8f42f2581..1d9964d72 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -16,13 +16,13 @@ class Users::DossiersController < UsersController @dossiers_filtered = case @liste when 'brouillon' - @user_dossiers.brouillon.order_by_updated_at + @user_dossiers.state_brouillon.order_by_updated_at when 'a_traiter' - @user_dossiers.en_construction.order_by_updated_at + @user_dossiers.state_en_construction.order_by_updated_at when 'en_instruction' - @user_dossiers.en_instruction.order_by_updated_at + @user_dossiers.state_en_instruction.order_by_updated_at when 'termine' - @user_dossiers.termine.order_by_updated_at + @user_dossiers.state_termine.order_by_updated_at when 'invite' current_user.invites else diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ab75d7608..91e19fced 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -41,18 +41,18 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user - scope :brouillon, -> { where(state: BROUILLON) } - scope :not_brouillon, -> { where.not(state: BROUILLON) } - scope :en_construction, -> { where(state: EN_CONSTRUCTION) } - scope :en_instruction, -> { where(state: EN_INSTRUCTION) } - scope :termine, -> { where(state: TERMINE) } + scope :state_brouillon, -> { where(state: BROUILLON) } + scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_termine, -> { where(state: TERMINE) } scope :archived, -> { where(archived: true) } scope :not_archived, -> { where(archived: false) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual @@ -173,7 +173,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.not_archived.order_by_updated_at(order) + state_not_brouillon.not_archived.order_by_updated_at(order) end def brouillon? diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 63a91783c..ce349258b 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -45,7 +45,7 @@ class DossiersListGestionnaireService end def termine - @termine ||= filter_dossiers.termine.not_archived + @termine ||= filter_dossiers.state_termine.not_archived end def filter_dossiers diff --git a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml index 9a6fff7a1..9b561f312 100644 --- a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml @@ -15,25 +15,25 @@ .procedure-list-element#brouillon{ class: ('active' if @liste == 'brouillon') } Brouillons .badge.progress-bar-default - = @user_dossiers.brouillon.count + = @user_dossiers.state_brouillon.count %a{ :href => "#{url_for users_dossiers_path(liste: 'a_traiter')}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.' } .procedure-list-element#a_traiter{ class: ('active' if @liste == 'a_traiter') } En construction .badge.progress-bar-danger - = @user_dossiers.en_construction.count + = @user_dossiers.state_en_construction.count %a{ :href => "#{url_for users_dossiers_path(liste: 'en_instruction')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours d\'examen par l\'administration compétante.' } .procedure-list-element#en_instruction{ class: ('active' if @liste == 'en_instruction') } En instruction .badge.progress-bar-default - = @user_dossiers.en_instruction.count + = @user_dossiers.state_en_instruction.count %a{ :href => "#{url_for users_dossiers_path(liste: 'termine')}", 'data-toggle' => :tooltip, title: 'Les dossiers cloturés qui peuvent être "Accepté", "Refusé" ou "Sans suite".' } .procedure-list-element#termine{ class: ('active' if @liste == 'termine') } Terminé .badge.progress-bar-success - = @user_dossiers.termine.count + = @user_dossiers.state_termine.count %a{ :href => "#{url_for users_dossiers_path(liste: 'invite')}" } .procedure-list-element#invite{ class: ('active' if @liste == 'invite') } diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 61701b4ff..71659b5a5 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -5,7 +5,7 @@ class AutoArchiveProcedureWorker procedures_to_archive = Procedure.not_archived.where("auto_archive_on <= ?", Date.today) procedures_to_archive.each do |p| - p.dossiers.en_construction.update_all(state: :received) + p.dossiers.state_en_construction.update_all(state: :received) end procedures_to_archive.update_all(archived: true, auto_archive_on: nil) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8b9c8244a..d301cb42a 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -455,8 +455,8 @@ describe Dossier do it { expect(subject.size).to eq(1) } end - describe '#en_instruction' do - subject { gestionnaire.dossiers.en_instruction } + describe '#state_en_instruction' do + subject { gestionnaire.dossiers.state_en_instruction } it { expect(subject.size).to eq(2) } it { expect(subject).to include(dossier6, dossier7) } diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index d45293868..cabb9da38 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -364,7 +364,7 @@ describe DossiersListGestionnaireService do let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived describe '#termine' do - subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine } + subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).state_termine } it { expect(subject.size).to eq(4) } it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) } diff --git a/spec/views/users/dossiers/index_html.haml_spec.rb b/spec/views/users/dossiers/index_html.haml_spec.rb index 09e787e99..3813456f8 100644 --- a/spec/views/users/dossiers/index_html.haml_spec.rb +++ b/spec/views/users/dossiers/index_html.haml_spec.rb @@ -43,7 +43,7 @@ describe 'users/dossiers/index.html.haml', type: :view do describe 'on tab en construction' do let(:total_dossiers) { 3 } let(:active_class) { '.active .text-danger' } - let(:dossiers_to_display) { user.dossiers.en_construction } + let(:dossiers_to_display) { user.dossiers.state_en_construction } let(:liste) { 'a_traiter' } it_behaves_like 'check_tab_content' do @@ -59,11 +59,10 @@ describe 'users/dossiers/index.html.haml', type: :view do end end - describe 'on tab etude en examen' do let(:total_dossiers) { 1 } let(:active_class) { '.active .text-default' } - let(:dossiers_to_display) { user.dossiers.en_instruction } + let(:dossiers_to_display) { user.dossiers.state_en_instruction } let(:liste) { 'en_instruction' } it_behaves_like 'check_tab_content' do @@ -74,7 +73,7 @@ describe 'users/dossiers/index.html.haml', type: :view do describe 'on tab etude termine' do let(:total_dossiers) { 3 } let(:active_class) { '.active .text-success' } - let(:dossiers_to_display) { user.dossiers.termine } + let(:dossiers_to_display) { user.dossiers.state_termine } let(:liste) { 'termine' } it_behaves_like 'check_tab_content' do From 9c2c0346b6a913c828d37c3150e9015f49cecd75 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:01:20 +0200 Subject: [PATCH 088/131] [Fix #125] Transform some Dossier class methods into scopes --- app/models/dossier.rb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 91e19fced..d6a65ef19 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -52,6 +52,12 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } + scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.where(state: NOUVEAUX).order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.where(state: OUVERT).order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual @@ -172,34 +178,10 @@ class Dossier < ActiveRecord::Base state end - def self.all_state order = 'ASC' - state_not_brouillon.not_archived.order_by_updated_at(order) - end - def brouillon? BROUILLON.include?(state) end - def self.nouveaux order = 'ASC' - not_archived.where(state: NOUVEAUX).order_by_updated_at(order) - end - - def self.waiting_for_gestionnaire order = 'ASC' - not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) - end - - def self.waiting_for_user order = 'ASC' - not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) - end - - def self.ouvert order = 'ASC' - not_archived.where(state: OUVERT).order_by_updated_at(order) - end - - def self.a_instruire order = 'ASC' - not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) - end - def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 end From 7055aec634993cbe38102b34789d51e598f396e7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:32:56 +0200 Subject: [PATCH 089/131] Add some more state scopes and use them --- app/models/dossier.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index d6a65ef19..0ceef148c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -43,8 +43,13 @@ class Dossier < ActiveRecord::Base scope :state_brouillon, -> { where(state: BROUILLON) } scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_nouveaux, -> { where(state: NOUVEAUX) } + scope :state_ouvert, -> { where(state: OUVERT) } + scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } + scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } scope :state_termine, -> { where(state: TERMINE) } scope :archived, -> { where(archived: true) } @@ -53,11 +58,11 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.where(state: NOUVEAUX).order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.where(state: OUVERT).order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From ddac4bbfdb95d5a59eb4b9876c79f44de22526c5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:33:30 +0200 Subject: [PATCH 090/131] Change the order in the all_state scope for consistency --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0ceef148c..bdf28fe36 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -57,7 +57,7 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } + scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } From e0a3a48f762bd87db58bddc4cbc76c0374f134fe Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 1 Jun 2017 11:05:51 +0200 Subject: [PATCH 091/131] Improve the formatting of Dossier scopes --- app/models/dossier.rb | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index bdf28fe36..eaf4486b0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -41,29 +41,29 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user - scope :state_brouillon, -> { where(state: BROUILLON) } - scope :state_not_brouillon, -> { where.not(state: BROUILLON) } - scope :state_nouveaux, -> { where(state: NOUVEAUX) } - scope :state_ouvert, -> { where(state: OUVERT) } - scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } - scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } - scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } - scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } - scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } - scope :state_termine, -> { where(state: TERMINE) } + scope :state_brouillon, -> { where(state: BROUILLON) } + scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_nouveaux, -> { where(state: NOUVEAUX) } + scope :state_ouvert, -> { where(state: OUVERT) } + scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } + scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } + scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } + scope :state_termine, -> { where(state: TERMINE) } - scope :archived, -> { where(archived: true) } - scope :not_archived, -> { where(archived: false) } + scope :archived, -> { where(archived: true) } + scope :not_archived, -> { where(archived: false) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } - scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } + scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From 8fb6a41386732672994f67bad5118a823f191fcd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:41:22 +0200 Subject: [PATCH 092/131] Remove an unused argument in some Dossier scopes --- app/models/dossier.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index eaf4486b0..66a8a0d51 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -57,12 +57,12 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } + scope :all_state, -> { not_archived.state_not_brouillon.order_by_updated_at(:asc) } + scope :nouveaux, -> { not_archived.state_nouveaux.order_by_updated_at(:asc) } + scope :waiting_for_gestionnaire, -> { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(:asc) } + scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } + scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } + scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From 68da2ecbae79da5332232f3711de248a3fce0be4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:45:08 +0200 Subject: [PATCH 093/131] Use symbols instead of strings in for the order arg in scopes --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 66a8a0d51..27e44af56 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -63,7 +63,7 @@ class Dossier < ActiveRecord::Base scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } - scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } accepts_nested_attributes_for :individual From 5e5a01cdc80a024c1c5c9f26be7b50ab1be96a02 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:19:44 +0200 Subject: [PATCH 094/131] Do not test scopes --- spec/models/dossier_spec.rb | 53 ------------------------------------- 1 file changed, 53 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index d301cb42a..b682281b7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -409,59 +409,6 @@ describe Dossier do end end end - - describe 'gestionnaire backoffice methods' do - let(:admin) { create(:administrateur) } - let(:admin_2) { create(:administrateur) } - - let(:gestionnaire) { create(:gestionnaire, administrateurs: [admin]) } - let(:procedure_admin) { create(:procedure, administrateur: admin) } - let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) } - - let!(:dossier) { create(:dossier, procedure: procedure_admin, state: 'draft') } - let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux - let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux - let!(:dossier4) { create(:dossier, procedure: procedure_admin, state: 'replied') } #en_attente - let!(:dossier5) { create(:dossier, procedure: procedure_admin, state: 'updated') } #a_traiter - let!(:dossier6) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire - let!(:dossier7) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire - let!(:dossier8) { create(:dossier, procedure: procedure_admin, state: 'closed') } #termine - let!(:dossier9) { create(:dossier, procedure: procedure_admin, state: 'refused') } #termine - let!(:dossier10) { create(:dossier, procedure: procedure_admin, state: 'without_continuation') } #termine - let!(:dossier11) { create(:dossier, procedure: procedure_admin_2, state: 'closed') } #termine - let!(:dossier12) { create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) } #a_traiter #archived - let!(:dossier13) { create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived - let!(:dossier14) { create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived - - before do - create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin - end - - describe '#nouveaux' do - subject { gestionnaire.dossiers.nouveaux } - - it { expect(subject.size).to eq(2) } - end - - describe '#waiting_for_gestionnaire' do - subject { gestionnaire.dossiers.waiting_for_gestionnaire } - - it { expect(subject.size).to eq(1) } - end - - describe '#waiting_for_user' do - subject { gestionnaire.dossiers.waiting_for_user } - - it { expect(subject.size).to eq(1) } - end - - describe '#state_en_instruction' do - subject { gestionnaire.dossiers.state_en_instruction } - - it { expect(subject.size).to eq(2) } - it { expect(subject).to include(dossier6, dossier7) } - end - end end describe '#cerfa_available?' do From 0971ede57e34d794b6f1a44c3185fa080ed6dfad Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:21:42 +0200 Subject: [PATCH 095/131] Add a termine scope to Dossier --- app/models/dossier.rb | 1 + app/services/dossiers_list_gestionnaire_service.rb | 2 +- spec/services/dossiers_list_gestionnaire_service_spec.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 27e44af56..b37609be4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -63,6 +63,7 @@ class Dossier < ActiveRecord::Base scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } + scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } accepts_nested_attributes_for :individual diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index ce349258b..b110fde11 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -45,7 +45,7 @@ class DossiersListGestionnaireService end def termine - @termine ||= filter_dossiers.state_termine.not_archived + @termine ||= filter_dossiers.termine end def filter_dossiers diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index cabb9da38..d45293868 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -364,7 +364,7 @@ describe DossiersListGestionnaireService do let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived describe '#termine' do - subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).state_termine } + subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine } it { expect(subject.size).to eq(4) } it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) } From d5023a3d3886816affa4e57e402c0a807c5c2cc4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:24:28 +0200 Subject: [PATCH 096/131] Use the same order for constants and scopes in Dossier --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b37609be4..c2b641644 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -59,9 +59,9 @@ class Dossier < ActiveRecord::Base scope :all_state, -> { not_archived.state_not_brouillon.order_by_updated_at(:asc) } scope :nouveaux, -> { not_archived.state_nouveaux.order_by_updated_at(:asc) } + scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :waiting_for_gestionnaire, -> { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(:asc) } scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } - scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } From c52a9791993284999087167c4bc3beb63eec757b Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 1 Jun 2017 17:44:56 +0200 Subject: [PATCH 097/131] Fix email collision in tests --- spec/factories/administrateur.rb | 2 +- spec/factories/gestionnaire.rb | 2 +- spec/factories/user.rb | 2 +- spec/views/admin/gestionnaires/index.html.haml_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/factories/administrateur.rb b/spec/factories/administrateur.rb index 05cfc88a2..f81e5a6a9 100644 --- a/spec/factories/administrateur.rb +++ b/spec/factories/administrateur.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - sequence(:administrateur_email) { |n| "plop#{n}@plop.com" } + sequence(:administrateur_email) { |n| "admin#{n}@admin.com" } factory :administrateur do email { generate(:administrateur_email) } password 'password' diff --git a/spec/factories/gestionnaire.rb b/spec/factories/gestionnaire.rb index 88043eecf..02ee8d5eb 100644 --- a/spec/factories/gestionnaire.rb +++ b/spec/factories/gestionnaire.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - sequence(:gestionnaire_email) { |n| "gest#{n}@plop.com" } + sequence(:gestionnaire_email) { |n| "gest#{n}@gest.com" } factory :gestionnaire do email { generate(:gestionnaire_email) } password 'password' diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 184da4b0a..c2d09396b 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - sequence(:user_email) { |n| "plop#{n}@plop.com" } + sequence(:user_email) { |n| "user#{n}@user.com" } factory :user do email { generate(:user_email) } password 'password' diff --git a/spec/views/admin/gestionnaires/index.html.haml_spec.rb b/spec/views/admin/gestionnaires/index.html.haml_spec.rb index 0ec5c815b..7f8820abd 100644 --- a/spec/views/admin/gestionnaires/index.html.haml_spec.rb +++ b/spec/views/admin/gestionnaires/index.html.haml_spec.rb @@ -29,6 +29,6 @@ describe 'admin/gestionnaires/index.html.haml', type: :view do array: true)) render end - it { expect(rendered).to match(/gest\d+@plop.com/) } + it { expect(rendered).to match(/gest\d+@gest.com/) } end end From 8b92b44ab0786c03ad01d2fbbff6d3c59103c5b1 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 1 Jun 2017 17:18:30 +0200 Subject: [PATCH 098/131] Track ask demo click on home page --- app/views/layouts/_google_analytics.html.haml | 9 +++++++++ app/views/root/landing.html.haml | 6 ++++-- config/deploy.rb | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 app/views/layouts/_google_analytics.html.haml diff --git a/app/views/layouts/_google_analytics.html.haml b/app/views/layouts/_google_analytics.html.haml new file mode 100644 index 000000000..5ab328f45 --- /dev/null +++ b/app/views/layouts/_google_analytics.html.haml @@ -0,0 +1,9 @@ +- ua_id = Rails.env.production? ? 'UA-63927236-2' : 'UA-63927236-4' +:javascript + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + + ga('create', '#{ua_id}', 'auto'); + ga('send', 'pageview'); diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 61c4ed7c4..67d96cab6 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -10,7 +10,8 @@ = link_to "Demander une démo", "mailto:#{t("dynamics.contact_email")}?subject=Demande de démo TPS", - :class => "hero-button" + class: "hero-button", + onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" %p.hero-phone-cta ou nous appeler au 01 40 15 68 49 @@ -132,6 +133,7 @@ %div = link_to "Demander une démo", "mailto:#{t('dynamics.contact_email')}?subject=Demande de démo TPS", - :class => "cta-panel-button" + class: "cta-panel-button", + onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" %p.cta-panel-phone-cta ou nous appeler au 01 40 15 68 49 diff --git a/config/deploy.rb b/config/deploy.rb index ef1d6b4e1..1895843ba 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -69,7 +69,6 @@ set :shared_paths, [ 'config/france_connect.yml', 'config/initializers/mailjet.rb', 'config/initializers/storage_url.rb', - 'app/views/layouts/_google_analytics.html', 'app/views/cgu/index.html.haml' ] From 9d323fd3877a3dfea7232540b6baf129eb16c96c Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 1 Jun 2017 17:19:33 +0200 Subject: [PATCH 099/131] =?UTF-8?q?Click=20on=20Demander=20une=20d=C3=A9mo?= =?UTF-8?q?,=20opens=20a=20new=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/root/landing.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/root/landing.html.haml b/app/views/root/landing.html.haml index 67d96cab6..ddff3b458 100644 --- a/app/views/root/landing.html.haml +++ b/app/views/root/landing.html.haml @@ -11,6 +11,7 @@ = link_to "Demander une démo", "mailto:#{t("dynamics.contact_email")}?subject=Demande de démo TPS", class: "hero-button", + target: "_blank", onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" %p.hero-phone-cta @@ -134,6 +135,7 @@ = link_to "Demander une démo", "mailto:#{t('dynamics.contact_email')}?subject=Demande de démo TPS", class: "cta-panel-button", + target: "_blank", onclick: "javascript: ga('send', 'pageview', '/demander-une-demo')" %p.cta-panel-phone-cta ou nous appeler au 01 40 15 68 49 From 1794da5a3088079aec1d6222f912133d6766a315 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 21:55:19 +0200 Subject: [PATCH 100/131] [Fix #234] Remove dynamic email templates handling code in Procedure --- app/models/procedure.rb | 58 +++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 0c33a5e94..fbeb71634 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -15,6 +15,12 @@ class Procedure < ActiveRecord::Base has_many :preference_list_dossiers + has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy + has_one :received_mail, class_name: "Mails::ReceivedMail", dependent: :destroy + has_one :closed_mail, class_name: "Mails::ClosedMail", dependent: :destroy + has_one :refused_mail, class_name: "Mails::RefusedMail", dependent: :destroy + has_one :without_continuation_mail, class_name: "Mails::WithoutContinuationMail", dependent: :destroy + delegate :use_api_carto, to: :module_api_carto accepts_nested_attributes_for :types_de_champ, :reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true @@ -30,25 +36,6 @@ class Procedure < ActiveRecord::Base validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false - # for all those mails do - # has_one :initiated_mail, class_name: 'Mails::InitiatedMail' - # - # add a method to return default mail if none is saved - # def initiated_mail_with_override - # self.initiated_mail_without_override || InitiatedMail.default - # end - # alias_method_chain :initiated_mail, :override - - MAIL_TEMPLATE_TYPES = %w(InitiatedMail ReceivedMail ClosedMail RefusedMail WithoutContinuationMail) - - MAIL_TEMPLATE_TYPES.each do |name| - has_one "#{name.underscore}".to_sym, class_name: "Mails::#{name}", dependent: :destroy - define_method("#{name.underscore}_with_override") do - self.send("#{name.underscore}_without_override") || Object.const_get("Mails::#{name}").default - end - alias_method_chain "#{name.underscore.to_sym}".to_s, :override - end - def path procedure_path.path unless procedure_path.nil? end @@ -112,9 +99,11 @@ class Procedure < ActiveRecord::Base procedure.logo_secure_token = nil procedure.remote_logo_url = self.logo_url - MAIL_TEMPLATE_TYPES.each do |mtt| - procedure.send("#{mtt.underscore}=", self.send("#{mtt.underscore}_without_override").try(:dup)) - end + procedure.initiated_mail = initiated_mail_without_override.try(:dup) + procedure.received_mail = received_mail_without_override.try(:dup) + procedure.closed_mail = closed_mail_without_override.try(:dup) + procedure.refused_mail = refused_mail_without_override.try(:dup) + procedure.without_continuation_mail = without_continuation_mail_without_override.try(:dup) return procedure if procedure.save end @@ -147,4 +136,29 @@ class Procedure < ActiveRecord::Base def procedure_overview(start_date, notifications_count) ProcedureOverview.new(self, start_date, notifications_count) end + + def initiated_mail_with_override + self.initiated_mail_without_override || Mails::InitiatedMail.default + end + alias_method_chain "initiated_mail", :override + + def received_mail_with_override + self.received_mail_without_override || Mails::ReceivedMail.default + end + alias_method_chain "received_mail", :override + + def closed_mail_with_override + self.closed_mail_without_override || Mails::ClosedMail.default + end + alias_method_chain "closed_mail", :override + + def refused_mail_with_override + self.refused_mail_without_override || Mails::RefusedMail.default + end + alias_method_chain "refused_mail", :override + + def without_continuation_mail_with_override + self.without_continuation_mail_without_override || Mails::WithoutContinuationMail.default + end + alias_method_chain "without_continuation_mail", :override end From ba865215af53b8622f48e7ae122cf7f5097fbc09 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 7 Jun 2017 14:53:10 +0200 Subject: [PATCH 101/131] Use the Chartkick colors option --- app/views/stats/index.html.haml | 21 +++++++-------------- config/initializers/chartkick.rb | 5 ++++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/views/stats/index.html.haml b/app/views/stats/index.html.haml index 8a63be266..4ca7c7914 100644 --- a/app/views/stats/index.html.haml +++ b/app/views/stats/index.html.haml @@ -24,11 +24,9 @@ .chart-container .chart.monthly-procedures-chart - = column_chart @procedures_in_the_last_4_months, - :colors => ["rgba(61, 149, 236, 1)"] + = column_chart @procedures_in_the_last_4_months .chart.cumulative-procedures-chart.hidden - = area_chart @procedures_cumulative, - :colors => ["rgba(61, 149, 236, 1)"] + = area_chart @procedures_cumulative .stat-card.stat-card-half.pull-left %ul.segmented-control.pull-right @@ -41,11 +39,9 @@ .chart-container .chart.monthly-dossiers-chart - = column_chart @dossiers_in_the_last_4_months, - :colors => ["rgba(61, 149, 236, 1)"] + = column_chart @dossiers_in_the_last_4_months .chart.cumulative-dossiers-chart.hidden - = area_chart @dossiers_cumulative, - :colors => ["rgba(61, 149, 236, 1)"] + = area_chart @dossiers_cumulative .stat-card.stat-card-half.pull-left %span.stat-card-title @@ -53,8 +49,7 @@ .chart-container .chart - = pie_chart @procedures_count_per_administrateur, - :colors => ["rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"] + = pie_chart @procedures_count_per_administrateur - if administration_signed_in? .stat-card.stat-card-half.pull-left @@ -63,8 +58,7 @@ .chart-container .chart = line_chart @dossier_instruction_mean_time, - :ytitle => "Jours", - :colors => ["rgba(61, 149, 236, 1)"] + :ytitle => "Jours" .stat-card.stat-card-half.pull-left %span.stat-card-title Temps de remplissage moyen d'un dossier @@ -72,8 +66,7 @@ .chart-container .chart = line_chart @dossier_filling_mean_time, - :ytitle => "Minutes", - :colors => ["rgba(61, 149, 236, 1)"] + :ytitle => "Minutes" .clearfix diff --git a/config/initializers/chartkick.rb b/config/initializers/chartkick.rb index 20cc32bc9..3fa55389c 100644 --- a/config/initializers/chartkick.rb +++ b/config/initializers/chartkick.rb @@ -1 +1,4 @@ -Chartkick.options[:content_for] = :charts_js +Chartkick.options = { + content_for: :charts_js, + colors: ["rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"] +} From 5a59115df4b3584523b89d952dd205da20776719 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:43:47 +0200 Subject: [PATCH 102/131] Refactor the TAGS management in MailTemplateConcern --- app/models/concerns/mail_template_concern.rb | 69 ++++++------------- app/models/mails/closed_mail.rb | 1 + app/models/mails/initiated_mail.rb | 1 + app/models/mails/received_mail.rb | 1 + app/models/mails/refused_mail.rb | 1 + app/models/mails/without_continuation_mail.rb | 1 + app/views/admin/mail_templates/edit.html.haml | 6 +- 7 files changed, 29 insertions(+), 51 deletions(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index f64de99d8..4ac7fe34f 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -4,50 +4,23 @@ module MailTemplateConcern include Rails.application.routes.url_helpers include ActionView::Helpers::UrlHelper - TAGS = { - numero_dossier: { - description: "Permet d'afficher le numéro de dossier de l'utilisateur.", - templates: [ - "initiated_mail", - "received_mail", - "closed_mail", - "refused_mail", - "without_continuation_mail" - ] - }, - lien_dossier: { - description: "Permet d'afficher un lien vers le dossier de l'utilisateur.", - templates: [ - "initiated_mail", - "received_mail", - "closed_mail", - "refused_mail", - "without_continuation_mail" - ] - }, - libelle_procedure: { - description: "Permet d'afficher le libellé de la procédure.", - templates: [ - "initiated_mail", - "received_mail", - "closed_mail", - "refused_mail", - "without_continuation_mail" - ] - }, - date_de_decision: { - description: "Permet d'afficher la date à laquelle la décision finale (acceptation, refus, classement sans suite) sur le dossier a été prise.", - templates: [ - "closed_mail", - "refused_mail", - "without_continuation_mail" - ] - } + TAGS = [] + TAGS << TAG_NUMERO_DOSSIER = { + name: "numero_dossier", + description: "Permet d'afficher le numéro de dossier de l'utilisateur." + } + TAGS << TAG_LIEN_DOSSIER = { + name: "lien_dossier", + description: "Permet d'afficher un lien vers le dossier de l'utilisateur." + } + TAGS << TAG_LIBELLE_PROCEDURE = { + name: "libelle_procedure", + description: "Permet d'afficher le libellé de la procédure." + } + TAGS << TAG_DATE_DE_DECISION = { + name: "date_de_decision", + description: "Permet d'afficher la date à laquelle la décision finale (acceptation, refus, classement sans suite) sur le dossier a été prise." } - - def self.tags_for_template(template) - TAGS.select { |key, value| value[:templates].include?(template) } - end def object_for_dossier(dossier) replace_tags(object, dossier) @@ -59,7 +32,7 @@ module MailTemplateConcern def replace_tags(string, dossier) TAGS.inject(string) do |acc, tag| - acc.gsub!("--#{tag.first}--", replace_tag(tag.first.to_sym, dossier)) || acc + acc.gsub!("--#{tag[:name]}--", replace_tag(tag, dossier)) || acc end end @@ -78,13 +51,13 @@ module MailTemplateConcern def replace_tag(tag, dossier) case tag - when :numero_dossier + when TAG_NUMERO_DOSSIER dossier.id.to_s - when :lien_dossier + when TAG_LIEN_DOSSIER link_to users_dossier_recapitulatif_url(dossier), users_dossier_recapitulatif_url(dossier), target: '_blank' - when :libelle_procedure + when TAG_LIBELLE_PROCEDURE dossier.procedure.libelle - when :date_de_decision + when TAG_DATE_DE_DECISION dossier.processed_at.present? ? dossier.processed_at.localtime.strftime("%d/%m/%Y") : "" else '--BALISE_NON_RECONNUE--' diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 2d113f71d..881a6e3b7 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -4,6 +4,7 @@ module Mails DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté' + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] end end diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 4f401e65e..dcb6591b1 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -4,6 +4,7 @@ module Mails DISPLAYED_NAME = 'Accusé de réception' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu' + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] end end diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index be65a36b2..49e8649d1 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -4,6 +4,7 @@ module Mails DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit' + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] end end diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index 281788535..f5d74d436 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -4,6 +4,7 @@ module Mails DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé' + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] end end diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 3d3bd8f74..18ffe37f6 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -4,6 +4,7 @@ module Mails DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite' + ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] end end diff --git a/app/views/admin/mail_templates/edit.html.haml b/app/views/admin/mail_templates/edit.html.haml index a35c13334..cac9b1e50 100644 --- a/app/views/admin/mail_templates/edit.html.haml +++ b/app/views/admin/mail_templates/edit.html.haml @@ -22,9 +22,9 @@ Balise %th Description - - MailTemplateConcern.tags_for_template(@mail_template_name).each do |balise| + - @mail_template.class.const_get(:ALLOWED_TAGS).each do |tag| %tr %td.center - = "--#{balise.first}--" + = "--#{tag[:name]}--" %td - = balise.second[:description] + = tag[:description] From e06ddeb168a2541e6b7465b26fbcd4e0a6e58a7b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:44:01 +0200 Subject: [PATCH 103/131] Make all Mails classes inherit from ApplicationRecord --- app/models/mails/closed_mail.rb | 2 +- app/models/mails/initiated_mail.rb | 2 +- app/models/mails/received_mail.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 881a6e3b7..cc22f1fe5 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -1,5 +1,5 @@ module Mails - class ClosedMail < ActiveRecord::Base + class ClosedMail < ApplicationRecord include MailTemplateConcern DISPLAYED_NAME = "Accusé d'acceptation" diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index dcb6591b1..49a6b0223 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -1,5 +1,5 @@ module Mails - class InitiatedMail < ActiveRecord::Base + class InitiatedMail < ApplicationRecord include MailTemplateConcern DISPLAYED_NAME = 'Accusé de réception' diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 49e8649d1..47a4dcb4f 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -1,5 +1,5 @@ module Mails - class ReceivedMail < ActiveRecord::Base + class ReceivedMail < ApplicationRecord include MailTemplateConcern DISPLAYED_NAME = 'Accusé de passage en instruction' From 9988444459fbc04db6d39594891d1f8c77c2ed66 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:44:24 +0200 Subject: [PATCH 104/131] Remove useless blank lines --- app/models/mails/closed_mail.rb | 1 - app/models/mails/initiated_mail.rb | 1 - app/models/mails/received_mail.rb | 1 - app/models/mails/refused_mail.rb | 1 - app/models/mails/without_continuation_mail.rb | 1 - 5 files changed, 5 deletions(-) diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index cc22f1fe5..410662a6d 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -5,6 +5,5 @@ module Mails DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] - end end diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 49a6b0223..8f7c67c84 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -5,6 +5,5 @@ module Mails DISPLAYED_NAME = 'Accusé de réception' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] - end end diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 47a4dcb4f..69ac71a02 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -5,6 +5,5 @@ module Mails DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] - end end diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index f5d74d436..ac0bb650b 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -5,6 +5,5 @@ module Mails DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] - end end diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 18ffe37f6..ae44e9b24 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -5,6 +5,5 @@ module Mails DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] - end end From 41b3fa62ed08c1a2bb5033eeff0cf262f3c80800 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:50:00 +0200 Subject: [PATCH 105/131] Refactor MailTemplatesController#mails --- app/controllers/admin/mail_templates_controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index 5967c3dd5..b7f27436d 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -19,8 +19,13 @@ class Admin::MailTemplatesController < AdminController private def mails - %w(initiated received closed refused without_continuation) - .map { |name| @procedure.send(name + "_mail") } + [ + @procedure.initiated_mail, + @procedure.received_mail, + @procedure.closed_mail, + @procedure.refused_mail, + @procedure.without_continuation_mail + ] end def find_the_right_mail type From 18d6204980f77599bd3980e2b1218aba0da22b2b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:50:29 +0200 Subject: [PATCH 106/131] find_the_right_email -> find_mail_template_by_slug --- app/controllers/admin/mail_templates_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index b7f27436d..71136038e 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -6,12 +6,12 @@ class Admin::MailTemplatesController < AdminController end def edit - @mail_template = find_the_right_mail params[:id] + @mail_template = find_mail_template_by_slug(params[:id]) @mail_template_name = params[:id] end def update - mail_template = find_the_right_mail params[:id] + mail_template = find_mail_template_by_slug(params[:id]) mail_template.update_attributes(update_params) redirect_to admin_procedure_mail_templates_path end @@ -28,8 +28,8 @@ class Admin::MailTemplatesController < AdminController ] end - def find_the_right_mail type - mails.find { |m| m.class.slug == type } + def find_mail_template_by_slug(slug) + mails.find { |m| m.class.slug == slug } end def update_params From 07ea0ceea1283face289eadaa4a5033e7b60c0d3 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:52:32 +0200 Subject: [PATCH 107/131] Make MailTemplateConcern.slug a constant --- app/controllers/admin/mail_templates_controller.rb | 2 +- app/models/concerns/mail_template_concern.rb | 4 ---- app/models/mails/closed_mail.rb | 1 + app/models/mails/initiated_mail.rb | 1 + app/models/mails/received_mail.rb | 1 + app/models/mails/refused_mail.rb | 1 + app/models/mails/without_continuation_mail.rb | 1 + app/views/admin/mail_templates/edit.html.haml | 2 +- app/views/admin/mail_templates/index.html.haml | 2 +- spec/controllers/admin/mail_templates_controller_spec.rb | 2 +- 10 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index 71136038e..76766c526 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -29,7 +29,7 @@ class Admin::MailTemplatesController < AdminController end def find_mail_template_by_slug(slug) - mails.find { |m| m.class.slug == slug } + mails.find { |m| m.class.const_get(:SLUG) == slug } end def update_params diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 4ac7fe34f..1a2e179f1 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -37,10 +37,6 @@ module MailTemplateConcern end module ClassMethods - def slug - self.name.demodulize.underscore.parameterize - end - def default body = ActionController::Base.new.render_to_string(template: self.name.underscore) self.new(object: self.const_get(:DEFAULT_OBJECT), body: body) diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 410662a6d..4860dc4aa 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -2,6 +2,7 @@ module Mails class ClosedMail < ApplicationRecord include MailTemplateConcern + SLUG = "closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 8f7c67c84..05a59648d 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -2,6 +2,7 @@ module Mails class InitiatedMail < ApplicationRecord include MailTemplateConcern + SLUG = "initiated_mail" DISPLAYED_NAME = 'Accusé de réception' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 69ac71a02..203aead0b 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -2,6 +2,7 @@ module Mails class ReceivedMail < ApplicationRecord include MailTemplateConcern + SLUG = "received_mail" DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index ac0bb650b..459042812 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -2,6 +2,7 @@ module Mails class RefusedMail < ApplicationRecord include MailTemplateConcern + SLUG = "refused_mail" DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index ae44e9b24..4961ee055 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -2,6 +2,7 @@ module Mails class WithoutContinuationMail < ApplicationRecord include MailTemplateConcern + SLUG = "without_continuation" DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] diff --git a/app/views/admin/mail_templates/edit.html.haml b/app/views/admin/mail_templates/edit.html.haml index cac9b1e50..af010fb95 100644 --- a/app/views/admin/mail_templates/edit.html.haml +++ b/app/views/admin/mail_templates/edit.html.haml @@ -4,7 +4,7 @@ = simple_form_for @mail_template, as: 'mail_template', - url: admin_procedure_mail_template_path(@procedure, @mail_template.class.slug), + url: admin_procedure_mail_template_path(@procedure, @mail_template.class.const_get(:SLUG)), method: :put do |f| .row .col-md-6 diff --git a/app/views/admin/mail_templates/index.html.haml b/app/views/admin/mail_templates/index.html.haml index b8eff250a..695f4e304 100644 --- a/app/views/admin/mail_templates/index.html.haml +++ b/app/views/admin/mail_templates/index.html.haml @@ -10,4 +10,4 @@ %td = mail.class.const_get(:DISPLAYED_NAME) %td.text-right - = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.slug) + = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.const_get(:SLUG)) diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb index 31adfd4ee..6545d1b77 100644 --- a/spec/controllers/admin/mail_templates_controller_spec.rb +++ b/spec/controllers/admin/mail_templates_controller_spec.rb @@ -25,7 +25,7 @@ describe Admin::MailTemplatesController, type: :controller do before :each do patch :update, params: { procedure_id: procedure.id, - id: initiated_mail.class.slug, + id: initiated_mail.class.const_get(:SLUG), mail_template: { object: object, body: body } } end From 07ad7b4c84e5d65c367508f1b441c8e504ca2ea6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:54:34 +0200 Subject: [PATCH 108/131] mails -> mail_templates --- app/controllers/admin/mail_templates_controller.rb | 6 +++--- app/views/admin/mail_templates/index.html.haml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index 76766c526..252884342 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -2,7 +2,7 @@ class Admin::MailTemplatesController < AdminController before_action :retrieve_procedure def index - @mails = mails + @mail_templates = mail_templates end def edit @@ -18,7 +18,7 @@ class Admin::MailTemplatesController < AdminController private - def mails + def mail_templates [ @procedure.initiated_mail, @procedure.received_mail, @@ -29,7 +29,7 @@ class Admin::MailTemplatesController < AdminController end def find_mail_template_by_slug(slug) - mails.find { |m| m.class.const_get(:SLUG) == slug } + mail_templates.find { |template| template.class.const_get(:SLUG) == slug } end def update_params diff --git a/app/views/admin/mail_templates/index.html.haml b/app/views/admin/mail_templates/index.html.haml index 695f4e304..32deb0a28 100644 --- a/app/views/admin/mail_templates/index.html.haml +++ b/app/views/admin/mail_templates/index.html.haml @@ -5,9 +5,9 @@ %tr %th{ colspan: 2 } Type d'email - - @mails.each do |mail| + - @mail_templates.each do |mail_template| %tr %td - = mail.class.const_get(:DISPLAYED_NAME) + = mail_template.class.const_get(:DISPLAYED_NAME) %td.text-right - = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail.class.const_get(:SLUG)) + = link_to "Personnaliser l'e-mail", edit_admin_procedure_mail_template_path(@procedure, mail_template.class.const_get(:SLUG)) From d557906fe953a4207de88e3c04bd250ff636d0dc Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 00:55:23 +0200 Subject: [PATCH 109/131] Remove unused variable in MailTemplatesController#edit --- app/controllers/admin/mail_templates_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index 252884342..db9eda6d9 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -7,7 +7,6 @@ class Admin::MailTemplatesController < AdminController def edit @mail_template = find_mail_template_by_slug(params[:id]) - @mail_template_name = params[:id] end def update From bc7fc2634eb988a587e9a9fcbfd4f5c662868614 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 29 May 2017 14:44:38 +0200 Subject: [PATCH 110/131] Fix test indentation, name and remove a blank line --- spec/models/procedure_spec.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 7a5717d99..404f11267 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1,13 +1,12 @@ require 'spec_helper' describe Procedure do - - describe 'mails' do - it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) } - it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) } - it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) } - it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) } - it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) } + describe 'mail templates' do + it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) } + it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) } + it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) } + it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) } + it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) } end describe 'initiated_mail' do From ec69086ebc358774e3e4d445582c0fc545fddabd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 01:08:01 +0200 Subject: [PATCH 111/131] =?UTF-8?q?Don=E2=80=99t=20use=20alias=5Fmethod=5F?= =?UTF-8?q?chain,=20use=20a=20proxy=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/mail_templates_controller.rb | 10 +++--- .../backoffice/dossiers_controller.rb | 8 ++--- .../users/description_controller.rb | 2 +- app/models/procedure.rb | 35 ++++++++----------- .../admin/mail_templates_controller_spec.rb | 2 +- .../previews/notification_mailer_preview.rb | 2 +- spec/models/procedure_spec.rb | 20 ++++++----- 7 files changed, 38 insertions(+), 41 deletions(-) diff --git a/app/controllers/admin/mail_templates_controller.rb b/app/controllers/admin/mail_templates_controller.rb index db9eda6d9..a0696fd49 100644 --- a/app/controllers/admin/mail_templates_controller.rb +++ b/app/controllers/admin/mail_templates_controller.rb @@ -19,11 +19,11 @@ class Admin::MailTemplatesController < AdminController def mail_templates [ - @procedure.initiated_mail, - @procedure.received_mail, - @procedure.closed_mail, - @procedure.refused_mail, - @procedure.without_continuation_mail + @procedure.initiated_mail_template, + @procedure.received_mail_template, + @procedure.closed_mail_template, + @procedure.refused_mail_template, + @procedure.without_continuation_mail_template ] end diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 8cc2260ae..ec34b7cff 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -99,7 +99,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController dossier.received! flash.notice = 'Dossier considéré comme reçu.' - NotificationMailer.send_notification(dossier, dossier.procedure.received_mail).deliver_now! + NotificationMailer.send_notification(dossier, dossier.procedure.received_mail_template).deliver_now! redirect_to backoffice_dossier_path(id: dossier.id) end @@ -112,7 +112,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController dossier.next_step! 'gestionnaire', 'refuse' flash.notice = 'Dossier considéré comme refusé.' - NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail).deliver_now! + NotificationMailer.send_notification(dossier, dossier.procedure.refused_mail_template).deliver_now! redirect_to backoffice_dossier_path(id: dossier.id) end @@ -125,7 +125,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController dossier.next_step! 'gestionnaire', 'without_continuation' flash.notice = 'Dossier considéré comme sans suite.' - NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail).deliver_now! + NotificationMailer.send_notification(dossier, dossier.procedure.without_continuation_mail_template).deliver_now! redirect_to backoffice_dossier_path(id: dossier.id) end @@ -138,7 +138,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController dossier.next_step! 'gestionnaire', 'close' flash.notice = 'Dossier traité avec succès.' - NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail).deliver_now! + NotificationMailer.send_notification(dossier, dossier.procedure.closed_mail_template).deliver_now! redirect_to backoffice_dossier_path(id: dossier.id) end diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index bdd38cce9..24ed37896 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -52,7 +52,7 @@ class Users::DescriptionController < UsersController else if dossier.draft? dossier.initiated! - NotificationMailer.send_notification(dossier, procedure.initiated_mail).deliver_now! + NotificationMailer.send_notification(dossier, procedure.initiated_mail_template).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) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index fbeb71634..c46b2d6da 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -99,11 +99,11 @@ class Procedure < ActiveRecord::Base procedure.logo_secure_token = nil procedure.remote_logo_url = self.logo_url - procedure.initiated_mail = initiated_mail_without_override.try(:dup) - procedure.received_mail = received_mail_without_override.try(:dup) - procedure.closed_mail = closed_mail_without_override.try(:dup) - procedure.refused_mail = refused_mail_without_override.try(:dup) - procedure.without_continuation_mail = without_continuation_mail_without_override.try(:dup) + procedure.initiated_mail = initiated_mail.try(:dup) + procedure.received_mail = received_mail.try(:dup) + procedure.closed_mail = closed_mail.try(:dup) + procedure.refused_mail = refused_mail.try(:dup) + procedure.without_continuation_mail = without_continuation_mail.try(:dup) return procedure if procedure.save end @@ -137,28 +137,23 @@ class Procedure < ActiveRecord::Base ProcedureOverview.new(self, start_date, notifications_count) end - def initiated_mail_with_override - self.initiated_mail_without_override || Mails::InitiatedMail.default + def initiated_mail_template + initiated_mail || Mails::InitiatedMail.default end - alias_method_chain "initiated_mail", :override - def received_mail_with_override - self.received_mail_without_override || Mails::ReceivedMail.default + def received_mail_template + received_mail || Mails::ReceivedMail.default end - alias_method_chain "received_mail", :override - def closed_mail_with_override - self.closed_mail_without_override || Mails::ClosedMail.default + def closed_mail_template + closed_mail || Mails::ClosedMail.default end - alias_method_chain "closed_mail", :override - def refused_mail_with_override - self.refused_mail_without_override || Mails::RefusedMail.default + def refused_mail_template + refused_mail || Mails::RefusedMail.default end - alias_method_chain "refused_mail", :override - def without_continuation_mail_with_override - self.without_continuation_mail_without_override || Mails::WithoutContinuationMail.default + def without_continuation_mail_template + without_continuation_mail || Mails::WithoutContinuationMail.default end - alias_method_chain "without_continuation_mail", :override end diff --git a/spec/controllers/admin/mail_templates_controller_spec.rb b/spec/controllers/admin/mail_templates_controller_spec.rb index 6545d1b77..09db84650 100644 --- a/spec/controllers/admin/mail_templates_controller_spec.rb +++ b/spec/controllers/admin/mail_templates_controller_spec.rb @@ -33,7 +33,7 @@ describe Admin::MailTemplatesController, type: :controller do it { expect(response).to redirect_to admin_procedure_mail_templates_path(procedure) } context 'the mail template' do - subject { procedure.reload ; procedure.initiated_mail } + subject { procedure.reload ; procedure.initiated_mail_template } it { expect(subject.object).to eq(object) } it { expect(subject.body).to eq(body) } diff --git a/spec/mailers/previews/notification_mailer_preview.rb b/spec/mailers/previews/notification_mailer_preview.rb index 25fa735c2..3cb6079a2 100644 --- a/spec/mailers/previews/notification_mailer_preview.rb +++ b/spec/mailers/previews/notification_mailer_preview.rb @@ -1,7 +1,7 @@ class NotificationMailerPreview < ActionMailer::Preview def send_notification - NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail) + NotificationMailer.send_notification(Dossier.last, Dossier.last.procedure.initiated_mail_template) end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 404f11267..a9e3f2185 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -2,18 +2,20 @@ require 'spec_helper' describe Procedure do describe 'mail templates' do - it { expect(subject.initiated_mail).to be_a(Mails::InitiatedMail) } - it { expect(subject.received_mail).to be_a(Mails::ReceivedMail) } - it { expect(subject.closed_mail).to be_a(Mails::ClosedMail) } - it { expect(subject.refused_mail).to be_a(Mails::RefusedMail) } - it { expect(subject.without_continuation_mail).to be_a(Mails::WithoutContinuationMail) } + subject { create(:procedure) } + + it { expect(subject.initiated_mail_template).to be_a(Mails::InitiatedMail) } + it { expect(subject.received_mail_template).to be_a(Mails::ReceivedMail) } + it { expect(subject.closed_mail_template).to be_a(Mails::ClosedMail) } + it { expect(subject.refused_mail_template).to be_a(Mails::RefusedMail) } + it { expect(subject.without_continuation_mail_template).to be_a(Mails::WithoutContinuationMail) } end describe 'initiated_mail' do subject { create(:procedure) } context 'when initiated_mail is not customize' do - it { expect(subject.initiated_mail.body).to eq(Mails::InitiatedMail.default.body) } + it { expect(subject.initiated_mail_template.body).to eq(Mails::InitiatedMail.default.body) } end context 'when initiated_mail is customize' do @@ -22,7 +24,7 @@ describe Procedure do subject.save subject.reload end - it { expect(subject.initiated_mail.body).to eq('sisi') } + it { expect(subject.initiated_mail_template.body).to eq('sisi') } end context 'when initiated_mail is customize ... again' do @@ -31,7 +33,7 @@ describe Procedure do subject.save subject.reload end - it { expect(subject.initiated_mail.body).to eq('toto') } + it { expect(subject.initiated_mail_template.body).to eq('toto') } it { expect(Mails::InitiatedMail.count).to eq(1) } end @@ -185,7 +187,7 @@ describe Procedure do end it 'should not duplicate default mail_template' do - expect(subject.initiated_mail.attributes).to eq Mails::InitiatedMail.default.attributes + expect(subject.initiated_mail_template.attributes).to eq Mails::InitiatedMail.default.attributes end it 'should not duplicate specific related objects' do From 585a5bcaba115d46d474e3f83a6dc9af6d35f61e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 01:16:38 +0200 Subject: [PATCH 112/131] Add TEMPLATE_NAME to Mail classes --- app/models/concerns/mail_template_concern.rb | 2 +- app/models/mails/closed_mail.rb | 1 + app/models/mails/initiated_mail.rb | 1 + app/models/mails/received_mail.rb | 1 + app/models/mails/refused_mail.rb | 1 + app/models/mails/without_continuation_mail.rb | 1 + 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index 1a2e179f1..25c87d133 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -38,7 +38,7 @@ module MailTemplateConcern module ClassMethods def default - body = ActionController::Base.new.render_to_string(template: self.name.underscore) + body = ActionController::Base.new.render_to_string(template: self.const_get(:TEMPLATE_NAME)) self.new(object: self.const_get(:DEFAULT_OBJECT), body: body) end end diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 4860dc4aa..80f706bf9 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -3,6 +3,7 @@ module Mails include MailTemplateConcern SLUG = "closed_mail" + TEMPLATE_NAME = "mails/closed_mail" DISPLAYED_NAME = "Accusé d'acceptation" DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été accepté' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] diff --git a/app/models/mails/initiated_mail.rb b/app/models/mails/initiated_mail.rb index 05a59648d..9d8edc903 100644 --- a/app/models/mails/initiated_mail.rb +++ b/app/models/mails/initiated_mail.rb @@ -3,6 +3,7 @@ module Mails include MailTemplateConcern SLUG = "initiated_mail" + TEMPLATE_NAME = "mails/initiated_mail" DISPLAYED_NAME = 'Accusé de réception' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été bien reçu' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] diff --git a/app/models/mails/received_mail.rb b/app/models/mails/received_mail.rb index 203aead0b..27175df37 100644 --- a/app/models/mails/received_mail.rb +++ b/app/models/mails/received_mail.rb @@ -3,6 +3,7 @@ module Mails include MailTemplateConcern SLUG = "received_mail" + TEMPLATE_NAME = "mails/received_mail" DISPLAYED_NAME = 'Accusé de passage en instruction' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- va être instruit' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE] diff --git a/app/models/mails/refused_mail.rb b/app/models/mails/refused_mail.rb index 459042812..f9b859e74 100644 --- a/app/models/mails/refused_mail.rb +++ b/app/models/mails/refused_mail.rb @@ -3,6 +3,7 @@ module Mails include MailTemplateConcern SLUG = "refused_mail" + TEMPLATE_NAME = "mails/refused_mail" DISPLAYED_NAME = 'Accusé de rejet du dossier' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été refusé' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] diff --git a/app/models/mails/without_continuation_mail.rb b/app/models/mails/without_continuation_mail.rb index 4961ee055..0115037c3 100644 --- a/app/models/mails/without_continuation_mail.rb +++ b/app/models/mails/without_continuation_mail.rb @@ -3,6 +3,7 @@ module Mails include MailTemplateConcern SLUG = "without_continuation" + TEMPLATE_NAME = "mails/without_continuation_mail" DISPLAYED_NAME = 'Accusé de classement sans suite' DEFAULT_OBJECT = 'Votre dossier TPS nº --numero_dossier-- a été classé sans suite' ALLOWED_TAGS = [TAG_NUMERO_DOSSIER, TAG_LIEN_DOSSIER, TAG_LIBELLE_PROCEDURE, TAG_DATE_DE_DECISION] From 23f558290707dd864d98f8dc2afb4033a513ba02 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 01:18:56 +0200 Subject: [PATCH 113/131] Improve a variable name --- app/mailers/notification_mailer.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index d2ddbb195..b2be1e922 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -6,10 +6,10 @@ class NotificationMailer < ApplicationMailer def send_notification dossier, mail_template vars_mailer(dossier) - @obj = mail_template.object_for_dossier dossier + @object = mail_template.object_for_dossier dossier @body = mail_template.body_for_dossier dossier - mail(subject: @obj) { |format| format.html { @body } } + mail(subject: @object) { |format| format.html { @body } } end def new_answer dossier @@ -22,7 +22,7 @@ class NotificationMailer < ApplicationMailer Commentaire.create( dossier: @dossier, email: I18n.t("dynamics.contact_email"), - body: ["[#{@obj}]", @body].join("

") + body: ["[#{@object}]", @body].join("

") ) end From cb81610e6091e3b6808b8e5c45ef9126b2fed94d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Sat, 27 May 2017 01:19:33 +0200 Subject: [PATCH 114/131] Add brackets around arguments --- app/mailers/notification_mailer.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index b2be1e922..6c7d4b91c 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -3,7 +3,7 @@ class NotificationMailer < ApplicationMailer after_action :create_commentaire_for_notification, only: :send_notification - def send_notification dossier, mail_template + def send_notification(dossier, mail_template) vars_mailer(dossier) @object = mail_template.object_for_dossier dossier @@ -12,7 +12,7 @@ class NotificationMailer < ApplicationMailer mail(subject: @object) { |format| format.html { @body } } end - def new_answer dossier + def new_answer(dossier) send_mail dossier, "Nouveau message pour votre dossier TPS nº #{dossier.id}" end @@ -26,12 +26,12 @@ class NotificationMailer < ApplicationMailer ) end - def vars_mailer dossier + def vars_mailer(dossier) @dossier = dossier @user = dossier.user end - def send_mail dossier, subject + def send_mail(dossier, subject) vars_mailer dossier mail(subject: subject) From 0b6f5a9603ac63c022dca56ee9184e966f0c899b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 8 Jun 2017 11:20:19 +0200 Subject: [PATCH 115/131] Remove bold weight on Avis sign up button --- app/assets/stylesheets/new_design/avis_sign_up.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/stylesheets/new_design/avis_sign_up.scss b/app/assets/stylesheets/new_design/avis_sign_up.scss index 10d6d64ee..9c94d35af 100644 --- a/app/assets/stylesheets/new_design/avis_sign_up.scss +++ b/app/assets/stylesheets/new_design/avis_sign_up.scss @@ -76,7 +76,6 @@ background-color: $blue; color: #FFFFFF; font-size: 16px; - font-weight: bold; text-align: center; width: 100%; margin: 55px 0; From 220b71abfdbd4f7af5a25b608d83535b43877bbc Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 7 Jun 2017 11:50:59 +0200 Subject: [PATCH 116/131] Fix invite guest email - fix typo - add a missing non-breaking space --- app/views/invite_mailer/invite_guest.text.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/invite_mailer/invite_guest.text.erb b/app/views/invite_mailer/invite_guest.text.erb index bfcfcc932..48774e6e0 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -2,9 +2,9 @@ Bonjour, L'utilisateur <%= @invite.email_sender %> souhaite que vous participiez à l'élaboration d'un dossier sur la plateforme TPS. -Cette plateforme permet à ses utilisateurs d'établir des dossiers 100% en ligne et de dialoguer avec plusieurs interlocuteurs privilégiés avant d'instruire un dépot. +Cette plateforme permet à ses utilisateurs d'établir des dossiers 100 % en ligne et de dialoguer avec plusieurs interlocuteurs privilégiés avant d'instruire un dépot. -Afin de répondre à cette invitation, merci de vous inscrit avec l'adresse email <%= @invite.email %> sur <%= users_dossiers_invite_url(@invite.id)+"?email=#{@invite.email}" %>. +Afin de répondre à cette invitation, merci de vous inscrire avec l'adresse email <%= @invite.email %> sur <%= users_dossiers_invite_url(@invite.id)+"?email=#{@invite.email}" %>. Bonne journée, From 3c83cc3c5273f3fbea2556522f1db8b5a0c41d78 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 8 Jun 2017 11:23:32 +0200 Subject: [PATCH 117/131] In Avis sign up, fix the numero character and add a non-breaking space --- app/views/backoffice/avis/sign_up.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/backoffice/avis/sign_up.html.haml b/app/views/backoffice/avis/sign_up.html.haml index c02191ce7..faeb3dadb 100644 --- a/app/views/backoffice/avis/sign_up.html.haml +++ b/app/views/backoffice/avis/sign_up.html.haml @@ -1,7 +1,7 @@ .avis-sign-up .left %p.description= @dossier.procedure.libelle - %p.dossier Dossier n°#{@dossier.id} + %p.dossier Dossier nº #{@dossier.id} .right %h1 Créez-vous un compte From d3f4e0c210f9245f51fd45fb0c6af6349e423ad2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 7 Jun 2017 11:48:48 +0200 Subject: [PATCH 118/131] Change the new admin account notification receiver --- app/mailers/new_admin_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/new_admin_mailer.rb b/app/mailers/new_admin_mailer.rb index 6ec6e7092..4527451a0 100644 --- a/app/mailers/new_admin_mailer.rb +++ b/app/mailers/new_admin_mailer.rb @@ -4,7 +4,7 @@ class NewAdminMailer < ApplicationMailer @admin = admin @password = password - mail(to: 'tech@apientreprise.fr', + mail(to: 'tech@tps.apientreprise.fr', subject: "Création d'un compte Admin TPS") end end From f8673894e2801d9a4e3bbabce748e8ea6ac9753e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:37:55 +0200 Subject: [PATCH 119/131] Stop erasing data when auto-archiving procedures --- app/workers/auto_archive_procedure_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 71659b5a5..dea73cfb3 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -8,7 +8,7 @@ class AutoArchiveProcedureWorker p.dossiers.state_en_construction.update_all(state: :received) end - procedures_to_archive.update_all(archived: true, auto_archive_on: nil) + procedures_to_archive.update_all(archived: true) end end From 68e734fbb51fc426e0181fb3d3c9fd510f593e5d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:31:17 +0200 Subject: [PATCH 120/131] Remove a blank line --- app/workers/auto_archive_procedure_worker.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index dea73cfb3..869c8b5c6 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -9,6 +9,5 @@ class AutoArchiveProcedureWorker end procedures_to_archive.update_all(archived: true) - end end From cc9521667282c270442d876f07eb2bbec11a2795 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:35:02 +0200 Subject: [PATCH 121/131] Refactor AutoArchiveProcedureWorker#perform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the loop failed, we wouldn’t update the archived attribute for procedures for which the folders were archived. That would have caused to re-run the task for procedures for which the task had already been run. --- app/workers/auto_archive_procedure_worker.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 869c8b5c6..13d14ad9f 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -2,12 +2,10 @@ class AutoArchiveProcedureWorker include Sidekiq::Worker def perform(*args) - procedures_to_archive = Procedure.not_archived.where("auto_archive_on <= ?", Date.today) + Procedure.not_archived.where("auto_archive_on <= ?", Date.today).each do |procedure| + procedure.dossiers.state_en_construction.update_all(state: :received) - procedures_to_archive.each do |p| - p.dossiers.state_en_construction.update_all(state: :received) + procedure.update_attributes!(archived: true) end - - procedures_to_archive.update_all(archived: true) end end From 67d0fb5ddc069668887ff5a2fa2d8e844a1a58d2 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:42:05 +0200 Subject: [PATCH 122/131] Further refactor of AutoArchiveProcedureWorker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call received! so that validation and save callbacks are called. Previously, we wouldn’t have update the received_at date --- app/workers/auto_archive_procedure_worker.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 13d14ad9f..54875a961 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -3,7 +3,9 @@ class AutoArchiveProcedureWorker def perform(*args) Procedure.not_archived.where("auto_archive_on <= ?", Date.today).each do |procedure| - procedure.dossiers.state_en_construction.update_all(state: :received) + procedure.dossiers.state_en_construction.each do |dossier| + dossier.received! + end procedure.update_attributes!(archived: true) end From 107c3220627aee743b9b91a7356ce5e6df20e57a Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 20:01:57 +0200 Subject: [PATCH 123/131] [Fix #323] Refactor received dossier notification: use a callback --- .../backoffice/dossiers_controller.rb | 2 -- app/models/dossier.rb | 7 ++++++ spec/models/dossier_spec.rb | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index ec34b7cff..77478f2c5 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -99,8 +99,6 @@ class Backoffice::DossiersController < Backoffice::DossiersListController dossier.received! flash.notice = 'Dossier considéré comme reçu.' - NotificationMailer.send_notification(dossier, dossier.procedure.received_mail_template).deliver_now! - redirect_to backoffice_dossier_path(id: dossier.id) end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c2b641644..8203618ed 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -78,6 +78,7 @@ class Dossier < ActiveRecord::Base after_save :build_default_champs, if: Proc.new { procedure_id_changed? } after_save :build_default_individual, if: Proc.new { procedure.for_individual? } + after_save :send_notification_email validates :user, presence: true @@ -302,4 +303,10 @@ class Dossier < ActiveRecord::Base def serialize_value_for_export(value) value.nil? || value.kind_of?(Time) ? value : value.to_s end + + def send_notification_email + if state_changed? && EN_INSTRUCTION.include?(state) + NotificationMailer.send_notification(self, procedure.received_mail_template).deliver_now! + end + end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index b682281b7..ac668ee64 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -867,4 +867,27 @@ describe Dossier do it { is_expected.to include(dossier3)} it { is_expected.to include(dossier4)} end + + describe "#send_notification_email" do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, procedure: procedure, state: :initiated) } + + before do + ActionMailer::Base.deliveries.clear + end + + it "sends an email when the dossier becomes received" do + dossier.received! + + mail = ActionMailer::Base.deliveries.last + + expect(mail.subject).to eq("Votre dossier TPS nº #{dossier.id} va être instruit") + end + + it "does not an email when the dossier becomes closed" do + dossier.closed! + + expect(ActionMailer::Base.deliveries.size).to eq(0) + end + end end From 9eb897f7211f084000128819235f543754cc731f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 23:31:45 +0200 Subject: [PATCH 124/131] Fix spacing in auto_archive_procedure_worker_spec.rb --- spec/workers/auto_archive_procedure_worker_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/workers/auto_archive_procedure_worker_spec.rb b/spec/workers/auto_archive_procedure_worker_spec.rb index e67a19133..2a30fa764 100644 --- a/spec/workers/auto_archive_procedure_worker_spec.rb +++ b/spec/workers/auto_archive_procedure_worker_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' RSpec.describe AutoArchiveProcedureWorker, type: :worker do - let!(:procedure) { create(:procedure, archived: false, auto_archive_on: nil )} let!(:procedure_hier) { create(:procedure, archived: false, auto_archive_on: 1.day.ago )} let!(:procedure_aujourdhui) { create(:procedure, archived: false, auto_archive_on: Date.today )} @@ -17,11 +16,9 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do end it { expect(procedure.archived).to eq false } - end context "when procedures have auto_archive_on set on yesterday or today" do - describe "titi" do before do subject @@ -31,12 +28,9 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do it { expect(procedure_hier.archived).to eq true } it { expect(procedure_aujourdhui.archived).to eq true } - end - context "with dossiers" do - let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'draft', archived: false)} let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'initiated', archived: false)} let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'replied', archived: false)} @@ -61,18 +55,14 @@ RSpec.describe AutoArchiveProcedureWorker, type: :worker do it { expect(dossier6.state).to eq 'closed' } it { expect(dossier7.state).to eq 'refused' } it { expect(dossier8.state).to eq 'without_continuation' } - end end context "when procedures have auto_archive_on set on future" do - before do subject end it { expect(procedure_demain.archived).to eq false } - end - end From 2a74207d15f5622a51e8004ccb1eab9bfcee794e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 7 Jun 2017 18:18:24 +0200 Subject: [PATCH 125/131] you_are_invited_on_dossier -> avis_invitation - shorter - clearer --- app/mailers/avis_mailer.rb | 2 +- app/models/avis.rb | 2 +- ...invited_on_dossier.html.haml => avis_invitation.html.haml} | 0 spec/mailers/avis_mailer_spec.rb | 4 ++-- spec/mailers/previews/avis_mailer_preview.rb | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) rename app/views/avis_mailer/{you_are_invited_on_dossier.html.haml => avis_invitation.html.haml} (100%) diff --git a/app/mailers/avis_mailer.rb b/app/mailers/avis_mailer.rb index 601ee464d..cf435cefc 100644 --- a/app/mailers/avis_mailer.rb +++ b/app/mailers/avis_mailer.rb @@ -1,6 +1,6 @@ class AvisMailer < ApplicationMailer - def you_are_invited_on_dossier(avis) + def avis_invitation(avis) @avis = avis email = @avis.gestionnaire.try(:email) || @avis.email mail(to: email, subject: "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})") diff --git a/app/models/avis.rb b/app/models/avis.rb index dfbebbc23..2d2480a2e 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -15,7 +15,7 @@ class Avis < ApplicationRecord end def notify_gestionnaire - AvisMailer.you_are_invited_on_dossier(self).deliver_now + AvisMailer.avis_invitation(self).deliver_now end def self.link_avis_to_gestionnaire(gestionnaire) diff --git a/app/views/avis_mailer/you_are_invited_on_dossier.html.haml b/app/views/avis_mailer/avis_invitation.html.haml similarity index 100% rename from app/views/avis_mailer/you_are_invited_on_dossier.html.haml rename to app/views/avis_mailer/avis_invitation.html.haml diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index cc5320d7a..83673e899 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" RSpec.describe AvisMailer, type: :mailer do - describe '.you_are_invited_on_dossier' do + describe '.avis_invitation' do let(:avis) { create(:avis) } - subject { described_class.you_are_invited_on_dossier(avis) } + subject { described_class.avis_invitation(avis) } it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } it { expect(subject.body).to include("Vous avez été invité par #{avis.claimant.email} à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") } diff --git a/spec/mailers/previews/avis_mailer_preview.rb b/spec/mailers/previews/avis_mailer_preview.rb index c911615e6..55d153cd1 100644 --- a/spec/mailers/previews/avis_mailer_preview.rb +++ b/spec/mailers/previews/avis_mailer_preview.rb @@ -1,8 +1,8 @@ # Preview all emails at http://localhost:3000/rails/mailers/avis_mailer class AvisMailerPreview < ActionMailer::Preview - def you_are_invited_on_dossier - AvisMailer.you_are_invited_on_dossier(Avis.last) + def avis_invitation + AvisMailer.avis_invitation(Avis.last) end end From 8968675cfbbce544df6007dcce426d59911f7f70 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 8 Jun 2017 11:41:51 +0200 Subject: [PATCH 126/131] [Fix #388] In avis email, redirect a signed in gest. to the dossier Instead to the sign in page --- app/views/avis_mailer/avis_invitation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index 26b129266..78added0b 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -12,7 +12,7 @@ - if @avis.gestionnaire.present? %p - = link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url + = link_to "Connectez-vous pour donner votre avis", backoffice_dossier_url(@avis.dossier) - else %p = link_to "Inscrivez-vous pour donner votre avis", avis_sign_up_url(@avis.id, @avis.email) From 96532cea6d888efba948a2c49ced0be554da068c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 12 Jun 2017 10:06:41 +0200 Subject: [PATCH 127/131] [Fix #388] In avis email, redirect a signed out gest. to the dossier --- app/controllers/backoffice/dossiers_controller.rb | 7 +++++++ app/controllers/users/sessions_controller.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 77478f2c5..753b40302 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -1,6 +1,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController respond_to :html, :xlsx, :ods, :csv + prepend_before_action :store_current_location, only: :show before_action :ensure_gestionnaire_is_authorized, only: :show def index @@ -192,6 +193,12 @@ class Backoffice::DossiersController < Backoffice::DossiersListController private + def store_current_location + if !gestionnaire_signed_in? + store_location_for(:gestionnaire, request.url) + end + end + def ensure_gestionnaire_is_authorized unless current_gestionnaire.can_view_dossier?(params[:id]) flash.alert = t('errors.messages.dossier_not_found') diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 3e8efd878..2a990beaf 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -33,7 +33,8 @@ class Users::SessionsController < Sessions::SessionsController if user_signed_in? redirect_to after_sign_in_path_for(:user) elsif gestionnaire_signed_in? - redirect_to backoffice_path + location = stored_location_for(:gestionnaire) || backoffice_path + redirect_to location elsif administrateur_signed_in? redirect_to admin_path else From 95481e7b85fd3d5e8d590c53bc46ad35280dc565 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 8 Jun 2017 18:07:00 +0200 Subject: [PATCH 128/131] Move date input in a partial --- app/views/users/description/champs/_date.html.haml | 7 +++++++ .../description/champs/_render_list_champs.html.haml | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/views/users/description/champs/_date.html.haml diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml new file mode 100644 index 000000000..2a286a499 --- /dev/null +++ b/app/views/users/description/champs/_date.html.haml @@ -0,0 +1,7 @@ +%input.form-control{ name: "champs['#{champ.id}']", + placeholder: champ.libelle, + id: "champs_#{champ.id}", + value: champ.value, + type: champ.type_champ, + "data-provide": champ.data_provide, + "data-date-format": champ.data_date_format } diff --git a/app/views/users/description/champs/_render_list_champs.html.haml b/app/views/users/description/champs/_render_list_champs.html.haml index 01c395d33..6bb776379 100644 --- a/app/views/users/description/champs/_render_list_champs.html.haml +++ b/app/views/users/description/champs/_render_list_champs.html.haml @@ -47,14 +47,16 @@ - when 'explication' + - when 'date' + = render partial: 'users/description/champs/date', locals: { champ: champ } + - else %input.form-control{ name: "champs['#{champ.id}']", placeholder: champ.libelle, id: "champs_#{champ.id}", value: champ.value, - type: champ.type_champ, - 'data-provide' => champ.data_provide, - 'data-date-format' => champ.data_date_format } + type: champ.type_champ } + - unless champ.description.empty? %div{ id: "description_champs_#{champ.id}", class: ('help-block' unless champ.type_champ == 'engagement') } From 2653862fa7992650dcf0d75b67042afe11dc5a80 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 9 Jun 2017 10:31:41 +0200 Subject: [PATCH 129/131] Add a placeholder to help IE users to fill the date input with the right format --- app/views/users/description/champs/_date.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml index 2a286a499..33a20565a 100644 --- a/app/views/users/description/champs/_date.html.haml +++ b/app/views/users/description/champs/_date.html.haml @@ -1,5 +1,5 @@ %input.form-control{ name: "champs['#{champ.id}']", - placeholder: champ.libelle, + placeholder: "JJ/MM/AAAA", id: "champs_#{champ.id}", value: champ.value, type: champ.type_champ, From 41a5ed59f36bc9af327afdc7e53af17ffb86ee93 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 9 Jun 2017 11:45:50 +0200 Subject: [PATCH 130/131] [Fix #376] Force every browser to use native input[type=date] on date champ --- app/decorators/champ_decorator.rb | 12 +++++++++--- app/models/champ.rb | 4 ++-- app/views/users/description/champs/_date.html.haml | 4 +--- spec/decorators/champ_decorator_spec.rb | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 1688c5f91..a56f24947 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -2,9 +2,15 @@ class ChampDecorator < Draper::Decorator delegate_all def value - return object.value == 'on' ? 'Oui' : 'Non' if type_champ == 'checkbox' - return JSON.parse(object.value).join(', ') if type_champ == 'multiple_drop_down_list' && object.value.present? - object.value + if type_champ == "date" && object.value.present? + Date.parse(object.value).strftime("%d/%m/%Y") + elsif type_champ == 'checkbox' + object.value == 'on' ? 'Oui' : 'Non' + elsif type_champ == 'multiple_drop_down_list' && object.value.present? + JSON.parse(object.value).join(', ') + else + object.value + end end def description_with_links diff --git a/app/models/champ.rb b/app/models/champ.rb index ce12e32a3..7e7a49811 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -12,12 +12,12 @@ class Champ < ActiveRecord::Base end def data_provide - return 'datepicker' if (type_champ == 'datetime' || type_champ == 'date') && !(BROWSER.value.chrome? || BROWSER.value.edge?) + return 'datepicker' if (type_champ == 'datetime') && !(BROWSER.value.chrome? || BROWSER.value.edge?) return 'typeahead' if type_champ == 'address' end def data_date_format - ('dd/mm/yyyy' if type_champ == 'datetime' || type_champ == 'date') + ('dd/mm/yyyy' if type_champ == 'datetime') end def same_hour? num diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml index 33a20565a..f04b581a6 100644 --- a/app/views/users/description/champs/_date.html.haml +++ b/app/views/users/description/champs/_date.html.haml @@ -2,6 +2,4 @@ placeholder: "JJ/MM/AAAA", id: "champs_#{champ.id}", value: champ.value, - type: champ.type_champ, - "data-provide": champ.data_provide, - "data-date-format": champ.data_date_format } + type: "date" } diff --git a/spec/decorators/champ_decorator_spec.rb b/spec/decorators/champ_decorator_spec.rb index c8b15056c..a5a2554a4 100644 --- a/spec/decorators/champ_decorator_spec.rb +++ b/spec/decorators/champ_decorator_spec.rb @@ -34,5 +34,19 @@ describe ChampDecorator do it { is_expected.to eq '' } end end + + describe "for a date" do + let(:type_champ) { :date } + + context "when value is an ISO date" do + before { champ.update value: "2017-12-31" } + it { is_expected.to eq "31/12/2017" } + end + + context "when value is empty" do + before { champ.update value: nil } + it { is_expected.to eq nil } + end + end end end From b9522ce40484d063736605d21d878de65942ff0c Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 9 Jun 2017 12:04:16 +0200 Subject: [PATCH 131/131] [Fix #376] Before save format champ date to ISO --- app/models/champ.rb | 10 ++++++++++ spec/factories/champ.rb | 2 ++ spec/models/champ_shared_example.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/app/models/champ.rb b/app/models/champ.rb index 7e7a49811..5b90b309a 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -5,6 +5,7 @@ class Champ < ActiveRecord::Base delegate :libelle, :type_champ, :order_place, :mandatory, :description, :drop_down_list, to: :type_de_champ + before_save :format_date_to_iso, if: Proc.new { type_champ == 'date' } after_save :internal_notification, if: Proc.new { !dossier.nil? } def mandatory? @@ -55,6 +56,15 @@ class Champ < ActiveRecord::Base private + def format_date_to_iso + date = begin + Date.parse(value).strftime("%F") + rescue + nil + end + self.value = date + end + def internal_notification unless dossier.state == 'draft' NotificationService.new('champs', self.dossier.id, self.libelle).notify diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 96620cb80..3a2302f4c 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -1,4 +1,6 @@ FactoryGirl.define do factory :champ do + + type_de_champ { FactoryGirl.create(:type_de_champ_public) } end end diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index b404154df..7dfe6bb1b 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -68,4 +68,30 @@ shared_examples 'champ_spec' do it { expect(subject).to include '99 - Étranger' } end + + context "when type_champ=date" do + let(:type_de_champ) { create(:type_de_champ_public, type_champ: "date")} + let(:champ) { create(:champ, type_de_champ: type_de_champ) } + + it "should convert %d/%m/%Y format to ISO" do + champ.value = "31/12/2017" + champ.save + champ.reload + expect(champ.value).to eq("2017-12-31") + end + + it "should convert to nil if date parse failed" do + champ.value = "bla" + champ.save + champ.reload + expect(champ.value).to be(nil) + end + + it "should convert empty string to nil" do + champ.value = "" + champ.save + champ.reload + expect(champ.value).to be(nil) + end + end end