fix(instructeur): procedure form preview

This commit is contained in:
Colin Darie 2024-11-25 15:59:32 +01:00
parent 7d2821aa81
commit 874f992e5e
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
9 changed files with 59 additions and 4 deletions

View file

@ -20,4 +20,13 @@ class EditableChamp::ChampLabelContentComponent < ApplicationComponent
def highlight? def highlight?
@champ.updated_at.present? && @seen_at&.<(@champ.updated_at) @champ.updated_at.present? && @seen_at&.<(@champ.updated_at)
end 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 end

View file

@ -10,7 +10,7 @@
%span.updated-at{ class: highlight_if_unseen_class } %span.updated-at{ class: highlight_if_unseen_class }
= t('.modified_at', datetime: try_format_datetime(@champ.updated_at)) = 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 %span.updated-at.highlighted
= t('.check_content_rebased') = t('.check_content_rebased')

View file

@ -266,6 +266,12 @@ module Instructeurs
@administrateurs = procedure.administrateurs @administrateurs = procedure.administrateurs
end end
def apercu
@procedure = procedure
@dossier = procedure.active_revision.dossier_for_preview(current_user)
DossierPreloader.load_one(@dossier)
end
private private
def assign_to_params def assign_to_params

View file

@ -37,7 +37,7 @@
%li %li
= link_to t('instructeurs.dossiers.header.banner.contact_users'), email_usagers_instructeur_procedure_path(procedure), class: 'fr-nav__link' = link_to t('instructeurs.dossiers.header.banner.contact_users'), email_usagers_instructeur_procedure_path(procedure), class: 'fr-nav__link'
%li %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 %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 = 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') = t('instructeurs.dossiers.header.banner.copy_link_button')

View file

@ -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 }

View file

@ -26,5 +26,6 @@ en:
buttons: buttons:
back_to_procedure: Back to procedure back_to_procedure: Back to procedure
save: Save save: Save
apercu:
title_with_libelle: Preview of « %{libelle} »
title: Procedure preview

View file

@ -30,3 +30,6 @@ fr:
buttons: buttons:
back_to_procedure: Revenir à la procédure back_to_procedure: Revenir à la procédure
save: Enregistrer save: Enregistrer
apercu:
title_with_libelle: Prévisualisation de « %{libelle} »
title: Prévisualisation de la démarche

View file

@ -490,6 +490,7 @@ Rails.application.routes.draw do
end end
end end
get 'apercu'
get 'download_export' get 'download_export'
post 'download_export' post 'download_export'
get 'polling_last_export' get 'polling_last_export'

View file

@ -926,4 +926,24 @@ describe Instructeurs::ProceduresController, type: :controller do
it { is_expected.to have_http_status(:forbidden) } it { is_expected.to have_http_status(:forbidden) }
end end
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 end