Make dossier link clickable for users in the Demande tab

This commit is contained in:
gregoirenovel 2018-12-28 17:22:51 +01:00
parent cc07f0d701
commit b4781f7440
3 changed files with 29 additions and 9 deletions

View file

@ -1,12 +1,16 @@
module DossierLinkHelper
def dossier_linked_path(gestionnaire, dossier)
if dossier.procedure.gestionnaires.include?(gestionnaire)
gestionnaire_dossier_path(dossier.procedure, dossier)
else
avis = dossier.avis.find_by(gestionnaire: gestionnaire)
if avis.present?
gestionnaire_avis_path(avis)
def dossier_linked_path(user, dossier)
if user.is_a?(Gestionnaire)
if dossier.procedure.gestionnaires.include?(user)
gestionnaire_dossier_path(dossier.procedure, dossier)
else
avis = dossier.avis.find_by(gestionnaire: user)
if avis.present?
gestionnaire_avis_path(avis)
end
end
elsif user.owns_or_invite?(dossier)
dossier_path(dossier)
end
end
end

View file

@ -1,6 +1,6 @@
- dossier = Dossier.includes(:procedure).find_by(id: champ.to_s)
- if dossier
- path = dossier_linked_path(current_gestionnaire, dossier)
- path = dossier_linked_path(current_gestionnaire || current_user, dossier)
- if path.present?
= link_to("Dossier nº #{dossier.id}", path, target: '_blank')
- else

View file

@ -1,12 +1,19 @@
describe DossierLinkHelper do
describe "#dossier_linked_path" do
context "when no access" do
context "when no access as a gestionnaire" do
let(:gestionnaire) { create(:gestionnaire) }
let(:dossier) { create(:dossier) }
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to be_nil }
end
context "when no access as a user" do
let(:user) { create(:user) }
let(:dossier) { create(:dossier) }
it { expect(helper.dossier_linked_path(user, dossier)).to be_nil }
end
context "when access as gestionnaire" do
let(:dossier) { create(:dossier) }
let(:gestionnaire) { create(:gestionnaire) }
@ -23,5 +30,14 @@ describe DossierLinkHelper do
it { expect(helper.dossier_linked_path(gestionnaire, dossier)).to eq(gestionnaire_avis_path(avis)) }
end
context "when access as user" do
let(:dossier) { create(:dossier) }
let(:user) { create(:user) }
before { dossier.user = user }
it { expect(helper.dossier_linked_path(user, dossier)).to eq(dossier_path(dossier)) }
end
end
end