From f0f794b00cca58b4a563f3f7811bc028d6b0f728 Mon Sep 17 00:00:00 2001 From: Fabrice Gangler Date: Thu, 10 Dec 2020 18:35:41 +0100 Subject: [PATCH 1/6] Fix(.gitignore): exclude /public/assets directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0f870d087..96eb56be5 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ yarn-debug.log* .yarn-integrity /.vscode /.idea +/public/assets /public/packs /public/packs-test /node_modules From 064ea776c79d36655d9d5f513efe78d237d8c2c3 Mon Sep 17 00:00:00 2001 From: Fabrice Gangler Date: Thu, 10 Dec 2020 21:05:42 +0100 Subject: [PATCH 2/6] allow default logo of a procedure to be configured in .env file Refs: #5795 --- app/models/procedure.rb | 2 +- config/env.example.optional | 3 +++ config/initializers/images.rb | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 1f48231c8..e8d970a33 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -568,7 +568,7 @@ class Procedure < ApplicationRecord if logo.attached? Rails.application.routes.url_helpers.url_for(logo) else - ActionController::Base.helpers.image_url("republique-francaise-logo.svg") + ActionController::Base.helpers.image_url(PROCEDURE_DEFAULT_LOGO_SRC) end end diff --git a/config/env.example.optional b/config/env.example.optional index 96e4e6956..7587634fb 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -41,5 +41,8 @@ APPLICATION_BASE_URL="https://www.demarches-simplifiees.fr" # Personnalisation d'instance - Logo dans l'entête des emails ---> à placer dans "app/assets/images" # MAILER_LOGO_SRC="mailer/instructeur_mailer/logo.png" +# Personnalisation d'instance - Logo par défaut d'une procédure ---> à placer dans "app/assets/images" +# PROCEDURE_DEFAULT_LOGO_SRC="republique-francaise-logo.svg" + # Personnalisation d'instance - fichier utilisé pour poser un filigrane sur les pièces d'identité # WATERMARK_FILE="" diff --git a/config/initializers/images.rb b/config/initializers/images.rb index d8415c742..628857d42 100644 --- a/config/initializers/images.rb +++ b/config/initializers/images.rb @@ -11,3 +11,6 @@ HEADER_LOGO_HEIGHT = ENV.fetch("HEADER_LOGO_HEIGHT", "56") # Mailer logo MAILER_LOGO_SRC = ENV.fetch("MAILER_LOGO_SRC", "mailer/instructeur_mailer/logo.png") + +# Default logo of a procedure +PROCEDURE_DEFAULT_LOGO_SRC = ENV.fetch("PROCEDURE_DEFAULT_LOGO_SRC", "republique-francaise-logo.svg") From bc4dc22aea941d674a5b7208878611e80e774f8d Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 14 Dec 2020 11:12:50 +0100 Subject: [PATCH 3/6] spec: use real signature to avoid mocking --- spec/models/bill_signature_spec.rb | 41 +++++++++++++----------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/spec/models/bill_signature_spec.rb b/spec/models/bill_signature_spec.rb index a31c399e6..a8d64a2fd 100644 --- a/spec/models/bill_signature_spec.rb +++ b/spec/models/bill_signature_spec.rb @@ -72,48 +72,41 @@ RSpec.describe BillSignature, type: :model do end describe 'check_signature_contents' do + let(:signature) { File.open('spec/fixtures/files/bill_signature/signature.der') } + let(:signature_date) { DateTime.parse('2019-04-30 15:30:20') } + let(:signature_digest) { Digest::SHA256.hexdigest('CECI EST UN BLOB') } + let(:current_date) { Time.zone.now } + before do - bill_signature.signature.attach(io: StringIO.new(signature), filename: 'file') if signature.present? - allow(ASN1::Timestamp).to receive(:signature_time).and_return(signature_time) - allow(ASN1::Timestamp).to receive(:signed_digest).and_return(signed_digest) - bill_signature.digest = digest + Timecop.freeze(current_date) + bill_signature.signature.attach(io: signature, filename: 'file') if signature.present? + bill_signature.digest = signature_digest bill_signature.valid? + Timecop.return end - context 'when the signature is correct' do - let(:signature) { 'signature' } - let(:signature_time) { 1.day.ago } - let(:digest) { 'abcd' } - let(:signed_digest) { 'abcd' } + subject { bill_signature.errors.details[:signature] } - it { expect(bill_signature.errors.details[:signature]).to be_empty } + context 'when the signature is correct' do + it { is_expected.to be_empty } end context 'when the signature isn’t set' do let(:signature) { nil } - let(:signature_time) { 1.day.ago } - let(:digest) { 'abcd' } - let(:signed_digest) { 'abcd' } - it { expect(bill_signature.errors.details[:signature]).to eq [error: :blank] } + it { is_expected.to eq [error: :blank] } end context 'when the signature time is in the future' do - let(:signature) { 'signature' } - let(:signature_time) { 1.day.from_now } - let(:digest) { 'abcd' } - let(:signed_digest) { 'abcd' } + let(:current_date) { signature_date - 1.day } - it { expect(bill_signature.errors.details[:signature]).to eq [error: :invalid_date] } + it { is_expected.to eq [error: :invalid_date] } end context 'when the signature doesn’t match the digest' do - let(:signature) { 'signature' } - let(:signature_time) { 1.day.ago } - let(:digest) { 'abcd' } - let(:signed_digest) { 'dcba' } + let(:signature_digest) { 'dcba' } - it { expect(bill_signature.errors.details[:signature]).to eq [error: :invalid] } + it { is_expected.to eq [error: :invalid] } end end end From 38a5847ca414c3627f60eab9d584ad47ba56644f Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 14 Dec 2020 11:13:36 +0100 Subject: [PATCH 4/6] rewind io before reading to allow multiple read --- app/models/bill_signature.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/bill_signature.rb b/app/models/bill_signature.rb index 3828c2f1f..7de9795cd 100644 --- a/app/models/bill_signature.rb +++ b/app/models/bill_signature.rb @@ -94,7 +94,10 @@ class BillSignature < ApplicationRecord def read_signature if attachment_changes['signature'] io = io_for_changes(attachment_changes['signature']) - io.read if io.present? + if io.present? + io.rewind + io.read + end elsif signature.attached? signature.download end @@ -103,7 +106,10 @@ class BillSignature < ApplicationRecord def read_serialized if attachment_changes['serialized'] io = io_for_changes(attachment_changes['serialized']) - io.read if io.present? + if io.present? + io.rewind + io.read + end elsif serialized.attached? serialized.download end From a941626d4519181ddb848c6e8322dc97109b29a9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 14 Dec 2020 14:08:39 +0100 Subject: [PATCH 5/6] factorize read_attachment --- app/models/bill_signature.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/models/bill_signature.rb b/app/models/bill_signature.rb index 7de9795cd..8b0e66cf5 100644 --- a/app/models/bill_signature.rb +++ b/app/models/bill_signature.rb @@ -92,20 +92,18 @@ class BillSignature < ApplicationRecord end def read_signature - if attachment_changes['signature'] - io = io_for_changes(attachment_changes['signature']) - if io.present? - io.rewind - io.read - end - elsif signature.attached? - signature.download - end + read_attachment('signature') end def read_serialized - if attachment_changes['serialized'] - io = io_for_changes(attachment_changes['serialized']) + read_attachment('serialized') + end + + private + + def read_attachment(attachment) + if attachment_changes[attachment] + io = io_for_changes(attachment_changes[attachment]) if io.present? io.rewind io.read @@ -115,8 +113,6 @@ class BillSignature < ApplicationRecord end end - private - def io_for_changes(attachment_changes) attachable = attachment_changes.attachable case attachable From 107ad1d28e53da2c3800113269f0819330597f5f Mon Sep 17 00:00:00 2001 From: Fabrice Gangler Date: Fri, 11 Dec 2020 01:28:21 +0100 Subject: [PATCH 6/6] Fix(form add/edit a service): use APPLICATION_NAME Refs: #5797 --- app/views/new_administrateur/services/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml index 0e262af20..775577eac 100644 --- a/app/views/new_administrateur/services/_form.html.haml +++ b/app/views/new_administrateur/services/_form.html.haml @@ -19,7 +19,7 @@ %h2.header-section Informations de contact %p.explication - Votre démarche sera hébergée par demarche-simplifiees.fr – mais nous ne pouvons pas assurer le support des démarches. Et malgré la dématérialisation, les usagers se poseront parfois des questions légitimes sur le processus administratif. + Votre démarche sera hébergée par #{APPLICATION_NAME} – mais nous ne pouvons pas assurer le support des démarches. Et malgré la dématérialisation, les usagers se poseront parfois des questions légitimes sur le processus administratif. %br Il est donc important que les usagers puissent vous contacter s'ils ont des questions sur votre démarche. %br