From f983bc68e29a849a3a4fd962506b0ad38b18b8a7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 20 Nov 2018 17:45:50 +0100 Subject: [PATCH 01/10] mailers: fix dossier mailer spec --- spec/mailers/dossier_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/dossier_mailer_spec.rb b/spec/mailers/dossier_mailer_spec.rb index d98dfb4ea..eaec0fc93 100644 --- a/spec/mailers/dossier_mailer_spec.rb +++ b/spec/mailers/dossier_mailer_spec.rb @@ -9,7 +9,7 @@ RSpec.describe DossierMailer, type: :mailer do subject { described_class.notify_new_draft(dossier) } it { expect(subject.subject).to include("brouillon") } - it { expect(subject.subject).to include(dossier.id.to_s) } + it { expect(subject.subject).to include(dossier.procedure.libelle) } it { expect(subject.body).to include(dossier.procedure.libelle) } it { expect(subject.body).to include(dossier_url(dossier)) } end From ac9a87f27b68eac7ae4743bb081d052fabba5b91 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 21 Nov 2018 11:28:13 +0000 Subject: [PATCH 02/10] config: fix email assets not having the full URL domain prepended When sending emails, the mailer doesn't have access to the request host. It needs to infer it by itself. For this we need two settings: - action_mailer.default_url_options, to generate urls to routes - action_mailer.asset_host, to generate full urls to assets Only the first one of these settings was set in production. Fix #2518 --- config/environments/development.rb | 7 +++++++ config/environments/production.rb | 3 +++ 2 files changed, 10 insertions(+) diff --git a/config/environments/development.rb b/config/environments/development.rb index f600e1bba..4dfddc69c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -46,6 +46,13 @@ Rails.application.configure do # Action Mailer settings config.action_mailer.delivery_method = :letter_opener_web + # Configure default root URL for generating URLs to routes + config.action_mailer.default_url_options = { + host: 'localhost', + port: 3000 + } + # Configure default root URL for email assets + config.action_mailer.asset_host = "http://" + ENV['APP_HOST'] Rails.application.routes.default_url_options = { host: 'localhost', diff --git a/config/environments/production.rb b/config/environments/production.rb index b79e63fbb..07e86f837 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -81,10 +81,13 @@ Rails.application.configure do config.action_mailer.delivery_method = :mailjet end + # Configure default root URL for generating URLs to routes config.action_mailer.default_url_options = { protocol: :https, host: ENV['APP_HOST'] } + # Configure default root URL for email assets + config.action_mailer.asset_host = "https://" + ENV['APP_HOST'] # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). From 49c872fb97eba1d4a01b54addd3d18ae62419ff8 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 21 Nov 2018 12:41:50 +0100 Subject: [PATCH 03/10] Fail fast if passed champ_id is invalid --- app/controllers/champs/carte_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/champs/carte_controller.rb b/app/controllers/champs/carte_controller.rb index d3a7dbb38..921c18b05 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -14,7 +14,7 @@ class Champs::CarteController < ApplicationController @champ = Champ .joins(:dossier) .where(dossiers: { user_id: logged_user_ids }) - .find_by(id: params[:champ_id]) + .find(params[:champ_id]) else @champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new( type_champ: TypeDeChamp.type_champs.fetch(:carte), From c99ef811b6ffcf267c3dd315441744967683f7b5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 21 Nov 2018 12:42:13 +0100 Subject: [PATCH 04/10] Do not save error json in database --- app/controllers/champs/carte_controller.rb | 12 +++++++----- spec/controllers/champs/carte_controller_spec.rb | 13 ++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/controllers/champs/carte_controller.rb b/app/controllers/champs/carte_controller.rb index 921c18b05..857970ac2 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -30,6 +30,8 @@ class Champs::CarteController < ApplicationController if geo_json.first == ["error", "TooManyPolygons"] @error = true + @champ.value = nil + @champ.geo_areas = [] elsif geo_json.present? if @champ.cadastres? cadastres = ModuleApiCartoService.generate_cadastre(geo_json) @@ -54,13 +56,13 @@ class Champs::CarteController < ApplicationController parcelle_agricole end end - end - @champ.geo_areas = geo_areas.map do |geo_area| - GeoArea.new(geo_area) - end + @champ.geo_areas = geo_areas.map do |geo_area| + GeoArea.new(geo_area) + end - @champ.value = geo_json.to_json + @champ.value = geo_json.to_json + end if @champ.persisted? @champ.save diff --git a/spec/controllers/champs/carte_controller_spec.rb b/spec/controllers/champs/carte_controller_spec.rb index 9a9d56896..267f6d3b2 100644 --- a/spec/controllers/champs/carte_controller_spec.rb +++ b/spec/controllers/champs/carte_controller_spec.rb @@ -15,10 +15,11 @@ describe Champs::CarteController, type: :controller do champ_id: champ.id } end + let(:geojson) { [] } let(:champ) do create(:type_de_champ_carte, options: { quartiers_prioritaires: true - }).champ.create(dossier: dossier) + }).champ.create(dossier: dossier, value: geojson.to_json) end describe 'POST #show' do @@ -46,5 +47,15 @@ describe Champs::CarteController, type: :controller do it { expect(response.body).to include('MultiPolygon') } it { expect(response.body).to include('[2.38715792094576,48.8723062632126]') } end + + context 'when error' do + let(:geojson) { [[{ "lat": 48.87442541960633, "lng": 2.3859214782714844 }, { "lat": 48.87273183590832, "lng": 2.3850631713867183 }, { "lat": 48.87081237174292, "lng": 2.3809432983398438 }, { "lat": 48.8712640169951, "lng": 2.377510070800781 }, { "lat": 48.87510283703279, "lng": 2.3778533935546875 }, { "lat": 48.87544154230615, "lng": 2.382831573486328 }, { "lat": 48.87442541960633, "lng": 2.3859214782714844 }]] } + let(:selection) { { error: "TooManyPolygons" } } + + it { + expect(champ.reload.value).to eq(nil) + expect(champ.reload.geo_areas).to eq([]) + } + end end end From 7c1768e5bb2c067b26fa5226928573ad3c7cdd4b Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 21 Nov 2018 12:09:41 +0100 Subject: [PATCH 05/10] [Fix #3016] Do not crash if PJ has no extension --- app/uploaders/piece_justificative_uploader.rb | 4 ++-- .../uploaders/piece_justificative_uploader_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 spec/uploaders/piece_justificative_uploader_spec.rb diff --git a/app/uploaders/piece_justificative_uploader.rb b/app/uploaders/piece_justificative_uploader.rb index f4fb1ce67..62cdb6c40 100644 --- a/app/uploaders/piece_justificative_uploader.rb +++ b/app/uploaders/piece_justificative_uploader.rb @@ -25,9 +25,9 @@ class PieceJustificativeUploader < BaseUploader def filename if original_filename.present? || model.content_secure_token if Flipflop.remote_storage? - filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}" + filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension&.downcase}" else - filename = "#{model.class.to_s.underscore}.#{file.extension.downcase}" + filename = "#{model.class.to_s.underscore}.#{file.extension&.downcase}" end end filename diff --git a/spec/uploaders/piece_justificative_uploader_spec.rb b/spec/uploaders/piece_justificative_uploader_spec.rb new file mode 100644 index 000000000..61078c3c6 --- /dev/null +++ b/spec/uploaders/piece_justificative_uploader_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe PieceJustificativeUploader do + let(:pj) { create(:piece_justificative, :rib) } + + it { expect(pj.content.filename).to eq 'piece_justificative.pdf' } + + context 'when extension is nil' do + it do + expect(pj.content.file).to receive(:extension).and_return(nil) + expect(pj.content.filename).to eq 'piece_justificative.' + end + end +end From 5c2fe50319ab3e45a00254814cb92fffbecc5161 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 20 Nov 2018 17:44:26 +0100 Subject: [PATCH 06/10] Fix width in manager procedure detail --- app/views/fields/mail_template_field/_show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/fields/mail_template_field/_show.html.haml b/app/views/fields/mail_template_field/_show.html.haml index e505a4989..47ffac191 100644 --- a/app/views/fields/mail_template_field/_show.html.haml +++ b/app/views/fields/mail_template_field/_show.html.haml @@ -1,7 +1,7 @@ %strong Sujet -%pre +%pre{ style: "white-space: pre-wrap;" } = field.data.subject %strong Corps -%pre +%pre{ style: "white-space: pre-wrap;" } = field.data.body From 3ce9dd39afb1cc6a79e52c56742f5f8db25db8b2 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Tue, 20 Nov 2018 17:38:04 +0100 Subject: [PATCH 07/10] [Fix #3008] Soft delete demarche button in manager --- app/controllers/manager/procedures_controller.rb | 7 +++++++ app/views/manager/procedures/show.html.erb | 2 ++ config/routes.rb | 1 + 3 files changed, 10 insertions(+) diff --git a/app/controllers/manager/procedures_controller.rb b/app/controllers/manager/procedures_controller.rb index 4035c968c..6dd920f94 100644 --- a/app/controllers/manager/procedures_controller.rb +++ b/app/controllers/manager/procedures_controller.rb @@ -17,5 +17,12 @@ module Manager end redirect_to manager_procedure_path(procedure) end + + def hide + procedure = Procedure.find(params[:id]) + procedure.hide! + flash[:notice] = "La démarche a bien été supprimée, en cas d'erreur contactez un développeur." + redirect_to manager_procedure_path(procedure) + end end end diff --git a/app/views/manager/procedures/show.html.erb b/app/views/manager/procedures/show.html.erb index deb79a1f3..8985c02a0 100644 --- a/app/views/manager/procedures/show.html.erb +++ b/app/views/manager/procedures/show.html.erb @@ -40,6 +40,8 @@ as well as a link to its edit page. <% if procedure.publiee? && procedure.dossiers.empty? %> <%= link_to 'passer en brouillon', draft_manager_procedure_path(procedure), method: :post, class: 'button' %> <% end %> + + <%= link_to 'supprimer la démarche', hide_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
diff --git a/config/routes.rb b/config/routes.rb index 7ca89638c..cf427f12d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ Rails.application.routes.draw do resources :procedures, only: [:index, :show] do post 'whitelist', on: :member post 'draft', on: :member + post 'hide', on: :member end resources :dossiers, only: [:index, :show] do From 88b8c190f5ae6e437848d9df43e434c7946325f8 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 21 Nov 2018 14:14:38 +0100 Subject: [PATCH 08/10] Cleanup releases after deploy --- config/deploy.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/deploy.rb b/config/deploy.rb index 5a36ae2ac..ad139f136 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -110,6 +110,7 @@ task :deploy do invoke :'service:restart_puma' invoke :'service:reload_nginx' invoke :'service:restart_delayed_job' + invoke :'deploy:cleanup' end end end From ae30a1b41cf84958ccba66fea31a8152b69622b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chai=CC=88b=20Martinez?= Date: Mon, 22 Oct 2018 14:32:56 +0200 Subject: [PATCH 09/10] MAJ du robots.txt pour bloquer l'indexation de certaines pages. --- public/robots.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/robots.txt b/public/robots.txt index 3c9c7c01f..257836137 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1,5 @@ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / +User-agent: * +Disallow: /commencer* From 167aff30f4a1178d2f86880700c0d27b3417987d Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 21 Nov 2018 16:28:02 +0100 Subject: [PATCH 10/10] Cancel cleanup --- config/deploy.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index ad139f136..5a36ae2ac 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -110,7 +110,6 @@ task :deploy do invoke :'service:restart_puma' invoke :'service:reload_nginx' invoke :'service:restart_delayed_job' - invoke :'deploy:cleanup' end end end