Merge pull request #232 from sgmap/fix-dossier-link
Change the link to a linked dossier depending on the user profile
This commit is contained in:
commit
99b232947e
4 changed files with 45 additions and 2 deletions
|
@ -10,5 +10,4 @@ class ChampDecorator < Draper::Decorator
|
||||||
def description_with_links
|
def description_with_links
|
||||||
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>').html_safe if description
|
description.gsub(URI.regexp, '<a target="_blank" href="\0">\0</a>').html_safe if description
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class DossierDecorator < Draper::Decorator
|
class DossierDecorator < Draper::Decorator
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
||||||
delegate_all
|
delegate_all
|
||||||
|
|
||||||
|
@ -14,6 +16,16 @@ class DossierDecorator < Draper::Decorator
|
||||||
DossierDecorator.case_state_fr state
|
DossierDecorator.case_state_fr state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url(gestionnaire_signed_in)
|
||||||
|
if gestionnaire_signed_in
|
||||||
|
backoffice_dossier_path(id)
|
||||||
|
elsif brouillon?
|
||||||
|
users_dossier_description_path(id)
|
||||||
|
else
|
||||||
|
users_dossier_recapitulatif_path(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.case_state_fr state=self.state
|
def self.case_state_fr state=self.state
|
||||||
h.t("activerecord.attributes.dossier.state.#{state}")
|
h.t("activerecord.attributes.dossier.state.#{state}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
- if champ.type_champ == 'dossier_link'
|
- if champ.type_champ == 'dossier_link'
|
||||||
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
|
- dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value)
|
||||||
- if dossier
|
- if dossier
|
||||||
= link_to("Dossier #{dossier.id}", backoffice_dossier_path(champ.decorate.value), target: '_blank')
|
= link_to("Dossier #{dossier.id}", dossier.decorate.url(gestionnaire_signed_in?), target: '_blank')
|
||||||
%br
|
%br
|
||||||
= dossier.text_summary
|
= dossier.text_summary
|
||||||
- else
|
- else
|
||||||
|
|
|
@ -57,4 +57,36 @@ describe DossierDecorator do
|
||||||
expect(subject).to eq('Refusé')
|
expect(subject).to eq('Refusé')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#url' do
|
||||||
|
context "when a gestionnaire is signed_in" do
|
||||||
|
subject { super().url(true) }
|
||||||
|
|
||||||
|
it { is_expected.to eq("/backoffice/dossiers/#{dossier.id}") }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a gestionnaire is not signed_in" do
|
||||||
|
context "when the dossier is in brouillon state" do
|
||||||
|
before do
|
||||||
|
dossier.state = 'draft'
|
||||||
|
dossier.save
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { super().url(false) }
|
||||||
|
|
||||||
|
it { is_expected.to eq("/users/dossiers/#{dossier.id}/description") }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the dossier is not in brouillon state" do
|
||||||
|
before do
|
||||||
|
dossier.state = 'updated'
|
||||||
|
dossier.save
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { super().url(false) }
|
||||||
|
|
||||||
|
it { is_expected.to eq("/users/dossiers/#{dossier.id}/recapitulatif") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue