From 0fbc54e140bc3b3a1aa507379d02903b1371c63e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Wed, 5 Jul 2017 14:41:00 +0200 Subject: [PATCH 1/4] [Fix #76] The develop branch is now dev --- .circleci/config.yml | 2 +- config/deploy.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c27c968f1..db32ad5ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ jobs: - "0a:67:42:7d:7e:b7:e1:3c:48:8f:bf:68:10:51:a8:44" - deploy: command: | - if [ "${CIRCLE_BRANCH}" == "develop" ]; then + if [ "${CIRCLE_BRANCH}" == "dev" ]; then bundle exec rake deploy_ha fi diff --git a/config/deploy.rb b/config/deploy.rb index 568cf4771..c6c264d9c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -24,7 +24,7 @@ set :deploy_to, '/var/www/tps_dev' case ENV["to"] when "staging" - set :branch, ENV['branch'] || 'develop' + set :branch, ENV['branch'] || 'dev' set :deploy_to, '/var/www/tps_dev' set :user, 'tps_dev' # Username in the server to SSH to. appname = 'tps_dev' From aa929bb5b25713ee3555e2d7fa57607957117723 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 6 Jul 2017 14:40:06 +0200 Subject: [PATCH 2/4] [Fix #554] If procedure is hidden, then don't crash --- app/controllers/users/dossiers_controller.rb | 2 +- spec/controllers/users/dossiers_controller_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8decc82ca..85209ca1e 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -39,7 +39,7 @@ class Users::DossiersController < UsersController unless params[:procedure_path].nil? procedure_path = ProcedurePath.where(path: params[:procedure_path]).last - if procedure_path.nil? + if procedure_path.nil? || procedure_path.procedure.nil? flash.alert = "Procédure inconnue" return redirect_to root_path else diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index abf8361a6..881184469 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -152,7 +152,7 @@ describe Users::DossiersController, type: :controller do end describe 'GET #commencer' do - subject { get :commencer, params: {procedure_path: procedure.path} } + subject { get :commencer, params: { procedure_path: procedure.path } } it { expect(subject.status).to eq 302 } it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } @@ -166,6 +166,12 @@ describe Users::DossiersController, type: :controller do it { expect(subject.status).to eq 200 } end + + context 'when procedure is hidden' do + let(:procedure) { create(:procedure, :published, hidden_at: DateTime.now) } + + it { expect(subject).to redirect_to(root_path) } + end end describe 'POST #siret_informations' do From b2ba5c597d1fb17f6fabae75c44f4819f1cd6f82 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Thu, 6 Jul 2017 19:54:16 +0200 Subject: [PATCH 3/4] [FIX #558] Attestation: fix access with multiple logins --- app/views/dossiers/_attestation.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/dossiers/_attestation.html.haml b/app/views/dossiers/_attestation.html.haml index dc77bc5f2..f221203f1 100644 --- a/app/views/dossiers/_attestation.html.haml +++ b/app/views/dossiers/_attestation.html.haml @@ -11,7 +11,7 @@ = image_tag('pdf.svg', width: '20px') %p.title= dossier.attestation.title %p.delivery Délivrée le #{l(dossier.attestation.created_at, format: '%d %B %Y')} - - if user_signed_in? + - if user_signed_in? && current_user == dossier.user = link_to 'Télécharger', dossier_attestation_path(dossier), target: '_blank', class: 'btn btn-primary' - else = link_to 'Télécharger', procedure_dossier_attestation_path(dossier.procedure, dossier), target: '_blank', class: 'btn btn-primary' From 9d4824966022aa6db4f4edf1abcc3b05012b19ac Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 5 Jul 2017 16:05:37 +0200 Subject: [PATCH 4/4] Attestation: uninterlaced png file to be compatible with Prawn --- Gemfile | 1 + Gemfile.lock | 2 ++ .../admin/attestation_templates_controller.rb | 24 +++++++++++++++--- .../attestation_templates_controller_spec.rb | 7 +++++ spec/fixtures/interlaced-black.png | Bin 0 -> 214 bytes spec/fixtures/uninterlaced-black.png | Bin 0 -> 165 bytes 6 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 spec/fixtures/interlaced-black.png create mode 100644 spec/fixtures/uninterlaced-black.png diff --git a/Gemfile b/Gemfile index c7b560dd2..839c2fe48 100644 --- a/Gemfile +++ b/Gemfile @@ -106,6 +106,7 @@ gem 'select2-rails' gem 'prawn', '~> 2.0.1' gem 'prawn_rails', '~> 0.0.11' +gem 'chunky_png' gem 'sentry-raven' group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 5ff8a870a..8c2ca041e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,7 @@ GEM mime-types (>= 1.16) mimemagic (>= 0.3.0) chartkick (2.2.1) + chunky_png (1.3.8) clamav-client (3.1.0) cliver (0.3.2) coderay (1.1.1) @@ -686,6 +687,7 @@ DEPENDENCIES capybara carrierwave chartkick + chunky_png clamav-client copy_carrierwave_file database_cleaner diff --git a/app/controllers/admin/attestation_templates_controller.rb b/app/controllers/admin/attestation_templates_controller.rb index bc3bf0f40..c49edfe13 100644 --- a/app/controllers/admin/attestation_templates_controller.rb +++ b/app/controllers/admin/attestation_templates_controller.rb @@ -57,8 +57,26 @@ class Admin::AttestationTemplatesController < AdminController private def activated_attestation_params - params.require(:attestation_template) - .permit(:title, :body, :footer, :logo, :signature) - .merge(activated: true) + # cache result to avoid multiple uninterlaced computations + if @activated_attestation_params.nil? + @activated_attestation_params = params.require(:attestation_template) + .permit(:title, :body, :footer, :signature) + .merge(activated: true) + + @activated_attestation_params.merge!(logo: uninterlaced_png(params['attestation_template']['logo'])) + @activated_attestation_params.merge!(signature: uninterlaced_png(params['attestation_template']['signature'])) + end + + @activated_attestation_params + end + + def uninterlaced_png(uploaded_file) + if uploaded_file.present? && uploaded_file.content_type == 'image/png' + chunky_img = ChunkyPNG::Image.from_io(uploaded_file) + chunky_img.save(uploaded_file.tempfile.to_path, interlace: false) + uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb') + end + + uploaded_file end end diff --git a/spec/controllers/admin/attestation_templates_controller_spec.rb b/spec/controllers/admin/attestation_templates_controller_spec.rb index cd318832a..e8c068559 100644 --- a/spec/controllers/admin/attestation_templates_controller_spec.rb +++ b/spec/controllers/admin/attestation_templates_controller_spec.rb @@ -4,6 +4,8 @@ describe Admin::AttestationTemplatesController, type: :controller do let!(:procedure) { create :procedure, administrateur: admin, attestation_template: attestation_template } let(:logo) { fixture_file_upload('spec/fixtures/white.png', 'image/png') } let(:signature) { fixture_file_upload('spec/fixtures/black.png', 'image/png') } + let(:interlaced_logo) { fixture_file_upload('spec/fixtures/interlaced-black.png', 'image/png') } + let(:uninterlaced_logo) { fixture_file_upload('spec/fixtures/uninterlaced-black.png', 'image/png') } before do sign_in admin @@ -19,6 +21,11 @@ describe Admin::AttestationTemplatesController, type: :controller do attestation_template: upload_params } end + context 'with an interlaced png' do + let(:upload_params) { { logo: interlaced_logo } } + it { expect(assigns(:logo).read).to eq(uninterlaced_logo.read) } + end + context 'if an attestation template does not exist on the procedure' do let(:attestation_template) { nil } it { expect(subject.status).to eq(200) } diff --git a/spec/fixtures/interlaced-black.png b/spec/fixtures/interlaced-black.png new file mode 100644 index 0000000000000000000000000000000000000000..eea46537d121c817a40af068488741f5e0ab8de4 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^j35jq95PRC0&-Z=9eo`c7&i8E|4C#8@|lvn-CYOJbhi+AF>JX=&G(+xV;1@#O3MY7{YNqIRVIKVqkovxW^dCQY~?fC`m~y zNwrEYN(E93Mh1rFx&~&thGrp#Mph=KR>tPq21Zr}1~MnFs-bAe%}>cptHiA#cS`Oo Ppaup{S3j3^P6