[fix #1066] Fix links to related dossier for experts
- link to full dossier if gestionnaire is affected on procedure - link to avis if avis expert requested on related dossier
This commit is contained in:
parent
2fb3e25626
commit
21bb04d74e
4 changed files with 74 additions and 11 deletions
12
app/helpers/dossier_link_helper.rb
Normal file
12
app/helpers/dossier_link_helper.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module DossierLinkHelper
|
||||
def dossier_linked_path(gestionnaire, dossier)
|
||||
if dossier.procedure.gestionnaires.include?(gestionnaire)
|
||||
dossier_path(dossier.procedure, dossier)
|
||||
else
|
||||
avis = dossier.avis.find_by(gestionnaire: gestionnaire)
|
||||
if avis.present?
|
||||
avis_path(avis)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,7 +21,11 @@
|
|||
%td.rich-text
|
||||
- dossier = Dossier.includes(:procedure).find_by(id: c.value)
|
||||
- if dossier
|
||||
= link_to("Dossier nº #{dossier.id}", dossier_path(dossier.procedure, dossier), target: '_blank')
|
||||
- path = dossier_linked_path(current_gestionnaire, dossier)
|
||||
- if path.present?
|
||||
= link_to("Dossier nº #{dossier.id}", path, target: '_blank')
|
||||
- else
|
||||
Dossier nº #{dossier.id}
|
||||
%br
|
||||
= dossier.text_summary
|
||||
- else
|
||||
|
|
27
spec/helpers/dossier_link_helper_spec.rb
Normal file
27
spec/helpers/dossier_link_helper_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
describe DossierLinkHelper do
|
||||
describe "#dossier_linked_path" do
|
||||
context "when no access" do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to be_nil }
|
||||
end
|
||||
|
||||
context "when access as gestionnaire" do
|
||||
let(:dossier) { create(:dossier ) }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
|
||||
before { dossier.procedure.gestionnaires << gestionnaire }
|
||||
|
||||
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to eq(dossier_path(dossier.procedure, dossier)) }
|
||||
end
|
||||
|
||||
context "when access as expert" do
|
||||
let(:dossier) { create(:dossier ) }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
|
||||
|
||||
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to eq(avis_path(avis)) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,31 +1,51 @@
|
|||
describe 'new_gestionnaire/dossiers/champs.html.haml', type: :view do
|
||||
before { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
|
||||
before do
|
||||
view.extend DossierLinkHelper
|
||||
allow(view).to receive(:current_gestionnaire).and_return(gestionnaire)
|
||||
end
|
||||
|
||||
subject { render 'new_gestionnaire/dossiers/champs.html.haml', champs: champs }
|
||||
|
||||
context "there are some champs" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:avis) { create :avis, dossier: dossier, gestionnaire: gestionnaire }
|
||||
let(:champ1) { create(:champ, :checkbox, value: "true") }
|
||||
let(:champ2) { create(:champ, :header_section, value: "Section") }
|
||||
let(:champ3) { create(:champ, :explication, value: "mazette") }
|
||||
let(:champ4) { create(:champ, :dossier_link, value: dossier.id) }
|
||||
let(:champs) { [champ1, champ2, champ3, champ4] }
|
||||
|
||||
it { expect(rendered).to include(champ1.libelle) }
|
||||
it { expect(rendered).to include(champ1.value) }
|
||||
before { dossier.avis << avis }
|
||||
|
||||
it { expect(rendered).to have_css(".header-section") }
|
||||
it { expect(rendered).to include(champ2.libelle) }
|
||||
it { is_expected.to include(champ1.libelle) }
|
||||
it { is_expected.to include(champ1.value) }
|
||||
|
||||
it { expect(rendered).not_to include(champ3.libelle) }
|
||||
it { expect(rendered).not_to include(champ3.value) }
|
||||
it { is_expected.to have_css(".header-section") }
|
||||
it { is_expected.to include(champ2.libelle) }
|
||||
|
||||
it { expect(rendered).to have_link("Dossier nº #{dossier.id}") }
|
||||
it { expect(rendered).to include(dossier.text_summary) }
|
||||
it { is_expected.not_to include(champ3.libelle) }
|
||||
it { is_expected.not_to include(champ3.value) }
|
||||
|
||||
it { is_expected.to have_link("Dossier nº #{dossier.id}") }
|
||||
it { is_expected.to include(dossier.text_summary) }
|
||||
end
|
||||
|
||||
context "with a dossier champ, but we are not authorized to acces the dossier" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ) { create(:champ, :dossier_link, value: dossier.id) }
|
||||
let(:champs) { [champ] }
|
||||
|
||||
it { is_expected.not_to have_link("Dossier nº #{dossier.id}") }
|
||||
it { is_expected.to include("Dossier nº #{dossier.id}") }
|
||||
it { is_expected.to include(dossier.text_summary) }
|
||||
end
|
||||
|
||||
context "with a dossier_link champ but without value" do
|
||||
let(:champ) { create(:champ, :dossier_link, value: nil) }
|
||||
let(:champs) { [champ] }
|
||||
|
||||
it { expect(rendered).to include("Pas de dossier associé") }
|
||||
it { is_expected.to include("Pas de dossier associé") }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue