Merge pull request #2897 from betagouv/frederic/fix_2675_sort_by_notification

Corrige le tri par notification sur l’onglet « tous les dossiers »
This commit is contained in:
Frederic Merizen 2018-10-24 17:20:11 +02:00 committed by GitHub
commit 02697948ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 26 deletions

View file

@ -126,7 +126,7 @@ class Gestionnaire < ApplicationRecord
procedure.dossiers.not_archived procedure.dossiers.not_archived
else else
procedure.dossiers.en_cours procedure.dossiers.en_cours
end.followed_by(self) end
dossiers_id_with_notifications(dossiers) dossiers_id_with_notifications(dossiers)
end end
@ -139,35 +139,14 @@ class Gestionnaire < ApplicationRecord
Dossier.not_archived Dossier.not_archived
else else
Dossier.en_cours Dossier.en_cours
end.followed_by(self) end
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
end end
def mark_tab_as_seen(dossier, tab)
attributes = {}
attributes["#{tab}_seen_at"] = DateTime.now
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
end
def invite!
reset_password_token = set_reset_password_token
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
end
private
def annotations_hash(demande, annotations_privees, avis, messagerie)
{
demande: demande,
annotations_privees: annotations_privees,
avis: avis,
messagerie: messagerie
}
end
def dossiers_id_with_notifications(dossiers) def dossiers_id_with_notifications(dossiers)
dossiers = dossiers.followed_by(self)
updated_demandes = dossiers updated_demandes = dossiers
.joins(:champs) .joins(:champs)
.where('champs.updated_at > follows.demande_seen_at') .where('champs.updated_at > follows.demande_seen_at')
@ -198,4 +177,27 @@ class Gestionnaire < ApplicationRecord
updated_messagerie updated_messagerie
].flat_map { |query| query.distinct.ids }.uniq ].flat_map { |query| query.distinct.ids }.uniq
end end
def mark_tab_as_seen(dossier, tab)
attributes = {}
attributes["#{tab}_seen_at"] = DateTime.now
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
end
def invite!
reset_password_token = set_reset_password_token
GestionnaireMailer.invite_gestionnaire(self, reset_password_token).deliver_later
end
private
def annotations_hash(demande, annotations_privees, avis, messagerie)
{
demande: demande,
annotations_privees: annotations_privees,
avis: avis,
messagerie: messagerie
}
end
end end

View file

@ -78,7 +78,7 @@ class ProcedurePresentation < ApplicationRecord
case table case table
when 'notifications' when 'notifications'
dossiers_id_with_notification = gestionnaire.notifications_for_procedure(procedure) dossiers_id_with_notification = gestionnaire.dossiers_id_with_notifications(dossiers)
if order == 'desc' if order == 'desc'
return dossiers_id_with_notification + return dossiers_id_with_notification +
(dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification) (dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification)

View file

@ -238,6 +238,7 @@ describe ProcedurePresentation do
before do before do
notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20)) notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20))
create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10)) create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10))
notified_dossier.touch(time: DateTime.new(2018, 9, 20))
recent_dossier.touch(time: DateTime.new(2018, 9, 25)) recent_dossier.touch(time: DateTime.new(2018, 9, 25))
older_dossier.touch(time: DateTime.new(2018, 5, 13)) older_dossier.touch(time: DateTime.new(2018, 5, 13))
end end
@ -253,6 +254,13 @@ describe ProcedurePresentation do
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) } it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
end end
context 'with a dossier terminé' do
let!(:notified_dossier) { create(:dossier, :accepte, procedure: procedure) }
let(:order) { 'desc' }
it { is_expected.to eq([notified_dossier, recent_dossier, older_dossier].map(&:id)) }
end
end end
context 'for self table' do context 'for self table' do