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)
processed = watermark_image(file, watermark)
blob.metadata[:watermark] = true if watermark.present?
blob.upload(processed) processed = watermark_image(file, watermark)
blob.save
blob.metadata[:watermark] = true
blob.upload(processed)
blob.save
else
blob.metadata[:watermark_invalid] = true
blob.save
end
end end
end end
@ -28,16 +34,18 @@ class TitreIdentiteWatermarkJob < ApplicationJob
def resize_watermark(file) def resize_watermark(file)
metadata = image_metadata(file) metadata = image_metadata(file)
width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE if metadata[:width].present? && metadata[:height].present?
height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE width = [metadata[:width], MAX_IMAGE_SIZE].min * SCALE
diagonal = Math.sqrt(height**2 + width**2) height = [metadata[:height], MAX_IMAGE_SIZE].min * SCALE
angle = Math.asin(height / diagonal) * 180 / Math::PI diagonal = Math.sqrt(height**2 + width**2)
angle = Math.asin(height / diagonal) * 180 / Math::PI
ImageProcessing::MiniMagick ImageProcessing::MiniMagick
.source(WATERMARK) .source(WATERMARK)
.resize_to_limit(diagonal, diagonal / 2) .resize_to_limit(diagonal, diagonal / 2)
.rotate(-angle, background: :transparent) .rotate(-angle, background: :transparent)
.call .call
end
end end
def image_metadata(file) def image_metadata(file)

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,9 +9,10 @@
%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']
%tr - if champ.data['siren_siret'].present?
%th.libelle SIREN/SIRET : %tr
%td= champ.data['siren_siret'] %th.libelle SIREN/SIRET :
%td= champ.data['siren_siret']
%tr %tr
%th.libelle Commune : %th.libelle Commune :
%td= "#{champ.data['nom_commune']} (#{champ.data['code_commune']})" %td= "#{champ.data['nom_commune']} (#{champ.data['code_commune']})"