From bd47bf2691a6a071abf77f37364d9b1f5134c2cd Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Thu, 20 Jun 2019 09:58:53 +0200 Subject: [PATCH] Disable Messagerie in archived Dossiers and procedures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use the existing Dossier#messagerie_available? method * Raise when attempting to build a Commentaire if not messagerie_available? * Disable the Messagerie form if not messagerie_available? * Add tests :) * Tweak the Horaires formatting while we’re here. --- app/models/dossier.rb | 2 +- app/services/commentaire_service.rb | 3 ++ .../shared/dossiers/_messagerie.html.haml | 5 ++- .../messages/_messagerie_disabled.html.haml | 14 +++++++++ app/views/users/_procedure_footer.html.haml | 4 ++- spec/mailers/notification_mailer_spec.rb | 2 +- spec/models/dossier_spec.rb | 31 +++++++++++++++++++ spec/services/commentaire_service_spec.rb | 2 +- 8 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 app/views/shared/dossiers/messages/_messagerie_disabled.html.haml diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b5b531cb6..18164a03b 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -177,7 +177,7 @@ class Dossier < ApplicationRecord end def messagerie_available? - !brouillon? && !archived + !brouillon? && !archived && !procedure.archivee? end def retention_end_date diff --git a/app/services/commentaire_service.rb b/app/services/commentaire_service.rb index fa3b9a576..b7e8ef206 100644 --- a/app/services/commentaire_service.rb +++ b/app/services/commentaire_service.rb @@ -12,6 +12,9 @@ class CommentaireService end def build_with_email(email, dossier, params) + if !dossier.messagerie_available? + raise ArgumentError, "Commentaires cannot be added to brouillons or archived Dossiers" + end attributes = params.merge(email: email, dossier: dossier) Commentaire.new(attributes) end diff --git a/app/views/shared/dossiers/_messagerie.html.haml b/app/views/shared/dossiers/_messagerie.html.haml index 5d589fa5b..c50c17eaa 100644 --- a/app/views/shared/dossiers/_messagerie.html.haml +++ b/app/views/shared/dossiers/_messagerie.html.haml @@ -4,4 +4,7 @@ %li.message{ class: commentaire_is_from_me_class(commentaire, connected_user) } = render partial: "shared/dossiers/messages/message", locals: { commentaire: commentaire, connected_user: connected_user, messagerie_seen_at: messagerie_seen_at } - = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } + - if dossier.archived? + = render partial: "shared/dossiers/messages/messagerie_disabled", locals: { service: dossier.procedure.service } + - else + = render partial: "shared/dossiers/messages/form", locals: { commentaire: new_commentaire, form_url: form_url } diff --git a/app/views/shared/dossiers/messages/_messagerie_disabled.html.haml b/app/views/shared/dossiers/messages/_messagerie_disabled.html.haml new file mode 100644 index 000000000..5b1564796 --- /dev/null +++ b/app/views/shared/dossiers/messages/_messagerie_disabled.html.haml @@ -0,0 +1,14 @@ +.card.feedback + .card-title + La messagerie est désormais désactivée. + %p + Pour poser une question sur ce dossier, contactez : + %p + = service.nom + %br + = service.organisme + %br + - horaires = "Horaires : #{formatted_horaires(service.horaires)}" + = simple_format(horaires) + %p + = link_to service.email, "mailto:#{service.email}" diff --git a/app/views/users/_procedure_footer.html.haml b/app/views/users/_procedure_footer.html.haml index 495010d95..458c6ed00 100644 --- a/app/views/users/_procedure_footer.html.haml +++ b/app/views/users/_procedure_footer.html.haml @@ -27,7 +27,9 @@ %a{ href: "tel:#{service.telephone}" }= service.telephone %p - Horaires : #{formatted_horaires(service.horaires)} + - horaires = "Horaires : #{formatted_horaires(service.horaires)}" + = simple_format(horaires) + - politiques = politiques_conservation_de_donnees(procedure) - if politiques.present? diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 219cbcae8..b0d203807 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -13,7 +13,7 @@ RSpec.describe NotificationMailer, type: :mailer do end let(:user) { create(:user) } - let(:dossier) { create(:dossier, :with_service, user: user) } + let(:dossier) { create(:dossier, :with_service, :en_construction, user: user) } describe '.send_notification' do let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index a39b96117..7f72f61e6 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -736,6 +736,37 @@ describe Dossier do end end + describe "#messagerie_available?" do + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, procedure: procedure) } + + subject { dossier.messagerie_available? } + + context "dossier is brouillon" do + before { dossier.state = Dossier.states.fetch(:brouillon) } + + it { is_expected.to be false } + end + + context "dossier is archived" do + before { dossier.archived = true } + + it { is_expected.to be false } + end + + context "procedure is archived" do + before { procedure.archived_at = Date.today } + + it { is_expected.to be false } + end + + context "procedure is not archived, dossier is not archived" do + before { dossier.state = Dossier.states.fetch(:en_instruction) } + + it { is_expected.to be true } + end + end + context "retention date" do let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } let(:uninstructed_dossier) { create(:dossier, :en_construction, procedure: procedure) } diff --git a/spec/services/commentaire_service_spec.rb b/spec/services/commentaire_service_spec.rb index d781ca8ca..1e80c92d3 100644 --- a/spec/services/commentaire_service_spec.rb +++ b/spec/services/commentaire_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe CommentaireService do describe '.create' do - let(:dossier) { create :dossier } + let(:dossier) { create :dossier, :en_construction } let(:sender) { dossier.user } let(:body) { 'Contenu du message.' } let(:file) { nil }