refactor(attestation): groupe instructeur add signature shared
Co-Authored-By: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
parent
4c7664d61c
commit
d231ec35f4
4 changed files with 65 additions and 54 deletions
|
@ -3,7 +3,7 @@ module Administrateurs
|
||||||
include ActiveSupport::NumberHelper
|
include ActiveSupport::NumberHelper
|
||||||
include Logic
|
include Logic
|
||||||
include UninterlacePngConcern
|
include UninterlacePngConcern
|
||||||
include PreviewAttestationConcern
|
include GroupeInstructeursSignatureConcern
|
||||||
|
|
||||||
before_action :ensure_not_super_admin!, only: [:add_instructeur]
|
before_action :ensure_not_super_admin!, only: [:add_instructeur]
|
||||||
|
|
||||||
|
@ -362,26 +362,6 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_signature
|
|
||||||
@procedure = procedure
|
|
||||||
@groupe_instructeur = groupe_instructeur
|
|
||||||
@instructeurs = paginated_instructeurs
|
|
||||||
@available_instructeur_emails = available_instructeur_emails
|
|
||||||
|
|
||||||
signature_file = params[:groupe_instructeur]&.delete('signature')
|
|
||||||
|
|
||||||
if params[:groupe_instructeur].nil? || signature_file.blank?
|
|
||||||
flash[:alert] = "Aucun fichier joint pour le tampon de l'attestation"
|
|
||||||
render :show
|
|
||||||
else
|
|
||||||
params[:groupe_instructeur][:signature] = uninterlace_png(signature_file)
|
|
||||||
if @groupe_instructeur.update(signature_params)
|
|
||||||
redirect_to admin_procedure_groupe_instructeur_path(procedure, groupe_instructeur),
|
|
||||||
notice: "Le tampon de l'attestation a bien été ajouté"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def closed_params?
|
def closed_params?
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
module GroupeInstructeursSignatureConcern
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
def add_signature
|
||||||
|
@procedure = procedure
|
||||||
|
@groupe_instructeur = groupe_instructeur
|
||||||
|
@instructeurs = paginated_instructeurs
|
||||||
|
|
||||||
|
signature_file = params[:groupe_instructeur][:signature]
|
||||||
|
|
||||||
|
if params[:groupe_instructeur].nil? || signature_file.blank?
|
||||||
|
if respond_to?(:available_instructeur_emails)
|
||||||
|
@available_instructeur_emails = available_instructeur_emails
|
||||||
|
end
|
||||||
|
|
||||||
|
flash[:alert] = "Aucun fichier joint pour le tampon de l'attestation"
|
||||||
|
render :show
|
||||||
|
else
|
||||||
|
signature = uninterlace_png(signature_file)
|
||||||
|
|
||||||
|
if @groupe_instructeur.signature.attach(signature)
|
||||||
|
handle_redirect :success
|
||||||
|
else
|
||||||
|
handle_redirect :alert
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def preview_attestation
|
||||||
|
attestation_template = procedure.attestation_template || procedure.build_attestation_template
|
||||||
|
@attestation = attestation_template.render_attributes_for({ groupe_instructeur: groupe_instructeur })
|
||||||
|
|
||||||
|
render 'administrateurs/attestation_templates/show', formats: [:pdf]
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def handle_redirect(status)
|
||||||
|
redirect, preview = if self.class.module_parent_name == "Administrateurs"
|
||||||
|
[
|
||||||
|
:admin_procedure_groupe_instructeur_path,
|
||||||
|
:preview_attestation_admin_procedure_groupe_instructeur_path
|
||||||
|
]
|
||||||
|
else
|
||||||
|
[
|
||||||
|
:instructeur_groupe_path,
|
||||||
|
:preview_attestation_instructeur_groupe_path
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_path = method(redirect).call(@procedure, @groupe_instructeur)
|
||||||
|
preview_path = method(preview).call(@procedure, @groupe_instructeur)
|
||||||
|
|
||||||
|
case status
|
||||||
|
when :success
|
||||||
|
redirect_to redirect_path, notice: "Le tampon de l’attestation a bien été ajouté. #{helpers.link_to("Prévisualiser l’attestation", preview_path)}"
|
||||||
|
when :alert
|
||||||
|
redirect_to redirect_path, alert: "Une erreur a empêché l’ajout du tampon. Réessayez dans quelques instants."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,12 +0,0 @@
|
||||||
module PreviewAttestationConcern
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
included do
|
|
||||||
def preview_attestation
|
|
||||||
attestation_template = procedure.attestation_template || procedure.build_attestation_template
|
|
||||||
@attestation = attestation_template.render_attributes_for({ groupe_instructeur: groupe_instructeur })
|
|
||||||
|
|
||||||
render 'administrateurs/attestation_templates/show', formats: [:pdf]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Instructeurs
|
module Instructeurs
|
||||||
class GroupeInstructeursController < InstructeurController
|
class GroupeInstructeursController < InstructeurController
|
||||||
include UninterlacePngConcern
|
include UninterlacePngConcern
|
||||||
include PreviewAttestationConcern
|
include GroupeInstructeursSignatureConcern
|
||||||
|
|
||||||
ITEMS_PER_PAGE = 25
|
ITEMS_PER_PAGE = 25
|
||||||
|
|
||||||
|
@ -16,26 +16,6 @@ module Instructeurs
|
||||||
@instructeurs = paginated_instructeurs
|
@instructeurs = paginated_instructeurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_signature
|
|
||||||
@procedure = procedure
|
|
||||||
@groupe_instructeur = groupe_instructeur
|
|
||||||
@instructeurs = paginated_instructeurs
|
|
||||||
|
|
||||||
signature_file = params[:groupe_instructeur][:signature]
|
|
||||||
|
|
||||||
if params[:groupe_instructeur].nil? || signature_file.blank?
|
|
||||||
flash[:alert] = "Aucun fichier joint pour le tampon de l'attestation"
|
|
||||||
render :show
|
|
||||||
else
|
|
||||||
file = uninterlace_png(signature_file)
|
|
||||||
params[:groupe_instructeur][:signature] = file
|
|
||||||
if @groupe_instructeur.update(signature: file)
|
|
||||||
redirect_to instructeur_groupe_path(@procedure, @groupe_instructeur),
|
|
||||||
notice: "Le tampon de l'attestation a bien été ajouté"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_instructeur
|
def add_instructeur
|
||||||
instructeur = Instructeur.by_email(instructeur_email) ||
|
instructeur = Instructeur.by_email(instructeur_email) ||
|
||||||
create_instructeur(instructeur_email)
|
create_instructeur(instructeur_email)
|
||||||
|
|
Loading…
Add table
Reference in a new issue