From 941c529b2cb21275b9b4ccd34558f0a220d49cc7 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 2 Oct 2018 13:51:56 +0200 Subject: [PATCH] Remove CGU checkbox fix #2725 --- app/assets/javascripts/old_design/dossiers.js | 25 +-------------- .../new_user/dossiers_controller.rb | 12 ++----- app/controllers/users/dossiers_controller.rb | 32 +++---------------- app/models/dossier.rb | 2 -- app/views/dossiers/add_siret.js.erb | 2 +- .../etapes/etape_2/_entreprise.html.haml | 6 +--- app/views/dossiers/new_siret.js.erb | 2 +- .../new_user/dossiers/identite.html.haml | 7 ---- .../new_user/dossiers_controller_spec.rb | 7 ++-- .../users/dossiers_controller_spec.rb | 18 +---------- spec/features/new_user/brouillon_spec.rb | 1 - .../features/new_user/linked_dropdown_spec.rb | 1 - spec/features/users/complete_demande_spec.rb | 1 - spec/features/users/dossier_creation_spec.rb | 8 ++--- spec/views/dossiers/show.html.haml_spec.rb | 12 ------- 15 files changed, 17 insertions(+), 119 deletions(-) diff --git a/app/assets/javascripts/old_design/dossiers.js b/app/assets/javascripts/old_design/dossiers.js index cdae8b72c..a436152fd 100644 --- a/app/assets/javascripts/old_design/dossiers.js +++ b/app/assets/javascripts/old_design/dossiers.js @@ -1,27 +1,4 @@ -$(document) - .on('turbolinks:load', the_terms) - .on('turbolinks:load', handle_siret_form_errors); - -function the_terms() { - var the_terms = $("#dossier_autorisation_donnees"); - - if (the_terms.length == 0) - return; - - check_value(the_terms); - - the_terms.click(function () { - check_value(the_terms); - }); - - function check_value(the_terms) { - if (the_terms.is(":checked")) { - $("#etape_suivante").removeAttr("disabled"); - } else { - $("#etape_suivante").attr("disabled", "disabled"); - } - } -} +$(document).on('turbolinks:load', handle_siret_form_errors); function error_form_siret(invalid_siret) { setTimeout(function () { diff --git a/app/controllers/new_user/dossiers_controller.rb b/app/controllers/new_user/dossiers_controller.rb index 7093665cf..83fe993a8 100644 --- a/app/controllers/new_user/dossiers_controller.rb +++ b/app/controllers/new_user/dossiers_controller.rb @@ -54,10 +54,8 @@ module NewUser def update_identite @dossier = dossier - individual_updated = @dossier.individual.update(individual_params) - dossier_updated = @dossier.update(dossier_params) - - if individual_updated && dossier_updated + if @dossier.individual.update(individual_params) + @dossier.update!(autorisation_donnees: true) flash.notice = "Identité enregistrée" if @dossier.procedure.module_api_carto.use_api_carto @@ -66,7 +64,7 @@ module NewUser redirect_to brouillon_dossier_path(@dossier) end else - flash.now.alert = @dossier.errors.full_messages + flash.now.alert = @dossier.individual.errors.full_messages render :identite end end @@ -257,10 +255,6 @@ module NewUser params.require(:individual).permit(:gender, :nom, :prenom, :birthdate) end - def dossier_params - params.require(:dossier).permit(:autorisation_donnees) - end - def commentaire_params params.require(:commentaire).permit(:body, :file) end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 9ff440f37..9658eed83 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -132,22 +132,12 @@ class Users::DossiersController < UsersController def update @facade = facade params[:dossier][:id] + @facade.dossier.update!(autorisation_donnees: true) - if individual_errors.any? - flash.alert = individual_errors - redirect_to users_dossier_path(id: @facade.dossier.id) + if @facade.dossier.procedure.module_api_carto.use_api_carto + redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id) else - if !Dossier.find(@facade.dossier.id).update(update_params) - flash.alert = @facade.dossier.errors.full_messages - - return redirect_to users_dossier_path(id: @facade.dossier.id) - end - - if @facade.dossier.procedure.module_api_carto.use_api_carto - redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id) - else - redirect_to brouillon_dossier_path(@facade.dossier) - end + redirect_to brouillon_dossier_path(@facade.dossier) end end @@ -181,20 +171,6 @@ class Users::DossiersController < UsersController render '/dossiers/new_siret', formats: :js, locals: { invalid_siret: siret } end - def update_params - params.require(:dossier).permit(:id, :autorisation_donnees) - end - - def individual_errors - errors = [] - - if update_params[:autorisation_donnees] != "1" - errors << "La validation des conditions d'utilisation est obligatoire" - end - - errors - end - def siret create_params[:siret] end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ef4ad39b6..102a6af7a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -36,8 +36,6 @@ class Dossier < ApplicationRecord accepts_nested_attributes_for :champs accepts_nested_attributes_for :champs_private - validates :autorisation_donnees, acceptance: { message: 'doit être coché' }, allow_nil: false, on: :update - default_scope { where(hidden_at: nil) } scope :state_brouillon, -> { where(state: states.fetch(:brouillon)) } scope :state_not_brouillon, -> { where.not(state: states.fetch(:brouillon)) } diff --git a/app/views/dossiers/add_siret.js.erb b/app/views/dossiers/add_siret.js.erb index 2ec6c4aa5..d0f81b82e 100644 --- a/app/views/dossiers/add_siret.js.erb +++ b/app/views/dossiers/add_siret.js.erb @@ -1,6 +1,6 @@ <% if flash.empty? %> $('.row.etape.etape-2').hide(300, render_new_siret); -$('.row.etape.etape-2').slideDown(400, the_terms); +$('.row.etape.etape-2').slideDown(400); <% else %> error_form_siret('<%= invalid_siret %>'); <% end %> diff --git a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml b/app/views/dossiers/etapes/etape_2/_entreprise.html.haml index 033584354..46af19602 100644 --- a/app/views/dossiers/etapes/etape_2/_entreprise.html.haml +++ b/app/views/dossiers/etapes/etape_2/_entreprise.html.haml @@ -33,8 +33,4 @@ %br = form_for @facade.dossier, url: { controller: '/users/dossiers', action: :update } do |f| = f.hidden_field :id - %label{ style: 'font-weight: normal;' } - = f.check_box :autorisation_donnees - J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles. - %br - = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float: right;', id: 'etape_suivante', disabled: :disabled + = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float: right;', id: 'etape_suivante' diff --git a/app/views/dossiers/new_siret.js.erb b/app/views/dossiers/new_siret.js.erb index 123aaf8db..7e9ac5949 100644 --- a/app/views/dossiers/new_siret.js.erb +++ b/app/views/dossiers/new_siret.js.erb @@ -1,6 +1,6 @@ <% if flash.empty? %> $('.row.etape.etape-2').hide(300, render_new_siret); -$('.row.etape.etape-2').slideDown(400, the_terms); +$('.row.etape.etape-2').slideDown(400); toggle_etape_1(); <% else %> error_form_siret('<%= invalid_siret %>'); diff --git a/app/views/new_user/dossiers/identite.html.haml b/app/views/new_user/dossiers/identite.html.haml index e4a5cc412..e967553d8 100644 --- a/app/views/new_user/dossiers/identite.html.haml +++ b/app/views/new_user/dossiers/identite.html.haml @@ -44,11 +44,4 @@ = f.label :birthdate, class: "required" = f.date_field :birthdate, value: @dossier.individual.birthdate, placeholder: 'format : AAAA-MM-JJ', required: true, class: "small" - = fields_for :dossier, @dossier do |df| - = label_tag do - = df.check_box :autorisation_donnees, required: true - J'accepte - = link_to "les CGU", CGU_URL, target: :blank - %span.mandatory * - = f.submit "Continuer", class: "button large primary expand" diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 352d56995..799c6c40b 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -162,7 +162,7 @@ describe NewUser::DossiersController, type: :controller do let(:procedure) { create(:procedure, :for_individual) } let(:dossier) { create(:dossier, user: user, procedure: procedure) } - subject { post :update_identite, params: { id: dossier.id, individual: individual_params, dossier: dossier_params } } + subject { post :update_identite, params: { id: dossier.id, individual: individual_params } } before do sign_in(user) @@ -171,7 +171,6 @@ describe NewUser::DossiersController, type: :controller do context 'with correct individual and dossier params' do let(:individual_params) { { gender: 'M', nom: 'Mouse', prenom: 'Mickey' } } - let(:dossier_params) { { autorisation_donnees: true } } it do expect(response).to redirect_to(brouillon_dossier_path(dossier)) @@ -189,7 +188,6 @@ describe NewUser::DossiersController, type: :controller do context 'when the identite cannot be updated by the user' do let(:dossier) { create(:dossier, :for_individual, :en_instruction, user: user, procedure: procedure) } let(:individual_params) { { gender: 'M', nom: 'Mouse', prenom: 'Mickey' } } - let(:dossier_params) { { autorisation_donnees: true } } it 'redirects to the dossiers list' do expect(response).to redirect_to(dossiers_path) @@ -199,11 +197,10 @@ describe NewUser::DossiersController, type: :controller do context 'with incorrect individual and dossier params' do let(:individual_params) { { gender: '', nom: '', prenom: '' } } - let(:dossier_params) { { autorisation_donnees: nil } } it do expect(response).not_to have_http_status(:redirect) - expect(flash[:alert]).to include("Civilité doit être rempli", "Nom doit être rempli", "Prénom doit être rempli", "Acceptation des CGU doit être coché") + expect(flash[:alert]).to include("Civilité doit être rempli", "Nom doit être rempli", "Prénom doit être rempli") end end end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 5161cb779..9e9ff9143 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -338,7 +338,7 @@ describe Users::DossiersController, type: :controller do end describe 'PUT #update' do - let(:params) { { id: dossier_id, dossier: { id: dossier_id, autorisation_donnees: autorisation_donnees, individual_attributes: individual_params } } } + let(:params) { { id: dossier_id, dossier: { id: dossier_id, individual_attributes: individual_params } } } let(:individual_params) { { gender: 'M.', nom: 'Julien', prenom: 'Xavier', birthdate: birthdate } } let(:birthdate) { '20/01/1991' } subject { put :update, params: params } @@ -351,8 +351,6 @@ describe Users::DossiersController, type: :controller do end context 'when Checkbox is checked' do - let(:autorisation_donnees) { '1' } - context 'procedure not use api carto' do it 'redirects to demande' do expect(response).to redirect_to(brouillon_dossier_path(dossier)) @@ -375,20 +373,6 @@ describe Users::DossiersController, type: :controller do expect(dossier.autorisation_donnees).to be_truthy end end - - context 'when Checkbox is not checked' do - let(:autorisation_donnees) { '0' } - it 'uses flash alert to display message' do - expect(flash[:alert]).to have_content('La validation des conditions d\'utilisation est obligatoire') - end - - it "doesn't update dossier autorisation_donnees" do - dossier.reload - expect(dossier.autorisation_donnees).to be_falsy - end - - it { is_expected.to redirect_to users_dossier_path(id: dossier.id) } - end end describe 'DELETE #destroy' do diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 30d5ef45e..4ffe73bae 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -150,7 +150,6 @@ feature 'The user' do def fill_individual fill_in('individual_prenom', with: 'prenom') fill_in('individual_nom', with: 'nom') - check 'dossier_autorisation_donnees' click_on 'Continuer' expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb index d4fe7cbae..70b9870e1 100644 --- a/spec/features/new_user/linked_dropdown_spec.rb +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -59,7 +59,6 @@ feature 'linked dropdown lists' do def fill_individual fill_in('individual_prenom', with: 'prenom') fill_in('individual_nom', with: 'nom') - check 'dossier_autorisation_donnees' click_on 'Continuer' expect(page).to have_current_path(brouillon_dossier_path(user_dossier)) end diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index 07e7fdd4c..8277a35ab 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -60,7 +60,6 @@ feature 'user path for dossier creation' do context 'when validating info entreprise recap page' do before do - page.check('dossier_autorisation_donnees') page.find_by_id('etape_suivante').click end scenario 'user is on edition page' do diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 310d43e64..a1fa282c8 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -15,7 +15,6 @@ feature 'As a User I wanna create a dossier' do visit commencer_path(procedure_path: procedure_for_individual.path) fill_in 'individual_nom', with: 'Nom' fill_in 'individual_prenom', with: 'Prenom' - check "dossier_autorisation_donnees" end context "when birthday is asked" do @@ -77,14 +76,13 @@ feature 'As a User I wanna create a dossier' do .to_return(status: 404, body: '') page.find_by_id('dossier-siret').set siret - page.find_by_id('submit-siret').click + click_on 'Valider' wait_for_ajax expect(page).to have_css('#recap-info-entreprise') - check 'dossier_autorisation_donnees' - page.find_by_id('etape_suivante').click + click_on 'Etape suivante' expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s)) - page.find_by_id('etape_suivante').click + click_on 'Etape suivante' expect(page).to have_current_path(brouillon_dossier_path(procedure_with_siret.dossiers.last)) end end diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb index 7c5bfba17..43d75fdd6 100644 --- a/spec/views/dossiers/show.html.haml_spec.rb +++ b/spec/views/dossiers/show.html.haml_spec.rb @@ -10,23 +10,11 @@ describe 'dossiers/show.html.haml', type: :view do render end - it 'have autorisation_donnees check box' do - expect(rendered).to have_css('#dossier_autorisation_donnees') - end - context "sur la page d'information d'un SIRET" do it 'Le formulaire envoie vers /users/dossiers/:dossier_id en #POST' do expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]") end - it "la checkbox d'information est présente" do - expect(rendered).to have_css('#dossier_autorisation_donnees') - end - - it "le texte d'information des droits est correct" do - expect(rendered).to have_content("J'autorise les décideurs publics à vérifier les informations de mon organisation auprès des administrations concernées. Ces informations resteront strictement confidentielles.") - end - it "les informations de l'entreprise sont présents" do expect(rendered).to have_content('Siret') end