From dc045bdefb776bb73ab3d4280303621d83ad4892 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 18:45:46 +0200 Subject: [PATCH 01/17] [Fix #1808] Use &. where possible --- .../admin/attestation_templates_controller.rb | 2 +- app/controllers/admin/procedures_controller.rb | 2 +- app/controllers/new_gestionnaire/avis_controller.rb | 2 +- app/helpers/application_helper.rb | 6 +++--- app/mailers/avis_mailer.rb | 2 +- app/models/avis.rb | 5 ++--- app/models/mails/closed_mail.rb | 2 +- app/models/procedure.rb | 10 +++++----- app/serializers/dossier_serializer.rb | 2 +- app/serializers/dossier_table_export_serializer.rb | 10 +++++----- app/views/layouts/_new_header.haml | 1 + .../dossiers/editable_champs/_dossier_link.html.haml | 2 +- .../users/description/champs/_dossier_link.html.haml | 2 +- lib/tasks/2018_02_28_clean_gestionnaire_emails.rake | 4 ++-- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/admin/attestation_templates_controller.rb b/app/controllers/admin/attestation_templates_controller.rb index 0cdff87c5..403bdb9e1 100644 --- a/app/controllers/admin/attestation_templates_controller.rb +++ b/app/controllers/admin/attestation_templates_controller.rb @@ -71,7 +71,7 @@ class Admin::AttestationTemplatesController < AdminController end def uninterlaced_png(uploaded_file) - if uploaded_file.present? && uploaded_file.content_type == 'image/png' + if uploaded_file&.content_type == 'image/png' chunky_img = ChunkyPNG::Image.from_io(uploaded_file) chunky_img.save(uploaded_file.tempfile.to_path, interlace: false) uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb') diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index ad6cb6b2c..9be16c708 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -225,7 +225,7 @@ class Admin::ProceduresController < AdminController def procedure_params editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on] - if @procedure.try(:locked?) + if @procedure&.locked? params.require(:procedure).permit(*editable_params) else params.require(:procedure).permit(*editable_params, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb index 00452c818..e20c36812 100644 --- a/app/controllers/new_gestionnaire/avis_controller.rb +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -118,7 +118,7 @@ module NewGestionnaire # a gestionnaire is authenticated ... lets see if it can view the dossier redirect_to gestionnaire_avis_url(avis) - elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email] + elsif avis.gestionnaire&.email == params[:email] # the avis gestionnaire has already signed up and it sould sign in redirect_to new_gestionnaire_session_url diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7fddc56a0..72b29f510 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,9 +15,9 @@ module ApplicationHelper end def current_email - current_user.try(:email) || - current_gestionnaire.try(:email) || - current_administrateur.try(:email) + current_user&.email || + current_gestionnaire&.email || + current_administrateur&.email end def root_path_for_profile(nav_bar_profile) diff --git a/app/mailers/avis_mailer.rb b/app/mailers/avis_mailer.rb index c84d6a74e..52c826b02 100644 --- a/app/mailers/avis_mailer.rb +++ b/app/mailers/avis_mailer.rb @@ -1,7 +1,7 @@ class AvisMailer < ApplicationMailer def avis_invitation(avis) @avis = avis - email = @avis.gestionnaire.try(:email) || @avis.email + email = @avis.gestionnaire&.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 37d8e96cf..f0b9eb6ec 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -19,7 +19,7 @@ class Avis < ApplicationRecord scope :updated_since?, -> (date) { where('avis.updated_at > ?', date) } def email_to_display - gestionnaire.try(:email) || email + gestionnaire&.email || email end def self.link_avis_to_gestionnaire(gestionnaire) @@ -27,8 +27,7 @@ class Avis < ApplicationRecord 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 + Avis.find_by(id: avis_id)&.email == email end private diff --git a/app/models/mails/closed_mail.rb b/app/models/mails/closed_mail.rb index 757593a3a..a52b9e515 100644 --- a/app/models/mails/closed_mail.rb +++ b/app/models/mails/closed_mail.rb @@ -11,7 +11,7 @@ module Mails def self.default_template_name_for_procedure(procedure) attestation_template = procedure.attestation_template - if attestation_template.present? && attestation_template.activated? + if attestation_template&.activated? "mails/closed_mail_with_attestation" else "mails/closed_mail" diff --git a/app/models/procedure.rb b/app/models/procedure.rb index b2b5420eb..fb88eed0f 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -209,11 +209,11 @@ class Procedure < ApplicationRecord end procedure.administrateur = admin - 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) + procedure.initiated_mail = initiated_mail&.dup + procedure.received_mail = received_mail&.dup + procedure.closed_mail = closed_mail&.dup + procedure.refused_mail = refused_mail&.dup + procedure.without_continuation_mail = without_continuation_mail&.dup procedure.cloned_from_library = from_library procedure.parent_procedure = self diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index 18601f89e..41204b774 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -31,7 +31,7 @@ class DossierSerializer < ActiveModel::Serializer end def email - object.user.try(:email) + object.user&.email end def entreprise diff --git a/app/serializers/dossier_table_export_serializer.rb b/app/serializers/dossier_table_export_serializer.rb index f19e1e0f8..dde389ddb 100644 --- a/app/serializers/dossier_table_export_serializer.rb +++ b/app/serializers/dossier_table_export_serializer.rb @@ -18,7 +18,7 @@ class DossierTableExportSerializer < ActiveModel::Serializer :individual_birthdate def email - object.user.try(:email) + object.user&.email end def state @@ -47,19 +47,19 @@ class DossierTableExportSerializer < ActiveModel::Serializer end def individual_prenom - object.individual.try(:prenom) + object.individual&.prenom end def individual_nom - object.individual.try(:nom) + object.individual&.nom end def individual_birthdate - object.individual.try(:birthdate) + object.individual&.birthdate end def individual_gender - object.individual.try(:gender) + object.individual&.gender end def emails_accompagnateurs diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 4e68d1123..f19ab1d10 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -1,3 +1,4 @@ +/ We can't use &. because the controller may not implement #nav_bar_profile - nav_bar_profile = controller.try(:nav_bar_profile) .new-header{ class: current_page?(root_path) ? nil : "new-header-with-border" } diff --git a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml index 53ca52c5c..72ce494ec 100644 --- a/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml +++ b/app/views/shared/dossiers/editable_champs/_dossier_link.html.haml @@ -1,7 +1,7 @@ - dossier = Dossier.find_by(id: champ.value) - show_text_summary = dossier.present? - show_warning = !show_text_summary && champ.value.present? -- text_summary = sanitize(dossier.try(:text_summary)) +- text_summary = sanitize(dossier&.text_summary) .dossier-link = form.number_field :value, diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml index c29f2745c..7af6d5016 100644 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ b/app/views/users/description/champs/_dossier_link.html.haml @@ -1,7 +1,7 @@ - dossier = Dossier.find_by(id: champ.value) - show_text_summary = dossier.present? - show_warning = !show_text_summary && champ.value.present? -- text_summary = dossier.try(:text_summary) +- text_summary = dossier&.text_summary .dossier-link %input.form-control{ name: "champs['#{ champ.id }']", diff --git a/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake b/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake index a95a934c3..dc3c581bc 100644 --- a/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake +++ b/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake @@ -1,11 +1,11 @@ namespace :'2018_02_28_clean_invalid_emails_accounts' do task clean: :environment do Gestionnaire.pluck(:email, :id).select { |e, id| e.include?(" ") }.each do |email, id| - Gestionnaire.find_by(id: id, current_sign_in_at: nil).try(:destroy) # ensure account was never used + Gestionnaire.find_by(id: id, current_sign_in_at: nil)&.destroy # ensure account was never used end User.pluck(:email, :id).select { |e, id| e.include?(" ") }.each do |email, id| - User.find_by(id: id, current_sign_in_at: nil).try(:destroy) # ensure account was never used + User.find_by(id: id, current_sign_in_at: nil)&.destroy # ensure account was never used end end end From faa56956c55adb6c5d3c2d09c4a5431c89cb87e1 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 18:54:12 +0200 Subject: [PATCH 02/17] [Fix #1744] Remove useless variable --- app/controllers/new_user/dossiers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index d2daad675..f710fe14f 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -138,7 +138,7 @@ module NewUser end def dossier_with_champs - @dossier_with_champs ||= Dossier.with_ordered_champs.find(params[:id]) + Dossier.with_ordered_champs.find(params[:id]) end def ensure_ownership! From 661010100d82d9a6d04bf10f6b59d6f93fe9b2f4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 18:58:09 +0200 Subject: [PATCH 03/17] [Fix #1536] Remove stringupcasepatch --- Gemfile | 2 -- Gemfile.lock | 2 -- app/views/dossiers/_edit_carto.html.haml | 2 +- app/views/dossiers/_edit_dossier.html.haml | 2 +- app/views/dossiers/_infos_dossier.html.haml | 6 +++--- .../_left_panel_admin_procedurescontroller_index.html.haml | 2 +- .../_left_panel_users_dossierscontroller_index.html.haml | 2 +- config/initializers/stringupcasepatch.rb | 7 ------- 8 files changed, 7 insertions(+), 18 deletions(-) delete mode 100644 config/initializers/stringupcasepatch.rb diff --git a/Gemfile b/Gemfile index 4127ede86..c515b2d96 100644 --- a/Gemfile +++ b/Gemfile @@ -38,8 +38,6 @@ gem 'kaminari' # Decorators gem 'draper' -gem 'unicode_utils' - # Gestion des comptes utilisateurs gem 'devise' gem 'devise-async' diff --git a/Gemfile.lock b/Gemfile.lock index 110b9c397..a91fc5d90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -746,7 +746,6 @@ GEM unf_ext unf_ext (0.0.7.5) unicode-display_width (1.3.2) - unicode_utils (1.4.0) unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) @@ -866,7 +865,6 @@ DEPENDENCIES turbolinks typhoeus uglifier - unicode_utils unicorn vcr warden! diff --git a/app/views/dossiers/_edit_carto.html.haml b/app/views/dossiers/_edit_carto.html.haml index 8d2e5dc9b..85567d5b2 100644 --- a/app/views/dossiers/_edit_carto.html.haml +++ b/app/views/dossiers/_edit_carto.html.haml @@ -2,4 +2,4 @@ - if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user)) %a#maj_carte.action{ href: "/users/dossiers/#{@facade.dossier.id}/carte" } .col-lg-2.col-md-2.col-sm-2.col-xs-2.action - = 'éditer'.upcase + = 'ÉDITER' diff --git a/app/views/dossiers/_edit_dossier.html.haml b/app/views/dossiers/_edit_dossier.html.haml index eecc8aab9..14e3800cd 100644 --- a/app/views/dossiers/_edit_dossier.html.haml +++ b/app/views/dossiers/_edit_dossier.html.haml @@ -2,4 +2,4 @@ - if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user)) = link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do #edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action - = "éditer".upcase + = "ÉDITER" diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index d5e0f1ec1..0677e67e3 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -3,7 +3,7 @@ - if @facade.procedure.for_individual? .row.title-row .col-xs-4.split-hr - .col-xs-4.dossier-title= t('utils.depositaire').upcase + .col-xs-4.dossier-title= t('utils.depositaire') .col-xs-4.split-hr .row .col-xs-6.depositaire-label Civilité @@ -29,7 +29,7 @@ - if champ.type_champ == 'header_section' .row.title-row.margin-top-40 .col-xs-3.split-hr - .col-xs-6.dossier-title= champ.libelle.upcase + .col-xs-6.dossier-title= champ.libelle .col-xs-3.split-hr - else .row @@ -60,7 +60,7 @@ .col-xs-12 .row.title-row .col-xs-4.split-hr - .col-xs-4.dossier-title= t('utils.pieces').upcase + .col-xs-4.dossier-title= t('utils.pieces') .col-xs-4.split-hr .col-xs-12#pieces-justificatives.margin-bot-40 diff --git a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml index 68291d6d5..362576da5 100644 --- a/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_admin_procedurescontroller_index.html.haml @@ -2,7 +2,7 @@ .en-cours %b = dossier_count = current_administrateur.procedures.count - = ("Procedures".pluralize(dossier_count)).upcase + = "Procedures".pluralize(dossier_count) #action-block 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 83c65aa77..31ad41f26 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 @@ -1,7 +1,7 @@ #first-block .en-cours = dossier_count = current_user.dossiers.count - = ("Dossier".pluralize(dossier_count)).upcase + = "Dossier".pluralize(dossier_count) %br EN COURS diff --git a/config/initializers/stringupcasepatch.rb b/config/initializers/stringupcasepatch.rb deleted file mode 100644 index 39d2e107a..000000000 --- a/config/initializers/stringupcasepatch.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "unicode_utils/upcase" - -class String - def upcase - UnicodeUtils.upcase(self) - end -end From 44af4e95f19e458599f17d610d490d60c1e311e8 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 30 May 2018 19:49:15 +0200 Subject: [PATCH 04/17] [Fix #2002] Create missing accuse de reception messages --- lib/tasks/2018_05_30_missed_ar_messages.rake | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/tasks/2018_05_30_missed_ar_messages.rake diff --git a/lib/tasks/2018_05_30_missed_ar_messages.rake b/lib/tasks/2018_05_30_missed_ar_messages.rake new file mode 100644 index 000000000..6f2cf858e --- /dev/null +++ b/lib/tasks/2018_05_30_missed_ar_messages.rake @@ -0,0 +1,29 @@ +namespace :'2018_05_30_missed_ar_messages' do + task restore: :environment do + create_commentaires(:en_construction_at, :initiated_mail_template) + create_commentaires(:processed_at, :closed_mail_template, Dossier.where(state: 'accepte')) + create_commentaires(:processed_at, :refused_mail_template, Dossier.where(state: 'refuse')) + create_commentaires(:processed_at, :without_continuation_mail_template, Dossier.where(state: 'sans_suite')) + end + + def create_commentaires(date_name, template_name, dossiers = Dossier) + error_range = DateTime.new(2018, 05, 28, 13, 33)..DateTime.new(2018, 05, 30, 15, 39) + + dossiers.includes(:procedure).where(date_name => error_range).find_each(batch_size: 100) do |dossier| + print "#{dossier.id}\n" + create_commentaire(dossier, dossier.procedure.send(template_name), dossier.send(date_name)) + end + end + + def create_commentaire(dossier, template, date) + subject = template.subject_for_dossier(dossier) + body = template.body_for_dossier(dossier) + + Commentaire.create( + dossier: dossier, + email: I18n.t("dynamics.contact_email"), + body: "[#{subject}]

#{body}", + created_at: date + ) + end +end From bb8adba9b9f364c5664c56a79eb5368bd41a4948 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 23:47:37 +0200 Subject: [PATCH 05/17] Use goddamn parentheses --- 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 7d803b9cf..749951da7 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -31,7 +31,7 @@ class NotificationMailer < ApplicationMailer end def new_answer(dossier) - send_mail dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}" + send_mail(dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}") end private @@ -39,8 +39,8 @@ class NotificationMailer < ApplicationMailer def send_notification(dossier, mail_template) vars_mailer(dossier) - @subject = mail_template.subject_for_dossier dossier - @body = mail_template.body_for_dossier dossier + @subject = mail_template.subject_for_dossier(dossier) + @body = mail_template.body_for_dossier(dossier) create_commentaire_for_notification @@ -61,7 +61,7 @@ class NotificationMailer < ApplicationMailer end def send_mail(dossier, subject) - vars_mailer dossier + vars_mailer(dossier) mail(subject: subject) end From 7ea37abefa1c4d7afe34dbe26c42dfaee4747676 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 23:51:29 +0200 Subject: [PATCH 06/17] Use a local variable instead of an instance variable --- app/mailers/notification_mailer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 749951da7..3440fd3f8 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -9,9 +9,9 @@ class NotificationMailer < ApplicationMailer def send_draft_notification(dossier) vars_mailer(dossier) - @subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}" + subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}" - mail(subject: @subject) + mail(subject: subject) end def send_initiated_notification(dossier) From a57e2388f6c92b2f36f88a6177bf971e4b26a79d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 30 May 2018 23:55:34 +0200 Subject: [PATCH 07/17] =?UTF-8?q?Unify=20NotificationMailer=20methods?= =?UTF-8?q?=E2=80=99=20signatures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/notification_mailer.rb | 3 +-- app/models/dossier.rb | 2 +- spec/mailers/notification_mailer_spec.rb | 2 +- spec/models/dossier_spec.rb | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 3440fd3f8..1df80c127 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,8 +1,7 @@ class NotificationMailer < ApplicationMailer default to: Proc.new { @user.email } - def send_dossier_received(dossier_id) - dossier = Dossier.find(dossier_id) + def send_dossier_received(dossier) send_notification(dossier, dossier.procedure.received_mail_template) end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9452cc0eb..ef2351dd4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -323,7 +323,7 @@ class Dossier < ApplicationRecord def send_dossier_received if saved_change_to_state? && en_instruction? - NotificationMailer.send_dossier_received(id).deliver_later + NotificationMailer.send_dossier_received(self).deliver_later end end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index d60fb10a3..37a579fa7 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -38,7 +38,7 @@ RSpec.describe NotificationMailer, type: :mailer do end describe '.send_dossier_received' do - subject { described_class.send_dossier_received(dossier.id) } + subject { described_class.send_dossier_received(dossier) } let(:email_template) { create(:received_mail) } before do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 09501c4d8..924aed3a5 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -603,7 +603,7 @@ describe Dossier do it "sends an email when the dossier becomes en_instruction" do dossier.en_instruction! - expect(NotificationMailer).to have_received(:send_dossier_received).with(dossier.id) + expect(NotificationMailer).to have_received(:send_dossier_received).with(dossier) end it "does not an email when the dossier becomes accepte" do From 02c2f681aa4b608b49e3e46e822acd073ca5ba2b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 00:04:06 +0200 Subject: [PATCH 08/17] Reorder some methods --- app/mailers/notification_mailer.rb | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 1df80c127..3bbf648d6 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,8 +1,8 @@ class NotificationMailer < ApplicationMailer default to: Proc.new { @user.email } - def send_dossier_received(dossier) - send_notification(dossier, dossier.procedure.received_mail_template) + def new_answer(dossier) + send_mail(dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}") end def send_draft_notification(dossier) @@ -13,6 +13,10 @@ class NotificationMailer < ApplicationMailer mail(subject: subject) end + def send_dossier_received(dossier) + send_notification(dossier, dossier.procedure.received_mail_template) + end + def send_initiated_notification(dossier) send_notification(dossier, dossier.procedure.initiated_mail_template) end @@ -29,11 +33,18 @@ class NotificationMailer < ApplicationMailer send_notification(dossier, dossier.procedure.without_continuation_mail_template) end - def new_answer(dossier) - send_mail(dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}") + private + + def vars_mailer(dossier) + @dossier = dossier + @user = dossier.user end - private + def send_mail(dossier, subject) + vars_mailer(dossier) + + mail(subject: subject) + end def send_notification(dossier, mail_template) vars_mailer(dossier) @@ -53,15 +64,4 @@ class NotificationMailer < ApplicationMailer body: ["[#{@subject}]", @body].join("

") ) end - - def vars_mailer(dossier) - @dossier = dossier - @user = dossier.user - end - - def send_mail(dossier, subject) - vars_mailer(dossier) - - mail(subject: subject) - end end From 8eacfa801cee721939c9e419b12886e511c3110c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 00:05:03 +0200 Subject: [PATCH 09/17] Use send_mail when possible --- app/mailers/notification_mailer.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 3bbf648d6..f1f6774aa 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -6,11 +6,7 @@ class NotificationMailer < ApplicationMailer end def send_draft_notification(dossier) - vars_mailer(dossier) - - subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}" - - mail(subject: subject) + send_mail(dossier, "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}") end def send_dossier_received(dossier) From 0d8cb50a3077119d655fef295f28654c9c671f9f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 00:07:08 +0200 Subject: [PATCH 10/17] Introduce a local variable to improve legibility --- app/mailers/notification_mailer.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index f1f6774aa..e4b13e53d 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -2,11 +2,15 @@ class NotificationMailer < ApplicationMailer default to: Proc.new { @user.email } def new_answer(dossier) - send_mail(dossier, "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}") + subject = "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}" + + send_mail(dossier, subject) end def send_draft_notification(dossier) - send_mail(dossier, "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}") + subject = "Retrouvez votre brouillon pour la démarche : #{dossier.procedure.libelle}" + + send_mail(dossier, subject) end def send_dossier_received(dossier) From 641f72a517225af4824b085529015b9f4f7d8e99 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 08:53:27 +0200 Subject: [PATCH 11/17] Stop relying on instance variables --- app/mailers/notification_mailer.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index e4b13e53d..48897fffd 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -49,19 +49,19 @@ class NotificationMailer < ApplicationMailer def send_notification(dossier, mail_template) vars_mailer(dossier) - @subject = mail_template.subject_for_dossier(dossier) - @body = mail_template.body_for_dossier(dossier) + subject = mail_template.subject_for_dossier(dossier) + body = mail_template.body_for_dossier(dossier) - create_commentaire_for_notification + create_commentaire_for_notification(dossier, subject, body) - mail(subject: @subject) { |format| format.html { @body } } + mail(subject: subject) { |format| format.html { body } } end - def create_commentaire_for_notification + def create_commentaire_for_notification(dossier, subject, body) Commentaire.create( - dossier: @dossier, + dossier: dossier, email: I18n.t("dynamics.contact_email"), - body: ["[#{@subject}]", @body].join("

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

") ) end end From 2e0abb054c80e264064f5cf31916528f75362a84 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 08:54:16 +0200 Subject: [PATCH 12/17] Stop doing something useless --- app/mailers/notification_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 48897fffd..1ae798e0f 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -36,12 +36,12 @@ class NotificationMailer < ApplicationMailer private def vars_mailer(dossier) - @dossier = dossier @user = dossier.user end def send_mail(dossier, subject) vars_mailer(dossier) + @dossier = dossier mail(subject: subject) end From 32a2ab153f021aea6e84647ccf40f886a4817f51 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 31 May 2018 08:56:32 +0200 Subject: [PATCH 13/17] Remove vars_mailer and simplify code --- app/mailers/notification_mailer.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 1ae798e0f..e01a681e4 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -1,6 +1,4 @@ class NotificationMailer < ApplicationMailer - default to: Proc.new { @user.email } - def new_answer(dossier) subject = "Nouveau message pour votre dossier demarches-simplifiees.fr nº #{dossier.id}" @@ -35,26 +33,22 @@ class NotificationMailer < ApplicationMailer private - def vars_mailer(dossier) - @user = dossier.user - end - def send_mail(dossier, subject) - vars_mailer(dossier) @dossier = dossier + email = dossier.user.email - mail(subject: subject) + mail(subject: subject, to: email) end def send_notification(dossier, mail_template) - vars_mailer(dossier) + email = dossier.user.email subject = mail_template.subject_for_dossier(dossier) body = mail_template.body_for_dossier(dossier) create_commentaire_for_notification(dossier, subject, body) - mail(subject: subject) { |format| format.html { body } } + mail(subject: subject, to: email) { |format| format.html { body } } end def create_commentaire_for_notification(dossier, subject, body) From 167ca260361dec3623d41be3f365cceb76cd05c5 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 31 May 2018 11:54:14 +0200 Subject: [PATCH 14/17] ManagerDemandeView: does not bug when there is no demand --- app/views/manager/demandes/index.html.erb | 96 ++++++++++++----------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/app/views/manager/demandes/index.html.erb b/app/views/manager/demandes/index.html.erb index f662a32a1..cefc88e74 100644 --- a/app/views/manager/demandes/index.html.erb +++ b/app/views/manager/demandes/index.html.erb @@ -8,54 +8,58 @@ -
- - - <% keys = @pending_demandes.first.keys %> - - <% keys.each do |key| %> - - <% end %> - - - - <% @pending_demandes.each do |demande| %> +<% if @pending_demandes.present? %> +
+
- <%= key %> - -
+ + <% keys = @pending_demandes.first.keys %> <% keys.each do |key| %> - + <% end %> - + + + <% @pending_demandes.each do |demande| %> + + <% keys.each do |key| %> + + <% end %> + - - - <% end %> - -
- <%= demande[key] %> - + <%= key %> + - <%= form_tag(manager_demandes_create_administrateur_path) do -%> - <%= select_tag "stage_id", - options_for_select({ - "administration centrale" => Pipedrive::DealAdapter::PIPEDRIVE_ADMIN_CENTRAL_STOCK_STAGE_ID, - "région" => Pipedrive::DealAdapter::PIPEDRIVE_REGIONS_STOCK_STAGE_ID, - "préfecture" => Pipedrive::DealAdapter::PIPEDRIVE_PREFECTURES_STOCK_STAGE_ID, - "département" =>Pipedrive::DealAdapter::PIPEDRIVE_DEPARTEMENTS_STOCK_STAGE_ID, - "commune" => Pipedrive::DealAdapter::PIPEDRIVE_COMMUNES_STOCK_STAGE_ID, - "organisme" => Pipedrive::DealAdapter::PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID - }), - style: 'margin-bottom: 20px; width: inherit;' %> + +
+ <%= demande[key] %> + + <%= form_tag(manager_demandes_create_administrateur_path) do -%> + <%= select_tag "stage_id", + options_for_select({ + "administration centrale" => Pipedrive::DealAdapter::PIPEDRIVE_ADMIN_CENTRAL_STOCK_STAGE_ID, + "région" => Pipedrive::DealAdapter::PIPEDRIVE_REGIONS_STOCK_STAGE_ID, + "préfecture" => Pipedrive::DealAdapter::PIPEDRIVE_PREFECTURES_STOCK_STAGE_ID, + "département" =>Pipedrive::DealAdapter::PIPEDRIVE_DEPARTEMENTS_STOCK_STAGE_ID, + "commune" => Pipedrive::DealAdapter::PIPEDRIVE_COMMUNES_STOCK_STAGE_ID, + "organisme" => Pipedrive::DealAdapter::PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID + }), + style: 'margin-bottom: 20px; width: inherit;' %> - <%= hidden_field_tag 'email', demande[:email] %> - <%= hidden_field_tag 'person_id', demande[:person_id] %> + <%= hidden_field_tag 'email', demande[:email] %> + <%= hidden_field_tag 'person_id', demande[:person_id] %> - <%= submit_tag 'Créer' %> - <% end -%> - - <%= button_to('Refuser', - manager_demandes_refuse_administrateur_path, - params: { person_id: demande[:person_id], email: demande[:email] }, - style: 'background-color: #FFFFFF; color: #293f54; border: 1px solid #dfe0e1') %> -
-
+ <%= submit_tag 'Créer' %> + <% end -%> + + + <%= button_to('Refuser', + manager_demandes_refuse_administrateur_path, + params: { person_id: demande[:person_id], email: demande[:email] }, + style: 'background-color: #FFFFFF; color: #293f54; border: 1px solid #dfe0e1') %> + + + <% end %> + + + +<% else %> +

Aucune demande

+<% end %> From 126c2f26875614388aa61748e30c70a1d82a325d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 31 May 2018 11:28:31 +0200 Subject: [PATCH 15/17] DubiousProcedure: update forbidden words --- app/jobs/find_dubious_procedures_job.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/jobs/find_dubious_procedures_job.rb b/app/jobs/find_dubious_procedures_job.rb index 22ac22f54..5f3edc1e4 100644 --- a/app/jobs/find_dubious_procedures_job.rb +++ b/app/jobs/find_dubious_procedures_job.rb @@ -3,8 +3,9 @@ class FindDubiousProceduresJob < ApplicationJob FORBIDDEN_KEYWORDS = [ 'NIR', 'NIRPP', 'race', 'religion', - 'carte bancaire', 'carte bleue', 'sécurité sociale', 'nationalité', - 'agdref', 'handicap', 'syndicat', 'politique' + 'carte bancaire', 'carte bleue', 'sécurité sociale', + 'agdref', 'handicap', 'syndicat', 'syndical', + 'parti politique', 'opinion politique', 'bord politique', 'courant politique' ] def perform(*args) From 2f5e02c90ea5b3ff428c5120afc6356e6b6d16a2 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 29 May 2018 16:52:30 +0200 Subject: [PATCH 16/17] Do not download backup if exists --- lib/tasks/dev.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 1a7b21198..c0bc7b01c 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -71,7 +71,10 @@ namespace :dev do task :import_db do filename = "tps_prod_#{1.day.ago.strftime("%d-%m-%Y")}.sql" local_file = "/tmp/#{filename}" - run_and_stop_if_error "scp -C deploy@sgmap_backup:/var/backup/production1/db/#{filename} #{local_file}" + + if !File.exist?(local_file) + run_and_stop_if_error "scp -C deploy@sgmap_backup:/var/backup/production1/db/#{filename} #{local_file}" + end dev_env_param = "RAILS_ENV=development" From 2f769ca933867c1085804fc88def7510876d97ba Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 30 May 2018 15:25:16 +0200 Subject: [PATCH 17/17] [#1995] Add gender and birthdate fields to API --- app/serializers/individual_serializer.rb | 6 ++++++ spec/serializers/individual_serializer_spec.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/serializers/individual_serializer.rb b/app/serializers/individual_serializer.rb index b35e01892..b7b3032a5 100644 --- a/app/serializers/individual_serializer.rb +++ b/app/serializers/individual_serializer.rb @@ -1,3 +1,9 @@ class IndividualSerializer < ActiveModel::Serializer + attribute :gender, key: :civilite attributes :nom, :prenom + attribute :birthdate, key: :date_naissance, if: :include_birthdate? + + def include_birthdate? + object&.dossier&.procedure&.ask_birthday + end end diff --git a/spec/serializers/individual_serializer_spec.rb b/spec/serializers/individual_serializer_spec.rb index f86b801a2..0617957f3 100644 --- a/spec/serializers/individual_serializer_spec.rb +++ b/spec/serializers/individual_serializer_spec.rb @@ -1,10 +1,20 @@ describe IndividualSerializer do describe '#attributes' do - let(:individual){ Individual.create(nom: 'nom', prenom: 'prenom') } + let(:procedure) { build(:procedure) } + let(:dossier) { build(:dossier, procedure: procedure) } + let(:individual) { build(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) } subject { IndividualSerializer.new(individual).serializable_hash } + it { is_expected.to include(civilite: 'M.') } it { is_expected.to include(nom: 'nom') } it { is_expected.to include(prenom: 'prenom') } + it { is_expected.not_to have_key(:date_naissance) } + + context 'when the procedure asks for a birthdate' do + let(:procedure) { build(:procedure, ask_birthday: true) } + + it { is_expected.to include(date_naissance: Date.new(2001, 8, 27)) } + end end end