Merge pull request #9906 from colinux/fix-search-notification
ETQ instructeur, la recherche de dossiers affiche les pastilles de notifications le cas échéant
This commit is contained in:
commit
ec339e0ccd
4 changed files with 34 additions and 8 deletions
|
@ -35,6 +35,7 @@ class RechercheController < ApplicationController
|
||||||
@dossiers_count = matching_dossiers_ids.count
|
@dossiers_count = matching_dossiers_ids.count
|
||||||
@followed_dossiers_id = current_instructeur&.followed_dossiers&.where(id: @paginated_ids)&.ids || []
|
@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 || {}
|
@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
|
# 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
|
# we want to display an alert in view
|
||||||
|
|
|
@ -134,12 +134,7 @@ class Instructeur < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_for_groupe_instructeurs(groupe_instructeurs)
|
def notifications_for_groupe_instructeurs(groupe_instructeurs)
|
||||||
Dossier
|
notifications_for(groupe_instructeur: groupe_instructeurs)
|
||||||
.visible_by_administration
|
|
||||||
.not_archived
|
|
||||||
.where(groupe_instructeur: groupe_instructeurs)
|
|
||||||
.merge(followed_dossiers)
|
|
||||||
.with_notifications
|
|
||||||
.pluck(:state, :id)
|
.pluck(:state, :id)
|
||||||
.reduce({ termines: [], en_cours: [] }) do |acc, e|
|
.reduce({ termines: [], en_cours: [] }) do |acc, e|
|
||||||
if Dossier::TERMINE.include?(e[0])
|
if Dossier::TERMINE.include?(e[0])
|
||||||
|
@ -151,6 +146,11 @@ class Instructeur < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notifications_for_dossiers(dossier_ids)
|
||||||
|
notifications_for(id: dossier_ids)
|
||||||
|
.pluck(:id)
|
||||||
|
end
|
||||||
|
|
||||||
def procedure_ids_with_notifications(scope)
|
def procedure_ids_with_notifications(scope)
|
||||||
groupe_instructeur_ids = Dossier
|
groupe_instructeur_ids = Dossier
|
||||||
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
||||||
|
@ -310,4 +310,13 @@ class Instructeur < ApplicationRecord
|
||||||
messagerie: messagerie
|
messagerie: messagerie
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notifications_for(condition)
|
||||||
|
Dossier
|
||||||
|
.visible_by_administration
|
||||||
|
.not_archived
|
||||||
|
.where(condition)
|
||||||
|
.merge(followed_dossiers)
|
||||||
|
.with_notifications
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
- if instructeur_and_expert_dossier
|
- if instructeur_and_expert_dossier
|
||||||
%td.text-center.cell-link
|
%td.text-center.cell-link
|
||||||
= dsfr_icon('fr-icon-file-text-line')
|
= dsfr_icon('fr-icon-file-text-line')
|
||||||
|
- if @notifications_dossier_ids.include?(p.dossier_id)
|
||||||
|
%span.notifications{ 'aria-label': 'notifications' }
|
||||||
%td.number-col
|
%td.number-col
|
||||||
.cell-link= p.dossier_id
|
.cell-link= p.dossier_id
|
||||||
%td
|
%td
|
||||||
|
@ -55,6 +57,8 @@
|
||||||
%td.text-center
|
%td.text-center
|
||||||
%a.cell-link{ href: path }
|
%a.cell-link{ href: path }
|
||||||
= dsfr_icon('fr-icon-file-text-line')
|
= dsfr_icon('fr-icon-file-text-line')
|
||||||
|
- if @notifications_dossier_ids.include?(p.dossier_id)
|
||||||
|
%span.notifications{ 'aria-label': 'notifications' }
|
||||||
|
|
||||||
%td.number-col
|
%td.number-col
|
||||||
%a.cell-link{ href: path }= p.dossier_id
|
%a.cell-link{ href: path }= p.dossier_id
|
||||||
|
|
|
@ -140,15 +140,26 @@ describe RechercheController, type: :controller do
|
||||||
describe 'by champs' do
|
describe 'by champs' do
|
||||||
let(:query) { 'district A' }
|
let(:query) { 'district A' }
|
||||||
|
|
||||||
before { subject }
|
|
||||||
|
|
||||||
it { is_expected.to have_http_status(200) }
|
it { is_expected.to have_http_status(200) }
|
||||||
|
|
||||||
it 'returns the expected dossier' do
|
it 'returns the expected dossier' do
|
||||||
|
subject
|
||||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier.id)
|
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier.id)
|
||||||
end
|
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
|
context 'as an expert' do
|
||||||
let(:user) { avis.experts_procedure.expert.user }
|
let(:user) { avis.experts_procedure.expert.user }
|
||||||
let(:query) { 'district' }
|
let(:query) { 'district' }
|
||||||
|
@ -156,6 +167,7 @@ describe RechercheController, type: :controller do
|
||||||
it { is_expected.to have_http_status(200) }
|
it { is_expected.to have_http_status(200) }
|
||||||
|
|
||||||
it 'returns only the dossier available to the expert' do
|
it 'returns only the dossier available to the expert' do
|
||||||
|
subject
|
||||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier_with_expert.id)
|
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier_with_expert.id)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue