From c6fd3045e414eb01b56959bcf4755a7bc9e2e853 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 10 May 2017 16:24:21 +0200 Subject: [PATCH 01/25] Fix #261 : add link to return to dossier list. --- app/assets/stylesheets/left_panel.scss | 8 ++++++++ ...eft_panel_users_recapitulatifcontroller_show.html.haml | 3 +++ 2 files changed, 11 insertions(+) diff --git a/app/assets/stylesheets/left_panel.scss b/app/assets/stylesheets/left_panel.scss index 02658aab1..c594715a2 100644 --- a/app/assets/stylesheets/left_panel.scss +++ b/app/assets/stylesheets/left_panel.scss @@ -10,6 +10,14 @@ color: #FFFFFF; overflow-y: scroll; + .link-to-dossiers { + padding: 15px 0 0 15px; + + a { + color: #FFFFFF; + } + } + #first-block { font-family: Arial; font-size: 16px; diff --git a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml index a32b48b77..1adb2c390 100644 --- a/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml +++ b/app/views/layouts/left_panels/_left_panel_users_recapitulatifcontroller_show.html.haml @@ -1,3 +1,6 @@ +.link-to-dossiers + = link_to 'retour aux dossiers', users_dossiers_path + #first-block .en-cours %h2 Récapitulatif From a31262838392e2ae9eee8972c932510b4f59d202 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 10 May 2017 15:44:47 +0200 Subject: [PATCH 02/25] Newsletter: add mailjet widget --- app/views/layouts/_mailjet_newsletter.html.haml | 2 ++ app/views/layouts/_new_footer.html.haml | 2 ++ app/views/layouts/new_application.html.haml | 1 + 3 files changed, 5 insertions(+) create mode 100644 app/views/layouts/_mailjet_newsletter.html.haml diff --git a/app/views/layouts/_mailjet_newsletter.html.haml b/app/views/layouts/_mailjet_newsletter.html.haml new file mode 100644 index 000000000..d99e0c794 --- /dev/null +++ b/app/views/layouts/_mailjet_newsletter.html.haml @@ -0,0 +1,2 @@ +%data.mj-w-data{ "data-apikey" => "1v5T", "data-base" => "http://app.mailjet.com", "data-height" => "328", "data-lang" => "fr_FR", "data-statics" => "statics", "data-token" => "11c89e7ddb46fbcdcb7f8fe5fdfca818", "data-w-id" => "39b", "data-width" => "640" } +%script{ src: 'http://app.mailjet.com/statics/js/widget.modal.js' } diff --git a/app/views/layouts/_new_footer.html.haml b/app/views/layouts/_new_footer.html.haml index 806541020..4bcc09bc8 100644 --- a/app/views/layouts/_new_footer.html.haml +++ b/app/views/layouts/_new_footer.html.haml @@ -25,6 +25,8 @@ %li.footer-column %ul.footer-links + %li.footer-link + %a{ href: '#', 'data-token' => '11c89e7ddb46fbcdcb7f8fe5fdfca818', onclick: 'mjOpenPopin(event, this)' } Newsletter %li.footer-link = link_to "Contact", "mailto:#{t('dynamics.contact_email')}", diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index 5310f24cf..ba6539661 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -33,6 +33,7 @@ = render partial: "layouts/new_footer" = render partial: "layouts/google_analytics" + = render partial: "layouts/mailjet_newsletter" = javascript_include_tag "application", "data-turbolinks-track" => true - if Rails.env == "test" From 07dfec9236a005c370ad653e2254d5fb864d4df9 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 11 May 2017 12:45:01 +0200 Subject: [PATCH 03/25] Clean: remove dead code --- app/decorators/entreprise_decorator.rb | 4 ---- spec/decorators/entreprise_decorator_spec.rb | 6 ------ 2 files changed, 10 deletions(-) diff --git a/app/decorators/entreprise_decorator.rb b/app/decorators/entreprise_decorator.rb index 6db7236fe..155a76b0c 100644 --- a/app/decorators/entreprise_decorator.rb +++ b/app/decorators/entreprise_decorator.rb @@ -29,8 +29,4 @@ class EntrepriseDecorator < Draper::Decorator def pretty_capital_social h.number_to_currency(capital_social, delimiter: ' ', unit: '€', format: '%n %u') end - - def pretty_date_creation - Time.at(date_creation).strftime('%d-%m-%Y') - end end diff --git a/spec/decorators/entreprise_decorator_spec.rb b/spec/decorators/entreprise_decorator_spec.rb index a039179d4..e5f229486 100644 --- a/spec/decorators/entreprise_decorator_spec.rb +++ b/spec/decorators/entreprise_decorator_spec.rb @@ -50,10 +50,4 @@ describe EntrepriseDecorator do expect(subject.pretty_capital_social).to eq('123 000,00 €') end end - - describe '#pretty_date_creation' do - it 'pretty print date creation' do - expect(subject.pretty_date_creation).to eq('28-01-2016') - end - end end From cebb197994a677b975a7f84efe448cdd133c0533 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 11 May 2017 12:46:42 +0200 Subject: [PATCH 04/25] Fix #171 : add localtime to a bunch of date --- app/models/concerns/mail_template_concern.rb | 2 +- app/models/dossier.rb | 2 +- app/views/admin/procedures/_informations.html.haml | 2 +- app/views/administrations/_list.html.haml | 2 +- app/views/dossiers/_infos_entreprise.html.haml | 2 +- ..._left_panel_backoffice_dossierscontroller_index.html.haml | 2 +- .../_left_panel_backoffice_dossierscontroller_show.html.haml | 2 +- spec/controllers/backoffice/dossiers_controller_spec.rb | 1 + spec/decorators/commentaire_decorator_spec.rb | 5 +++-- 9 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/concerns/mail_template_concern.rb b/app/models/concerns/mail_template_concern.rb index f5a41a156..f64de99d8 100644 --- a/app/models/concerns/mail_template_concern.rb +++ b/app/models/concerns/mail_template_concern.rb @@ -85,7 +85,7 @@ module MailTemplateConcern when :libelle_procedure dossier.procedure.libelle when :date_de_decision - dossier.processed_at.present? ? dossier.processed_at.strftime("%d/%m/%Y") : "" + dossier.processed_at.present? ? dossier.processed_at.localtime.strftime("%d/%m/%Y") : "" else '--BALISE_NON_RECONNUE--' end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ed875bceb..c6eee566f 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -289,7 +289,7 @@ class Dossier < ActiveRecord::Base else parts = [ "Dossier déposé le ", - initiated_at.strftime("%d/%m/%Y"), + initiated_at.localtime.strftime("%d/%m/%Y"), " sur la procédure ", procedure.libelle, " gérée par l'organisme ", diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 253ee6729..cb2c4aa2e 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.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.localtime.strftime("%d-%m-%Y") }, data: { provide: 'datepicker', 'date-language' => 'fr', 'date-format' => 'dd/mm/yyyy' } (à 00h00) %p.help-block %i.fa.fa-info-circle diff --git a/app/views/administrations/_list.html.haml b/app/views/administrations/_list.html.haml index 3af742c9c..171418756 100644 --- a/app/views/administrations/_list.html.haml +++ b/app/views/administrations/_list.html.haml @@ -15,7 +15,7 @@ - unless admin.last_sign_in_at.nil? = time_ago_in_words(l(admin.last_sign_in_at, format: "%d/%m/%Y %H:%M UTC +02:00")) ( - = admin.last_sign_in_at.to_date.strftime('%d/%m/%Y') + = admin.last_sign_in_at.to_date.localtime.strftime('%d/%m/%Y') ) %td = admin.procedures.where(published: true).count diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml index 661634697..6594bffec 100644 --- a/app/views/dossiers/_infos_entreprise.html.haml +++ b/app/views/dossiers/_infos_entreprise.html.haml @@ -24,7 +24,7 @@ .col-xs-8.entreprise-info= @facade.etablissement.naf .row .col-xs-4.entreprise-label Date de création : - .col-xs-8.entreprise-info= Time.at(@facade.entreprise.date_creation).strftime "%d-%m-%Y" + .col-xs-8.entreprise-info= Time.at(@facade.entreprise.date_creation).localtime.strftime "%d-%m-%Y" .row .col-xs-4.entreprise-label Effectif organisation : .col-xs-8.entreprise-info= @facade.entreprise.effectif 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 5d6e6c9d7..cdbc2b329 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 @@ -40,5 +40,5 @@ = link_to backoffice_dossier_path(dossier.id) do .notification .dossier-index= "Dossier nº #{dossier.id}" - .updated-at-index= dossier.first_unread_notification.created_at.strftime('%d/%m %H:%M') + .updated-at-index= dossier.first_unread_notification.created_at.localtime.strftime('%d/%m %H:%M') .count= dossier.unreaded_notifications.count 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 8ffd1196e..ccc0aaa36 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 @@ -45,7 +45,7 @@ %i.fa.fa-bell-o - @facade.last_notifications.each do |notification| .notification - .updated-at= notification.updated_at.strftime('%d/%m/%Y %H:%M') + .updated-at= notification.updated_at.localtime.strftime('%d/%m/%Y %H:%M') = render partial: "layouts/left_panels/type_notif_fa", locals: { notification: notification } - if ['champs'].include?(notification.type_notif) - if notification.liste.size > 1 diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 7ba92db57..91f0b7173 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -188,6 +188,7 @@ describe Backoffice::DossiersController, type: :controller do end it 'returns nothing' do + expect(assigns(:dossiers).count).to eq(0) end end diff --git a/spec/decorators/commentaire_decorator_spec.rb b/spec/decorators/commentaire_decorator_spec.rb index 5a6cc6231..06b821416 100644 --- a/spec/decorators/commentaire_decorator_spec.rb +++ b/spec/decorators/commentaire_decorator_spec.rb @@ -1,14 +1,15 @@ require 'spec_helper' describe CommentaireDecorator do - let(:commentaire) { Timecop.freeze(Time.utc(2008, 9, 1, 10, 5, 0)) {create :commentaire} } + let(:time) { Time.utc(2008, 9, 1, 10, 5, 0) } + let(:commentaire) { Timecop.freeze(time) { create :commentaire } } let(:decorator) { commentaire.decorate } describe 'created_at_fr' do subject { decorator.created_at_fr } context 'when created_at have a value' do - it { is_expected.to eq '01/09/2008 - 10:05' } + it { is_expected.to eq time.localtime.strftime('%d/%m/%Y - %H:%M') } end end end From 459c2afe337cbd373b7e0b6b1daf873a4579344b Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 11 May 2017 18:15:53 +0200 Subject: [PATCH 05/25] remove empty line --- spec/controllers/backoffice/dossiers_controller_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 91f0b7173..7ba92db57 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -188,7 +188,6 @@ describe Backoffice::DossiersController, type: :controller do end it 'returns nothing' do - expect(assigns(:dossiers).count).to eq(0) end end From cfba1af7a483aae4c5f39459b51eb14b6d4b03f5 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 10 May 2017 18:10:43 +0200 Subject: [PATCH 06/25] Ensure that read notifications are not counted --- spec/models/gestionnaire_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index a9c88fa92..9a49c8af4 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -288,6 +288,13 @@ describe Gestionnaire, type: :model do it { is_expected.to eq(1) } end + context 'when there is one notification read' do + let(:notification){ create(:notification, already_read: true) } + let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) } + + it { is_expected.to eq(0) } + end + context 'when there are many notifications for one dossier' do let(:notification){ create(:notification, already_read: false) } let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) } From e5ac555a41ca5d96bb4a34e0eef5a62c16c09a79 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 11 May 2017 10:15:18 +0200 Subject: [PATCH 07/25] fix #245 it should only count dossiers with notifications on followed dossiers --- ...koffice_dossierscontroller_index.html.haml | 2 +- spec/models/gestionnaire_spec.rb | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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 cdbc2b329..320dadc79 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 @@ -28,7 +28,7 @@ - if total_new > 0 .badge.progress-bar-success{ title: 'Nouveaux dossiers' } = total_new - - unread_notif_count = procedure.notifications.unread.count + - unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure) - if unread_notif_count > 0 .badge.progress-bar-warning{ title: 'Notifications' } = unread_notif_count diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 9a49c8af4..b3a20f6d6 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -312,4 +312,36 @@ describe Gestionnaire, type: :model do it { is_expected.to eq(2) } end end + + describe '#dossier_with_notification_for' do + subject { gestionnaire.dossier_with_notification_for(procedure) } + + context 'without notifications' do + it { is_expected.to eq(0) } + end + + context 'with a followed dossier' do + let!(:dossier){create(:dossier, procedure: procedure, state: 'received')} + let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) } + + context 'with 1 notification' do + let!(:notification){ create(:notification, already_read: false, dossier: dossier) } + + it { is_expected.to eq(1) } + end + + context 'with 1 read notification' do + let!(:notification){ create(:notification, already_read: true, dossier: dossier) } + + it { is_expected.to eq(0) } + end + + context 'with 2 notification' do + let!(:notification){ create(:notification, already_read: false, dossier: dossier) } + let!(:notification2){ create(:notification, already_read: false, dossier: dossier) } + + it { is_expected.to eq(1) } + end + end + end end From e14d1a6c154d20da2ea6d65b7dc0e51a93411f18 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 11 May 2017 18:24:43 +0200 Subject: [PATCH 08/25] Remove useless from parameter in mailers We already defined a default one in ApplicationMailer --- app/mailers/gestionnaire_mailer.rb | 3 +-- app/mailers/invite_mailer.rb | 3 +-- app/mailers/new_admin_mailer.rb | 2 +- app/mailers/notification_mailer.rb | 3 +-- app/mailers/welcome_mailer.rb | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/mailers/gestionnaire_mailer.rb b/app/mailers/gestionnaire_mailer.rb index 74765352b..8acbe7237 100644 --- a/app/mailers/gestionnaire_mailer.rb +++ b/app/mailers/gestionnaire_mailer.rb @@ -18,7 +18,6 @@ class GestionnaireMailer < ApplicationMailer def send_mail email, args, subject vars_mailer email, args - mail(from: "tps@apientreprise.fr", to: email, - subject: subject) + mail(to: email, subject: subject) end end diff --git a/app/mailers/invite_mailer.rb b/app/mailers/invite_mailer.rb index c536d9d46..09b58f229 100644 --- a/app/mailers/invite_mailer.rb +++ b/app/mailers/invite_mailer.rb @@ -19,8 +19,7 @@ class InviteMailer < ApplicationMailer end def send_mail email, subject, reply_to - mail(from: "tps@apientreprise.fr", - to: email, + mail(to: email, subject: subject, reply_to: reply_to) end diff --git a/app/mailers/new_admin_mailer.rb b/app/mailers/new_admin_mailer.rb index f7acb8e7e..6ec6e7092 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(from: "tps@apientreprise.fr", to: 'tech@apientreprise.fr', + mail(to: 'tech@apientreprise.fr', subject: "Création d'un compte Admin TPS") end end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 1fa5265ea..7bca836bc 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,6 +1,5 @@ class NotificationMailer < ApplicationMailer - default from: 'tps@apientreprise.fr', - to: Proc.new { @user.email } + default to: Proc.new { @user.email } def send_notification dossier, mail_template vars_mailer(dossier) diff --git a/app/mailers/welcome_mailer.rb b/app/mailers/welcome_mailer.rb index b3542aecd..4306ee974 100644 --- a/app/mailers/welcome_mailer.rb +++ b/app/mailers/welcome_mailer.rb @@ -3,7 +3,7 @@ class WelcomeMailer < ApplicationMailer @user = user - mail(from: "tps@apientreprise.fr", to: user.email, + mail(to: user.email, subject: "Création de votre compte TPS") end end From 84ae1a0c0b9fa79f05121f92f06864a2746f4538 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 11 May 2017 14:32:32 +0200 Subject: [PATCH 09/25] Change the email address we send emails with Also add a display name, so that we don't show just a dumb email address --- app/mailers/application_mailer.rb | 2 +- config/initializers/devise.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 68533b7dd..243266f78 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "tps@apientreprise.fr" + default from: "'Téléprocédures Simplifiées' " layout 'mailer' end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8d3886482..37cbd567a 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -10,7 +10,7 @@ Devise.setup do |config| # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'tps@apientreprise.fr' + config.mailer_sender = "'Téléprocédures Simplifiées' " # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' From 09ba66dc41cd3db9b8423e2fbc248f85cdcf866d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 11 May 2017 14:29:59 +0200 Subject: [PATCH 10/25] [Fix #274] Change the email signatures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Equide -> Equipe - TPS -> Téléprocédures simplifiées - Remove the email address --- 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/new_admin_mailer/new_admin_email.text.erb | 2 +- app/views/notification_mailer/new_answer.text.erb | 2 +- app/views/welcome_mailer/welcome_email.text.erb | 2 +- 8 files changed, 8 insertions(+), 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 1cc3186e0..80466e643 100644 --- a/app/views/devise/mailer/reset_password_instructions.html.erb +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -12,4 +12,4 @@

---
- L'équipe TPS - tps@apientreprise.fr

\ No newline at end of file + 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 414086802..694f454b8 100644 --- a/app/views/gestionnaire_mailer/new_assignement.text.erb +++ b/app/views/gestionnaire_mailer/new_assignement.text.erb @@ -8,4 +8,4 @@ Vous venez d'être assigné à un administrateur sur la plateforme TPS. Voici qu Bonne journée, --- -L'équipe TPS - tps@apientreprise.fr \ No newline at end of file +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 c68a7ae98..f7472cb9e 100644 --- a/app/views/gestionnaire_mailer/new_gestionnaire.text.erb +++ b/app/views/gestionnaire_mailer/new_gestionnaire.text.erb @@ -9,4 +9,4 @@ Vous venez d'être nommé accompagnateur sur la plateforme TPS. Pour mémoire, v Bonne journée, --- -L'équipe TPS - tps@apientreprise.fr \ No newline at end of file +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 1e5c87712..73894115d 100644 --- a/app/views/invite_mailer/invite_guest.text.erb +++ b/app/views/invite_mailer/invite_guest.text.erb @@ -9,4 +9,4 @@ Afin de répondre à cette invitation, merci de vous inscrit avec l'adresse emai Bonne journée. --- -L'équide TPS - tps@apientreprise.fr \ No newline at end of file +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 57827303c..53e98e30c 100644 --- a/app/views/invite_mailer/invite_user.text.erb +++ b/app/views/invite_mailer/invite_user.text.erb @@ -7,4 +7,4 @@ Pour le consulter, merci de suivre ce lien : <%= users_dossiers_invite_url(@invi Bonne journée. --- -L'équide TPS - tps@apientreprise.fr \ No newline at end of file +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 8b4d474df..547713f13 100644 --- a/app/views/new_admin_mailer/new_admin_email.text.erb +++ b/app/views/new_admin_mailer/new_admin_email.text.erb @@ -6,4 +6,4 @@ Login : <%= @admin.email %> Password : <%= @password %> --- -L'équipe TPS - tps@apientreprise.fr \ No newline at end of file +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 d6874bd6d..039d306de 100644 --- a/app/views/notification_mailer/new_answer.text.erb +++ b/app/views/notification_mailer/new_answer.text.erb @@ -11,4 +11,4 @@ Merci de ne pas répondre à ce mail. Postez directement vos questions dans votr --- --- -L'équide TPS - tps@apientreprise.fr \ No newline at end of file +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 57984af05..90b547ce5 100644 --- a/app/views/welcome_mailer/welcome_email.text.erb +++ b/app/views/welcome_mailer/welcome_email.text.erb @@ -12,4 +12,4 @@ Oubli de mot de passe, pas de problème : Bonne journée, --- -L'équipe TPS - tps@apientreprise.fr \ No newline at end of file +L'équipe Téléprocédures Simplifiées From 70f637f088806e4879b96aaf8a5ab60f40e8c78b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 11 May 2017 18:07:37 +0200 Subject: [PATCH 11/25] [Fix #198] Add a Commentaire when we send a Notification email to a user --- app/mailers/notification_mailer.rb | 16 +++++++++++++--- spec/mailers/notification_mailer_spec.rb | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 7bca836bc..9bf486f17 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,13 +1,15 @@ class NotificationMailer < ApplicationMailer default to: Proc.new { @user.email } + after_action :create_commentaire_for_notification, only: :send_notification + def send_notification dossier, mail_template vars_mailer(dossier) - obj = mail_template.object_for_dossier dossier - body = mail_template.body_for_dossier dossier + @obj = mail_template.object_for_dossier dossier + @body = mail_template.body_for_dossier dossier - mail(subject: obj) { |format| format.html { body } } + mail(subject: @obj) { |format| format.html { @body } } end def new_answer dossier @@ -16,6 +18,14 @@ class NotificationMailer < ApplicationMailer private + def create_commentaire_for_notification + Commentaire.create( + dossier: @dossier, + email: "contact@tps.apientreprise.fr", + body: ["[#{@obj}]", @body].join("

") + ) + end + def vars_mailer dossier @dossier = dossier @user = dossier.user diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 4c8f26fc1..e9a66e4a7 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -5,10 +5,23 @@ RSpec.describe NotificationMailer, type: :mailer do let(:user) { create(:user) } let(:dossier) { create(:dossier, user: user) } let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') } + let (:notifications_count_before) { Notification.count } subject { described_class.send_notification(dossier, email) } it { expect(subject.subject).to eq(email.object_for_dossier) } it { expect(subject.body).to eq(email.body_for_dossier) } + + it "creates a commentaire, which is not notified" do + described_class.send_notification(dossier, email).deliver_now + + commentaire = Commentaire.last + notifications_count_after = Notification.count + + expect(commentaire.dossier).to eq(dossier) + expect(commentaire.email).to eq("contact@tps.apientreprise.fr") + expect(commentaire.body).to eq("[object]

body") + expect(notifications_count_before).to eq(notifications_count_after) + end end describe ".new_answer" do From 8f5fdfa81f0a44d516697ebf5481090428b8d1b6 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 12 May 2017 11:35:01 +0200 Subject: [PATCH 12/25] Rename dossier_with_notification_for --- app/facades/dossiers_list_facades.rb | 2 +- app/models/gestionnaire.rb | 2 +- .../_left_panel_backoffice_dossierscontroller_index.html.haml | 2 +- spec/models/gestionnaire_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/facades/dossiers_list_facades.rb b/app/facades/dossiers_list_facades.rb index 016d007d8..9ab6b6055 100644 --- a/app/facades/dossiers_list_facades.rb +++ b/app/facades/dossiers_list_facades.rb @@ -30,7 +30,7 @@ class DossiersListFacades end def gestionnaire_procedures_name_and_id_list - @current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossier_with_notification_for(procedure)}) } + @current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle, unread_notifications: @current_devise_profil.dossiers_with_notifications_count_for_procedure(procedure)}) } end def unread_notifications diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index d646d7177..c45386825 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -86,7 +86,7 @@ class Gestionnaire < ActiveRecord::Base 0 end - def dossier_with_notification_for procedure + def dossiers_with_notifications_count_for_procedure(procedure) procedure_ids = dossiers_follow.pluck(:procedure_id) if procedure_ids.include?(procedure.id) 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 320dadc79..60f5ed36b 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 @@ -28,7 +28,7 @@ - if total_new > 0 .badge.progress-bar-success{ title: 'Nouveaux dossiers' } = total_new - - unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure) + - unread_notif_count = current_gestionnaire.dossiers_with_notifications_count_for_procedure(procedure) - if unread_notif_count > 0 .badge.progress-bar-warning{ title: 'Notifications' } = unread_notif_count diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index b3a20f6d6..9414266f3 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -313,8 +313,8 @@ describe Gestionnaire, type: :model do end end - describe '#dossier_with_notification_for' do - subject { gestionnaire.dossier_with_notification_for(procedure) } + describe '#dossiers_with_notifications_count_for_procedure' do + subject { gestionnaire.dossiers_with_notifications_count_for_procedure(procedure) } context 'without notifications' do it { is_expected.to eq(0) } From 58abd9eaf161d879e24124c41abda4f2f71d3f4d Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 12 May 2017 12:12:57 +0200 Subject: [PATCH 13/25] Fix #276 Rewrite #dossiers_with_notifications_count_for_procedure and add tests --- app/models/gestionnaire.rb | 11 ++--------- spec/models/gestionnaire_spec.rb | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index c45386825..6dda6ed7a 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -87,15 +87,8 @@ class Gestionnaire < ActiveRecord::Base end def dossiers_with_notifications_count_for_procedure(procedure) - procedure_ids = dossiers_follow.pluck(:procedure_id) - - if procedure_ids.include?(procedure.id) - return dossiers_follow.where(procedure_id: procedure.id) - .inject(0) do |acc, dossier| - acc += ((dossier.notifications.where(already_read: false).count) > 0 ? 1 : 0) - end - end - 0 + followed_dossiers_id = dossiers_follow.where(procedure: procedure).pluck(:id) + Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count end def dossiers_with_notifications_count diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 9414266f3..5b286ceaa 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -336,12 +336,28 @@ describe Gestionnaire, type: :model do it { is_expected.to eq(0) } end - context 'with 2 notification' do + context 'with 2 notifications' do let!(:notification){ create(:notification, already_read: false, dossier: dossier) } let!(:notification2){ create(:notification, already_read: false, dossier: dossier) } it { is_expected.to eq(1) } end + + context 'with another dossier' do + let!(:dossier2){create(:dossier, procedure: procedure, state: 'received')} + let!(:follow2){ create(:follow, dossier: dossier2, gestionnaire: gestionnaire) } + + context 'and some notifications' do + let!(:notification){ create(:notification, already_read: false, dossier: dossier) } + let!(:notification2){ create(:notification, already_read: false, dossier: dossier) } + let!(:notification3){ create(:notification, already_read: false, dossier: dossier) } + + let!(:notification4){ create(:notification, already_read: false, dossier: dossier2) } + let!(:notification5){ create(:notification, already_read: false, dossier: dossier2) } + + it { is_expected.to eq(2) } + end + end end end end From cae3e1f420877e3bf97e73ef06d2cbe546f22f9d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 10:03:21 +0200 Subject: [PATCH 14/25] Commentaire#internal_notification => #notify_gestionnaires --- app/models/commentaire.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 0e39e5eba..fb9a2f509 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -4,7 +4,7 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative - after_save :internal_notification + after_save :notify_gestionnaires def header "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') @@ -12,7 +12,7 @@ class Commentaire < ActiveRecord::Base private - def internal_notification + def notify_gestionnaires if email == dossier.user.email || dossier.invites_user.pluck(:email).to_a.include?(email) NotificationService.new('commentaire', self.dossier.id).notify end From 9c3cde2b2eaf6f7c64ebc43e20d62415afa7787d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 13:40:32 +0200 Subject: [PATCH 15/25] Move CommentairesController#notify_user_user_with_mail to Commentaire --- app/controllers/commentaires_controller.rb | 11 +-------- app/models/commentaire.rb | 5 ++++ .../dossiers/commentaires_controller_spec.rb | 23 ------------------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index 920a64155..b22ada7eb 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -35,15 +35,12 @@ class CommentairesController < ApplicationController end @commentaire.body = params['texte_commentaire'] - saved = false unless @commentaire.body.blank? && @commentaire.piece_justificative.nil? - saved = @commentaire.save unless flash.alert + @commentaire.save unless flash.alert else flash.alert = "Veuillez rédiger un message ou ajouter une pièce jointe." end - notify_user_with_mail(@commentaire) if saved - if is_gestionnaire? unless current_gestionnaire.follow? @commentaire.dossier current_gestionnaire.toggle_follow_dossier @commentaire.dossier @@ -63,10 +60,4 @@ class CommentairesController < ApplicationController def is_gestionnaire? false end - - private - - def notify_user_with_mail(commentaire) - NotificationMailer.new_answer(commentaire.dossier).deliver_now! unless current_user.try(:email) == commentaire.dossier.user.email - end end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index fb9a2f509..8956831bd 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -5,6 +5,7 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative after_save :notify_gestionnaires + after_save :notify_user_with_mail def header "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') @@ -17,4 +18,8 @@ class Commentaire < ActiveRecord::Base NotificationService.new('commentaire', self.dossier.id).notify end end + + def notify_user_with_mail + NotificationMailer.new_answer(dossier).deliver_now! unless (current_user.try(:email) == dossier.user.email || email == 'contact@tps.apientreprise.fr') + end end diff --git a/spec/controllers/users/dossiers/commentaires_controller_spec.rb b/spec/controllers/users/dossiers/commentaires_controller_spec.rb index d56a18d9b..f83943979 100644 --- a/spec/controllers/users/dossiers/commentaires_controller_spec.rb +++ b/spec/controllers/users/dossiers/commentaires_controller_spec.rb @@ -45,27 +45,4 @@ describe Users::Dossiers::CommentairesController, type: :controller do end end - - describe '#notify_user_with_mail' do - let(:commentaire){create(:commentaire)} - - context 'when usager is writing a commentaire on dossier' do - before { sign_in commentaire.dossier.user } - - it { - expect(NotificationMailer).to_not receive(:new_answer) - subject.send(:notify_user_with_mail, commentaire) - } - end - - context 'when anybody else but usager is writing a commentaire' do - before { sign_in create(:user, email: 'administrateur@test.fr') } - - it { - expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer) - expect(NotificationMailer).to receive(:deliver_now!) - subject.send(:notify_user_with_mail, commentaire) - } - end - end end From c07b83b26601270e6f3c3e3cd7f4df8f9fce8891 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 10 May 2017 10:56:30 +0200 Subject: [PATCH 16/25] Commentaire#notify_user_with_mail -> #notify_user --- app/models/commentaire.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 8956831bd..e0f6598cb 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -5,7 +5,7 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative after_save :notify_gestionnaires - after_save :notify_user_with_mail + after_save :notify_user def header "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') @@ -19,7 +19,7 @@ class Commentaire < ActiveRecord::Base end end - def notify_user_with_mail + def notify_user NotificationMailer.new_answer(dossier).deliver_now! unless (current_user.try(:email) == dossier.user.email || email == 'contact@tps.apientreprise.fr') end end From 1235fce34ab9433cdabef20f208de204884236c6 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 13:44:40 +0200 Subject: [PATCH 17/25] Refactor Commentaire#notify_user --- app/models/commentaire.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index e0f6598cb..1617e36c7 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -20,6 +20,8 @@ class Commentaire < ActiveRecord::Base end def notify_user - NotificationMailer.new_answer(dossier).deliver_now! unless (current_user.try(:email) == dossier.user.email || email == 'contact@tps.apientreprise.fr') + if email != dossier.user.email && email != 'contact@tps.apientreprise.fr' + NotificationMailer.new_answer(dossier).deliver_now! + end end end From 8a5420301c2caa5ba0482ed9cd84b6fa6d4aa9b3 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 13:32:48 +0200 Subject: [PATCH 18/25] Add Commentaire#notify to dispatch notifications --- app/models/commentaire.rb | 32 +++++++++++++++----- spec/factories/invite_user.rb | 24 +++++++++++++++ spec/models/commentaire_spec.rb | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 spec/factories/invite_user.rb diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 1617e36c7..001976ab3 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -4,8 +4,7 @@ class Commentaire < ActiveRecord::Base belongs_to :piece_justificative - after_save :notify_gestionnaires - after_save :notify_user + after_create :notify def header "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') @@ -13,15 +12,32 @@ class Commentaire < ActiveRecord::Base private - def notify_gestionnaires - if email == dossier.user.email || dossier.invites_user.pluck(:email).to_a.include?(email) - NotificationService.new('commentaire', self.dossier.id).notify + def notify + dossier_user_email = dossier.user.email + invited_users_emails = dossier.invites_user.pluck(:email).to_a + + case email + when "contact@tps.apientreprise.fr" + # The commentaire is a copy of an automated notification email + # we sent to a user, so do nothing + when dossier_user_email, *invited_users_emails + # A user or an inved user posted a commentaire, + # we need to notify the gestionnaires + + notify_gestionnaires + else + # A gestionnaire posted a commentaire, + # we need to notify the user + + notify_user end end + def notify_gestionnaires + NotificationService.new('commentaire', self.dossier.id).notify + end + def notify_user - if email != dossier.user.email && email != 'contact@tps.apientreprise.fr' - NotificationMailer.new_answer(dossier).deliver_now! - end + NotificationMailer.new_answer(dossier).deliver_now! end end diff --git a/spec/factories/invite_user.rb b/spec/factories/invite_user.rb new file mode 100644 index 000000000..c4f7dcdbd --- /dev/null +++ b/spec/factories/invite_user.rb @@ -0,0 +1,24 @@ +FactoryGirl.define do + factory :invite_user do + email 'plop@octo.com' + + after(:build) do |invite, _evaluator| + if invite.dossier.nil? + invite.dossier = create(:dossier) + end + + unless invite.user.nil? + invite.email = invite.user.email + end + end + + trait :with_user do + after(:build) do |invite, _evaluator| + if invite.user.nil? + invite.user = create(:user) + invite.email = invite.user.email + end + end + end + end +end diff --git a/spec/models/commentaire_spec.rb b/spec/models/commentaire_spec.rb index efcf9bff1..8decaf4ae 100644 --- a/spec/models/commentaire_spec.rb +++ b/spec/models/commentaire_spec.rb @@ -8,4 +8,56 @@ describe Commentaire do it { is_expected.to belong_to(:dossier) } it { is_expected.to belong_to(:piece_justificative) } + + describe "#notify" do + let(:procedure) { create(:procedure) } + let(:gestionnaire) { create(:gestionnaire) } + let(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: procedure) } + let(:user) { create(:user) } + let(:dossier) { create(:dossier, procedure: procedure, user: user) } + let(:commentaire) { Commentaire.new(dossier: dossier) } + + context "with a commentaire created by a user" do + it "calls notify_gestionnaires" do + expect(commentaire).to receive(:notify_gestionnaires) + + commentaire.email = user.email + commentaire.save + end + end + + context "with a commentaire created by an invited user" do + let(:user_invite) { create(:user) } + + before do + FactoryGirl.create(:invite_user, email: "invite@tps.apientreprise.fr", dossier: dossier, user: user_invite) + end + + it "calls notify_gestionnaires" do + expect(commentaire).to receive(:notify_gestionnaires) + + commentaire.email = user_invite.email + commentaire.save + end + end + + context "with a commentaire created by a gestionnaire" do + it "calls notify_user" do + expect(commentaire).to receive(:notify_user) + + commentaire.email = gestionnaire.email + commentaire.save + end + end + + context "with a commentaire automatically created (notification)" do + it "does not call notify_user or notify_gestionnaires" do + expect(commentaire).not_to receive(:notify_user) + expect(commentaire).not_to receive(:notify_gestionnaires) + + commentaire.email = "contact@tps.apientreprise.fr" + commentaire.save + end + end + end end From 8ba55a0d5d50b9ed07285b9c6534dbe813cd5703 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 14:35:57 +0200 Subject: [PATCH 19/25] Mutualize the email address in a localised string --- app/mailers/application_mailer.rb | 2 +- app/mailers/notification_mailer.rb | 2 +- app/models/commentaire.rb | 2 +- config/initializers/devise.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 243266f78..8730c2d2e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "'Téléprocédures Simplifiées' " + default from: "'Téléprocédures Simplifiées' <#{I18n.t('dynamics.contact_email')}>" layout 'mailer' end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 9bf486f17..d2ddbb195 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -21,7 +21,7 @@ class NotificationMailer < ApplicationMailer def create_commentaire_for_notification Commentaire.create( dossier: @dossier, - email: "contact@tps.apientreprise.fr", + email: I18n.t("dynamics.contact_email"), body: ["[#{@obj}]", @body].join("

") ) end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 001976ab3..d62e87eac 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -17,7 +17,7 @@ class Commentaire < ActiveRecord::Base invited_users_emails = dossier.invites_user.pluck(:email).to_a case email - when "contact@tps.apientreprise.fr" + when I18n.t("dynamics.contact_email") # The commentaire is a copy of an automated notification email # we sent to a user, so do nothing when dossier_user_email, *invited_users_emails diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 37cbd567a..60f55f640 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -10,7 +10,7 @@ Devise.setup do |config| # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = "'Téléprocédures Simplifiées' " + config.mailer_sender = "'Téléprocédures Simplifiées' <#{I18n.t('dynamics.contact_email')}>" # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' From ac1782256a43c01c217cba9df26894766ee5dc84 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 12 May 2017 11:26:20 +0200 Subject: [PATCH 20/25] Fix #282 use disable_with to avoid sending same message twice --- app/views/dossiers/commentaires/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/dossiers/commentaires/_form.html.haml b/app/views/dossiers/commentaires/_form.html.haml index e88551110..8360e1ba1 100644 --- a/app/views/dossiers/commentaires/_form.html.haml +++ b/app/views/dossiers/commentaires/_form.html.haml @@ -7,4 +7,4 @@ %h4.text-primary{ style: 'margin-top: 0px;' } Ajouter un fichier = file_field_tag "piece_justificative[content]", accept: PieceJustificative.accept_format, style: 'float: left; margin-left: 20px;' .col-md-6.text-right - %input#save-message.form-control.btn.btn-danger{ type: 'submit', value: 'ENVOYER' } + = submit_tag 'Envoyer', id: 'save-message', class: 'form-control btn btn-danger', data: { disable_with: 'Envoi...' } From 2b25a17af1ee8e0579955649769ec29d4a5c5e63 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 16:23:41 +0200 Subject: [PATCH 21/25] [Ref #288] Remove /bin from .gitignore, add binstubs --- .gitignore | 1 - bin/bundle | 3 +++ bin/rails | 4 ++++ bin/rake | 4 ++++ bin/setup | 34 ++++++++++++++++++++++++++++++++++ bin/update | 29 +++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/update diff --git a/.gitignore b/.gitignore index 308ee4352..b14ef0756 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,6 @@ public/uploads public/downloads -bin/* config/initializers/token.rb config/initializers/super_admin.rb doc/*.svg diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 000000000..073966023 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..e620b4dad --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..a8e4462f2 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end From 48a7f8aaf2ba1b944b09017db526a394bd9d5169 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Mon, 15 May 2017 15:14:03 +0200 Subject: [PATCH 22/25] Locales: fix wrong indentation in yaml --- config/locales/fr.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 912dd5bd5..f1da0acaa 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -213,6 +213,24 @@ fr: - oct. - nov. - déc. + month_names: + - + - janvier + - février + - mars + - avril + - mai + - juin + - juillet + - août + - septembre + - octobre + - novembre + - décembre + order: + - :day + - :month + - :year day_names: - dimanche - lundi @@ -225,24 +243,6 @@ fr: default: "%d/%m/%Y" short: "%e %b" long: "%e %B %Y" - month_names: - - - - janvier - - février - - mars - - avril - - mai - - juin - - juillet - - août - - septembre - - octobre - - novembre - - décembre - order: - - :day - - :month - - :year datetime: distance_in_words: about_x_hours: From f67aa63766c5e8338572fa9b6257332744bcabae Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 17:56:01 +0200 Subject: [PATCH 23/25] [Fix #285] Use a has_many through for Gestionnaire#dossiers_follow --- app/models/gestionnaire.rb | 5 +---- spec/models/gestionnaire_spec.rb | 13 ------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 6dda6ed7a..5fc2ee2be 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -9,6 +9,7 @@ class Gestionnaire < ActiveRecord::Base has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures + has_many :dossiers_follow, through: :follows, source: :dossier has_many :follows has_many :preference_list_dossiers @@ -17,10 +18,6 @@ class Gestionnaire < ActiveRecord::Base include CredentialsSyncableConcern - def dossiers_follow - @dossiers_follow ||= dossiers.joins(:follows).where("follows.gestionnaire_id = #{id}") - end - def procedure_filter return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter]) diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 5b286ceaa..8525b2e86 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -116,19 +116,6 @@ describe Gestionnaire, type: :model do end end - describe '#dossiers_follow' do - let!(:dossier) { create :dossier, procedure: procedure, state: :initiated } - - before do - create :follow, dossier_id: dossier.id, gestionnaire_id: gestionnaire.id - end - - subject { gestionnaire.dossiers_follow } - - it { expect(Follow.all.size).to eq 1 } - it { expect(subject.first).to eq dossier } - end - describe '#build_default_preferences_list_dossier' do subject { gestionnaire.preference_list_dossiers } From a58a8684d9452c838b9c26565ab554878b1c7b1b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 12 May 2017 17:58:25 +0200 Subject: [PATCH 24/25] [Fix #285] Gestionnaire.dossiers_follow -> followed_dossiers --- app/facades/dossiers_list_facades.rb | 2 +- app/models/gestionnaire.rb | 8 ++++---- app/services/dossiers_list_gestionnaire_service.rb | 2 +- ...ft_panel_backoffice_dossierscontroller_index.html.haml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/facades/dossiers_list_facades.rb b/app/facades/dossiers_list_facades.rb index 9ab6b6055..0a05a4148 100644 --- a/app/facades/dossiers_list_facades.rb +++ b/app/facades/dossiers_list_facades.rb @@ -18,7 +18,7 @@ class DossiersListFacades end def total_dossier_follow - @current_devise_profil.dossiers_follow.count + @current_devise_profil.followed_dossiers.count end def total_new_dossier diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 5fc2ee2be..b5e84bcdd 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -9,7 +9,7 @@ class Gestionnaire < ActiveRecord::Base has_many :assign_to, dependent: :destroy has_many :procedures, through: :assign_to has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures - has_many :dossiers_follow, through: :follows, source: :dossier + has_many :followed_dossiers, through: :follows, source: :dossier has_many :follows has_many :preference_list_dossiers @@ -72,10 +72,10 @@ class Gestionnaire < ActiveRecord::Base end def notifications_for procedure - procedure_ids = dossiers_follow.pluck(:procedure_id) + procedure_ids = followed_dossiers.pluck(:procedure_id) if procedure_ids.include?(procedure.id) - return dossiers_follow.where(procedure_id: procedure.id) + return followed_dossiers.where(procedure_id: procedure.id) .inject(0) do |acc, dossier| acc += dossier.notifications.where(already_read: false).count end @@ -84,7 +84,7 @@ class Gestionnaire < ActiveRecord::Base end def dossiers_with_notifications_count_for_procedure(procedure) - followed_dossiers_id = dossiers_follow.where(procedure: procedure).pluck(:id) + followed_dossiers_id = followed_dossiers.where(procedure: procedure).pluck(:id) Notification.unread.where(dossier_id: followed_dossiers_id).select(:dossier_id).distinct(:dossier_id).count end diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index a53c35b4c..63a91783c 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -25,7 +25,7 @@ class DossiersListGestionnaireService end def suivi - @suivi ||= @current_devise_profil.dossiers_follow.merge(dossiers_to_display) + @suivi ||= @current_devise_profil.followed_dossiers.merge(dossiers_to_display) end def nouveaux 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 60f5ed36b..c1dfe2bd7 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 @@ -1,6 +1,6 @@ #first-block .dossiers-en-cours - .count= current_gestionnaire.dossiers_follow.count + .count= current_gestionnaire.followed_dossiers.count .text SUIVIS .nouveaux-dossiers .count= current_gestionnaire.dossiers.nouveaux.count From 9bec2e9536aa5014632414a79fcb9cba35692c8a Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Mon, 15 May 2017 15:32:31 +0200 Subject: [PATCH 25/25] Fix #281 Remove unreadable tooltip on procedure libelle --- .../_navbar_backoffice_dossierscontroller_show.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 194f5d82f..97027181d 100644 --- a/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml +++ b/app/views/layouts/navbars/_navbar_backoffice_dossierscontroller_show.html.haml @@ -1,6 +1,5 @@ .col-xs-7.main-info - %span{ 'data-toggle' => :tooltip, "data-placement" => :bottom, title: @facade.dossier.procedure.libelle } - = @facade.dossier.procedure.libelle + = @facade.dossier.procedure.libelle .col-xs-3.options .row .col-xs-12