From 04aa4818f9c4f3c39675e83e9fc382b0d4c4c836 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 14 Jan 2025 11:35:48 +0100 Subject: [PATCH] [#9513] Display previous_paths on /path page --- app/models/concerns/procedure_path_concern.rb | 4 ++++ .../administrateurs/procedures/path.html.haml | 9 +++++++++ .../concerns/procedure_path_concern_spec.rb | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/app/models/concerns/procedure_path_concern.rb b/app/models/concerns/procedure_path_concern.rb index 8fbd9a4b14f..08a0145687c 100644 --- a/app/models/concerns/procedure_path_concern.rb +++ b/app/models/concerns/procedure_path_concern.rb @@ -60,6 +60,10 @@ def path_available?(path) other_procedure_with_path(path).blank? end + def previous_paths + procedure_paths.reject { |path| path.path == self.path || path.uuid_path? } + end + def path_customized? !path.match?(/[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}/) end diff --git a/app/views/administrateurs/procedures/path.html.haml b/app/views/administrateurs/procedures/path.html.haml index 297213df1d6..76d7a68381d 100644 --- a/app/views/administrateurs/procedures/path.html.haml +++ b/app/views/administrateurs/procedures/path.html.haml @@ -33,4 +33,13 @@ data: { controller: 'turbo-input', turbo_input_url_value: admin_procedure_check_path_path }) #check_path + - if @procedure.previous_paths.any? + .fr-mt-2w + %p.fr-text--sm.fr-mb-1w + Pour information les liens précédents resteront accessibles tant qu'ils ne sont pas utilisés par une autre de vos démarches : + %ul + - @procedure.previous_paths.each do |path| + %li.fr-mb-1w + = link_to commencer_url(path: path.path), commencer_url(path: path.path), class: 'fr-link fr-link--sm' + = render Procedure::FixedFooterComponent.new(procedure: @procedure, form: f) diff --git a/spec/models/concerns/procedure_path_concern_spec.rb b/spec/models/concerns/procedure_path_concern_spec.rb index ec0a9c2d47f..cb7f9b08dbb 100644 --- a/spec/models/concerns/procedure_path_concern_spec.rb +++ b/spec/models/concerns/procedure_path_concern_spec.rb @@ -146,4 +146,19 @@ # test if the procedure path is owned by another administrateur end + + describe '#previous_paths' do + let(:procedure) { create(:procedure) } + + context 'when the path has been changed twice' do + before do + procedure.claim_path!(procedure.administrateurs.first, 'custom_path') + procedure.claim_path!(procedure.administrateurs.first, 'custom_path_2') + end + + it "should only contain the paths that are not the current one nor the uuid" do + expect(procedure.previous_paths.map(&:path)).to eq(['custom_path']) + end + end + end end