From 610058c534648ff5d4b3831d20c6e95b8b7dcb2f Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 14 Mar 2018 18:57:56 +0100 Subject: [PATCH 1/2] [Fix #1619] Do not consider invitations to deleted dossiers --- app/models/invite.rb | 7 +++++++ spec/models/invite_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/invite.rb b/app/models/invite.rb index 3abb44e39..887a2ad0c 100644 --- a/app/models/invite.rb +++ b/app/models/invite.rb @@ -10,4 +10,11 @@ class Invite < ApplicationRecord validates :email, uniqueness: { scope: :dossier_id } validates :email, format: { with: Devise.email_regexp, message: "n'est pas valide" }, allow_nil: true + + # #1619 When an administrateur deletes a `Procedure`, its `hidden_at` field, and + # the `hidden_at` field of its `Dossier`s, get set, effectively removing the Procedure + # and Dossier from their respective `default_scope`s. + # Therefore, we also remove `Invite`s for such effectively deleted `Dossier`s + # from their default scope. + default_scope { joins(:dossier).where(dossiers: { hidden_at: nil }) } end diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index e952df95d..38799c399 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -56,4 +56,22 @@ describe Invite do end end end + + describe "#default_scope" do + let(:dossier) { create(:dossier, hidden_at: hidden_at) } + let!(:invite) { create(:invite, email: "email@totor.com", dossier: dossier) } + + context "when dossier is not hidden" do + let(:hidden_at) { nil } + + it { expect(Invite.count).to eq(1) } + it { expect(Invite.all).to include(invite) } + end + + context "when dossier is hidden" do + let(:hidden_at) { 1.day.ago } + + it { expect(Invite.count).to eq(0) } + end + end end From 6c669ccc39ddfaee1c72d1ef12ea8e90958c6762 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 15 Mar 2018 10:55:10 +0100 Subject: [PATCH 2/2] [Fix #1614] Show newlines for textarea champs --- app/views/dossiers/_infos_dossier.html.haml | 2 ++ app/views/new_gestionnaire/dossiers/_champs.html.haml | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 7fae0d674..8b73387a7 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -50,6 +50,8 @@ - pj = champ.piece_justificative_file %a{ href: url_for(pj), target: '_blank' } = pj.filename.to_s + - elsif champ.type_champ == 'textarea' + = simple_format(champ.decorate.value) - else = sanitize(champ.decorate.value) diff --git a/app/views/new_gestionnaire/dossiers/_champs.html.haml b/app/views/new_gestionnaire/dossiers/_champs.html.haml index 8ad5469ac..4335f9510 100644 --- a/app/views/new_gestionnaire/dossiers/_champs.html.haml +++ b/app/views/new_gestionnaire/dossiers/_champs.html.haml @@ -40,6 +40,12 @@ = pj.filename.to_s - else Pièce justificative non fournie + - when "textarea" + %th.libelle + = "#{c.libelle} :" + %td.rich-text + %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } + = simple_format(c.value) - else %th.libelle = "#{c.libelle} :"