From df475dc30644dd86224fdc26f3826ca92a241525 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 27 Jan 2021 15:25:58 +0100 Subject: [PATCH 1/4] Make siren_siret on annuaire education optional --- app/schemas/etablissement-annuaire-education.json | 1 - app/views/shared/champs/annuaire_education/_show.html.haml | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/schemas/etablissement-annuaire-education.json b/app/schemas/etablissement-annuaire-education.json index 2adce12ff..0ed7e6c96 100644 --- a/app/schemas/etablissement-annuaire-education.json +++ b/app/schemas/etablissement-annuaire-education.json @@ -170,7 +170,6 @@ "type_contrat_prive", "nom_commune", "code_commune", - "siren_siret", "libelle_academie", "code_academie", "libelle_nature", diff --git a/app/views/shared/champs/annuaire_education/_show.html.haml b/app/views/shared/champs/annuaire_education/_show.html.haml index baed3184d..18e458621 100644 --- a/app/views/shared/champs/annuaire_education/_show.html.haml +++ b/app/views/shared/champs/annuaire_education/_show.html.haml @@ -9,9 +9,10 @@ %tr %th.libelle L’identifiant de l’etablissement : %td= champ.data['identifiant_de_l_etablissement'] - %tr - %th.libelle SIREN/SIRET : - %td= champ.data['siren_siret'] + - if champ.data['siren_siret'].present? + %tr + %th.libelle SIREN/SIRET : + %td= champ.data['siren_siret'] %tr %th.libelle Commune : %td= "#{champ.data['nom_commune']} (#{champ.data['code_commune']})" From 0633d4386861eb8d9afb1581c803063f023ee4e0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 27 Jan 2021 15:58:49 +0100 Subject: [PATCH 2/4] Stop crashing if attachment can not be watermarked and mark blob as invalid --- app/jobs/titre_identite_watermark_job.rb | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/app/jobs/titre_identite_watermark_job.rb b/app/jobs/titre_identite_watermark_job.rb index 66eb1d33a..c3faae73d 100644 --- a/app/jobs/titre_identite_watermark_job.rb +++ b/app/jobs/titre_identite_watermark_job.rb @@ -6,11 +6,17 @@ class TitreIdentiteWatermarkJob < ApplicationJob def perform(blob) blob.open do |file| watermark = resize_watermark(file) - processed = watermark_image(file, watermark) - blob.metadata[:watermark] = true - blob.upload(processed) - blob.save + if watermark.present? + processed = watermark_image(file, watermark) + + blob.metadata[:watermark] = true + blob.upload(processed) + blob.save + else + blob.metadata[:watermark_invalid] = true + blob.save + end end end @@ -28,16 +34,18 @@ class TitreIdentiteWatermarkJob < ApplicationJob def resize_watermark(file) metadata = image_metadata(file) - width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE - height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE - diagonal = Math.sqrt(height**2 + width**2) - angle = Math.asin(height / diagonal) * 180 / Math::PI + if metadata[:width].present? && metadata[:height].present? + width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE + height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE + diagonal = Math.sqrt(height**2 + width**2) + angle = Math.asin(height / diagonal) * 180 / Math::PI - ImageProcessing::MiniMagick - .source(WATERMARK) - .resize_to_limit(diagonal, diagonal / 2) - .rotate(-angle, background: :transparent) - .call + ImageProcessing::MiniMagick + .source(WATERMARK) + .resize_to_limit(diagonal, diagonal / 2) + .rotate(-angle, background: :transparent) + .call + end end def image_metadata(file) From 3d0c888058a6382a656da093ba9f734c573fb2f5 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 27 Jan 2021 14:15:58 +0100 Subject: [PATCH 3/4] Stop crashing if a selection utilisateur contains no geometry --- 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 fc9a55833..c15ce9774 100644 --- a/app/controllers/champs/carte_controller.rb +++ b/app/controllers/champs/carte_controller.rb @@ -71,7 +71,7 @@ class Champs::CarteController < ApplicationController def cadastres_features_collection(feature_collection) coordinates = feature_collection[:features].filter do |feature| - feature[:properties][:source] == GeoArea.sources.fetch(:selection_utilisateur) && feature[:geometry]['type'] == 'Polygon' + feature[:properties][:source] == GeoArea.sources.fetch(:selection_utilisateur) && feature[:geometry] && feature[:geometry]['type'] == 'Polygon' end.map do |feature| feature[:geometry]['coordinates'][0].map { |(lng, lat)| { 'lng' => lng, 'lat' => lat } } end From 1b5aef10f23a3f0598588f9c7e5d573fe6350ec6 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 26 Jan 2021 16:50:32 +0100 Subject: [PATCH 4/4] Stop crashing when removed repetition row is submitted --- app/controllers/users/dossiers_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 60d549162..7d17e2b1d 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -346,6 +346,11 @@ module Users if champs_params[:dossier] @dossier.assign_attributes(champs_params[:dossier]) + # FIXME in some cases a removed repetition bloc row is submitted. + # In this case it will be trated as a new records and action will fail. + @dossier.champs.filter(&:repetition?).each do |champ| + champ.champs = champ.champs.filter(&:persisted?) + end if @dossier.champs.any?(&:changed?) @dossier.last_champ_updated_at = Time.zone.now end