[Fix #763] Add annotations_privees to buggy annotation system

This commit is contained in:
Simon Lehericey 2017-09-27 15:08:34 +02:00
parent f2e1480c73
commit 2b760c85c4
6 changed files with 29 additions and 10 deletions

View file

@ -16,6 +16,7 @@ module NewGestionnaire
def annotations_privees def annotations_privees
@dossier = dossier @dossier = dossier
dossier.notifications.annotations_privees.mark_as_read
end end
def avis def avis

View file

@ -83,8 +83,12 @@ class Champ < ActiveRecord::Base
end end
def internal_notification def internal_notification
unless dossier.state == 'draft' if dossier.state != 'draft'
if type == 'ChampPublic'
NotificationService.new('champs', self.dossier.id, self.libelle).notify NotificationService.new('champs', self.dossier.id, self.libelle).notify
else
NotificationService.new('annotations_privees', self.dossier.id, self.libelle).notify
end
end end
end end

View file

@ -97,7 +97,8 @@ class Dossier < ActiveRecord::Base
{ {
demande: unread_notifications.select(&:demande?).present?, demande: unread_notifications.select(&:demande?).present?,
avis: unread_notifications.select(&:avis?).present?, avis: unread_notifications.select(&:avis?).present?,
messagerie: unread_notifications.select(&:messagerie?).present? messagerie: unread_notifications.select(&:messagerie?).present?,
annotations_privees: unread_notifications.select(&:annotations_privees?).present?
} }
end end

View file

@ -12,6 +12,7 @@ class Notification < ActiveRecord::Base
DEMANDE = %w(cerfa piece_justificative champs submitted) DEMANDE = %w(cerfa piece_justificative champs submitted)
AVIS = %w(avis) AVIS = %w(avis)
MESSAGERIE = %w(commentaire) MESSAGERIE = %w(commentaire)
ANNOTATIONS_PRIVEES = %w(annotations_privees)
belongs_to :dossier belongs_to :dossier
@ -19,7 +20,7 @@ class Notification < ActiveRecord::Base
scope :demande, -> { where(type_notif: DEMANDE) } scope :demande, -> { where(type_notif: DEMANDE) }
scope :avis, -> { where(type_notif: AVIS) } scope :avis, -> { where(type_notif: AVIS) }
scope :messagerie, -> { where(type_notif: MESSAGERIE) } scope :messagerie, -> { where(type_notif: MESSAGERIE) }
scope :annotations_privees, -> { where(type_notif: annotations_privees) } scope :annotations_privees, -> { where(type_notif: ANNOTATIONS_PRIVEES) }
scope :mark_as_read, -> { update_all(already_read: true) } scope :mark_as_read, -> { update_all(already_read: true) }
def demande? def demande?
@ -33,4 +34,8 @@ class Notification < ActiveRecord::Base
def messagerie? def messagerie?
Notification::MESSAGERIE.include?(type_notif) Notification::MESSAGERIE.include?(type_notif)
end end
def annotations_privees?
Notification::ANNOTATIONS_PRIVEES.include?(type_notif)
end
end end

View file

@ -16,6 +16,8 @@
%span.notifications{ 'aria-label': 'notifications' } %span.notifications{ 'aria-label': 'notifications' }
= link_to "Demande", dossier_path(dossier.procedure, dossier) = link_to "Demande", dossier_path(dossier.procedure, dossier)
%li{ class: current_page?(annotations_privees_dossier_path(dossier.procedure, dossier)) ? 'active' : nil } %li{ class: current_page?(annotations_privees_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
- if notifications_summary[:annotations_privees]
%span.notifications{ 'aria-label': 'notifications' }
= link_to "Annotations Privées", annotations_privees_dossier_path(dossier.procedure, dossier) = link_to "Annotations Privées", annotations_privees_dossier_path(dossier.procedure, dossier)
%li{ class: current_page?(avis_dossier_path(dossier.procedure, dossier)) ? 'active' : nil } %li{ class: current_page?(avis_dossier_path(dossier.procedure, dossier)) ? 'active' : nil }
- if notifications_summary[:avis] - if notifications_summary[:avis]

View file

@ -74,28 +74,34 @@ describe NewGestionnaire::DossiersController, type: :controller do
it { expect(response).to redirect_to(procedures_url) } it { expect(response).to redirect_to(procedures_url) }
end end
describe '#show #messagerie #instruction' do describe '#show #messagerie #annotations_privees #avis' do
before do before do
dossier.notifications = %w(champs avis commentaire).map{ |type| Notification.create!(type_notif: type) } dossier.notifications = %w(champs annotations_privees avis commentaire).map{ |type| Notification.create!(type_notif: type) }
get method, params: { procedure_id: procedure.id, dossier_id: dossier.id } get method, params: { procedure_id: procedure.id, dossier_id: dossier.id }
dossier.notifications.each(&:reload) dossier.notifications.each(&:reload)
end end
context '#show' do context '#show' do
let(:method) { :show } let(:method) { :show }
it { expect(dossier.notifications.map(&:already_read)).to match([true, false, false]) } it { expect(dossier.notifications.map(&:already_read)).to match([true, false, false, false]) }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
end end
context '#instruction' do context '#annotations_privees' do
let(:method) { :annotations_privees } let(:method) { :annotations_privees }
it { expect(dossier.notifications.map(&:already_read)).to match([false, true, false]) } it { expect(dossier.notifications.map(&:already_read)).to match([false, true, false, false]) }
it { expect(response).to have_http_status(:success) }
end
context '#avis' do
let(:method) { :avis }
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, true, false]) }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
end end
context '#messagerie' do context '#messagerie' do
let(:method) { :messagerie } let(:method) { :messagerie }
it { expect(dossier.notifications.map(&:already_read)).to match([false, false, true]) } it { expect(dossier.notifications.map(&:already_read)).to match([false, false, false, true]) }
it { expect(response).to have_http_status(:success) } it { expect(response).to have_http_status(:success) }
end end
end end