- QP not research if module_api_carto have not activated quartiers_prioritaires

- Carte page is not accessible if module_api_cart have not activated use_api_carto
This commit is contained in:
Xavier J 2015-12-08 11:18:49 +01:00
parent 0e3bec7f9f
commit 11596ade65
9 changed files with 95 additions and 34 deletions

View file

@ -17,10 +17,7 @@ function initCarto() {
layers: [OSM] layers: [OSM]
}); });
freeDraw = new L.FreeDraw({ freeDraw = new L.FreeDraw();
//mode: L.FreeDraw.MODES.CREATE
});
map.addLayer(freeDraw); map.addLayer(freeDraw);
if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') { if ($("#json_latlngs").val() != '' && $("#json_latlngs").val() != '[]') {
@ -35,13 +32,16 @@ function initCarto() {
add_event_freeDraw(); add_event_freeDraw();
if (qp_active())
display_qp(JSON.parse($("#quartier_prioritaires").val())); display_qp(JSON.parse($("#quartier_prioritaires").val()));
} }
function add_event_freeDraw() { function add_event_freeDraw() {
freeDraw.on('markers', function (e) { freeDraw.on('markers', function (e) {
$("#json_latlngs").val(JSON.stringify(e.latLngs)); $("#json_latlngs").val(JSON.stringify(e.latLngs));
display_qp(get_qp(e.latLngs)['quartier_prioritaires']);
if (qp_active())
display_qp(get_qp(e.latLngs));
}); });
$("#new").on('click', function (e) { $("#new").on('click', function (e) {
@ -71,7 +71,14 @@ function get_position() {
return position; return position;
} }
function qp_active() {
return $("#map.qp").length > 0
}
function get_qp(coordinates) { function get_qp(coordinates) {
if (!qp_active())
return;
var qp; var qp;
$.ajax({ $.ajax({
@ -84,10 +91,13 @@ function get_qp(coordinates) {
qp = data qp = data
}); });
return qp; return qp['quartier_prioritaires'];
} }
function display_qp(qp_list) { function display_qp(qp_list) {
if (!qp_active())
return;
qp_array = jsObject_to_array(qp_list); qp_array = jsObject_to_array(qp_list);
$("#qp_list ul").html(''); $("#qp_list ul").html('');

View file

@ -3,6 +3,12 @@ class Users::CarteController < UsersController
def show def show
@dossier = current_user_dossier @dossier = current_user_dossier
unless @dossier.procedure.module_api_carto.use_api_carto
flash.alert = t('errors.messages.dossier_map_not_activated')
redirect_to url_for(root_path)
end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found') flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(root_path) redirect_to url_for(root_path)

View file

@ -23,5 +23,8 @@
Quartiers Prioritaires Quartiers Prioritaires
%li %li
%label %label
= ff.check_box :cadastre = ff.check_box :cadastre, disabled: :disabled
Cadastre Cadastre
%i
%strong
(bientôt disponible)

View file

@ -12,10 +12,13 @@
%br %br
%br %br
.row .row
- if @dossier.procedure.module_api_carto.quartiers_prioritaires
#map.qp #map.qp
#qp_list #qp_list
%h3 Quartiers prioritaites %h3 Quartiers prioritaites
%ul %ul
-else
#map
= form_tag(url_for({controller: :carte, action: :save, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do = form_tag(url_for({controller: :carte, action: :save, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%br %br

View file

@ -91,6 +91,7 @@ fr:
one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :" one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :"
other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :" other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :"
dossier_not_found: "Le dossier n'existe pas ou vous n'y avez pas accès." dossier_not_found: "Le dossier n'existe pas ou vous n'y avez pas accès."
dossier_map_not_activated: "Le dossier n'a pas accès à la cartographie."
invalid_siret: "Le siret est incorrect" invalid_siret: "Le siret est incorrect"
france_connect: france_connect:
connexion: "Erreur lors de la connexion à France Connect." connexion: "Erreur lors de la connexion à France Connect."

View file

@ -3,7 +3,10 @@ require 'spec_helper'
RSpec.describe Users::CarteController, type: :controller do RSpec.describe Users::CarteController, type: :controller do
let(:bad_adresse) { 'babouba' } let(:bad_adresse) { 'babouba' }
let(:dossier) { create(:dossier, :with_user, :with_procedure) } let(:procedure) { create(:procedure, :with_api_carto) }
let(:dossier) { create(:dossier, :with_user, procedure: procedure) }
let(:dossier_with_no_carto) { create(:dossier, :with_user, :with_procedure) }
let!(:entreprise) { create(:entreprise, dossier: dossier) } let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) } let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:bad_dossier_id) { Dossier.count + 1000 } let(:bad_dossier_id) { Dossier.count + 1000 }
@ -25,15 +28,24 @@ RSpec.describe Users::CarteController, type: :controller do
end end
end end
it 'returns http success' do it 'returns http success if carto is activated' do
get :show, dossier_id: dossier.id get :show, dossier_id: dossier.id
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it 'redirection vers la liste des dossiers du user si dossier ID n\'existe pas' do context 'when procedure not have activate api carto' do
it 'redirection on user dossier list' do
get :show, dossier_id: dossier_with_no_carto.id
expect(response).to redirect_to(root_path)
end
end
context 'when dossier id not exist' do
it 'redirection on user dossier list' do
get :show, dossier_id: bad_dossier_id get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to(root_path) expect(response).to redirect_to(root_path)
end end
end
it_behaves_like "not owner of dossier", :show it_behaves_like "not owner of dossier", :show
end end

View file

@ -8,7 +8,7 @@ FactoryGirl.define do
use_api_carto true use_api_carto true
end end
trait :with_qp do trait :with_quartiers_prioritaires do
use_api_carto true use_api_carto true
quartiers_prioritaires true quartiers_prioritaires true
end end

View file

@ -5,9 +5,11 @@ FactoryGirl.define do
description "Demande de subvention à l'intention des associations" description "Demande de subvention à l'intention des associations"
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|
if procedure.module_api_carto.nil?
module_api_carto = create(:module_api_carto) module_api_carto = create(:module_api_carto)
procedure.module_api_carto = module_api_carto procedure.module_api_carto = module_api_carto
end end
end
trait :with_api_carto do trait :with_api_carto do
after(:build) do |procedure, _evaluator| after(:build) do |procedure, _evaluator|

View file

@ -2,7 +2,9 @@ require 'spec_helper'
feature 'drawing a zone with freedraw' do feature 'drawing a zone with freedraw' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:dossier) { create(:dossier, :with_procedure, :with_entreprise, user: user) } let(:module_api_carto) { create(:module_api_carto, :with_api_carto) }
let(:procedure) { create(:procedure, module_api_carto: module_api_carto) }
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, user: user) }
context 'when user is not logged in' do context 'when user is not logged in' do
before do before do
@ -22,20 +24,41 @@ feature 'drawing a zone with freedraw' do
end end
end end
context 'when procedure have api carto activated' do
scenario 'he is redirected to carte page' do scenario 'he is redirected to carte page' do
expect(page).to have_css('.content #map') expect(page).to have_css('.content #map')
end end
end
context 'when procedure does not have api carto activated' do
let(:module_api_carto) { create(:module_api_carto) }
scenario 'he is redirect to user dossiers index' do
expect(page).to have_css('#users_index')
end
scenario 'alert message is present' do
expect(page).to have_content('Le dossier n\'a pas accès à la cartographie')
end
end
context 'when draw a zone on #map', js: true do context 'when draw a zone on #map', js: true do
context 'when module quartiers prioritaires is activated' do
let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) }
before do before do
allow_any_instance_of(Users::CarteController). allow_any_instance_of(Users::CarteController).
to receive(:generate_qp). to receive(:generate_qp).
and_return({"QPCODE1234" => { :code => "QPCODE1234", :nom => "Quartier de test", :commune => "Paris", :geometry => { :type=>"MultiPolygon", :coordinates=>[[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] }}}) and_return({"QPCODE1234" => {:code => "QPCODE1234", :nom => "Quartier de test", :commune => "Paris", :geometry => {:type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]]}}})
page.execute_script('freeDraw.fire("markers", {latLngs: []});') page.execute_script('freeDraw.fire("markers", {latLngs: []});')
wait_for_ajax wait_for_ajax
end end
scenario 'div #map .qp is present' do
expect(page).to have_css('.content #map.qp')
end
scenario 'QP name is present on page' do scenario 'QP name is present on page' do
expect(page).to have_content('Quartier de test') expect(page).to have_content('Quartier de test')
end end
@ -46,4 +69,5 @@ feature 'drawing a zone with freedraw' do
end end
end end
end end
end
end end