fix(recherche): show notification indicator for instructeurs
This commit is contained in:
parent
62bd2cc0d7
commit
8a83fd2ce0
4 changed files with 34 additions and 8 deletions
|
@ -35,6 +35,7 @@ class RechercheController < ApplicationController
|
|||
@dossiers_count = matching_dossiers_ids.count
|
||||
@followed_dossiers_id = current_instructeur&.followed_dossiers&.where(id: @paginated_ids)&.ids || []
|
||||
@dossier_avis_ids_h = current_expert&.avis&.where(dossier_id: @paginated_ids)&.pluck(:dossier_id, :id).to_h || {}
|
||||
@notifications_dossier_ids = current_instructeur&.notifications_for_dossiers(@paginated_ids) || []
|
||||
|
||||
# if an instructor search for a dossier which is in his procedures but not available to his intructor group
|
||||
# we want to display an alert in view
|
||||
|
|
|
@ -134,12 +134,7 @@ class Instructeur < ApplicationRecord
|
|||
end
|
||||
|
||||
def notifications_for_groupe_instructeurs(groupe_instructeurs)
|
||||
Dossier
|
||||
.visible_by_administration
|
||||
.not_archived
|
||||
.where(groupe_instructeur: groupe_instructeurs)
|
||||
.merge(followed_dossiers)
|
||||
.with_notifications
|
||||
notifications_for(groupe_instructeur: groupe_instructeurs)
|
||||
.pluck(:state, :id)
|
||||
.reduce({ termines: [], en_cours: [] }) do |acc, e|
|
||||
if Dossier::TERMINE.include?(e[0])
|
||||
|
@ -151,6 +146,11 @@ class Instructeur < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def notifications_for_dossiers(dossier_ids)
|
||||
notifications_for(id: dossier_ids)
|
||||
.pluck(:id)
|
||||
end
|
||||
|
||||
def procedure_ids_with_notifications(scope)
|
||||
groupe_instructeur_ids = Dossier
|
||||
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
||||
|
@ -310,4 +310,13 @@ class Instructeur < ApplicationRecord
|
|||
messagerie: messagerie
|
||||
}
|
||||
end
|
||||
|
||||
def notifications_for(condition)
|
||||
Dossier
|
||||
.visible_by_administration
|
||||
.not_archived
|
||||
.where(condition)
|
||||
.merge(followed_dossiers)
|
||||
.with_notifications
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
- if instructeur_and_expert_dossier
|
||||
%td.text-center.cell-link
|
||||
= dsfr_icon('fr-icon-file-text-line')
|
||||
- if @notifications_dossier_ids.include?(p.dossier_id)
|
||||
%span.notifications{ 'aria-label': 'notifications' }
|
||||
%td.number-col
|
||||
.cell-link= p.dossier_id
|
||||
%td
|
||||
|
@ -55,6 +57,8 @@
|
|||
%td.text-center
|
||||
%a.cell-link{ href: path }
|
||||
= dsfr_icon('fr-icon-file-text-line')
|
||||
- if @notifications_dossier_ids.include?(p.dossier_id)
|
||||
%span.notifications{ 'aria-label': 'notifications' }
|
||||
|
||||
%td.number-col
|
||||
%a.cell-link{ href: path }= p.dossier_id
|
||||
|
|
|
@ -140,15 +140,26 @@ describe RechercheController, type: :controller do
|
|||
describe 'by champs' do
|
||||
let(:query) { 'district A' }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns the expected dossier' do
|
||||
subject
|
||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier.id)
|
||||
end
|
||||
|
||||
context 'when dossier has notification' do
|
||||
before do
|
||||
instructeur.follow(dossier)
|
||||
dossier.touch(:last_commentaire_updated_at)
|
||||
end
|
||||
|
||||
it 'assigns notification' do
|
||||
subject
|
||||
expect(assigns(:notifications_dossier_ids)).to eq([dossier.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'as an expert' do
|
||||
let(:user) { avis.experts_procedure.expert.user }
|
||||
let(:query) { 'district' }
|
||||
|
@ -156,6 +167,7 @@ describe RechercheController, type: :controller do
|
|||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns only the dossier available to the expert' do
|
||||
subject
|
||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier_with_expert.id)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue