[Fix #1494] Display a warning when accepting a dossier if needed

Show the accompagnateur the unspecified demande
champs and attestations privées needed for the
attestation
This commit is contained in:
kemar 2018-04-06 13:09:37 +02:00 committed by gregoirenovel
parent 23bc67214a
commit b42e410da0
5 changed files with 126 additions and 0 deletions

View file

@ -17,6 +17,20 @@ class AttestationTemplate < ApplicationRecord
Attestation.new(title: replace_tags(title, dossier), pdf: build_pdf(dossier))
end
def unspecified_champs_for_dossier(dossier)
all_champs_with_libelle_index = (dossier.champs + dossier.champs_private)
.reduce({}) do |acc, champ|
acc[champ.libelle] = champ
acc
end
used_tags.map do |used_tag|
corresponding_champ = all_champs_with_libelle_index[used_tag]
corresponding_champ.value.blank? ? corresponding_champ : nil
end.compact
end
def dup
result = AttestationTemplate.new(title: title, body: body, footer: footer, activated: activated)
@ -33,6 +47,14 @@ class AttestationTemplate < ApplicationRecord
private
def used_tags
delimiters_regex = /--(?<capture>((?!--).)*)--/
[title, body]
.map { |str| str.scan(delimiters_regex) }
.flatten
end
def logo_signature_file_size
%i[logo signature]
.select { |file_name| send(file_name).present? }