diff --git a/app/controllers/administrateurs/attestation_template_v2s_controller.rb b/app/controllers/administrateurs/attestation_template_v2s_controller.rb index 6783ba8f8..1902221b6 100644 --- a/app/controllers/administrateurs/attestation_template_v2s_controller.rb +++ b/app/controllers/administrateurs/attestation_template_v2s_controller.rb @@ -6,7 +6,21 @@ module Administrateurs json_body = @attestation_template.json_body&.deep_symbolize_keys @body = TiptapService.to_html(json_body, {}) - render layout: 'attestation' + respond_to do |format| + format.html do + render layout: 'attestation' + end + + format.pdf do + html = render_to_string('/administrateurs/attestation_template_v2s/show', layout: 'attestation', formats: [:html]) + + result = Typhoeus.post(WEASYPRINT_URL, + headers: { 'content-type': 'application/json' }, + body: { html: html }.to_json) + + send_data(result.body, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline') + end + end end def edit diff --git a/config/env.example.optional b/config/env.example.optional index be5510643..65fcedbd8 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -250,3 +250,6 @@ ADMINS_GROUP_ENABLED="disabled" # Do you want to isolate bulk email (notifications) from transactional ones (ex: reset password). # BULK_EMAIL_QUEUE will host bulk email (notifications) BULK_EMAIL_QUEUE="low_priority" + +# work in progress about attestation_v2 +WEASYPRINT_URL="http://10.33.23.204:5000/pdf" diff --git a/config/initializers/02_urls.rb b/config/initializers/02_urls.rb index dc8c105b7..847c1f427 100644 --- a/config/initializers/02_urls.rb +++ b/config/initializers/02_urls.rb @@ -14,6 +14,7 @@ SENDINBLUE_API_V3_URL = ENV.fetch("SENDINBLUE_API_V3_URL", "https://api.sendinbl UNIVERSIGN_API_URL = ENV.fetch("UNIVERSIGN_API_URL", "https://ws.universign.eu/tsa/post/") CERTIGNA_API_URL = ENV.fetch("CERTIGNA_API_URL", "https://timestamp.dhimyotis.com/api/v1/") FEATURE_UPVOTE_URL = ENV.fetch("FEATURE_UPVOTE_URL", "https://demarches-simplifiees.featureupvote.com") +WEASYPRINT_URL = ENV.fetch("WEASYPRINT_URL", nil) # Internal URLs FOG_OPENSTACK_URL = ENV.fetch("FOG_OPENSTACK_URL", "https://auth.cloud.ovh.net")