Merge pull request #7061 from tchak/fix-notifications

fix(dossiers): mark as read dossier on update_annotations
This commit is contained in:
Paul Chavard 2022-03-22 09:23:58 +01:00 committed by GitHub
commit f033194ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 8 deletions

View file

@ -203,8 +203,7 @@ module Instructeurs
end end
def update_annotations def update_annotations
dossier = current_instructeur.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id]) dossier_with_champs.assign_attributes(champs_private_params)
dossier.assign_attributes(champs_private_params)
if dossier.champs_private.any?(&:changed?) if dossier.champs_private.any?(&:changed?)
dossier.last_champ_private_updated_at = Time.zone.now dossier.last_champ_private_updated_at = Time.zone.now
end end
@ -278,19 +277,19 @@ module Instructeurs
end end
def mark_demande_as_read def mark_demande_as_read
current_instructeur.mark_tab_as_seen(@dossier, :demande) current_instructeur.mark_tab_as_seen(dossier, :demande)
end end
def mark_messagerie_as_read def mark_messagerie_as_read
current_instructeur.mark_tab_as_seen(@dossier, :messagerie) current_instructeur.mark_tab_as_seen(dossier, :messagerie)
end end
def mark_avis_as_read def mark_avis_as_read
current_instructeur.mark_tab_as_seen(@dossier, :avis) current_instructeur.mark_tab_as_seen(dossier, :avis)
end end
def mark_annotations_privees_as_read def mark_annotations_privees_as_read
current_instructeur.mark_tab_as_seen(@dossier, :annotations_privees) current_instructeur.mark_tab_as_seen(dossier, :annotations_privees)
end end
def aasm_error_message(exception, target_state:) def aasm_error_message(exception, target_state:)

View file

@ -408,8 +408,9 @@ describe Instructeurs::DossiersController, type: :controller do
end end
describe '#messagerie' do describe '#messagerie' do
before { expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie) }
subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } } subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
it { expect(response).to have_http_status(:ok) } it { expect(subject).to have_http_status(:ok) }
end end
describe "#create_commentaire" do describe "#create_commentaire" do
@ -431,6 +432,7 @@ describe Instructeurs::DossiersController, type: :controller do
} }
before do before do
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie)
allow(ClamavService).to receive(:safe_file?).and_return(scan_result) allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
Timecop.freeze(now) Timecop.freeze(now)
end end
@ -480,6 +482,10 @@ describe Instructeurs::DossiersController, type: :controller do
let(:saved_avis) { dossier.avis.first } let(:saved_avis) { dossier.avis.first }
let!(:old_avis_count) { Avis.count } let!(:old_avis_count) { Avis.count }
before do
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :avis)
end
subject do subject do
post :create_avis, params: { post :create_avis, params: {
procedure_id: procedure.id, procedure_id: procedure.id,
@ -617,7 +623,10 @@ describe Instructeurs::DossiersController, type: :controller do
} }
end end
before { subject } before do
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :demande)
subject
end
it { expect(assigns(:include_infos_administration)).to eq(true) } it { expect(assigns(:include_infos_administration)).to eq(true) }
it { expect(response).to render_template 'dossiers/show' } it { expect(response).to render_template 'dossiers/show' }
@ -654,6 +663,7 @@ describe Instructeurs::DossiersController, type: :controller do
end end
before do before do
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :annotations_privees)
another_instructeur.follow(dossier) another_instructeur.follow(dossier)
Timecop.freeze(now) Timecop.freeze(now)
patch :update_annotations, params: params patch :update_annotations, params: params