diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 2f4540d52..575b3d0e4 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -18,6 +18,7 @@ module Instructeurs 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] + after_action :mark_pieces_jointes_as_read, only: [:pieces_jointes] def extend_conservation dossier.extend_conservation(1.month) @@ -466,6 +467,10 @@ module Instructeurs current_instructeur.mark_tab_as_seen(dossier, :annotations_privees) end + def mark_pieces_jointes_as_read + current_instructeur.mark_tab_as_seen(dossier, :pieces_jointes) + end + def aasm_error_message(exception, target_state:) if exception.originating_state == target_state "Le dossier est déjà #{dossier_display_state(target_state, lower: true)}." diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 824751910..b7166d911 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -341,7 +341,10 @@ module Users @commentaire = CommentaireService.create(current_user, dossier, commentaire_params) if @commentaire.errors.empty? - @commentaire.dossier.update!(last_commentaire_updated_at: Time.zone.now) + timestamps = [:last_commentaire_updated_at, :updated_at] + timestamps << :last_commentaire_piece_jointe_updated_at if @commentaire.piece_jointe.attached? + + @commentaire.dossier.touch(*timestamps) flash.notice = t('.message_send') redirect_to messagerie_dossier_path(dossier) diff --git a/app/models/concerns/dossier_clone_concern.rb b/app/models/concerns/dossier_clone_concern.rb index 691226c0e..6d7b185e4 100644 --- a/app/models/concerns/dossier_clone_concern.rb +++ b/app/models/concerns/dossier_clone_concern.rb @@ -71,6 +71,7 @@ module DossierCloneConcern diff = make_diff(editing_fork) apply_diff(diff) touch(:last_champ_updated_at) + touch(:last_champ_piece_jointe_updated_at) if diff[:updated].any? { |c| c.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) } end reload index_search_terms_later diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9a980ae60..f6707f444 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -377,7 +377,9 @@ class Dossier < ApplicationRecord ' OR groupe_instructeur_updated_at > follows.demande_seen_at' \ ' OR last_champ_private_updated_at > follows.annotations_privees_seen_at' \ ' OR last_avis_updated_at > follows.avis_seen_at' \ - ' OR last_commentaire_updated_at > follows.messagerie_seen_at') + ' OR last_commentaire_updated_at > follows.messagerie_seen_at' \ + ' OR last_commentaire_piece_jointe_updated_at > follows.pieces_jointes_seen_at' \ + ' OR last_champ_piece_jointe_updated_at > follows.pieces_jointes_seen_at') .distinct end diff --git a/app/models/follow.rb b/app/models/follow.rb index c494eb47d..7c2dcaed2 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -18,5 +18,6 @@ class Follow < ApplicationRecord self.annotations_privees_seen_at ||= Time.zone.now self.avis_seen_at ||= Time.zone.now self.messagerie_seen_at ||= Time.zone.now + self.pieces_jointes_seen_at ||= Time.zone.now end end diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index b9e105802..6c9f388af 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -125,10 +125,11 @@ class Instructeur < ApplicationRecord annotations_privees = dossier.last_champ_private_updated_at&.>(follow.annotations_privees_seen_at) || false avis_notif = dossier.last_avis_updated_at&.>(follow.avis_seen_at) || false messagerie = dossier.last_commentaire_updated_at&.>(follow.messagerie_seen_at) || false + pieces_jointes = dossier.last_champ_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || dossier.last_commentaire_piece_jointe_updated_at&.>(follow.pieces_jointes_seen_at) || false - annotations_hash(demande, annotations_privees, avis_notif, messagerie) + annotations_hash(demande, annotations_privees, avis_notif, messagerie, pieces_jointes) else - annotations_hash(false, false, false, false) + annotations_hash(false, false, false, false, false) end end @@ -314,12 +315,13 @@ class Instructeur < ApplicationRecord private - def annotations_hash(demande, annotations_privees, avis, messagerie) + def annotations_hash(demande, annotations_privees, avis, messagerie, pieces_jointes) { demande: demande, annotations_privees: annotations_privees, avis: avis, - messagerie: messagerie + messagerie: messagerie, + pieces_jointes: pieces_jointes } end diff --git a/app/views/instructeurs/dossiers/_header_bottom.html.haml b/app/views/instructeurs/dossiers/_header_bottom.html.haml index 0358c4aa0..1af884845 100644 --- a/app/views/instructeurs/dossiers/_header_bottom.html.haml +++ b/app/views/instructeurs/dossiers/_header_bottom.html.haml @@ -9,7 +9,8 @@ - if dossier.champs.map(&:piece_justificative_file).flatten.any? = dynamic_tab_item(t('views.instructeurs.dossiers.tab_steps.attachments'), - pieces_jointes_instructeur_dossier_path(dossier.procedure, dossier)) + pieces_jointes_instructeur_dossier_path(dossier.procedure, dossier), + notification: notifications_summary[:pieces_jointes]) = dynamic_tab_item(t('views.instructeurs.dossiers.tab_steps.private_annotations'), annotations_privees_instructeur_dossier_path(dossier.procedure, dossier), diff --git a/spec/models/concerns/dossier_clone_concern_spec.rb b/spec/models/concerns/dossier_clone_concern_spec.rb index e7e5f4869..dd33470ab 100644 --- a/spec/models/concerns/dossier_clone_concern_spec.rb +++ b/spec/models/concerns/dossier_clone_concern_spec.rb @@ -44,7 +44,9 @@ RSpec.describe DossierCloneConcern do expect(new_dossier.last_avis_updated_at).to be_nil expect(new_dossier.last_champ_private_updated_at).to be_nil expect(new_dossier.last_champ_updated_at).to be_nil + expect(new_dossier.last_champ_piece_jointe_updated_at).to be_nil expect(new_dossier.last_commentaire_updated_at).to be_nil + expect(new_dossier.last_commentaire_piece_jointe_updated_at).to be_nil expect(new_dossier.motivation).to be_nil expect(new_dossier.processed_at).to be_nil end diff --git a/spec/models/instructeur_spec.rb b/spec/models/instructeur_spec.rb index 54f2a21b0..9523e6779 100644 --- a/spec/models/instructeur_spec.rb +++ b/spec/models/instructeur_spec.rb @@ -196,7 +196,7 @@ describe Instructeur, type: :model do subject { instructeur.notifications_for_dossier(dossier) } context 'when the instructeur has just followed the dossier' do - it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) } end context 'when there is a modification on public champs' do @@ -205,20 +205,20 @@ describe Instructeur, type: :model do dossier.update(last_champ_updated_at: Time.zone.now) } - it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) } end context 'when there is a modification on identity' do before { dossier.update(identity_updated_at: Time.zone.now) } - it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) } end context 'when there is a modification on groupe instructeur' do let(:groupe_instructeur) { create(:groupe_instructeur, instructeurs: [instructeur], procedure: dossier.procedure) } before { dossier.assign_to_groupe_instructeur(groupe_instructeur, DossierAssignment.modes.fetch(:auto)) } - it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: true, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) } end context 'when there is a modification on private champs' do @@ -227,7 +227,7 @@ describe Instructeur, type: :model do dossier.update(last_champ_private_updated_at: Time.zone.now) } - it { is_expected.to match({ demande: false, annotations_privees: true, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: false, annotations_privees: true, avis: false, messagerie: false, pieces_jointes: false }) } end context 'when there is a modification on avis' do @@ -236,23 +236,34 @@ describe Instructeur, type: :model do dossier.update(last_avis_updated_at: Time.zone.now) } - it { is_expected.to match({ demande: false, annotations_privees: false, avis: true, messagerie: false }) } + it { is_expected.to match({ demande: false, annotations_privees: false, avis: true, messagerie: false, pieces_jointes: false }) } end context 'messagerie' do context 'when there is a new commentaire' do - before { - create(:commentaire, dossier: dossier, email: 'a@b.com') - dossier.update(last_commentaire_updated_at: Time.zone.now) - } + context 'without a file' do + before { + create(:commentaire, dossier: dossier, email: 'a@b.com') + dossier.update(last_commentaire_updated_at: Time.zone.now) + } - it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true }) } + it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true, pieces_jointes: false }) } + end + + context 'with a file' do + before { + create(:commentaire, :with_file, dossier: dossier, email: 'a@b.com') + dossier.update(last_commentaire_updated_at: Time.zone.now, last_commentaire_piece_jointe_updated_at: Time.zone.now) + } + + it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: true, pieces_jointes: true }) } + end end context 'when there is a new commentaire issued by tps' do before { create(:commentaire, dossier: dossier, email: CONTACT_EMAIL) } - it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false }) } + it { is_expected.to match({ demande: false, annotations_privees: false, avis: false, messagerie: false, pieces_jointes: false }) } end end end