Track dossier demander un avis

This commit is contained in:
Paul Chavard 2019-05-02 16:24:24 +02:00
parent 9c472e6524
commit b8bf662c6d
4 changed files with 30 additions and 0 deletions

View file

@ -29,6 +29,9 @@ module CreateAvisConcern
if persisted.any?
sent_emails_addresses = persisted.map(&:email_to_display).join(", ")
flash.notice = "Une demande d'avis a été envoyée à #{sent_emails_addresses}"
persisted.each do |avis|
dossier.demander_un_avis!(avis)
end
end
if failed.any?

View file

@ -371,6 +371,11 @@ class Dossier < ApplicationRecord
log_dossier_operation(gestionnaire, :modifier_annotation, champ)
end
end
def demander_un_avis!(avis)
log_dossier_operation(avis.claimant, :demander_un_avis, avis)
end
private
def log_dossier_operation(author, operation, subject = nil)

View file

@ -7,6 +7,7 @@ class DossierOperationLog < ApplicationRecord
classer_sans_suite: 'classer_sans_suite',
supprimer: 'supprimer',
modifier_annotation: 'modifier_annotation',
demander_un_avis: 'demander_un_avis'
}
belongs_to :dossier
@ -62,6 +63,8 @@ class DossierOperationLog < ApplicationRecord
DossierSerializer.new(subject).as_json
when Champ
ChampSerializer.new(subject).as_json
when Avis
AvisSerializer.new(subject).as_json
end
end
end

View file

@ -0,0 +1,19 @@
class AvisSerializer < ActiveModel::Serializer
attributes :email,
:answer,
:introduction,
:created_at,
:answered_at
def email
object.email_to_display
end
def created_at
object.created_at&.in_time_zone('UTC')
end
def answered_at
object.updated_at&.in_time_zone('UTC')
end
end