Add champ carte endpoint

This commit is contained in:
Paul Chavard 2018-10-17 13:02:34 +03:00
parent 383a14ff06
commit 99e1a20d98
8 changed files with 128 additions and 1 deletions

View file

@ -37,6 +37,10 @@ class ApplicationController < ActionController::Base
logged_user.present? logged_user.present?
end end
def logged_user_ids
logged_users.map(&:id)
end
helper_method :logged_in? helper_method :logged_in?
protected protected

View file

@ -0,0 +1,61 @@
class Champs::CarteController < ApplicationController
before_action :authenticate_logged_user!
def show
@selector = ".carte-#{params[:position]}"
if params[:dossier].key?(:champs_attributes)
geo_json = params[:dossier][:champs_attributes][params[:position]][:value]
else
geo_json = params[:dossier][:champs_private_attributes][params[:position]][:value]
end
if params[:champ_id].present?
@champ = Champ
.joins(:dossier)
.where(dossiers: { user_id: logged_user_ids })
.find_by(id: params[:champ_id])
else
@champ = Champs::CarteChamp.new(type_de_champ: TypeDeChamp.new(
type_champ: TypeDeChamp.type_champs.fetch(:carte),
options: {
quartiers_prioritaires: true,
cadastres: true
}
))
end
geo_areas = []
geo_json = JSON.parse(geo_json)
if geo_json.first == ["error", "TooManyPolygons"]
@error = true
else
if @champ.cadastres?
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
geo_areas += cadastres.map do |cadastre|
cadastre[:source] = GeoArea.sources.fetch(:cadastre)
cadastre
end
end
if @champ.quartiers_prioritaires?
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
geo_areas += quartiers_prioritaires.map do |qp|
qp[:source] = GeoArea.sources.fetch(:quartier_prioritaire)
qp
end
end
end
@champ.geo_areas = geo_areas.map do |geo_area|
GeoArea.new(geo_area)
end
@champ.value = geo_json.to_json
if @champ.persisted?
@champ.save
end
end
end

View file

@ -34,4 +34,8 @@ class Champs::CarteChamp < Champ
{ lon: lon, lat: lat, zoom: zoom } { lon: lon, lat: lat, zoom: zoom }
end end
end end
def zones
value.blank? ? [] : JSON.parse(value)
end
end end

View file

@ -0,0 +1,5 @@
<%= render_to_element("#{@selector} + .geo-areas",
partial: 'shared/champs/carte/geo_areas',
locals: { champ: @champ, error: @error }) %>
DS.drawMapData("<%= @selector %>", <%= geo_data(@champ) %>);

View file

@ -0,0 +1,27 @@
- if champ.quartiers_prioritaires?
.areas-title Quartiers prioritaires
.areas
- if error.present?
.error Merci de dessiner une surface plus petite afin de récupérer les quartiers prioritaires.
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.quartiers_prioritaires.blank?
= t('errors.messages.quartiers_prioritaires_empty', count: champ.zones.size)
- else
%ul
- champ.quartiers_prioritaires.each do |qp|
%li #{qp.commune} : #{qp.nom}
- if champ.cadastres?
.areas-title Parcelles cadastrales
.areas
- if error.present?
.error Merci de dessiner une surface plus petite afin de récupérer les parcelles cadastrales.
- elsif champ.value.blank?
Aucune zone tracée
- elsif champ.cadastres.blank?
= t('errors.messages.cadastres_empty', count: champ.zones.size)
- else
%ul
- champ.cadastres.each do |pc|
%li Parcelle n° #{pc.numero} - Feuille #{pc.code_arr} #{pc.section} #{pc.feuille}

View file

@ -1,5 +1,24 @@
{ {
"ignored_warnings": [ "ignored_warnings": [
{
"warning_type": "Cross-Site Scripting",
"warning_code": 2,
"fingerprint": "0d61a1267d264f1e61cc2398a2683703ac60878129dc9515542f246a80ad575b",
"check_name": "CrossSiteScripting",
"message": "Unescaped model attribute",
"file": "app/views/champs/carto/show.js.erb",
"line": 5,
"link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting",
"code": "geo_data((Champ.joins(:dossier).where(:dossiers => ({ :user_id => logged_user_ids })).find_by(:id => params.permit(:champ_id)) or CartoChamp.new))",
"render_path": [{"type":"controller","class":"Champs::CartoController","method":"show","line":48,"file":"app/controllers/champs/carto_controller.rb"}],
"location": {
"type": "template",
"template": "champs/carto/show"
},
"user_input": "Champ.joins(:dossier).where(:dossiers => ({ :user_id => logged_user_ids }))",
"confidence": "Weak",
"note": "Not an injection because logged_user_ids have no user input"
},
{ {
"warning_type": "SQL Injection", "warning_type": "SQL Injection",
"warning_code": 0, "warning_code": 0,
@ -61,6 +80,6 @@
"note": "Not an injection because of `sanitized_column`" "note": "Not an injection because of `sanitized_column`"
} }
], ],
"updated": "2018-10-11 12:09:03 +0200", "updated": "2018-10-16 11:28:34 +0300",
"brakeman_version": "4.3.1" "brakeman_version": "4.3.1"
} }

View file

@ -177,6 +177,12 @@ fr:
connexion: "Erreur lors de la connexion à France Connect." connexion: "Erreur lors de la connexion à France Connect."
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide." extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier." procedure_archived: "Cette démarche en ligne a été fermée, il n'est plus possible de déposer de dossier."
cadastres_empty:
one: "Aucune parcelle cadastrale sur la zone séléctionnée"
other: "Aucune parcelle cadastrale sur les zones séléctionnées"
quartiers_prioritaires_empty:
one: "Aucun quartier prioritaire sur la zone séléctionnée"
other: "Aucun quartier prioritaire sur les zones séléctionnées"
date: date:
abbr_day_names: abbr_day_names:

View file

@ -125,6 +125,7 @@ Rails.application.routes.draw do
namespace :champs do namespace :champs do
get ':position/siret', to: 'siret#show', as: :siret get ':position/siret', to: 'siret#show', as: :siret
get ':position/dossier_link', to: 'dossier_link#show', as: :dossier_link get ':position/dossier_link', to: 'dossier_link#show', as: :dossier_link
post ':position/carte', to: 'carte#show', as: :carte
end end
namespace :commencer do namespace :commencer do