Merge pull request #5863 from betagouv/dev

2021-01-27-02
This commit is contained in:
Paul Chavard 2021-01-27 18:05:57 +01:00 committed by GitHub
commit cbb3b36e52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 18 deletions

View file

@ -71,7 +71,7 @@ class Champs::CarteController < ApplicationController
def cadastres_features_collection(feature_collection) def cadastres_features_collection(feature_collection)
coordinates = feature_collection[:features].filter do |feature| 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| end.map do |feature|
feature[:geometry]['coordinates'][0].map { |(lng, lat)| { 'lng' => lng, 'lat' => lat } } feature[:geometry]['coordinates'][0].map { |(lng, lat)| { 'lng' => lng, 'lat' => lat } }
end end

View file

@ -346,6 +346,11 @@ module Users
if champs_params[:dossier] if champs_params[:dossier]
@dossier.assign_attributes(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?) if @dossier.champs.any?(&:changed?)
@dossier.last_champ_updated_at = Time.zone.now @dossier.last_champ_updated_at = Time.zone.now
end end

View file

@ -6,11 +6,17 @@ class TitreIdentiteWatermarkJob < ApplicationJob
def perform(blob) def perform(blob)
blob.open do |file| blob.open do |file|
watermark = resize_watermark(file) watermark = resize_watermark(file)
if watermark.present?
processed = watermark_image(file, watermark) processed = watermark_image(file, watermark)
blob.metadata[:watermark] = true blob.metadata[:watermark] = true
blob.upload(processed) blob.upload(processed)
blob.save blob.save
else
blob.metadata[:watermark_invalid] = true
blob.save
end
end end
end end
@ -28,6 +34,7 @@ class TitreIdentiteWatermarkJob < ApplicationJob
def resize_watermark(file) def resize_watermark(file)
metadata = image_metadata(file) metadata = image_metadata(file)
if metadata[:width].present? && metadata[:height].present?
width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE
height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE
diagonal = Math.sqrt(height**2 + width**2) diagonal = Math.sqrt(height**2 + width**2)
@ -39,6 +46,7 @@ class TitreIdentiteWatermarkJob < ApplicationJob
.rotate(-angle, background: :transparent) .rotate(-angle, background: :transparent)
.call .call
end end
end
def image_metadata(file) def image_metadata(file)
read_image(file) do |image| read_image(file) do |image|

View file

@ -170,7 +170,6 @@
"type_contrat_prive", "type_contrat_prive",
"nom_commune", "nom_commune",
"code_commune", "code_commune",
"siren_siret",
"libelle_academie", "libelle_academie",
"code_academie", "code_academie",
"libelle_nature", "libelle_nature",

View file

@ -9,6 +9,7 @@
%tr %tr
%th.libelle Lidentifiant de letablissement : %th.libelle Lidentifiant de letablissement :
%td= champ.data['identifiant_de_l_etablissement'] %td= champ.data['identifiant_de_l_etablissement']
- if champ.data['siren_siret'].present?
%tr %tr
%th.libelle SIREN/SIRET : %th.libelle SIREN/SIRET :
%td= champ.data['siren_siret'] %td= champ.data['siren_siret']