Remove unused users/carte_controller
This commit is contained in:
parent
b015d1ca27
commit
37a7e26fc3
9 changed files with 0 additions and 549 deletions
|
@ -1,78 +0,0 @@
|
|||
class Users::CarteController < UsersController
|
||||
before_action only: [:show] do
|
||||
authorized_routes? self.class
|
||||
end
|
||||
|
||||
def show
|
||||
@dossier = current_user_dossier
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for(root_path)
|
||||
end
|
||||
|
||||
def save
|
||||
geo_json = clean_json_latlngs(params[:selection])
|
||||
dossier = current_user_dossier
|
||||
|
||||
dossier.quartier_prioritaires.each(&:destroy)
|
||||
dossier.cadastres.each(&:destroy)
|
||||
|
||||
if geo_json.present?
|
||||
ModuleApiCartoService.save_qp!(dossier, geo_json)
|
||||
ModuleApiCartoService.save_cadastre!(dossier, geo_json)
|
||||
end
|
||||
|
||||
dossier.update!(json_latlngs: geo_json)
|
||||
|
||||
redirect_to brouillon_dossier_path(dossier)
|
||||
end
|
||||
|
||||
def zones
|
||||
@dossier = current_user_dossier
|
||||
@data = {}
|
||||
|
||||
geo_json = JSON.parse(params.fetch(:selection, '[]'))
|
||||
|
||||
if geo_json.first == ["error", "TooManyPolygons"]
|
||||
@error = true
|
||||
else
|
||||
if @dossier.procedure.module_api_carto.quartiers_prioritaires?
|
||||
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
|
||||
@dossier.quartier_prioritaires.build(quartiers_prioritaires)
|
||||
@data[:quartiersPrioritaires] = quartiers_prioritaires
|
||||
end
|
||||
|
||||
if @dossier.procedure.module_api_carto.cadastre?
|
||||
cadastres = ModuleApiCartoService.generate_cadastre(geo_json)
|
||||
@dossier.cadastres.build(cadastres)
|
||||
@data[:cadastres] = cadastres
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.route_authorization
|
||||
{
|
||||
states: [Dossier.states.fetch(:brouillon), Dossier.states.fetch(:en_construction)],
|
||||
api_carto: true
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clean_json_latlngs(json_latlngs)
|
||||
# a polygon must contain at least 4 points
|
||||
# https://tools.ietf.org/html/rfc7946#section-3.1.6
|
||||
if json_latlngs.present?
|
||||
multipolygone = JSON.parse(json_latlngs)
|
||||
if multipolygone.first == ["error", "TooManyPolygons"]
|
||||
[].to_json
|
||||
else
|
||||
multipolygone.reject! { |polygone| polygone.count < 4 }
|
||||
if multipolygone.present?
|
||||
multipolygone.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
class UsersController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def current_user_dossier(dossier_id = nil)
|
||||
dossier_id ||= params[:dossier_id] || params[:id]
|
||||
|
||||
dossier = Dossier.find(dossier_id)
|
||||
|
||||
if !current_user.owns_or_invite?(dossier)
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
dossier
|
||||
end
|
||||
|
||||
def authorized_routes?(controller)
|
||||
if !UserRoutesAuthorizationService.authorized_route?(controller, current_user_dossier)
|
||||
redirect_to_root_path 'Le statut de votre dossier n\'autorise pas cette URL'
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to_root_path 'Vous n’avez pas accès à ce dossier.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def redirect_to_root_path(message)
|
||||
flash.alert = message
|
||||
redirect_to url_for root_path
|
||||
end
|
||||
end
|
|
@ -1,28 +1,4 @@
|
|||
class ModuleApiCartoService
|
||||
def self.save_qp!(dossier, json_latlngs)
|
||||
if dossier.procedure.module_api_carto.quartiers_prioritaires?
|
||||
qp_list = generate_qp(JSON.parse(json_latlngs))
|
||||
|
||||
qp_list.each do |qp|
|
||||
qp[:dossier_id] = dossier.id
|
||||
qp[:geometry] = qp[:geometry].to_json
|
||||
QuartierPrioritaire.create(qp)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.save_cadastre!(dossier, json_latlngs)
|
||||
if dossier.procedure.module_api_carto.cadastre?
|
||||
cadastre_list = generate_cadastre JSON.parse(json_latlngs)
|
||||
|
||||
cadastre_list.each do |cadastre|
|
||||
cadastre[:dossier_id] = dossier.id
|
||||
cadastre[:geometry] = cadastre[:geometry].to_json
|
||||
Cadastre.create(cadastre)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_qp(coordinates)
|
||||
coordinates.flat_map do |coordinate|
|
||||
ApiCarto::QuartiersPrioritairesAdapter.new(
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
class UserRoutesAuthorizationService
|
||||
def self.authorized_route?(controller, dossier)
|
||||
auth = controller.route_authorization
|
||||
|
||||
auth[:states].include?(dossier.state) &&
|
||||
(auth[:api_carto].nil? ? true : auth[:api_carto] == dossier.use_legacy_carto?)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue