feat(gallery): notify instructeur if pieces jointes updates

This commit is contained in:
Eric Leroy-Terquem 2024-09-10 16:09:43 +02:00
parent 5153b9a3ff
commit d9f604e8ce
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
9 changed files with 47 additions and 19 deletions

View file

@ -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)}."

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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),

View file

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

View file

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