From eea575875320fea1fcdfd019a4c265110db7e59e Mon Sep 17 00:00:00 2001 From: mfo Date: Fri, 29 Nov 2024 11:56:34 +0100 Subject: [PATCH] feat(Instructeurs#*): plugs next/prev dossier component on all required routes --- app/controllers/application_controller.rb | 4 ---- app/controllers/concerns/instructeur_concern.rb | 11 +++++++++++ .../instructeurs/commentaires_controller.rb | 2 ++ .../instructeurs/dossiers_controller.rb | 15 ++++++++++----- .../commentaires/destroy.turbo_stream.haml | 2 +- app/views/instructeurs/dossiers/_header.html.haml | 2 +- .../instructeurs/dossiers/_header_top.html.haml | 13 ++++--------- .../dossiers/annotations_privees.html.haml | 2 +- app/views/instructeurs/dossiers/avis.html.haml | 2 +- .../instructeurs/dossiers/avis_new.html.haml | 2 +- .../dossiers/change_state.turbo_stream.haml | 2 +- .../instructeurs/dossiers/messagerie.html.haml | 2 +- .../dossiers/personnes_impliquees.html.haml | 2 +- .../dossiers/pieces_jointes.html.haml | 2 +- .../instructeurs/dossiers/reaffectation.html.haml | 2 +- app/views/instructeurs/dossiers/show.html.haml | 2 +- .../dossiers/annotations_privee.html.haml_spec.rb | 3 +++ .../instructeur/dossiers/show.html.haml_spec.rb | 11 ++++++++++- 18 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 app/controllers/concerns/instructeur_concern.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index df11a2a4b..f540da41b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -426,8 +426,4 @@ class ApplicationController < ActionController::Base def cast_bool(value) ActiveRecord::Type::Boolean.new.deserialize(value) end - - def retrieve_procedure_presentation - @procedure_presentation ||= current_instructeur.procedure_presentation_for_procedure_id(params[:procedure_id]) - end end diff --git a/app/controllers/concerns/instructeur_concern.rb b/app/controllers/concerns/instructeur_concern.rb new file mode 100644 index 000000000..6ccc57c4e --- /dev/null +++ b/app/controllers/concerns/instructeur_concern.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module InstructeurConcern + extend ActiveSupport::Concern + + included do + def retrieve_procedure_presentation + @procedure_presentation ||= current_instructeur.procedure_presentation_for_procedure_id(params[:procedure_id]) + end + end +end diff --git a/app/controllers/instructeurs/commentaires_controller.rb b/app/controllers/instructeurs/commentaires_controller.rb index 38855904e..f8d71d166 100644 --- a/app/controllers/instructeurs/commentaires_controller.rb +++ b/app/controllers/instructeurs/commentaires_controller.rb @@ -2,10 +2,12 @@ module Instructeurs class CommentairesController < ApplicationController + include InstructeurConcern before_action :authenticate_instructeur_or_expert! after_action :mark_messagerie_as_read def destroy + retrieve_procedure_presentation if current_instructeur if commentaire.sent_by?(current_instructeur) || commentaire.sent_by?(current_expert) commentaire.soft_delete! diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index bd8d9f203..89c34d2fb 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -7,15 +7,16 @@ module Instructeurs include CreateAvisConcern include DossierHelper include TurboChampsConcern - + include InstructeurConcern include ActionController::Streaming include Zipline before_action :redirect_on_dossier_not_found, only: :show before_action :redirect_on_dossier_in_batch_operation, only: [:archive, :unarchive, :follow, :unfollow, :passer_en_instruction, :repasser_en_construction, :repasser_en_instruction, :terminer, :restore, :destroy, :extend_conservation] before_action :set_gallery_attachments, only: [:show, :pieces_jointes, :annotations_privees, :avis, :messagerie, :personnes_impliquees, :reaffectation] - after_action :mark_demande_as_read, only: :show + before_action :retrieve_procedure_presentation, only: [:annotations_privees, :avis_new, :avis, :messagerie, :personnes_impliquees, :pieces_jointes, :reaffectation, :show, :dossier_labels, :passer_en_instruction, :repasser_en_construction, :repasser_en_instruction, :terminer, :pending_correction, :create_avis, :create_commentaire] + after_action :mark_demande_as_read, only: :show after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire, :pending_correction] after_action :mark_avis_as_read, only: [:avis, :create_avis] after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations] @@ -391,20 +392,20 @@ module Instructeurs end def next - navigate_throw_dossier_list do |cache| + navigate_through_dossiers_list do |cache| cache.next_dossier_id(from_id: params[:dossier_id]) end end def previous - navigate_throw_dossier_list do |cache| + navigate_through_dossiers_list do |cache| cache.previous_dossier_id(from_id: params[:dossier_id]) end end private - def navigate_throw_dossier_list + def navigate_through_dossiers_list dossier = dossier_scope.find(params[:dossier_id]) procedure_presentation = current_instructeur.procedure_presentation_for_procedure_id(dossier.procedure.id) cache = Cache::ProcedureDossierPagination.new(procedure_presentation:, statut: params[:statut]) @@ -417,6 +418,10 @@ module Instructeurs redirect_back fallback_location: instructeur_dossier_path(procedure_id: procedure.id, dossier_id: dossier.id, statut: params[:statut]), alert: "Une erreur est survenue" end rescue ActiveRecord::RecordNotFound + Sentry.capture_message( + "Navigation through dossier failed => ActiveRecord::RecordNotFound", + extra: { dossier_id: params[:dossier_id] } + ) redirect_to instructeur_procedure_path(procedure_id: procedure.id), alert: "Une erreur est survenue" end diff --git a/app/views/instructeurs/commentaires/destroy.turbo_stream.haml b/app/views/instructeurs/commentaires/destroy.turbo_stream.haml index afe148257..610ded463 100644 --- a/app/views/instructeurs/commentaires/destroy.turbo_stream.haml +++ b/app/views/instructeurs/commentaires/destroy.turbo_stream.haml @@ -3,4 +3,4 @@ = render Dossiers::MessageComponent.new(commentaire: @commentaire, connected_user: @commentaire.instructeur || @commentaire.expert) - if current_user.instructeur? && @commentaire.dossier_correction.present? - = turbo_stream.replace 'header-top', partial: 'instructeurs/dossiers/header_top', locals: { dossier: @commentaire.dossier } + = turbo_stream.replace 'header-top', partial: 'instructeurs/dossiers/header_top', locals: { dossier: @commentaire.dossier, procedure_presentation: @procedure_presentation } diff --git a/app/views/instructeurs/dossiers/_header.html.haml b/app/views/instructeurs/dossiers/_header.html.haml index 0a0a1607a..d449e3033 100644 --- a/app/views/instructeurs/dossiers/_header.html.haml +++ b/app/views/instructeurs/dossiers/_header.html.haml @@ -10,7 +10,7 @@ locals: { steps: [[t('show_procedure', scope: [:layouts, :breadcrumb], libelle: dossier.procedure.libelle.truncate(22)), instructeur_procedure_path(dossier.procedure)], [t('show_dossier', scope: [:layouts, :breadcrumb], dossier_id: dossier.id, owner_name: dossier.owner_name)]] } - = render partial: 'instructeurs/dossiers/header_top', locals: { dossier: } + = render partial: 'instructeurs/dossiers/header_top', locals: { dossier:, procedure_presentation: } = render partial: 'instructeurs/dossiers/header_bottom', locals: { dossier:, gallery_attachments: } .fr-container diff --git a/app/views/instructeurs/dossiers/_header_top.html.haml b/app/views/instructeurs/dossiers/_header_top.html.haml index 45805fbb6..366cb4498 100644 --- a/app/views/instructeurs/dossiers/_header_top.html.haml +++ b/app/views/instructeurs/dossiers/_header_top.html.haml @@ -1,14 +1,9 @@ #header-top.fr-container - .flex + = render Instructeurs::DossiersNavigationComponent.new(dossier:, procedure_presentation:, statut: params[:statut]) + + .flex.fr-mb-3w %div - .flex.fr-mb-1w - = render Instructeurs::BackButtonComponent.new(to: instructeur_procedure_path(dossier.procedure, statut: params[:statut])) - %h1.fr-h3.fr-mb-1w - = t('show_dossier', scope: [:layouts, :breadcrumb], dossier_id: dossier.id, owner_name: dossier.owner_name) - - - = link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link" - .fr-mt-2w.fr-badge-group + .fr-mt-2w.badge-group = procedure_badge(dossier.procedure) = status_badge(dossier.state) diff --git a/app/views/instructeurs/dossiers/annotations_privees.html.haml b/app/views/instructeurs/dossiers/annotations_privees.html.haml index f603d753a..61708ae5e 100644 --- a/app/views/instructeurs/dossiers/annotations_privees.html.haml +++ b/app/views/instructeurs/dossiers/annotations_privees.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Annotations privées · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } #dossier-annotations-privees .fr-container diff --git a/app/views/instructeurs/dossiers/avis.html.haml b/app/views/instructeurs/dossiers/avis.html.haml index 172816591..4e81a8110 100644 --- a/app/views/instructeurs/dossiers/avis.html.haml +++ b/app/views/instructeurs/dossiers/avis.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } .container .fr-grid-row diff --git a/app/views/instructeurs/dossiers/avis_new.html.haml b/app/views/instructeurs/dossiers/avis_new.html.haml index 5b9125a98..5d6a78956 100644 --- a/app/views/instructeurs/dossiers/avis_new.html.haml +++ b/app/views/instructeurs/dossiers/avis_new.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } .container .fr-grid-row diff --git a/app/views/instructeurs/dossiers/change_state.turbo_stream.haml b/app/views/instructeurs/dossiers/change_state.turbo_stream.haml index d7dd8ded2..5dd2e0d9f 100644 --- a/app/views/instructeurs/dossiers/change_state.turbo_stream.haml +++ b/app/views/instructeurs/dossiers/change_state.turbo_stream.haml @@ -1 +1 @@ -= turbo_stream.replace 'header-top', partial: 'header_top', locals: { dossier: @dossier } += turbo_stream.replace 'header-top', partial: 'header_top', locals: { dossier: @dossier, procedure_presentation: @procedure_presentation } diff --git a/app/views/instructeurs/dossiers/messagerie.html.haml b/app/views/instructeurs/dossiers/messagerie.html.haml index 33395d7f1..28adc6020 100644 --- a/app/views/instructeurs/dossiers/messagerie.html.haml +++ b/app/views/instructeurs/dossiers/messagerie.html.haml @@ -1,5 +1,5 @@ - content_for(:title, "Messagerie · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } = render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, connected_user: current_instructeur, messagerie_seen_at: @messagerie_seen_at , new_commentaire: @commentaire, form_url: commentaire_instructeur_dossier_path(@dossier.procedure, @dossier, statut: params[:statut]) } diff --git a/app/views/instructeurs/dossiers/personnes_impliquees.html.haml b/app/views/instructeurs/dossiers/personnes_impliquees.html.haml index 30d3224ec..4472d0999 100644 --- a/app/views/instructeurs/dossiers/personnes_impliquees.html.haml +++ b/app/views/instructeurs/dossiers/personnes_impliquees.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Personnes impliquées · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } .personnes-impliquees.container = render partial: 'instructeurs/dossiers/envoyer_dossier_block', locals: { dossier: @dossier, potential_recipients: @potential_recipients } diff --git a/app/views/instructeurs/dossiers/pieces_jointes.html.haml b/app/views/instructeurs/dossiers/pieces_jointes.html.haml index 527b2c65c..94ef1015a 100644 --- a/app/views/instructeurs/dossiers/pieces_jointes.html.haml +++ b/app/views/instructeurs/dossiers/pieces_jointes.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Pièces jointes") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } .fr-container .gallery.gallery-pieces-jointes{ "data-controller": "lightbox" } diff --git a/app/views/instructeurs/dossiers/reaffectation.html.haml b/app/views/instructeurs/dossiers/reaffectation.html.haml index 364b5415a..3c0038f11 100644 --- a/app/views/instructeurs/dossiers/reaffectation.html.haml +++ b/app/views/instructeurs/dossiers/reaffectation.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Réaffectation · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } .container.groupe-instructeur diff --git a/app/views/instructeurs/dossiers/show.html.haml b/app/views/instructeurs/dossiers/show.html.haml index 8c9ad55e4..0bd246e42 100644 --- a/app/views/instructeurs/dossiers/show.html.haml +++ b/app/views/instructeurs/dossiers/show.html.haml @@ -1,6 +1,6 @@ - content_for(:title, "Demande · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") -= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments } += render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation } - if @dossier.etablissement&.as_degraded_mode? diff --git a/spec/views/instructeur/dossiers/annotations_privee.html.haml_spec.rb b/spec/views/instructeur/dossiers/annotations_privee.html.haml_spec.rb index c5a01535e..4b9690cba 100644 --- a/spec/views/instructeur/dossiers/annotations_privee.html.haml_spec.rb +++ b/spec/views/instructeur/dossiers/annotations_privee.html.haml_spec.rb @@ -3,12 +3,15 @@ describe 'instructeurs/dossiers/annotations_privees', type: :view do let(:current_instructeur) { create(:instructeur) } let(:dossier) { create(:dossier, :en_construction) } + let(:procedure_presentation) { double(instructeur: current_instructeur, procedure: dossier.procedure) } before do sign_in(current_instructeur.user) allow(view).to receive(:current_instructeur).and_return(current_instructeur) + allow(controller).to receive(:params).and_return({ statut: 'a-suivre' }) assign(:dossier, dossier) + assign(:procedure_presentation, procedure_presentation) end subject { render } diff --git a/spec/views/instructeur/dossiers/show.html.haml_spec.rb b/spec/views/instructeur/dossiers/show.html.haml_spec.rb index 6414fbc77..0eea3dc15 100644 --- a/spec/views/instructeur/dossiers/show.html.haml_spec.rb +++ b/spec/views/instructeur/dossiers/show.html.haml_spec.rb @@ -3,12 +3,15 @@ describe 'instructeurs/dossiers/show', type: :view do let(:current_instructeur) { create(:instructeur) } let(:dossier) { create(:dossier, :en_construction) } + let(:statut) { { statut: 'tous' } } + let(:procedure_presentation) { double(instructeur: current_instructeur, procedure: dossier.procedure) } before do sign_in(current_instructeur.user) allow(view).to receive(:current_instructeur).and_return(current_instructeur) - allow(controller).to receive(:params).and_return(statut: 'a-suivre') + allow(controller).to receive(:params).and_return(statut:) assign(:dossier, dossier) + assign(:procedure_presentation, procedure_presentation) end subject { render } @@ -17,6 +20,12 @@ describe 'instructeurs/dossiers/show', type: :view do expect(subject).to have_text("Dossier nº #{dossier.id}") end + context 'when procedure statut / page was saved in session' do + it 'renders back button with saved state' do + expect(subject).to have_selector("a[href=\"#{instructeur_procedure_path(dossier.procedure, statut: statut)}\"]") + end + end + it 'renders the dossier infos' do expect(subject).to have_text('Identité') expect(subject).to have_text('Demande')