From 9a0df71887460c6d62f881a591a9fca7ff37b95f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Tue, 2 May 2017 15:32:39 +0200 Subject: [PATCH] Change the link to a linked dossier depending on the user profile --- app/decorators/champ_decorator.rb | 1 - app/decorators/dossier_decorator.rb | 12 ++++++++ app/views/dossiers/_infos_dossier.html.haml | 2 +- spec/decorators/dossier_decorator_spec.rb | 32 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/decorators/champ_decorator.rb b/app/decorators/champ_decorator.rb index 8c95b8183..1688c5f91 100644 --- a/app/decorators/champ_decorator.rb +++ b/app/decorators/champ_decorator.rb @@ -10,5 +10,4 @@ class ChampDecorator < Draper::Decorator def description_with_links description.gsub(URI.regexp, '\0').html_safe if description end - end diff --git a/app/decorators/dossier_decorator.rb b/app/decorators/dossier_decorator.rb index 8bf76769b..438c67061 100644 --- a/app/decorators/dossier_decorator.rb +++ b/app/decorators/dossier_decorator.rb @@ -1,4 +1,6 @@ class DossierDecorator < Draper::Decorator + include Rails.application.routes.url_helpers + delegate :current_page, :per_page, :offset, :total_entries, :total_pages delegate_all @@ -14,6 +16,16 @@ class DossierDecorator < Draper::Decorator DossierDecorator.case_state_fr state 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 h.t("activerecord.attributes.dossier.state.#{state}") end diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 959f82c78..7de372ba2 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -41,7 +41,7 @@ - if champ.type_champ == 'dossier_link' - dossier = Dossier.includes(:procedure).find_by(id: champ.decorate.value) - 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 = dossier.text_summary - else diff --git a/spec/decorators/dossier_decorator_spec.rb b/spec/decorators/dossier_decorator_spec.rb index 31a32b161..9920a89b4 100644 --- a/spec/decorators/dossier_decorator_spec.rb +++ b/spec/decorators/dossier_decorator_spec.rb @@ -57,4 +57,36 @@ describe DossierDecorator do expect(subject).to eq('Refusé') 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