From 874f992e5e59dd76d9193808e16bf3a7bacc59b3 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 25 Nov 2024 15:59:32 +0100 Subject: [PATCH] fix(instructeur): procedure form preview --- .../champ_label_content_component.rb | 9 +++++++++ .../champ_label_content_component.html.haml | 2 +- .../instructeurs/procedures_controller.rb | 6 ++++++ .../instructeurs/procedures/_header.html.haml | 2 +- .../instructeurs/procedures/apercu.html.haml | 15 ++++++++++++++ .../procedures/email_notifications/en.yml | 5 +++-- .../procedures/email_notifications/fr.yml | 3 +++ config/routes.rb | 1 + .../procedures_controller_spec.rb | 20 +++++++++++++++++++ 9 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 app/views/instructeurs/procedures/apercu.html.haml diff --git a/app/components/editable_champ/champ_label_content_component.rb b/app/components/editable_champ/champ_label_content_component.rb index 94978c7b0..6b0c88730 100644 --- a/app/components/editable_champ/champ_label_content_component.rb +++ b/app/components/editable_champ/champ_label_content_component.rb @@ -20,4 +20,13 @@ class EditableChamp::ChampLabelContentComponent < ApplicationComponent def highlight? @champ.updated_at.present? && @seen_at&.<(@champ.updated_at) end + + def rebased? + return false if @champ.rebased_at.blank? + return false if @champ.rebased_at <= (@seen_at || @champ.updated_at) + return false if !current_user.owns_or_invite?(@champ.dossier) + return false if @champ.dossier.for_procedure_preview? + + true + end end diff --git a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml index 5a65163b7..38e4a4e6b 100644 --- a/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml +++ b/app/components/editable_champ/champ_label_content_component/champ_label_content_component.html.haml @@ -10,7 +10,7 @@ %span.updated-at{ class: highlight_if_unseen_class } = t('.modified_at', datetime: try_format_datetime(@champ.updated_at)) -- if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && current_user.owns_or_invite?(@champ.dossier) +- if rebased? %span.updated-at.highlighted = t('.check_content_rebased') diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index a93eabf2f..c563d87c7 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -266,6 +266,12 @@ module Instructeurs @administrateurs = procedure.administrateurs end + def apercu + @procedure = procedure + @dossier = procedure.active_revision.dossier_for_preview(current_user) + DossierPreloader.load_one(@dossier) + end + private def assign_to_params diff --git a/app/views/instructeurs/procedures/_header.html.haml b/app/views/instructeurs/procedures/_header.html.haml index e175248ca..6fac4a5de 100644 --- a/app/views/instructeurs/procedures/_header.html.haml +++ b/app/views/instructeurs/procedures/_header.html.haml @@ -37,7 +37,7 @@ %li = link_to t('instructeurs.dossiers.header.banner.contact_users'), email_usagers_instructeur_procedure_path(procedure), class: 'fr-nav__link' %li - = link_to t('instructeurs.dossiers.header.banner.preview'), apercu_admin_procedure_path(@procedure), target: "_blank", rel: "noopener", class: 'fr-nav__link' + = link_to t('instructeurs.dossiers.header.banner.preview'), apercu_instructeur_procedure_path(@procedure), target: "_blank", rel: "noopener", class: 'fr-nav__link' %li = link_to "#", class: "fr-nav__link fr-link fr-link--md fr-link--icon-left fr-icon-clipboard-line", data: {controller: "clipboard", clipboard_text_value: commencer_url(@procedure.path), action: "click->clipboard#copy" } do = t('instructeurs.dossiers.header.banner.copy_link_button') diff --git a/app/views/instructeurs/procedures/apercu.html.haml b/app/views/instructeurs/procedures/apercu.html.haml new file mode 100644 index 000000000..6d6d315b4 --- /dev/null +++ b/app/views/instructeurs/procedures/apercu.html.haml @@ -0,0 +1,15 @@ +- content_for(:title, t('.title_with_libelle', libelle: @dossier.procedure.libelle)) + +.sub-header + .fr-container.flex.column + = render partial: 'instructeurs/breadcrumbs', + locals: { steps: [[t('show_procedure', scope: [:layouts, :breadcrumb], libelle: @procedure.libelle.truncate(22)), instructeur_procedure_path(@procedure)], + [t('instructeurs.dossiers.header.banner.preview')]] } + = render partial: 'instructeurs/procedures/header', + locals: { procedure: @procedure } + + +.fr-container + %h2.fr-h4= t('.title') + += render partial: "shared/dossiers/edit", locals: { dossier: @dossier } diff --git a/config/locales/views/instructeurs/procedures/email_notifications/en.yml b/config/locales/views/instructeurs/procedures/email_notifications/en.yml index 0c5f274fa..11155c920 100644 --- a/config/locales/views/instructeurs/procedures/email_notifications/en.yml +++ b/config/locales/views/instructeurs/procedures/email_notifications/en.yml @@ -26,5 +26,6 @@ en: buttons: back_to_procedure: Back to procedure save: Save - - \ No newline at end of file + apercu: + title_with_libelle: Preview of « %{libelle} » + title: Procedure preview diff --git a/config/locales/views/instructeurs/procedures/email_notifications/fr.yml b/config/locales/views/instructeurs/procedures/email_notifications/fr.yml index 5a1d662d2..3bb4905d5 100644 --- a/config/locales/views/instructeurs/procedures/email_notifications/fr.yml +++ b/config/locales/views/instructeurs/procedures/email_notifications/fr.yml @@ -30,3 +30,6 @@ fr: buttons: back_to_procedure: Revenir à la procédure save: Enregistrer + apercu: + title_with_libelle: Prévisualisation de « %{libelle} » + title: Prévisualisation de la démarche diff --git a/config/routes.rb b/config/routes.rb index f4532277e..c3dd53caa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -490,6 +490,7 @@ Rails.application.routes.draw do end end + get 'apercu' get 'download_export' post 'download_export' get 'polling_last_export' diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index bb9725a39..5d3239f50 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -926,4 +926,24 @@ describe Instructeurs::ProceduresController, type: :controller do it { is_expected.to have_http_status(:forbidden) } end end + + describe '#preview' do + render_views + + let(:instructeur) { create(:instructeur) } + let(:procedure) { create(:procedure, types_de_champ_public: [type: :text, libelle: "Premier champ"]) } + + before do + sign_in(instructeur.user) + create(:groupe_instructeur, procedure:, instructeurs: [instructeur]) + end + + it 'displays preview' do + get :apercu, params: { procedure_id: procedure.id } + + expect(response).to have_http_status(:success) + expect(response.body).to include("Premier champ") + expect(response.body).not_to include("Déposer") + end + end end