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

View file

@ -3,6 +3,12 @@ class Users::CarteController < UsersController
def show
@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
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(root_path)

View file

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

View file

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

View file

@ -91,6 +91,7 @@ fr:
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) :"
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"
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
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!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:bad_dossier_id) { Dossier.count + 1000 }
@ -25,15 +28,24 @@ RSpec.describe Users::CarteController, type: :controller do
end
end
it 'returns http success' do
it 'returns http success if carto is activated' do
get :show, dossier_id: dossier.id
expect(response).to have_http_status(:success)
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
expect(response).to redirect_to(root_path)
end
end
it_behaves_like "not owner of dossier", :show
end

View file

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

View file

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

View file

@ -2,7 +2,9 @@ require 'spec_helper'
feature 'drawing a zone with freedraw' do
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
before do
@ -22,11 +24,28 @@ feature 'drawing a zone with freedraw' do
end
end
context 'when procedure have api carto activated' do
scenario 'he is redirected to carte page' do
expect(page).to have_css('.content #map')
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 module quartiers prioritaires is activated' do
let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) }
before do
allow_any_instance_of(Users::CarteController).
to receive(:generate_qp).
@ -36,6 +55,10 @@ feature 'drawing a zone with freedraw' do
wait_for_ajax
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
expect(page).to have_content('Quartier de test')
end
@ -47,3 +70,4 @@ feature 'drawing a zone with freedraw' do
end
end
end
end