fix(dossier): do not show unwanted closed procedure banners

This commit is contained in:
Paul Chavard 2022-04-14 11:08:17 +02:00
parent c789484880
commit c671f25d34
5 changed files with 54 additions and 9 deletions

View file

@ -631,6 +631,10 @@ class Dossier < ApplicationRecord
termine_close_to_expiration_notice_sent_at: nil)
end
def show_procedure_state_warning?
procedure.discarded? || (brouillon? && !procedure.dossier_can_transition_to_en_construction?)
end
def show_groupe_instructeur_details?
procedure.routee? && groupe_instructeur.present? && (!procedure.feature_enabled?(:procedure_routage_api) || !defaut_groupe_instructeur?)
end

View file

@ -8,8 +8,8 @@
= render(partial: 'users/dossiers/expiration_banner', locals: {dossier: dossier})
- if current_user.owns?(dossier) && !dossier.procedure.discarded? && !dossier.procedure.close?
- if dossier.show_procedure_state_warning?
= render(partial: 'users/dossiers/procedure_removed_banner', locals: { dossier: dossier })
- elsif current_user.owns?(dossier)
.header-actions
= render partial: 'invites/dropdown', locals: { dossier: dossier }
- else
= render(partial: 'users/dossiers/procedure_removed_banner', locals: { dossier: dossier })

View file

@ -12,16 +12,15 @@
= render(partial: 'users/dossiers/expiration_banner', locals: {dossier: dossier})
- if (current_user.owns?(dossier) && !dossier.procedure.discarded?) || (!dossier.procedure.discarded? && !dossier.procedure.close? && !dossier.en_construction?)
- if dossier.show_procedure_state_warning?
= render(partial: 'users/dossiers/procedure_removed_banner', locals: { dossier: dossier })
- elsif current_user.owns?(dossier)
.header-actions
= render partial: 'invites/dropdown', locals: { dossier: dossier }
- if dossier.can_be_updated_by_user? && !current_page?(modifier_dossier_path(dossier))
= link_to t('views.users.dossiers.show.header.edit_dossier'), modifier_dossier_path(dossier), class: 'button accepted edit-form', 'title'=> "Vous pouvez modifier votre dossier tant qu'il n'est passé en instruction"
= render(partial: 'users/dossiers/show/print_dossier', locals: { dossier: dossier })
- else
= render(partial: 'users/dossiers/procedure_removed_banner', locals: { dossier: dossier })
%nav.tabs
%ul
= dynamic_tab_item(t('views.users.dossiers.show.header.summary'), dossier_path(dossier))

View file

@ -1,9 +1,10 @@
describe 'dossiers/show/header.html.haml', type: :view do
let(:procedure) { create(:procedure, :discarded) }
let(:dossier) { create(:dossier, state: "brouillon", procedure: procedure) }
let(:user) { dossier.user }
before do
sign_in dossier.user
sign_in user
end
subject! { render 'shared/dossiers/header.html.haml', dossier: dossier }
@ -31,4 +32,24 @@ describe 'dossiers/show/header.html.haml', type: :view do
expect(rendered).not_to have_text("Tout le dossier")
end
end
context "when user is invited" do
context "when the procedure is closed with a dossier en construction" do
let(:procedure) { create(:procedure, :closed) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:user) { create(:user) }
before do
create(:invite, user: user, dossier: dossier)
end
it "n'affiche pas de banner" do
expect(rendered).not_to have_text("La démarche liée à votre dossier est close")
end
it 'can not download the dossier' do
expect(rendered).not_to have_text("Tout le dossier")
end
end
end
end

View file

@ -1,8 +1,9 @@
describe 'users/dossiers/show/header.html.haml', type: :view do
let(:dossier) { create(:dossier, :en_construction, procedure: create(:procedure)) }
let(:user) { dossier.user }
before do
sign_in dossier.user
sign_in user
end
subject! { render 'users/dossiers/show/header.html.haml', dossier: dossier }
@ -57,4 +58,24 @@ describe 'users/dossiers/show/header.html.haml', type: :view do
expect(rendered).to have_text("Tout le dossier")
end
end
context "when user is invited" do
context "when the procedure is closed with a dossier en construction" do
let(:procedure) { create(:procedure, :closed) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:user) { create(:user) }
before do
create(:invite, user: user, dossier: dossier)
end
it "n'affiche pas de banner" do
expect(rendered).not_to have_text("La démarche liée à votre dossier est close")
end
it 'can not download the dossier' do
expect(rendered).not_to have_text("Tout le dossier")
end
end
end
end