Merge pull request #9507 from demarches-simplifiees/9449-signature-groupe-instructeur
9449 ETQ instructeur ou admin, je peux apposer sur une attestation un tampon dédié à un groupe instructeur
This commit is contained in:
commit
428ae4a45a
21 changed files with 258 additions and 76 deletions
|
@ -60,16 +60,27 @@ class AttestationTemplate < ApplicationRecord
|
|||
end
|
||||
|
||||
def render_attributes_for(params = {})
|
||||
dossier = params.fetch(:dossier, false)
|
||||
|
||||
{
|
||||
attributes = {
|
||||
created_at: Time.zone.now,
|
||||
title: dossier ? replace_tags(title, dossier) : params.fetch(:title, title),
|
||||
body: dossier ? replace_tags(body, dossier) : params.fetch(:body, body),
|
||||
footer: params.fetch(:footer, footer),
|
||||
logo: params.fetch(:logo, logo.attached? ? logo : nil),
|
||||
signature: params.fetch(:signature, signature.attached? ? signature : nil)
|
||||
logo: params.fetch(:logo, logo.attached? ? logo : nil)
|
||||
}
|
||||
|
||||
dossier = params[:dossier]
|
||||
|
||||
if dossier.present?
|
||||
attributes.merge({
|
||||
title: replace_tags(title, dossier),
|
||||
body: replace_tags(body, dossier),
|
||||
signature: signature_to_render(dossier.groupe_instructeur)
|
||||
})
|
||||
else
|
||||
attributes.merge({
|
||||
title: params.fetch(:title, title),
|
||||
body: params.fetch(:body, body),
|
||||
signature: signature_to_render(params[:groupe_instructeur])
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def logo_checksum
|
||||
|
@ -90,6 +101,14 @@ class AttestationTemplate < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def signature_to_render(groupe_instructeur)
|
||||
if groupe_instructeur&.signature&.attached?
|
||||
groupe_instructeur.signature
|
||||
else
|
||||
signature
|
||||
end
|
||||
end
|
||||
|
||||
def used_tags
|
||||
used_tags_for(title) + used_tags_for(body)
|
||||
end
|
||||
|
|
|
@ -15,6 +15,11 @@ class GroupeInstructeur < ApplicationRecord
|
|||
has_one :defaut_procedure, -> { with_discarded }, class_name: 'Procedure', foreign_key: :defaut_groupe_instructeur_id, dependent: :nullify, inverse_of: :defaut_groupe_instructeur
|
||||
has_one :contact_information
|
||||
|
||||
has_one_attached :signature
|
||||
|
||||
SIGNATURE_MAX_SIZE = 1.megabytes
|
||||
validates :signature, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: SIGNATURE_MAX_SIZE }
|
||||
|
||||
validates :label, presence: true, allow_nil: false
|
||||
validates :label, uniqueness: { scope: :procedure }
|
||||
validates :closed, acceptance: { accept: [false] }, if: -> { (self == procedure.defaut_groupe_instructeur) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue